Raspberry Pi Pico 2
The Raspberry Pi Pico 2 is Raspberry Pi's successor to the Raspberry Pi Pico board, based on their new RP2350 processor:
The RP2350 has the following features:
-
Dual ARM Cortex-M33 or dual RISC-V Hazard3 processors @ 150MHz
-
520 KB on-chip SRAM; 4 MB on-board QSPI flash
-
26 multi-purpose GPIO pins, including 4 that can be used for ADC
-
2 × UARTs, 2 × SPI controllers, and 2 × I2C controllers
-
24 × PWM channels
-
1 × USB 1.1 controller and PHY, with host and device support
-
12 × PIO state machines
The Raspberry Pi Pico 2 provides over twice as much workspace as the RP2040-based Raspberry Pi Pico, and is significantly faster. You can run uLisp on either the ARM or RISC-V core, and it's therefore possible to run either ARM or RISC-V machine code. For more information see Raspberry Pi Pico 2.
The Raspberry Pi Pico 2 is available from several suppliers; for example, in the UK from The Pi Hut: Raspberry Pi Pico 2.
Introduction
Saving the workspace
The Raspberry Pi Pico 2 uses the LittleFS flash filesystem supported by the Raspberry Pi Pico/RP2040/2350 core to allow you to save the entire workspace using save-image.
ARM and RISC-V assemblers
You can run uLisp on either the ARM or RISC-V core of the RP2350, and it's therefore possible to run either ARM or RISC-V machine code using the defcode function built in to uLisp.
There are both ARM and RISC-V assemblers that you can use to generate machine code from assembler programs; these are written in Lisp to make it easy to extend them or add new instructions. For more information see ARM assembler overview or RISC-V assembler overview.
Installing uLisp from the Arduino IDE
Install the Raspberry Pi RP2040/RP2350 core
- Add the following URL to the Additional Boards Manager URLs list in the Arduino IDE Preferences dialog box:
https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
- In the Arduino IDE search for the Raspberry Pi Pico/RP2040/RP2350 core in Boards Manager and install it.
To use the RISC-V core you need version 4.1.0 or later. I used 4.1.1.
- Select Raspberry Pi RP2040 from the Board menu, and Raspberry Pi Pico 2 from the submenu.
- Set Flash Size to the option that gives FS: 3MB. On the Raspberry Pi Pico 2 this is 4MB (Sketch: 1MB, FS: 3MB).
This allocates enough space for use by LittleFS to save the entire workspace with save-image.
- Set CPU Architecture to ARM or RISC-V to choose which core you want to use.
You can leave all the other options at their defaults.
Upload uLisp
- Download the latest ARM version of uLisp from the Download uLisp page.
- Select the board's USB port from the Port menu
- Upload uLisp to the board.
Using uLisp
- You may need to select the board's USB port from the Port menu again.
- Select Serial Monitor from the Tools menu.
- Enter Lisp commands.
Putting the board into upload mode
If the upload fails you may need to put the board into upload mode first.
- Unplug the USB port.
- Press and hold the BOOTSEL button.
- Plug in the USB port.
- Release the BOOTSEL button.
Error on save-image
If when you call save-image you get the error;
Error: 'save-image' problem saving to LittleFS
the most likely explanation is that you didn't set the Flash Size option to the appropriate value to reserve memory for LittleFS before uploading uLisp.
P2350-E9 Errata
A bug has been reported in the first A2 batch of RP2350 chips that means that in some cases when an input pin is being driven by a weak (high impedance) input, it may not read properly. There are workarounds for most practical applications; see the RP2350-E9 Errata for more details.
Pinout
The following diagram shows the pinout of the peripherals available from uLisp with the Raspberry Pi Pico 2:
LEDs
The Raspberry Pi Pico 2 has a green LED connected to the digital pin 25 which you can flash with the following program:
(defun blink (&optional x) (pinmode :led-builtin t) (digitalwrite :led-builtin x)
(delay 1000) (blink (not x)))
Run it by typing:
(blink)
All pins can also be used for analogue (PWM) output, so you can pulsate the LED slowly on and off with the program:
(defun pulse () (let (down) (loop (dotimes (x 256) (delay 5) (analogwrite :led-builtin (if down (- 255 x) x)))
(setq down (not down)))))
Run it by typing:
(pulse)
Exit from either program by entering ~.
Analogue inputs
The Raspberry Pi Pico 2 has three analogue inputs which you can access on digital pins 26, 27, and 28. They have 12-bit precision.
Analogue outputs
You can generate an analogue output using PWM on any of the digital pins 0 to 28. By default the precision is 8 bits, but you can change it to a value from 4 to 16 bits by calling, for example:
(analogwriteresolution 16)
Playing notes
You can use the note function to play tunes on any pin. For example, the following function scale plays the scale of C on the specified pin:
(defun scale (pin) (mapc (lambda (n) (note pin n 4) (delay 500)) '(0 2 4 5 7 9 11 12)) (note))
For example, connect a piezo speaker between digital pin 10 and GND, and evaluate:
(scale 10)
Serial
The Raspberry Pi Pico 2 has two serial ports: Serial1 on pin numbers 0 (TX) and 1 (RX), and Serial2 on pin numbers 8 (TX) and 9 (RX).
SPI
The Raspberry Pi Pico 2 has two SPI ports: SPI0 on pin numbers 16 (MISO), 19 (MOSI), 18 (SCK) and 17 (SS), and SPI1 on pin numbers 12 (MISO), 15 (MOSI), 14 (SCK) and 13 (SS).
I2C
The Raspberry Pi Pico 2 has two I2C ports: Wire0 on pin numbers 4 (SDA) and 5 (SCL), and Wire1 on pin numbers 26 (SDA) and 27 (SCL).