Skip to content
Closed
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
11 changes: 11 additions & 0 deletions boards/rpi-pico-2-riscv/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# SPDX-FileCopyrightText: 2025 Tom Hert <[email protected]>
# SPDX-FileCopyrightText: 2025 HAW Hamburg
# SPDX-License-Identifier: LGPL-2.1-only

config BOARD
default "rpi-pico-2-riscv" if BOARD_RPI_PICO_2_RISCV

config BOARD_RPI_PICO_2_RISV
bool
default y
select CPU_MODEL_RP2350_RISCV
3 changes: 3 additions & 0 deletions boards/rpi-pico-2-riscv/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MODULE = board

include $(RIOTBASE)/Makefile.base
5 changes: 5 additions & 0 deletions boards/rpi-pico-2-riscv/Makefile.features
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CPU := rp2350_riscv

FEATURES_PROVIDED += periph_uart
FEATURES_PROVIDED += periph_gpio
FEATURES_PROVIDED += periph_pmp
7 changes: 7 additions & 0 deletions boards/rpi-pico-2-riscv/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CPU_MODEL := RP2350_RISCV
PORT_LINUX ?= /dev/ttyACM0

# JLink isnt tested yet on RP2350
# ifeq ($(PROGRAMMER),jlink)
# JLINK_DEVICE = RP2350_M33_0
# endif
15 changes: 15 additions & 0 deletions boards/rpi-pico-2-riscv/board.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* SPDX-FileCopyrightText: 2025 Tom Hert <[email protected]>
* SPDX-FileCopyrightText: 2025 HAW Hamburg
* SPDX-License-Identifier: LGPL-2.1-only
*/

#include "board.h"

void board_init(void) {
/* Re-enable the LED0 pin
* Otherwise the LED will not work after a reset
* This is needed, esp. when the LED is used via
* the define macros */
gpio_init(LED0_PIN_ID, GPIO_OUT);
}
6 changes: 6 additions & 0 deletions boards/rpi-pico-2-riscv/dist/openocd.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
echo "Make sure to use the Raspberry Pi OpenOCD version!"
source [find target/rp2350-riscv.cfg]
set USE_CORE SMP
set RESCUE 1
$_TARGETNAME_0 configure -rtos auto
adapter speed 5000
116 changes: 116 additions & 0 deletions boards/rpi-pico-2-riscv/doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
@defgroup boards_rpi_pico_2_riscv Raspberry Pi Pico 2
@ingroup boards
@brief Support for the RP2350 RISCV based Raspberry Pi Pico board

@warning The support for the Raspberry Pi Pico 2 is still in a very early stage!
See [Known Issues](#rpi_pico_2_riscv_known_issues).

## Overview

The Raspberry Pi Pico 2 is a microcontroller board based on the RP2350 chip,
featuring dual-core Arm Cortex-M0+ processors and RISC-V Hazard secondary
architecture. It is designed for a wide range of applications,
from hobbyist projects to professional embedded systems
for a fairly affordable price.

![The Raspberry Pi Pico 2 Board](https://www.raspberrypi.com/documentation/microcontrollers/images/pico-2.png)

## Hardware

| MCU | RP2350 |
|:-----------|:------------------------------------------------------------|
| Family | Dual Cortex-M33 or Hazard3 (RISC-V) |
| Vendor | Raspberry Pi |
| RAM | 520 kB on-chip SRAM (10 independent banks) |
| Flash | Up to 16 MB external QSPI flash (Pico 2 has 4 MB by default)|
| Frequency | up to 150 MHz (Set to 125 MHz in RIOT) |
| Security | Boot signing, key storage, SHA-256 accelerator |
| PIOs | 12 state machines |
| UARTs | 2 |
| SPIs | 2 |
| I2Cs | 2 |
| PWM | 24 channels |
| USB | USB 1.1 controller with host and device support |
| Power | On-chip switched-mode power supply with LDO sleep mode |
| OTP | 8 kB of one-time-programmable storage |
| Datasheet | [RP2350 Datasheet](https://datasheets.raspberrypi.com/rp2350/rp2350-datasheet.pdf) |

## User Interfaces

| Interface | Description |
|:-----------|:-------------------------------------------------------------|
| LED0 | User LED (GPIO 0 at Pin 25) |
| SW0 | Button used in flash process, can be accessed using registers but difficult |

## Pinout

![Pinout Diagram](https://www.raspberrypi.com/documentation/microcontrollers/images/pico-2-r4-pinout.svg)

## Flashing the Board

The Raspberry Pi Pico 2 has a built-in bootloader that allows flashing via USB.
However, you can also use OpenOCD for flashing the board.
If you are using picotool, you need to hold the bootselect button
(the only button on the board) while connecting the board to
your computer via USB. This will put the board into bootloader mode,
allowing you to flash it.

### Flashing using OpenOCD

If you have two Raspberry Pi Pico boards,
you can utilize one as a programmer to program the other board.

Please refer to the
[Debugprobe documentation](https://www.raspberrypi.com/documentation/microcontrollers/debug-probe.html#getting-started)
for more details.

Note that Raspberry Pi actually uses their own OpenOCD fork, which is available
in the [RP2040 OpenOCD repository](https://github.com/raspberrypi/openocd).
While technically you can use the standard OpenOCD,
it is recommended to use the Raspberry Pi fork for better compatibility with the
RP2350, as its still fairly "new" and under development,
which is why even their own Pico SDK Extension
uses the Raspberry Pi fork of OpenOCD, instead of the standard one.

To do this, you need to connect the board to your computer
and use the following command:

```bash
PROGRAMMER=openocd BOARD=rpi-pico-2 make flash
```

You can then debug your application using GDB with the following command:

```bash
PROGRAMMER=openocd BOARD=rpi-pico-2 make debug
```

### Flashing using Picotool

Simply connect the board to your computer via USB and use the following command:

```bash
BOARD=rpi-pico-2 make flash
```

This is the default method for flashing the Raspberry Pi Pico 2.
However, it does not allow for debugging using GDB.

@note When programming the board with the Picotool for the first time,
RIOT will download and install the Picotool locally in the RIOT folder.
This process will take some minutes to complete.

## Known Issues {#rpi_pico_2_riscv_known_issues}

Currently RP2350 support is rather minimal,
as such peripheral support is extremely limited.
The following peripherals are supported:

- GPIO
- Non-configurable write-only UART (UART0 using Pin 0 and 1)
- The UART Baudrate is set to 115200.
- UART does not work via USB, you need to connect it directly to the GPIO pins.

More peripherals will be added in the future.
It should also be noted that we currently only support the Cortex M33 cores,
not the RISC-V Hazard cores.
42 changes: 42 additions & 0 deletions boards/rpi-pico-2-riscv/include/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* SPDX-FileCopyrightText: 2025 Tom Hert <[email protected]>
* SPDX-FileCopyrightText: 2025 HAW Hamburg
* SPDX-License-Identifier: LGPL-2.1-only
*/

#pragma once

/**
* @ingroup boards_rpi_pico_2_riscv
* @{
*
* @file
* @brief Board specific definitions for the Raspberry Pi Pico 2
*
* @author Tom Hert <[email protected]>
*/

#include "cpu.h"
#include "periph_conf.h"

#include "periph/gpio.h"

/** GPIO Pin ID for the onboard LED */
#define LED0_PIN_ID 25u
#define LED0_ON gpio_set(LED0_PIN_ID)
#define LED0_OFF gpio_clear(LED0_PIN_ID)
#define LED0_TOGGLE gpio_toggle(LED0_PIN_ID)
#define LED0_NAME "LED(Green)"

#ifdef __cplusplus
extern "C" {
#endif

/** Initialize the board, called from the cpu startup code */
void board_init(void);

#ifdef __cplusplus
}
#endif

/** @} */
18 changes: 18 additions & 0 deletions boards/rpi-pico-2-riscv/include/gpio_params.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* SPDX-FileCopyrightText: 2025 Tom Hert <[email protected]>
* SPDX-FileCopyrightText: 2025 HAW Hamburg
* SPDX-License-Identifier: LGPL-2.1-only
*/

#pragma once

#include "board.h"
#include "saul/periph.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
#endif
63 changes: 63 additions & 0 deletions boards/rpi-pico-2-riscv/include/periph_conf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* SPDX-FileCopyrightText: 2025 Tom Hert <[email protected]>
* SPDX-FileCopyrightText: 2025 HAW Hamburg
* SPDX-License-Identifier: LGPL-2.1-only
*/

#pragma once

/**
* @ingroup boards_rpi_pico_2_riscv
* @{
*
* @file
* @brief Board specific periph definitions
* for the Raspberry Pi Pico 2
*
* @author Tom Hert <[email protected]>
*/

#include "kernel_defines.h"
#include <stdint.h>
#include "periph_cpu.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Configuration details for an UART interface needed by the RPX0XX peripheral
@todo this is shared between both
*/
typedef struct {
UART0_Type *dev; /**< Base address of the I/O registers of the device */
gpio_t rx_pin; /**< GPIO pin to use for RX */
gpio_t tx_pin; /**< GPIO pin to use for TX */
IRQn_Type irqn; /**< IRQ number of the UART interface */
} uart_conf_t;

static const uart_conf_t uart_config[] = {
{
.dev = UART0,
.rx_pin = GPIO_PIN(0, 1),
.tx_pin = GPIO_PIN(0, 0),
.irqn = UART0_IRQ_IRQn
},
{
.dev = UART1,
.rx_pin = GPIO_PIN(0, 9),
.tx_pin = GPIO_PIN(0, 8),
.irqn = UART1_IRQ_IRQn
}
};

#define UART_0_ISR (isr_uart0)
#define UART_1_ISR (isr_uart1)

#define UART_NUMOF ARRAY_SIZE(uart_config)

#ifdef __cplusplus
}
#endif

/** @} */
67 changes: 67 additions & 0 deletions cpu/riscv_common/include/xh3irq.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* SPDX-FileCopyrightText: 2025 Tom Hert <[email protected]>
* SPDX-FileCopyrightText: 2025 HAW Hamburg
* SPDX-License-Identifier: LGPL-2.1-only
*/

#pragma once

#include <stdio.h>
#include "cpu_conf.h"
#include "panic.h"

/**
* @ingroup cpu_riscv_common
* @{
*
* @file
* @brief xh3irq.h interrupt controller support
*
* @author Tom Hert <[email protected]>
*/

#ifdef __cplusplus
extern "C" {
#endif

/** CPU specific interrupt vector table
* @see 3.2 Interrupts and IRQn_Type in RP2350.h
*/
extern const void *vector_cpu[CPU_IRQ_NUMOF];

/**
* @brief Check if there are any pending interrupts
* @return 1 if there are pending interrupts, 0 otherwise
*/
uint32_t xh3irq_has_pending(void);

/**
* @brief The main IRQ handler, called from the assembly IRQ handler
* @note This function must clear the pending interrupt in the interrupt controller
*/
void xh3irq_handler(void);

/**
* @brief Enable the given IRQ number
* @param irq_no The IRQ number to enable
*/
void xh3irq_enable_irq(uint32_t irq_no);

/**
* @brief Disable the given IRQ number
* @param irq_no The IRQ number to disable
*/
void xh3irq_disable_irq(uint32_t irq_no);

/**
* @brief Force the given IRQ number to be pending
* @param irq_no The IRQ number to force
* @note The IRQ still must be enabled to be handled
*/
void xh3irq_force_irq(uint32_t irq_no);

#ifdef __cplusplus
}
#endif

/** @} */
Loading
Loading