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

boards: Add support for the raspberrypi pico #34835

Merged
merged 8 commits into from
Feb 2, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1454,12 +1454,27 @@ if(CONFIG_BUILD_OUTPUT_BIN)
endif()

if(CONFIG_BUILD_OUTPUT_BIN AND CONFIG_BUILD_OUTPUT_UF2)
if(CONFIG_BUILD_OUTPUT_UF2_USE_FLASH_BASE)
set(flash_addr "${CONFIG_FLASH_BASE_ADDRESS}")
else()
set(flash_addr "${CONFIG_FLASH_LOAD_OFFSET}")
endif()

if(CONFIG_BUILD_OUTPUT_UF2_USE_FLASH_OFFSET)
# Note, the `+ 0` in formula below avoids errors in cases where a Kconfig
# variable is undefined and thus expands to nothing.
math(EXPR flash_addr
"${flash_addr} + ${CONFIG_FLASH_LOAD_OFFSET} + 0"
OUTPUT_FORMAT HEXADECIMAL
)
endif()

list(APPEND
post_build_commands
COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/uf2conv.py
-c
-f ${CONFIG_BUILD_OUTPUT_UF2_FAMILY_ID}
-b ${CONFIG_FLASH_LOAD_OFFSET}
-b ${flash_addr}
-o ${KERNEL_UF2_NAME}
${KERNEL_BIN_NAME}
)
Expand Down
6 changes: 6 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
/soc/arm/nuvoton_npcx/ @MulinChao @WealianLiao @ChiHuaL
/soc/arm/nuvoton_numicro/ @ssekar15
/soc/arm/quicklogic_eos_s3/ @kowalewskijan @kgugala
/soc/arm/rpi_pico/ @yonsch
/soc/arm/silabs_exx32/efm32pg1b/ @rdmeneze
/soc/arm/silabs_exx32/efr32mg21/ @l-alfred
/soc/arm/st_stm32/ @erwango
Expand Down Expand Up @@ -129,6 +130,7 @@
/boards/arm/quick_feather/ @kowalewskijan @kgugala
/boards/arm/rak4631_nrf52840/ @gpaquet85
/boards/arm/rak5010_nrf52840/ @gpaquet85
/boards/arm/rpi_pico/ @yonsch
/boards/arm/ronoth_lodev/ @NorthernDean
/boards/arm/xmc45_relax_kit/ @parthitce
/boards/arm/sam4e_xpro/ @nandojve
Expand Down Expand Up @@ -265,6 +267,7 @@
/drivers/gpio/*eos_s3* @wtatarski @kowalewskijan @kgugala
/drivers/gpio/*rcar* @julien-massot
/drivers/gpio/*esp32* @glaubermaroto
/drivers/gpio/*rpi_pico* @yonsch
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link

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.

/drivers/hwinfo/ @alexanderwachter
/drivers/i2c/i2c_common.c @sjg20
/drivers/i2c/i2c_emul.c @sjg20
Expand Down Expand Up @@ -353,6 +356,7 @@
/drivers/serial/uart_mcux_iuart.c @Mani-Sadhasivam
/drivers/serial/Kconfig.rtt @carlescufi @pkral78
/drivers/serial/uart_rtt.c @carlescufi @pkral78
/drivers/serial/*rpi_pico* @yonsch
/drivers/serial/Kconfig.xlnx @wjliang
/drivers/serial/uart_xlnx_ps.c @wjliang
/drivers/serial/uart_xlnx_uartlite.c @henrikbrixandersen
Expand Down Expand Up @@ -448,6 +452,7 @@
/dts/arm/nuvoton/ @ssekar15 @MulinChao @WealianLiao @ChiHuaL
/dts/arm/nxp/ @mmahadevan108 @dleach02
/dts/arm/microchip/ @franciscomunoz @albertofloyd @sjvasanth1
/dts/arm/rpi_pico/ @yonsch
/dts/arm/silabs/efm32_pg_1b.dtsi @rdmeneze
/dts/arm/silabs/efm32gg11b* @oanerer
/dts/arm/silabs/efm32_jg_pg* @chrta
Expand Down Expand Up @@ -489,6 +494,7 @@
/dts/bindings/*/nordic* @anangl
/dts/bindings/*/nxp* @mmahadevan108 @dleach02
/dts/bindings/*/openisa* @dleach02
/dts/bindings/*/raspberrypi*pico* @yonsch
/dts/bindings/*/st* @erwango
/dts/bindings/sensor/ams* @alexanderwachter
/dts/bindings/*/sifive* @mateusz-holenko @kgugala @pgielda
Expand Down
9 changes: 9 additions & 0 deletions Kconfig.zephyr
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ config BUILD_OUTPUT_UF2_FAMILY_ID
default "0xada52840" if SOC_NRF52840_QIAA
default "0x4fb2d5bd" if SOC_SERIES_IMX_RT
default "0x2abc77ec" if SOC_SERIES_LPC55XXX
default "0xe48bff56" if SOC_SERIES_RP2XXX
default "0x68ed2b88" if SOC_SERIES_SAMD21
default "0x55114460" if SOC_SERIES_SAMD51
default "0x647824b6" if SOC_SERIES_STM32F0X
Expand All @@ -486,6 +487,14 @@ config BUILD_OUTPUT_UF2_FAMILY_ID
name string. If the SoC in use is known by UF2, the Family ID will
be pre-filled with the known value.

config BUILD_OUTPUT_UF2_USE_FLASH_BASE
bool
default n

config BUILD_OUTPUT_UF2_USE_FLASH_OFFSET
bool
default n

endif # BUILD_OUTPUT_UF2

config BUILD_OUTPUT_STRIPPED
Expand Down
6 changes: 6 additions & 0 deletions boards/arm/rpi_pico/Kconfig.board
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
12 changes: 12 additions & 0 deletions boards/arm/rpi_pico/Kconfig.defconfig
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
Empty file.
Binary file added boards/arm/rpi_pico/doc/img/rpi_pico.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
119 changes: 119 additions & 0 deletions boards/arm/rpi_pico/doc/index.rst
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
Copy link

Choose a reason for hiding this comment

The 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"

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.
18 changes: 18 additions & 0 deletions boards/arm/rpi_pico/rpi_pico-pinctrl.dtsi
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;
};
};
};
69 changes: 69 additions & 0 deletions boards/arm/rpi_pico/rpi_pico.dts
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";
};
13 changes: 13 additions & 0 deletions boards/arm/rpi_pico/rpi_pico.yaml
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
9 changes: 9 additions & 0 deletions boards/arm/rpi_pico/rpi_pico_defconfig
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
Copy link

Choose a reason for hiding this comment

The 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?
The sysclock frequency is also program modifiable at runtime.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link

Choose a reason for hiding this comment

The 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
1 change: 1 addition & 0 deletions drivers/gpio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ zephyr_library_sources_ifdef(CONFIG_GPIO_SAM4L gpio_sam4l.c)
zephyr_library_sources_ifdef(CONFIG_GPIO_SX1509B gpio_sx1509b.c)
zephyr_library_sources_ifdef(CONFIG_GPIO_INTEL gpio_intel.c)
zephyr_library_sources_ifdef(CONFIG_GPIO_STELLARIS gpio_stellaris.c)
zephyr_library_sources_ifdef(CONFIG_GPIO_RPI_PICO gpio_rpi_pico.c)
zephyr_library_sources_ifdef(CONFIG_GPIO_RV32M1 gpio_rv32m1.c)
zephyr_library_sources_ifdef(CONFIG_GPIO_LMP90XXX gpio_lmp90xxx.c)
zephyr_library_sources_ifdef(CONFIG_GPIO_LITEX gpio_litex.c)
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ source "drivers/gpio/Kconfig.xec"

source "drivers/gpio/Kconfig.stellaris"

source "drivers/gpio/Kconfig.rpi_pico"

source "drivers/gpio/Kconfig.rv32m1"

source "drivers/gpio/Kconfig.lmp90xxx"
Expand Down
10 changes: 10 additions & 0 deletions drivers/gpio/Kconfig.rpi_pico
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"