Skip to content

rp2: Add support for new RP2350 MCU. #15619

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

Merged
merged 31 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
525fce7
py/usermod.cmake: Check target exists in usermod_gather_sources.
Gadgetoid Jun 28, 2024
70a884d
lib/pico-sdk: Update to version 2.0.0.
dpgeorge Aug 8, 2024
815d6a1
rp2/mpconfigport: Set MCU name for RP2350.
peterharperuk May 22, 2024
c90d996
rp2: Update custom linker scripts for new pico-sdk.
peterharperuk May 22, 2024
d1423ef
rp2/modmachine: Implement lightsleep for RP2350.
peterharperuk May 22, 2024
27aeade
rp2/rp2_dma: Generalise DMA for RP2350.
peterharperuk Jun 3, 2024
d2c85c7
rp2: Integrate RP2350 and use aon_timer instead of rtc API.
peterharperuk May 23, 2024
6d39418
rp2: Add support for 48-pin RP2350 variant.
Gadgetoid Jul 1, 2024
a3d1c59
rp2/machine_pin: Move decl of machine_pin_obj_table to public header.
dpgeorge Sep 2, 2024
e6093c0
rp2/rp2_pio: Add support for RP2350A/B variants in PIO interface.
Gadgetoid Jul 2, 2024
4af09de
rp2/boards/make-pins.py: Pass num-gpios/num-ext-gpios into make-pins.
peterharperuk Jul 8, 2024
733052f
rp2/machine_pin: Use 64-bit gpio functions to allow gpios >=32 to work.
peterharperuk Jul 10, 2024
57f4cab
rp2/machine_pin: Generalise gpio_irq handler for pins >32.
Gadgetoid Jul 8, 2024
d0bc427
rp2/clocks_extra: Update runtime_clocks_init based on new pico-sdk.
peterharperuk Jul 10, 2024
34e463d
rp2/machine_adc: Add ADC support for RP2350B.
Gadgetoid Aug 5, 2024
4fc6cf9
rp2: Add support for RP2350 in RISCV mode.
dpgeorge Aug 8, 2024
f2f08ef
rp2/Makefile: Allow CMAKE_ARGS to be set by user.
dpgeorge Aug 8, 2024
7a78e5a
rp2/machine_bitstream: Set SysTick reset value.
sfe-SparkFro Aug 5, 2024
957cea2
rp2/machine_uart: Allow new TX/RX pins on RP2350.
sfe-SparkFro Aug 6, 2024
ea2eed1
rp2/mphalport: Implement mp_hal_ticks_cpu for RISCV using mcycle.
dpgeorge Aug 8, 2024
fa15ae4
rp2/machine_bitstream: Implement bitstream for RISC-V using mcycle.
dpgeorge Aug 8, 2024
8cc7c64
rp2: Workaround pico_aon_timer timezone binary size increase.
projectgus Aug 13, 2024
27904ae
rp2/machine_pwm: Add RP2350 slices to machine.PWM.
Gadgetoid Aug 15, 2024
137e9e8
rp2/main: Set CPU frequency to default for the MCU.
dpgeorge Sep 23, 2024
e32e13f
rp2/boards/RPI_PICO2: Add new RPI_PICO2 board definition.
peterharperuk May 22, 2024
f9cebe6
tools/ci.sh: Add RPI_PICO2 to CI.
dpgeorge Aug 9, 2024
fda7ae8
tests/ports/rp2: Update DMA test to work on RP2350.
dpgeorge Aug 7, 2024
651b63c
tests/ports/rp2: Add simple rp2-specific UART test.
dpgeorge Aug 9, 2024
b42bb91
tests/ports/rp2: Update lightsleep/machine_idle to skip on RP2350.
dpgeorge Oct 11, 2024
b33f647
tests/run-tests.py: Only run inlineasm tests on rp2 ARM targets.
dpgeorge Oct 11, 2024
51663b9
rp2/machine_uart: Clear timeout_char when UART is first constructed.
dpgeorge Oct 11, 2024
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 docs/library/rp2.PIO.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ Constructors
Methods
-------

.. method:: PIO.gpio_base([base])

Query and optionally set the current GPIO base for this PIO instance.

If an argument is given then it must be a pin (or integer corresponding to a pin
number), restricted to either GPIO0 or GPIO16. The GPIO base will then be set to
that pin. Setting the GPIO base must be done before any programs are added or state
machines created.

Returns the current GPIO base pin.

.. method:: PIO.add_program(program)

Add the *program* to the instruction memory of this PIO instance.
Expand Down
2 changes: 1 addition & 1 deletion lib/pico-sdk
Submodule pico-sdk updated 977 files
102 changes: 90 additions & 12 deletions ports/rp2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ include(${MICROPY_DIR}/py/usermod.cmake)

add_executable(${MICROPY_TARGET})

# Provide a C-level definitions of PICO_ARM.
# (The pico-sdk already defines PICO_RISCV when it's enabled.)
if(PICO_ARM)
target_compile_definitions(pico_platform_headers INTERFACE
PICO_ARM=1
)
endif()

set(MICROPY_QSTRDEFS_PORT
${MICROPY_PORT_DIR}/qstrdefsport.h
)
Expand All @@ -108,7 +116,6 @@ set(MICROPY_SOURCE_LIB
${MICROPY_DIR}/shared/netutils/netutils.c
${MICROPY_DIR}/shared/netutils/trace.c
${MICROPY_DIR}/shared/readline/readline.c
${MICROPY_DIR}/shared/runtime/gchelper_thumb1.s
${MICROPY_DIR}/shared/runtime/gchelper_native.c
${MICROPY_DIR}/shared/runtime/interrupt_char.c
${MICROPY_DIR}/shared/runtime/mpirq.c
Expand All @@ -123,13 +130,24 @@ set(MICROPY_SOURCE_LIB
${MICROPY_DIR}/shared/tinyusb/mp_usbd_runtime.c
)

if(PICO_ARM)
list(APPEND MICROPY_SOURCE_LIB
${MICROPY_DIR}/shared/runtime/gchelper_thumb1.s
)
elseif(PICO_RISCV)
list(APPEND MICROPY_SOURCE_LIB
${MICROPY_DIR}/shared/runtime/gchelper_rv32i.s
)
endif()

set(MICROPY_SOURCE_DRIVERS
${MICROPY_DIR}/drivers/bus/softspi.c
${MICROPY_DIR}/drivers/dht/dht.c
)

set(MICROPY_SOURCE_PORT
clocks_extra.c
datetime_patch.c
fatfs_port.c
help.c
machine_bitstream.c
Expand Down Expand Up @@ -178,9 +196,9 @@ set(MICROPY_SOURCE_QSTR
)

set(PICO_SDK_COMPONENTS
cmsis_core
hardware_adc
hardware_base
hardware_boot_lock
hardware_clocks
hardware_dma
hardware_flash
Expand All @@ -191,19 +209,26 @@ set(PICO_SDK_COMPONENTS
hardware_pll
hardware_pwm
hardware_regs
hardware_rtc
hardware_resets
hardware_spi
hardware_structs
hardware_sync
hardware_sync_spin_lock
hardware_timer
hardware_uart
hardware_watchdog
hardware_xosc
pico_aon_timer
pico_base_headers
pico_binary_info
pico_bootrom
pico_multicore
pico_platform
pico_platform_compiler
pico_platform_panic
pico_platform_sections
pico_runtime
pico_runtime_init
pico_stdio
pico_stdlib
pico_sync
Expand All @@ -214,6 +239,17 @@ set(PICO_SDK_COMPONENTS
tinyusb_device
)

if(PICO_ARM)
list(APPEND PICO_SDK_COMPONENTS
cmsis_core
)
elseif(PICO_RISCV)
list(APPEND PICO_SDK_COMPONENTS
hardware_hazard3
hardware_riscv
)
endif()

# Use our custom pico_float_micropython float implementation. This is needed for two reasons:
# - to fix inf handling in pico-sdk's __wrap___aeabi_fadd();
# - so we can use our own libm functions, to fix inaccuracies in the pico-sdk versions.
Expand All @@ -224,14 +260,24 @@ pico_add_library(pico_float_micropython)

# pico_float_micropython: add pico-sdk float and our libm source files.
target_sources(pico_float_micropython INTERFACE
${PICO_SDK_PATH}/src/rp2_common/pico_float/float_aeabi.S
${PICO_SDK_PATH}/src/rp2_common/pico_float/float_init_rom.c
${PICO_SDK_PATH}/src/rp2_common/pico_float/float_v1_rom_shim.S
${MICROPY_SOURCE_LIB_LIBM}
${MICROPY_SOURCE_LIB_LIBM_SQRT_SW}
${MICROPY_PORT_DIR}/libm_extra.c
)

if(PICO_RP2040)
target_sources(pico_float_micropython INTERFACE
${PICO_SDK_PATH}/src/rp2_common/pico_float/float_aeabi_rp2040.S
${PICO_SDK_PATH}/src/rp2_common/pico_float/float_init_rom_rp2040.c
${PICO_SDK_PATH}/src/rp2_common/pico_float/float_v1_rom_shim_rp2040.S
)
elseif(PICO_RP2350 AND PICO_ARM)
target_sources(pico_float_micropython INTERFACE
${PICO_SDK_PATH}/src/rp2_common/pico_float/float_aeabi_dcp.S
${PICO_SDK_PATH}/src/rp2_common/pico_float/float_conv_m33.S
)
endif()

# pico_float_micropython: wrap low-level floating-point ops, to call the pico-sdk versions.
pico_wrap_function(pico_float_micropython __aeabi_fdiv)
pico_wrap_function(pico_float_micropython __aeabi_fmul)
Expand All @@ -253,7 +299,9 @@ pico_wrap_function(pico_float_micropython __aeabi_ul2f)
pico_wrap_function(pico_float_micropython __aeabi_f2iz)
pico_wrap_function(pico_float_micropython __aeabi_f2lz)
pico_wrap_function(pico_float_micropython __aeabi_f2uiz)
pico_wrap_function(pico_float_micropython __aeabi_f2ulz)
if(PICO_RP2040)
pico_wrap_function(pico_float_micropython __aeabi_f2ulz)
endif()
pico_wrap_function(pico_float_micropython __aeabi_f2d)

if (MICROPY_PY_LWIP)
Expand Down Expand Up @@ -468,9 +516,15 @@ target_compile_options(${MICROPY_TARGET} PRIVATE
target_link_options(${MICROPY_TARGET} PRIVATE
-Wl,--defsym=__micropy_c_heap_size__=${MICROPY_C_HEAP_SIZE}
-Wl,--wrap=dcd_event_handler
-Wl,--wrap=clocks_init
-Wl,--wrap=runtime_init_clocks
)

if(PICO_RP2350)
target_link_options(${MICROPY_TARGET} PRIVATE
-Wl,--defsym=__micropy_extra_stack__=4096
)
endif()

# Apply optimisations to performance-critical source code.
set_source_files_properties(
${MICROPY_PY_DIR}/map.c
Expand Down Expand Up @@ -507,9 +561,18 @@ target_compile_definitions(${MICROPY_TARGET} PRIVATE
PICO_NO_PROGRAM_VERSION_STRING=1 # do it ourselves in main.c
MICROPY_BUILD_TYPE="${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION} ${CMAKE_BUILD_TYPE}"
PICO_NO_BI_STDIO_UART=1 # we call it UART REPL
PICO_RP2040_USB_DEVICE_ENUMERATION_FIX=1
)

if(PICO_RP2040)
target_compile_definitions(${MICROPY_TARGET} PRIVATE
PICO_RP2040_USB_DEVICE_ENUMERATION_FIX=1
)
elseif(PICO_RP2350)
target_compile_definitions(${MICROPY_TARGET} PRIVATE
PICO_EMBED_XIP_SETUP=1 # to put flash into continuous read mode
)
endif()

target_link_libraries(${MICROPY_TARGET}
${PICO_SDK_COMPONENTS}
)
Expand All @@ -525,12 +588,16 @@ endif()
# a linker script modification) until we explicitly add macro calls around the function
# defs to move them into RAM.
if (PICO_ON_DEVICE AND NOT PICO_NO_FLASH AND NOT PICO_COPY_TO_RAM)
pico_set_linker_script(${MICROPY_TARGET} ${CMAKE_CURRENT_LIST_DIR}/memmap_mp.ld)
if(PICO_RP2040)
pico_set_linker_script(${MICROPY_TARGET} ${CMAKE_CURRENT_LIST_DIR}/memmap_mp_rp2040.ld)
elseif(PICO_RP2350)
pico_set_linker_script(${MICROPY_TARGET} ${CMAKE_CURRENT_LIST_DIR}/memmap_mp_rp2350.ld)
endif()
endif()

pico_add_extra_outputs(${MICROPY_TARGET})

pico_find_compiler(PICO_COMPILER_SIZE ${PICO_GCC_TRIPLE}-size)
pico_find_compiler_with_triples(PICO_COMPILER_SIZE "${PICO_GCC_TRIPLE}" size)

add_custom_command(TARGET ${MICROPY_TARGET}
POST_BUILD
Expand All @@ -544,6 +611,9 @@ foreach(comp ${PICO_SDK_COMPONENTS})
micropy_gather_target_properties(${comp}_headers)
endforeach()

set(MICROPY_CPP_FLAGS_EXTRA ${PICO_COMMON_LANG_FLAGS})
separate_arguments(MICROPY_CPP_FLAGS_EXTRA)

# Include the main MicroPython cmake rules.
include(${MICROPY_DIR}/py/mkrules.cmake)

Expand All @@ -553,6 +623,14 @@ set(GEN_PINS_MKPINS "${MICROPY_PORT_DIR}/boards/make-pins.py")
set(GEN_PINS_SRC "${CMAKE_BINARY_DIR}/pins_${MICROPY_BOARD}.c")
set(GEN_PINS_HDR "${MICROPY_GENHDR_DIR}/pins.h")

if(NOT PICO_NUM_GPIOS)
set(PICO_NUM_GPIOS 30)
endif()

if(NOT PICO_NUM_EXT_GPIOS)
set(PICO_NUM_EXT_GPIOS 10)
endif()

if(EXISTS "${MICROPY_BOARD_DIR}/pins.csv")
set(GEN_PINS_BOARD_CSV "${MICROPY_BOARD_DIR}/pins.csv")
set(GEN_PINS_CSV_ARG --board-csv "${GEN_PINS_BOARD_CSV}")
Expand All @@ -565,7 +643,7 @@ target_sources(${MICROPY_TARGET} PRIVATE
# Generate pins
add_custom_command(
OUTPUT ${GEN_PINS_HDR} ${GEN_PINS_SRC}
COMMAND ${Python3_EXECUTABLE} ${GEN_PINS_MKPINS} ${GEN_PINS_CSV_ARG} --af-csv ${GEN_PINS_AF_CSV} --prefix ${GEN_PINS_PREFIX} --output-source ${GEN_PINS_SRC} --output-header ${GEN_PINS_HDR}
COMMAND ${Python3_EXECUTABLE} ${GEN_PINS_MKPINS} ${GEN_PINS_CSV_ARG} --af-csv ${GEN_PINS_AF_CSV} --prefix ${GEN_PINS_PREFIX} --output-source ${GEN_PINS_SRC} --num-gpios ${PICO_NUM_GPIOS} --num-ext-gpios ${PICO_NUM_EXT_GPIOS} --output-header ${GEN_PINS_HDR}
DEPENDS
${GEN_PINS_AF_CSV}
${GEN_PINS_BOARD_CSV}
Expand Down
2 changes: 1 addition & 1 deletion ports/rp2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ endif

$(VERBOSE)MAKESILENT = -s

CMAKE_ARGS = -DMICROPY_BOARD=$(BOARD) -DMICROPY_BOARD_DIR="$(abspath $(BOARD_DIR))"
CMAKE_ARGS += -DMICROPY_BOARD=$(BOARD) -DMICROPY_BOARD_DIR="$(abspath $(BOARD_DIR))"

ifdef USER_C_MODULES
CMAKE_ARGS += -DUSER_C_MODULES=${USER_C_MODULES}
Expand Down
1 change: 1 addition & 0 deletions ports/rp2/boards/RPI_PICO/mpconfigboard.cmake
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# cmake file for Raspberry Pi Pico
set(PICO_BOARD "pico")
set(PICO_PLATFORM "rp2040")
22 changes: 22 additions & 0 deletions ports/rp2/boards/RPI_PICO2/board.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"deploy": [
"../deploy.md"
],
"docs": "",
"features": [
"Dual-core",
"External Flash",
"USB"
],
"images": [
"rp2-pico2.jpg"
],
"mcu": "rp2350",
"product": "Pico 2",
"thumbnail": "",
"url": "https://www.raspberrypi.com/products/raspberry-pi-pico-2/",
"variants": {
"RISCV": "RISC-V CPU mode"
},
"vendor": "Raspberry Pi"
}
5 changes: 5 additions & 0 deletions ports/rp2/boards/RPI_PICO2/mpconfigboard.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# cmake file for Raspberry Pi Pico2
set(PICO_BOARD "pico2")

# To change the gpio count for QFN-80
# set(PICO_NUM_GPIOS 48)
3 changes: 3 additions & 0 deletions ports/rp2/boards/RPI_PICO2/mpconfigboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Board and hardware specific configuration
#define MICROPY_HW_BOARD_NAME "Raspberry Pi Pico2"
#define MICROPY_HW_FLASH_STORAGE_BYTES (PICO_FLASH_SIZE_BYTES - 1024 * 1024)
1 change: 1 addition & 0 deletions ports/rp2/boards/RPI_PICO2/mpconfigvariant.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(PICO_PLATFORM "rp2350")
1 change: 1 addition & 0 deletions ports/rp2/boards/RPI_PICO2/mpconfigvariant_RISCV.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(PICO_PLATFORM "rp2350-riscv")
28 changes: 28 additions & 0 deletions ports/rp2/boards/RPI_PICO2/pins.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
GP0,GPIO0
GP1,GPIO1
GP2,GPIO2
GP3,GPIO3
GP4,GPIO4
GP5,GPIO5
GP6,GPIO6
GP7,GPIO7
GP8,GPIO8
GP9,GPIO9
GP10,GPIO10
GP11,GPIO11
GP12,GPIO12
GP13,GPIO13
GP14,GPIO14
GP15,GPIO15
GP16,GPIO16
GP17,GPIO17
GP18,GPIO18
GP19,GPIO19
GP20,GPIO20
GP21,GPIO21
GP22,GPIO22
GP25,GPIO25
GP26,GPIO26
GP27,GPIO27
GP28,GPIO28
LED,GPIO25
35 changes: 27 additions & 8 deletions ports/rp2/boards/make-pins.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import boardgen

# This is NUM_BANK0_GPIOS. Pin indices are 0 to 29 (inclusive).
NUM_GPIOS = 30
NUM_GPIOS = None
# Up to 32 additional extended pins (e.g. via the wifi chip or io expanders).
NUM_EXT_GPIOS = 32
NUM_EXT_GPIOS = None


class Rp2Pin(boardgen.Pin):
Expand Down Expand Up @@ -108,12 +108,6 @@ def __init__(self):
enable_af=True,
)

# Pre-define the pins (i.e. don't require them to be listed in pins.csv).
for i in range(NUM_GPIOS):
self.add_cpu_pin("GPIO{}".format(i))
for i in range(NUM_EXT_GPIOS):
self.add_cpu_pin("EXT_GPIO{}".format(i))

# Provided by pico-sdk.
def cpu_table_size(self):
return "NUM_BANK0_GPIOS"
Expand All @@ -128,6 +122,31 @@ def print_source(self, out_source):
super().print_source(out_source)
self.print_cpu_locals_dict(out_source)

def extra_args(self, parser):
parser.add_argument("--num-gpios", type=int)
parser.add_argument("--num-ext-gpios", type=int)

def load_inputs(self, out_source):
global NUM_GPIOS
global NUM_EXT_GPIOS

# Needed by validate_cpu_pin_name
NUM_GPIOS = self.args.num_gpios
NUM_EXT_GPIOS = self.args.num_ext_gpios

if NUM_GPIOS is None:
raise boardgen.PinGeneratorError("Please pass num-gpios")

if NUM_EXT_GPIOS is None:
NUM_EXT_GPIOS = 0
# Pre-define the pins (i.e. don't require them to be listed in pins.csv).
for i in range(NUM_GPIOS):
self.add_cpu_pin("GPIO{}".format(i))
for i in range(NUM_EXT_GPIOS):
self.add_cpu_pin("EXT_GPIO{}".format(i))

super().load_inputs(out_source)


if __name__ == "__main__":
Rp2PinGenerator().main()
Loading
Loading