arch/risc-v/rp23xx-riscv: Add rp23xx RISC-V cores support (Hazard3)

Chip name   : rp23xx-rv
Board name  : raspberrypi-pico-2-rv
Arch        : risc-v

Changes from ARM rp23xx impl

- Linker script update
- ASM head start
- Update chip start
- New Hazard3 registers
- Remove rp23xx chip hw spinlocks/testset
- New irq handling (external IRQ interrupt Hazard3)
- New timerisr based on RISC-V std MTIME and alarm arch
- No SMP yet
- Tickless option
- Double size for idle, irq and main stacks
- Board reset via watchdog trigger

Signed-off-by: Serg Podtynnyi <serg@podtynnyi.com>
This commit is contained in:
Serg Podtynnyi
2025-05-22 02:38:16 +07:00
committed by Xiang Xiao
parent d218334baa
commit 2e7f75f6e0
154 changed files with 41402 additions and 2 deletions
@@ -0,0 +1,230 @@
===============================
Raspberry Pi Pico 2 RISC-V
===============================
.. tags:: chip:rp2350
The `Raspberry Pi Pico 2 <https://www.raspberrypi.com/products/raspberry-pi-pico-2/>`_ is a general purpose board supplied by
the Raspberry Pi Foundation.
.. figure:: pico-2.png
:align: center
Features
========
* RP2350 microcontroller chip
* Dual-core Hazard3 RISC-V processor, flexible clock running up to 150 MHz
* 520kB of SRAM, and 4MB of on-board Flash memory
* Castellated module allows soldering direct to carrier boards
* USB 1.1 Host and Device support
* Low-power sleep and dormant modes
* Drag & drop programming using mass storage over USB
* 26 multi-function GPIO pins
* 2× SPI, 2× I2C, 2× UART, 3× 12-bit ADC, 16× controllable PWM channels
* Accurate clock and timer on-chip
* Temperature sensor
* Accelerated floating point libraries on-chip
* 12 × Programmable IO (PIO) state machines for custom peripheral support
Serial Console
==============
By default a serial console appears on pins 1 (TX GPIO0) and pin 2
(RX GPIO1). This console runs a 115200-8N1.
The board can be configured to use the USB connection as the serial console.
See the `usbnsh` configuration.
Buttons and LEDs
================
User LED controlled by GPIO25 and is configured as autoled by default.
A BOOTSEL button, which if held down when power is first
applied to the board, will cause the Pico 2 to boot into programming
mode and appear as a storage device to the computer connected via USB.
Saving a .UF2 file to this device will replace the Flash ROM contents
on the Pico 2.
Pin Mapping
===========
Pads numbered anticlockwise from USB connector.
===== ========== ==========
Pad Signal Notes
===== ========== ==========
1 GPIO0 Default TX for UART0 serial console
2 GPIO1 Default RX for UART1 serial console
3 Ground
4 GPIO2
5 GPIO3
6 GPIO4 Default SDA for I2C0
7 GPIO5 Default SCL for I2C0
8 Ground
9 GPIO6 Default SDA for I2C1
10 GPIO7 Default SCL for I2C1
11 GPIO8 Default RX for SPI1
12 GPIO9 Default CSn for SPI1
13 Ground
14 GPIO10 Default SCK for SPI1
15 GPIO11 Default TX for SPI1
16 GPIO12
17 GPIO13
18 Ground
19 GPIO14
20 GPIO15
21 GPIO16 Default RX for SPI0
22 GPIO17 Default CSn for SPI0
23 Ground
24 GPIO18 Default SCK for SPI0
25 GPIO19 Default TX for SPI0
26 GPIO20 Default TX for UART1 serial console
27 GPIO21 Default RX for UART1 serial console
28 Ground
29 GPIO22
30 Run
31 GPIO26 ADC0
32 GPIO27 ADC1
33 AGND Analog Ground
34 GPIO28 ADC2
35 ADC_VREF Analog reference voltage
36 3V3 Power output to peripherals
37 3V3_EN Pull to ground to turn off.
38 Ground
39 VSYS +5V Supply to board
40 VBUS Connected to USB +5V
===== ========== ==========
Other Pico 2 Pins
=================
GPIO23 Output - Power supply control.
GPIO24 Input - High if USB port or Pad 40 supplying power.
GPIO25 Output - On board LED.
ADC3 Input - Analog voltage equal to one third of VSys voltage.
Separate pins for the Serial Debug Port (SDB) are available
Power Supply
============
The Raspberry Pi Pico 2 can be powered via the USB connector,
or by supplying +5V to pin 39. The board had a diode that prevents
power from pin 39 from flowing back to the USB socket, although
the socket can be power via pin 30.
The Raspberry Pi Pico chip run on 3.3 volts. This is supplied
by an onboard voltage regulator. This regulator can be disabled
by pulling pin 37 to ground.
The regulator can run in two modes. By default the regulator runs
in PFM mode which provides the best efficiency, but may be
switched to PWM mode for improved ripple by outputting a one
on GPIO23.
Supported Capabilities
======================
NuttX supports the following Pico 2 capabilities:
* UART (console port)
* GPIO 0 (UART0 TX) and GPIO 1 (UART0 RX) are used for the console.
* I2C
* SPI (master only)
* DMAC
* PWM
* ADC
* Watchdog
* USB device
* MSC, CDC/ACM serial and these composite device are supported.
* CDC/ACM serial device can be used for the console.
* PIO (RP2350 Programmable I/O)
* Flash ROM Boot
* SRAM Boot
* If Pico SDK is available, nuttx.uf2 file which can be used in BOOTSEL mode will be created.
* Persistent flash filesystem in unused flash ROM
There is currently no direct user mode access to these RP2350 hardware features:
* SPI Slave Mode
* SSI
* RTC
* Timers
RICS-V toolchain
================
Download and install RISC-V compatible toolchain
with arch `rv32imac` and `ilp32` abi.
https://xpack-dev-tools.github.io/riscv-none-elf-gcc-xpack/
Installation
============
1. Download Raspberry Pi Pico SDK
.. code-block:: console
$ git clone -b 2.1.1 https://github.com/raspberrypi/pico-sdk.git
2. Download and install picotool
Instructions can be found here: https://github.com/raspberrypi/picotool
If you are on Arch Linux, you can install the picotool through the AUR:
.. code-block:: console
$ yay -S picotool
3. Set PICO_SDK_PATH environment variable
.. code-block:: console
$ export PICO_SDK_PATH=<absolute_path_to_pico-sdk_directory>
4. Configure and build NuttX
.. code-block:: console
$ git clone https://github.com/apache/nuttx.git nuttx
$ git clone https://github.com/apache/nuttx-apps.git apps
$ cd nuttx
$ make distclean
$ ./tools/configure.sh raspberrypi-pico-2-rv:nsh
$ make V=1
5. Connect Raspberry Pi Pico 2 board to USB port while pressing BOOTSEL.
The board will be detected as USB Mass Storage Device.
Then copy "nuttx.uf2" into the device.
(Same manner as the standard Pico SDK applications installation.)
6. To access the console, GPIO 0 and 1 pins must be connected to the
device such as USB-serial converter.
`usbnsh` configuration provides the console access by USB CDC/ACM serial
device. The console is available by using a terminal software on the USB
host.
Configurations
==============
nsh
---
Basic NuttShell configuration (console enabled in UART0, at 115200 bps).
usbnsh
---
Basic NuttShell configuration (console enabled via USB CDC/ACM).
Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

@@ -0,0 +1,219 @@
=========================
RaspberryPi rp2350 RISC-V
=========================
.. tags:: chip:rp2350
The rp2350 is a dual core chip produced by the RaspberryPi Foundation that
is based on ARM Cortex-M33 or the Hazard3 RISC-V.
ARM Cortex-M33 and Hazard3 RISC-V cores are supported.
This is RISC-V version of the chip configuration.
This port is experimental and still a work in progress. Use with caution.
SMP (dual core configuration not supported yet)
Peripheral Support
==================
Most drivers were copied from the rp2040 port with some modifications.
The following list indicates peripherals currently supported in NuttX:
============== ============ =====
Peripheral Status Notes
============== ============ =====
GPIO Working See Supported Boards documentation for available pins.
UART Working GPIO 0 (UART0 TX) and GPIO 1 (UART0 RX) are used for the console.
I2C Working
SPI Master Working
SPI Slave Untested
DMAC Working
PWM Working
USB Working
PIO Working
IRQs Working
WDOG Working
DMA Working
FPU/DSP INOP Available in ARM configuration of the chip
Clock Output Untested
Flash ROM Boot Working Does not require boot2 from pico-sdk
If picotool is available a nuttx.uf2 file will be created
SRAM Boot Working Requires external SWD debugger
PSRAM Working Three modes of heap allocation described below
============== ============ =====
Installation
============
1. Download and build picotool, make it available in the PATH::
git clone https://github.com/raspberrypi/picotool.git picotool
cd picotool
mkdir build
cd build
cmake ..
make
cp picotool ~/local/bin # somewhere in your PATH
2. Download NuttX and the companion applications. These must both be
contained in the same directory::
git clone https://github.com/apache/nuttx.git nuttx
git clone https://github.com/apache/nuttx-apps.git apps
3. Download and install RISC-V compatible toolchain
with arch `rv32imac` and `ilp32` abi.
https://xpack-dev-tools.github.io/riscv-none-elf-gcc-xpack/
Building NuttX
==============
1. Change to NuttX directory::
cd nuttx
2. Select a configuration. The available configurations
can be listed with the command::
./tools/configure.sh -L
3. Load the selected configuration.::
make distclean
./tools/configure.sh raspberrypi-pico-2-rv:usbnsh
4. Modify the configuration as needed (optional)::
make menuconfig
5. Build NuttX::
make
Flash boot
==========
By default, the system is built to build and run from the flash
using XIP. By using the default `BOOT_RUNFROMFLASH` configuration,
the full image is run from the flash making most of the internal
SRAM available for the OS and applications, however the execution
is slower. The cache can speed up, but you might want set your
time critical functions to be placed in the SRAM (copied from
the flash on startup).
It is also possible to execute from SRAM, which reduces the
available SRAM to the OS and applications, however it is very
useful when debugging as erasing and rewriting the flash on
every build is tedious and slow. This option is enabled with
`BOOT_RUNFROMISRAM` and requires `openocd`` and/or `gdb`.
There is a third option which is to write the firmware on the
flash and it gets copied to the SRAM. This is enabled with
`CONFIG_BOOT_COPYTORAM` and might be useful for time critical
applications, on the expense of reduced usable internal SRAM
memory.
PSRAM
=====
Some boards like the `pimoroni-pico-2-plus` have a PSRAM
which greatly increases the available memory for applications.
The PSRAM is very slow compared to the internal SRAM,
so depending on the application, different configuration might
be necessary.
To use the PSRAM, enable the `RP23XX_PSRAM` and select the GPIO
pin used as CS1n with `RP23XX_PSRAM_CS1_GPIO`. See the RP2350
datasheet for more information.
The port offers three options for configuring the heaps to use
the external PSRAM, described below. More custom configurations
can be used with custom board initialization functions.
Use PSRAM and SRAM as a single main heap
----------------------------------------
This option is selected with `RP23XX_PSRAM_HEAP_SINGLE` and
requires `MM_REGIONS > 1`, as the PSRAM memory region will
be added to the heap. It is also necessary to disable
`MM_KERNEL_HEAP`, as there will only be a single heap.
This is the simplest configuration because it will unify the
memories into a single main heap. This way you can see the `free`
command output the total amount of usable RAM in the heap.
However, there are some unpredictable performance issues because
there is no control of where the memory is allocated when issuing
`malloc(3)` and `free(3)`. For this reason, you might want to
consider the other options.
Use PSRAM as user heap, SRAM as kernel heap
-------------------------------------------
This option is selected with `RP23XX_PSRAM_HEAP_USER` and
requires `MM_KERNEL_HEAP` to be set.
The external PSRAM is allocated to the default heap, while
the internal SRAM will be used for the kernel heap. This
configuration is useful because it allows drivers to
use the SRAM and behave much faster than if they used
memory on the PSRAM. While user applications can take
the bull benefit of the larger slower heap on the PSRAM.
Use PSRAM as a separate heap
----------------------------
This option is selected with `RP23XX_PSRAM_HEAP_SEPARATE` and
requires `ARCH_HAVE_EXTRA_HEAPS` to be set.
The internal SRAM is used as the main heap for kernel and
applications, as if there was no PSRAM configured. The
external PSRAM is configured as a separate user heap called
`psram` and can be used through the global variable
`g_psramheap` after including `rp23xx_heaps.h`
Programming
============
Programming using BOOTSEL
-------------------------
Connect board to USB port while holding BOOTSEL.
The board will be detected as USB Mass Storage Device.
Then copy "nuttx.uf2" into the device.
(Same manner as the standard Pico SDK applications installation.)
Programming with picotool
-------------------------
You can use picotool to load the elf (or the uf2)::
picotool load nuttx -t elf
Programming using SWD debugger
------------------------------
Most boards provide a serial (SWD) debug port.
The "nuttx" ELF file can be uploaded with an appropriate SDB programmer
module and companion software (openocd and gdb)
Running NuttX
=============
Most builds provide access to the console via UART0. To access this
GPIO 0 and 1 pins must be connected to the device such as USB-serial converter.
The `usbnsh` configuration provides the console access by USB CDC/ACM serial
device. The console is available by using a terminal software on the USB host.
Supported Boards
================
.. toctree::
:glob:
:maxdepth: 1
boards/*/*