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

Add support for Raspberry Pi Pico 2 #77368

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

ajf58
Copy link
Contributor

@ajf58 ajf58 commented Aug 21, 2024

This is a PR to add support for the Raspberry Pi Pico 2 board, and the RP2350 SoC. See also the discussion at #77329

This should not be merged currently, as it includes changes that will break the clock control driver for the RP2040.

Dependencies

#76986

cc: @yonsch @soburi

@zephyrbot
Copy link
Collaborator

The following west manifest projects have been modified in this Pull Request:

Name Old Revision New Revision Diff
hal_rpi_pico zephyrproject-rtos/hal_rpi_pico@fba7162 (zephyr) zephyrproject-rtos/hal_rpi_pico#6 zephyrproject-rtos/hal_rpi_pico#6/files

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@zephyrbot zephyrbot added manifest manifest-hal_rpi_pico DNM This PR should not be merged (Do Not Merge) labels Aug 21, 2024
@soburi
Copy link
Member

soburi commented Aug 22, 2024

@ajf58
First, I've listed some points that caught my attention at a glance.
I haven't been able to check it thoroughly yet, so I'll look at it a bit more.

soc/raspberrypi/rp2xxx/Kconfig Outdated Show resolved Hide resolved
soc/raspberrypi/soc.yml Outdated Show resolved Hide resolved
@soburi
Copy link
Member

soburi commented Aug 22, 2024

modules/hal_rpi_pico/CMakeLists.txt Outdated Show resolved Hide resolved
dts/arm/rpi_pico/rpi_pico_2_common.dtsi Outdated Show resolved Hide resolved
soc/raspberrypi/CMakeLists.txt Outdated Show resolved Hide resolved
@@ -219,7 +219,7 @@ manifest:
- hal
- name: hal_rpi_pico
path: modules/hal/rpi_pico
revision: fba7162cc7bee06d0149622bbcaac4e41062d368
revision: pull/6/head
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can I help get this PR approved and merged?

nordicjm
nordicjm previously approved these changes Aug 27, 2024
Copy link
Collaborator

@nordicjm nordicjm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updates are OK. Though migration guide entry needed for the SoC symbol change

boards/raspberrypi/rpi_pico_2/rpi_pico_2-pinctrl.dtsi Outdated Show resolved Hide resolved
@ajf58 ajf58 force-pushed the add-rpi-pico-2-support branch 5 times, most recently from b4d5164 to f5d043c Compare August 29, 2024 07:25
@ajf58 ajf58 force-pushed the add-rpi-pico-2-support branch 2 times, most recently from be3d6b9 to 384b0ee Compare August 29, 2024 21:01
@ajf58
Copy link
Contributor Author

ajf58 commented Aug 30, 2024

Updates are OK. Though migration guide entry needed for the SoC symbol change

@nordicjm where should this update go? Is under boards in doc/releases/migration-guide-4.0.rst correct?

@nordicjm
Copy link
Collaborator

nordicjm commented Sep 2, 2024

Updates are OK. Though migration guide entry needed for the SoC symbol change

@nordicjm where should this update go? Is under boards in doc/releases/migration-guide-4.0.rst correct?

Yes

@soburi
Copy link
Member

soburi commented Sep 27, 2024

If it fails the test for some valid reason, you can explain why and exclude it.
I think this is the approach we should take now.

Is there a finer-grained option to exclude a single test, or would we just need to exclude the entire thing via tests/drivers/gpio/gpio_api_1pin/testcase.yaml ?

Please add rpi_pico2 to platform_exclude:.
Also you need explain in commit message why this test failed and enough reason to excluding.
If it is an unavoidable event, it should be explained in the documentation.

@ajf58
Copy link
Contributor Author

ajf58 commented Sep 27, 2024

If a driver doesn't pass the tests then why is it being added?

@nordicjm because sometimes it's a bad test, not a bad driver :-). The test case makes assumptions about how GPIOs connected to LEDs work, and those assumptions aren't always true.

@nordicjm
Copy link
Collaborator

If a driver doesn't pass the tests then why is it being added?

@nordicjm because sometimes it's a bad test, not a bad driver :-). The test case makes assumptions about how GPIOs connected to LEDs work, and those assumptions aren't always true.

@henrikbrixandersen can you comment on this?

@Manu3l0us
Copy link

Manu3l0us commented Sep 27, 2024

Currently, I don't understand exactly what the combination of flags is expecting to achieve, but I don't think the combination of GPIO_OUTPUT_HIGH | GPIO_INPUT is handled by the logic at gpio_rpi_pico.c#L49-L78 . I'm not confident about my analysis of this though.

@ajf58 I took some time for a deeper dive into this. From my understanding the idea is trying to check if the open-drain configuration is working properly:

  • Open drain output high: pad is high impedance, i.e. the low-side transistor is not active
  • The internal pull-down pulls the pad low.
  • The Input buffer is active so the pin can be read back and checked

This test would fail if the the pin is still push-pull and therefore driving out a high level but also if the internal pull-down is not strong enough due to leakage.

In the GPIO_OUTPUT_HIGH | GPIO_INPUT case, the GPIO_INPUT actually does nothing in addition, but it is handled by the fact that the input buffer is enabled in the gpio_set_function() from the SDK (although there is a minor difference that the input buffer was enabled by default on RP2040 and is disabled by default on the RP2350).

So for me, this points again to errata E9 according to which, the internal pull-down may not be strong enough to pull the pad low if the input buffer is enabled and the pin is not actively driven. I can verify this early next week in the office by placing a pull-down < 8.2k on the pin. Unfortunately, I have currently no resistors at hand where I'm at right now. I will also connect a scope to the pin and to a trace before and after the modification to verify the behaviour.

@soburi
Copy link
Member

soburi commented Sep 27, 2024

@ajf58

You should also test it yourself and confirm it. It can be check all the items with uf2 transfer, but that's practically impossible, I think.
Cherry-pick my patch (5f62ea1) and run it as I showed you before. I've heard that OpenOCD is already working, so I don't think there's any problem.

@Manu3l0us
Copy link

@soburi @ajf58
I can confirm that OpenOCD is working fine on my side using this patch (and the openocd Windows binaries released by Raspberry Pi)

soburi and others added 23 commits September 27, 2024 12:57
Update RaspberryPi Pico hal to 2.0.0 release

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
The directory structure has changed in 2.0.0,
so we update it accordingly.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Following the GPIO interface changes in pico-sdk 2.0.0.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Some symbol names have been conflicted with introducing pico-sdk 2.0.0.
Rename these.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Follow the wider directory convention of dts/<arch>/<vendor>/<family>.

This is foundation work ahead of introducing support for the RP2350.

Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
Rename rpi_pico_common.dtsi to rp2040_reset.h . This is more consistent
with the wider Zephyr source tree, and is foundation work ahead of
introducing the RP2350 SoC.

Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
RESETS_RESET_PLL_USB_BITS was logically or'd twice and 'unreset'ting
PWM doesn't seem to be required, based on the contents of the SDK.

Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
No in-tree board uses this driver's pinctrl functionality, and every
RP2040-based board was configuring this to be an empty node in the
device tree, so remove them.

Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
RP2350 is Raspberry Pi's newest SoC. From the datasheet:

"RP2350 is a new family of microcontrollers from Raspberry Pi that
offers significant enhancements over RP2040. Key features include:
• Dual Cortex-M33 or Hazard3 processors at 150 MHz
• 520 kB on-chip SRAM, in 10 independent banks
• 8 kB of one-time-programmable storage (OTP)
• Up to 16 MB of external QSPI flash/PSRAM via dedicated QSPI bus
...
"

This commit introduces some changes to support the existing RP2040 and
what is describe by Raspberry Pi as the "RP2350 family". Currently there
are 4 published products in the family: RP2350A, RP2350B, RP2354A, and
RP2354A. Within Zephyr's taxonomy, split the configuration as follows:
Family: Raspberry Pi Pico. This contains all RP2XXX SoCs,
SoC Series: RP2040 and RP2350.
SoC: RP2040 and, for now, just the RP2350A, which is present on the Pico
2, where the A suffix indicates  QFN-60 package type. This structure is
reflected in `soc/raspberrypi/soc.yml`, and somewhat assumes that there
won't be a RP2050, for example, as a RP2040 with more RAM.

This is foundation work ahead of introducing support for Raspberry Pi's
Pico 2 board, which is fitted with a RP2350A and 4MB of flash.

Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
Add support for SoC-specific clock ids and update the initialization
function to support the existing RP2040 and add support for the RP2350.

clock_control_rpi_pico.c uses numerical values for clock ids taken from
rpi_pico_clock.h which are the "clock generator". For the RP2350 these
values are different for some of the same logical clock sources, as well
as the RP2040 and RP2350 having different clock sources available.

Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
Extend the existing driver to add some initial support for the new SoC,
whilst maintaining compatibility with the RP2040.

Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
Unlike the RP2040, the RP2350 has multiple tick generators that need to
be started. Start TIMER0 and TIMER1 tick generators during
clock_control_init.

Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
The watchdog register configuration of RP2350 differs from that
of RP2040, so we make fit that.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
The RP2350 SoC series contain two timer peripherals. Extend the driver
to support using the second timer (`TIMER1`).

N.b. this requires a fix from the Pico SDK to be patched into
hal_rpi_pico. See raspberrypi/pico-sdk#1949 .

Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
A significant amount of the pin muxing is duplicated between the RP2040,
the RP2350A, and RP2350B. Reflect this in the file structure, with a
`-common` suffix used to to indicate this.

Macros are defined in ascending order of the function index in the
relevant table in the datasheet. SoC/SoC-series specific macros are
defined in their respective tables. Functions that are not currently
used (e.g. the new HSTX) are intentionally not defined here as they do
not (currently) have any use in the Zephyr tree (i.e. there's no drivers
that make use of this functionality).

clang-format has been run over the existing definitions to reduce the
noise generated by CI. These are cosmetic changes; I've tried to retain
attribution to the relevant authors where applicable.

Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
The Raspberry Pi Pico 2 is Raspberry Pi's first board fitted with their
RP2350A SoC.

This adds a minimal board definition, sufficient to build and run
`samples/hello_world` and `samples/basic/blinky` on the board. Images
can be run on the target using OpenOCD. Raspberry Pi's `picotool` can
create a UF2 binary, which ensures that errata RP2350-E10 is avoided
e.g.

```
> picotool uf2 convert build\rpi_pico2\hello_world\zephyr\zephyr.elf \
    build\rpi_pico2\hello_world\zephyr\zephyr.uf2 \
    --family rp2350-arm-s --abs-block`
```

Raspberry Pi Pico 2 is a low-cost, high-performance microcontroller
board with flexible digital interfaces. Key features include:

- RP2350A microcontroller chip designed by Raspberry Pi in the United
  Kingdom
- Dual Cortex-M33 or Hazard3 processors at up to 150MHz
- 520KB of SRAM, and 4MB of on-board flash memory
- USB 1.1 with device and host support
- Low-power sleep and dormant modes
- Drag-and-drop programming using mass storage over USB
- 26x multi-function GPIO pins including 3 that can be used for ADC
- 2x SPI, 2x I2C, 2x UART, 3x 12-bit 500ksps Analogue to Digital
  Converter (ADC), 24x controllable PWM channels
- 2x Timer with 4 alarms, 1x AON Timer
- Temperature sensor
- 3x Programmable IO (PIO) blocks, 12 state machines total for custom
  peripheral support
    - Flexible, user-programmable high-speed IO
    - Can emulate interfaces such as SD Card and VGA

The Raspberry Pi Pico 2 comes as a castellated module which allows
soldering direct to carrier boards.

Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
Add UF2 Family ID for Raspberry Pi 2350 and build
UF2 image by default for Pico 2 board

Signed-off-by: Ryan Grachek <grachek@gmail.com>
Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
The Raspberry Pi Pico 2's device is compatible with the existing Pico 1.
The build system requires a `<board>.overlay` file, but these use the
pre-processing to #include the sibling rpi_pico.overlay files rather
than duplicating the contents as an attempt to keep things DRY.

Tested locally.

Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
For these tests' needs, the RP2350 on the Pico 2 is compatible with the
RP2040 on the Pico 1. #include the latter's overlay in preference to
duplicating the content.

Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
…ico 2

Only enable timer 0 for testing. Timer 1 won't work correctly until the
rpi_pico HAL has picked up the fix for `hardware_alarm_irq_handler`. See
raspberrypi/pico-sdk#1949 .

Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
Add some documentation for the board itself (mostly aiming to refer to
canonical sources of information rather duplicate). Add entries in the
release notes where applicable.

boards/raspberrypi/rpi_pico2/doc/img/pico-2.jpg is a cropped and
compressed version of https://www.raspberrypi.com/documentation/microcontrollers/images/pico-2.png
which is released under the CC-BY-SA-4.0 license. See https://github.com/raspberrypi/documentation/blob/develop/LICENSE.md

Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
Add OpenOCD debugger support.
For now we will need a RaspberryPi forked version of OpenOCD.

https://github.com/raspberrypi/openocd

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@fujitsu.com>
Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
- Remove redundant `transport select swd`. This is already done in
  `interface/rp2350.cfg`
- Set the adapter speed to match Raspberry Pi's documentation.

Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DNM This PR should not be merged (Do Not Merge) manifest manifest-hal_rpi_pico platform: Raspberry Pi Pico Raspberry Pi Pico (RPi Pico)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants