Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raspberry Pico 2 porting #14831

Merged
merged 9 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
README
======

This directory contains the porting of NuttX to the Raspberry Pi Pico 2.
See https://www.raspberrypi.org/products/raspberry-pi-pico-2/ for information
about Raspberry Pi Pico 2.

NuttX supports the following RP2350 capabilities:
- UART (console port)
- GPIO 0 (UART0 TX) and GPIO 1 (UART0 RX) are used for the console.
- ADC
- USB device
- CDC/ACM serial device can be used for the console.
- Flash ROM Boot
- SRAM Boot

Installation
============

1. Configure and build NuttX

$ 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:nsh
$ make -j

4. Connect Raspberry Pi Pico 2 board to the 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.)

5. To access the console, GPIO 0 and 1 pins must be connected to the
device such as a 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.

Defconfigs
==========

- nsh
Minimum configuration with NuttShell

- usbnsh
USB CDC/ACM serial console with NuttShell
137 changes: 137 additions & 0 deletions Documentation/platforms/arm/rp23xx/boards/raspberrypi-pico-2/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
===============================
Raspberry Pi Pico 2
===============================

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 ARM Cortex M33 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 RP2350 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 RP2350.

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
7 GPIO5
8 Ground
9 GPIO6
10 GPIO7
11 GPIO8
12 GPIO9
13 Ground
14 GPIO10
15 GPIO11
16 GPIO12
17 GPIO13
18 Ground
19 GPIO14
20 GPIO15
21 GPIO16
22 GPIO17
23 Ground
24 GPIO18
25 GPIO19
26 GPIO20
27 GPIO21
28 Ground
29 GPIO22
30 Run
31 GPIO26 ADC0
32 GPIO27 ADC1
33 AGND Analog Ground
34 GPIO28 ADC2
35 ADC_VREF
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 RP2350 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.

Configurations
==============

nsh
---

Basic NuttShell configuration (console enabled in UART0, at 115200 bps).


README.txt
==========

.. include:: README.txt
:literal:
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
207 changes: 207 additions & 0 deletions Documentation/platforms/arm/rp23xx/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
==================
RaspberryPi 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.

For now, only the ARM Cortex-M33 is supported.

This port is experimental and still a work in progress. Use with caution.

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 Untested
SPI Master Working
SPI Slave Untested
DMAC Untested
PWM Untested
USB Experimental usbnsh configuration is somewhat working with some data corruption
PIO Working
IRQs Working
DMA Untested
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

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: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/*/*
Loading
Loading