-
Notifications
You must be signed in to change notification settings - Fork 7.3k
boards: Add support for the raspberrypi pico #34835
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
Changes from all commits
cdec99c
2eb2990
62c9aad
8cea7bc
5d49e53
7d1d764
d41250d
c93f206
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Copyright (c) 2021 Yonatan Schachter | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
config BOARD_RPI_PICO | ||
bool "Raspberry Pi Pico Board" | ||
depends on SOC_RP2040 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright (c) 2021 Yonatan Schachter | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
if BOARD_RPI_PICO | ||
|
||
config BOARD | ||
default "rpi_pico" | ||
|
||
config RP2_FLASH_W25Q080 | ||
default y | ||
|
||
endif # BOARD_RPI_PICO |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
.. _rpi_pico: | ||
|
||
Raspberry Pi Pico | ||
################# | ||
|
||
Overview | ||
******** | ||
|
||
The Raspberry Pi Pico is a small, low-cost, versatile board from | ||
Raspberry Pi. It is equipped with an RP2040 SoC, an on-board LED, | ||
a USB connector, and an SWD interface. The USB bootloader allows it | ||
to be flashed without any adapter, in a drag-and-drop manner. | ||
It is also possible to flash and debug the Pico with its SWD interface, | ||
using an external adapter. | ||
tejlmand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Hardware | ||
******** | ||
- Dual core Arm Cortex-M0+ processor running up to 133MHz | ||
- 264KB on-chip SRAM | ||
- 2MB on-board QSPI flash with XIP capabilities | ||
- 26 GPIO pins | ||
- 3 Analog inputs | ||
- 2 UART peripherals | ||
- 2 SPI controllers | ||
- 2 I2C controllers | ||
- 16 PWM channels | ||
- USB 1.1 controller (host/device) | ||
- 8 Programmable I/O (PIO) for custom peripherals | ||
- On-board LED | ||
|
||
|
||
.. figure:: img/rpi_pico.png | ||
:width: 150px | ||
:align: center | ||
:alt: Raspberry Pi Pico | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. alt text is not a title but is descriptive, e.g "Top down view of the 40-pin DIP-shaped Raspberry Pi Pico board" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other boards seem to do the same, so I won't be the exception, unless requested. |
||
|
||
Raspberry Pi Pico (Image courtesy of Raspberry Pi) | ||
|
||
Supported Features | ||
================== | ||
|
||
The rpi_pico board configuration supports the following | ||
hardware features: | ||
|
||
.. list-table:: | ||
:header-rows: 1 | ||
|
||
* - Peripheral | ||
- Kconfig option | ||
- Devicetree compatible | ||
* - NVIC | ||
- N/A | ||
- :dtcompatible:`arm,v6m-nvic` | ||
* - UART | ||
- :kconfig:`CONFIG_SERIAL` | ||
- :dtcompatible:`rpi,pico-uart` | ||
* - GPIO | ||
- :kconfig:`CONFIG_GPIO` | ||
- :dtcompatible:`rpi,pico-gpio` | ||
|
||
Programming and Debugging | ||
************************* | ||
|
||
Flashing | ||
======== | ||
|
||
Using an SWD adapter | ||
-------------------- | ||
|
||
The Raspberry Pi Pico has an SWD interface that can be used to program | ||
and debug the on board RP2040. This interface can be utilized by openocd. | ||
However, to use it with the RP2040, a custom fork of openocd is needed. | ||
This fork can be found here: https://github.com/raspberrypi/openocd | ||
|
||
Depending on the interface used (such as JLink), you might need to | ||
checkout to a branch that supports this interface, before proceeding. | ||
Build and install openocd as described in the README. | ||
|
||
When openocd is installed, you can flash the board with the following | ||
command (assuming JLink is used): | ||
|
||
.. code-block:: console | ||
|
||
$ openocd -f interface/jlink.cfg -c 'transport select swd' -f target/rp2040.cfg -c "adapter speed 2000" -c 'targets rp2040.core0' -c 'program path/to/zephyr.elf verify reset exit' | ||
|
||
Using UF2 | ||
--------- | ||
|
||
If you don't have an SWD adapter, you can flash the Raspberry Pi Pico with | ||
a UF2 file. By default, building an app for this board will generate a | ||
`build/zephyr/zephyr.uf2` file. If the Pico is powered on with the `BOOTSEL` | ||
button pressed, it will appear on the host as a mass storage device. The | ||
UF2 file should be drag-and-dropped to the device, which will flash the Pico. | ||
|
||
Debugging | ||
========= | ||
|
||
The SWD interface can also be used to debug the board. To achieve this, | ||
install openocd as described for flashing the board. Also, install gdb-multiarch. | ||
Then run the following command: | ||
|
||
.. code-block:: console | ||
|
||
$ openocd -f interface/jlink.cfg -c 'transport select swd' -f target/rp2040.cfg -c "adapter speed 2000" -c 'targets rp2040.core0' | ||
|
||
On another terminal, run: | ||
|
||
.. code-block:: console | ||
|
||
$ gdb-multiarch | ||
|
||
Inside gdb, run: | ||
|
||
.. code-block:: console | ||
|
||
(gdb) tar ext :3333 | ||
(gdb) file path/to/zephyr.elf | ||
|
||
You can then start debugging the board. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (c) 2021, Yonatan Schachter | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <dt-bindings/pinctrl/rpi-pico-rp2040-pinctrl.h> | ||
|
||
&pinctrl { | ||
uart0_default: uart0_default { | ||
group1 { | ||
pinmux = <UART0_TX_P0>; | ||
}; | ||
group2 { | ||
pinmux = <UART0_RX_P1>; | ||
input-enable; | ||
}; | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (c) 2021 Yonatan Schachter | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/dts-v1/; | ||
|
||
#include <rpi_pico/rp2040.dtsi> | ||
#include "rpi_pico-pinctrl.dtsi" | ||
|
||
/ { | ||
chosen { | ||
zephyr,sram = &sram0; | ||
zephyr,flash = &flash0; | ||
zephyr,console = &uart0; | ||
zephyr,code-partition = &code_partition; | ||
}; | ||
|
||
leds { | ||
compatible = "gpio-leds"; | ||
led0: led_0 { | ||
gpios = <&gpio0 25 GPIO_ACTIVE_LOW>; | ||
label = "LED"; | ||
}; | ||
}; | ||
|
||
aliases { | ||
led0 = &led0; | ||
}; | ||
}; | ||
|
||
&flash0 { | ||
reg = <0x10000000 DT_SIZE_M(2)>; | ||
|
||
partitions { | ||
compatible = "fixed-partitions"; | ||
#address-cells = <1>; | ||
#size-cells = <1>; | ||
|
||
/* Reserved memory for the second stage bootloader */ | ||
second_stage_bootloader: partition@0 { | ||
label = "second_stage_bootloader"; | ||
reg = <0x00000000 0x100>; | ||
read-only; | ||
}; | ||
|
||
/* | ||
* Usable flash. Starts at 0x100, after the bootloader. The partition | ||
* size is 2MB minus the 0x100 bytes taken by the bootloader. | ||
*/ | ||
code_partition: partition@100 { | ||
label = "code-partition"; | ||
reg = <0x100 (DT_SIZE_M(2) - 0x100)>; | ||
read-only; | ||
}; | ||
}; | ||
}; | ||
|
||
&uart0 { | ||
current-speed = <115200>; | ||
status = "okay"; | ||
pinctrl-0 = <&uart0_default>; | ||
pinctrl-names = "default"; | ||
}; | ||
|
||
&gpio0 { | ||
status = "okay"; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
identifier: rpi_pico | ||
name: RaspberryPi-Pico | ||
type: mcu | ||
arch: arm | ||
flash: 2048 | ||
ram: 264 | ||
toolchain: | ||
- zephyr | ||
- gnuarmemb | ||
- xtools | ||
gmarull marked this conversation as resolved.
Show resolved
Hide resolved
|
||
supported: | ||
- uart | ||
- gpio |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CONFIG_SOC_SERIES_RP2XXX=y | ||
CONFIG_SOC_RP2040=y | ||
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=125000000 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The rp2040's max clock freq is 133MHz, does the chip on the pico board only run at 125MHz? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, can't find a better source right now, hope this qualifies: https://forums.raspberrypi.com/viewtopic.php?t=302191 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks fair enough to me... though as the last post says, you can change the rate dynamically. |
||
CONFIG_SERIAL=y | ||
CONFIG_CONSOLE=y | ||
CONFIG_UART_CONSOLE=y | ||
carlescufi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
CONFIG_GPIO=y | ||
CONFIG_USE_DT_CODE_PARTITION=y | ||
CONFIG_BUILD_OUTPUT_UF2=y |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Copyright (c) 2021 Yonatan Schachter | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# Workaround for not being able to have commas in macro arguments | ||
DT_COMPAT_RPI_PICO_GPIO := raspberrypi,pico-gpio | ||
|
||
config GPIO_RPI_PICO | ||
default $(dt_compat_enabled,$(DT_COMPAT_RPI_PICO_GPIO)) | ||
select PICOSDK_USE_GPIO | ||
bool "Raspberry Pi Pico GPIO driver" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is rp2040 better for it ? Since pico is board name instead of soc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mentioned in another review, the naming convention used to derive the rp2040 SoC implies there's room for other chips in the same family in the future. I think making this specifically rp2040 will just lead to future refactors.
The upstream SDK uses rp2, or pico all over the place, so either of those is preferable, IMHO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with no1wudi on this occasion. While there is indeed an implication of a future rp4040 or whatever, there is no guarantee of it at all, especially with chip crisis raging, and even less guarantee that the devices will be sufficiently similar to share soc definitions.
In the case of the Motorola 68000 the ports were named the mc68k or similar, based on the initial chip name. I think it would be quite reasonable to do the same here.