Skip to content

Commit 58a46cb

Browse files
committed
cpu/rp2350_common: create shared folder for RISCV & ARM
1 parent c5dd279 commit 58a46cb

File tree

21 files changed

+1322
-2
lines changed

21 files changed

+1322
-2
lines changed

cpu/riscv_common/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
DIRS = periph
1+
DIRS += periph
22

33
include $(RIOTBASE)/Makefile.base

cpu/rp2350/doc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@defgroup cpu_rp2350 RP2350 MCUs
1+
@defgroup cpu_rp2350_arm RP2350 MCUs
22
@ingroup cpu
33
@brief RP2350 MCU code and definitions
44

cpu/rp2350_arm/Makefile.include

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# CPU and architecture specific flags
2+
CFLAGS += -D$(CPU_MODEL)
3+
CFLAGS += -DROM_START_ADDR=$(ROM_START_ADDR)
4+
CFLAGS += -DRAM_START_ADDR=$(RAM_START_ADDR)
5+
6+
# Linker flags
7+
LINKFLAGS += -mcpu=$(CPU_ARCH) -mthumb
8+
LINKFLAGS += -Wl,--gc-sections
9+
LINKFLAGS += -Wl,--start-group -lc -lm -Wl,--end-group
10+
11+
# Vector table configuration
12+
VECTORS_O ?= $(BINDIR)/cpu/vectors.o
13+
VECTORS_FILE := $(RIOTCPU)/rp2350_common/vectors.c
14+
15+
include $(RIOTCPU)/rp2350_common/Makefile.include
16+
17+
# Include the base Cortex-M makefile
18+
include $(RIOTMAKE)/arch/cortexm.inc.mk

cpu/rp2350_common/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
DIRS += periph
2+
3+
include $(RIOTBASE)/Makefile.base

cpu/rp2350_common/Makefile.dep

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
USEMODULE += periph
2+
USEPKG += picosdk
3+
# We tell the build system that common needs to be built
4+
USEMODULE += rp2350_common
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FEATURES_PROVIDED += periph_gpio
2+
FEATURES_PROVIDED += periph_uart

cpu/rp2350_common/Makefile.include

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ROM_LEN ?= 2097152 # = 2 MiB used in the RPi Pico
2+
ROM_OFFSET := 0 # bootloader size
3+
RAM_LEN := 0x82000 # 520kB = 532479 used in the RPi Pico 2350
4+
ROM_START_ADDR := 0x10000000 # XIP Non-Secure address for rp2350
5+
RAM_START_ADDR := 0x20000000 # Non-Secure RAM address for rp2350
6+
7+
INCLUDES += -I$(RIOTCPU)/rp2350_common/include
8+
INCLUDES += -isystem$(RIOTBASE)/build/pkg/picosdk/src/rp2_common/cmsis/stub/CMSIS/Core/Include
9+
INCLUDES += -isystem$(RIOTBASE)/build/pkg/picosdk/src/rp2_common/cmsis/stub/CMSIS/Device/RP2350/Include
10+
INCLUDES += -isystem$(RIOTBASE)/build/pkg/picosdk/src/rp2350/hardware_regs/include/hardware
11+
12+
# Supported programmers and debuggers
13+
PROGRAMMERS_SUPPORTED := picotool openocd jlink
14+
PROGRAMMER ?= picotool
15+
OPENOCD_DEBUG_ADAPTER ?= dap

cpu/rp2350_common/clock.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Tom Hert <[email protected]>
3+
* SPDX-FileCopyrightText: 2025 HAW Hamburg
4+
* SPDX-License-Identifier: LGPL-2.1-only
5+
*/
6+
7+
/**
8+
* @ingroup cpu_rp2350
9+
* @{
10+
*
11+
* @file
12+
* @brief Clock configuration implementation for the RP2350
13+
*
14+
* @author Tom Hert <[email protected]>
15+
*/
16+
17+
#include "periph_cpu.h"
18+
19+
void clock_reset(void) {
20+
/* Reset the clock system */
21+
reset_component(RESET_PLL_SYS, RESET_PLL_SYS);
22+
}
23+
24+
/**
25+
* @brief Configures the XOSC and then sets CLK_SYS, PLL_SYS and CLK_PERI to it
26+
* @warning Make sure to call clock_reset() before this function to reset the
27+
* clock system
28+
* @see RP2350 Docs Chapter 8, mostly 8.2 for more details
29+
*/
30+
void cpu_clock_init(void) {
31+
/* Enable the XOSC */
32+
xosc_start();
33+
34+
/* Setup the PLL using the XOSC as the reference clock. */
35+
PLL_SYS->FBDIV_INT =
36+
PLL_FEEDBACK_DIVIDER_VALUE; /* Set the feedback divider */
37+
38+
/* Set the post-dividers for the PLL output.*/
39+
PLL_SYS->PRIM = PDIV;
40+
/* Turn on PLL */
41+
atomic_clear(&PLL_SYS->PWR,
42+
PLL_PWR_PD_BITS | PLL_PWR_VCOPD_BITS | PLL_PWR_POSTDIVPD_BITS);
43+
44+
/* sleep 10ms to allow the PLL to stabilize */
45+
xosc_sleep(10);
46+
47+
/* Based on the description in chapter 8 this is something that should be done
48+
* However, it appears to cause issues and is not done by other examples on the
49+
* internet. This needs to be investigated further. */
50+
51+
/* Wait for lock */
52+
/* while (!(PLL_SYS->CS & PLL_CS_LOCK_BITS)) { */
53+
/* Wait for the PLL to lock */
54+
/* } */
55+
56+
/* AUXSRC = 0x0 7:5 && SRC == 0x0 0 */
57+
CLOCKS->CLK_SYS_CTRL = CLK_SYS_PERI_CTRL_ENABLE_BIT;
58+
59+
/* This register contains one decoded bit for each of the clock sources
60+
* enumerated in the CTRL SRC field. The bit does not directly correlate with
61+
* the value of the SRC field For example 0x0 is the first bit while 0x1 is
62+
* the second bit. In some way this makes sense, in some way I lost too much
63+
* time on this. */
64+
while (CLOCKS->CLK_SYS_SELECTED != CLK_SYS_SELECTED_PERI_FIELD_VALUE) {
65+
}
66+
67+
/* AUXSRC = 0x0 -> CLK_SYS Indirectly through lower line */
68+
CLOCKS->CLK_PERI_CTRL = CLK_PERI_CTRL_ENABLE_BIT;
69+
}
70+
71+
/** @} */

cpu/rp2350_common/cpu.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Tom Hert <[email protected]>
3+
* SPDX-FileCopyrightText: 2025 HAW Hamburg
4+
* SPDX-License-Identifier: LGPL-2.1-only
5+
*/
6+
7+
/**
8+
* @ingroup cpu_rp2350
9+
* @{
10+
*
11+
* @file
12+
* @brief Implementation of the CPU initialization for RP2350
13+
*
14+
* @author Tom Hert <[email protected]>
15+
* @}
16+
*/
17+
18+
#include <sys/unistd.h>
19+
20+
#include "board.h"
21+
#include "cpu.h"
22+
#include "clock_conf.h"
23+
#include "kernel_init.h"
24+
#include "periph/init.h"
25+
#include "periph/uart.h"
26+
#include "periph_conf.h"
27+
28+
void gpio_reset(void)
29+
{
30+
reset_component(RESET_PADS_BANK0, RESET_PADS_BANK0);
31+
reset_component(RESET_IO_BANK0, RESET_IO_BANK0);
32+
}
33+
34+
/**
35+
* @brief Initialize the CPU, set IRQ priorities, clocks, peripheral
36+
*/
37+
void rp2350_init(void)
38+
{
39+
/* Reset GPIO state */
40+
gpio_reset();
41+
42+
/* Reset clock to default state */
43+
clock_reset();
44+
45+
/* initialize the CPU clock */
46+
cpu_clock_init();
47+
48+
/* initialize the early peripherals */
49+
early_init();
50+
51+
/* trigger static peripheral initialization */
52+
periph_init();
53+
54+
/* initialize the board */
55+
board_init();
56+
}

cpu/rp2350_common/doc.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@defgroup cpu_rp2350 RP2350 MCUs
2+
@ingroup cpu
3+
@brief RP2350 MCU code and definitions
4+
5+
This module contains the code and definitions for MCUs of the RP2350 used by the Pi Pico 2.

0 commit comments

Comments
 (0)