circuitpython/ports/rp2
Damien George b5fcb33eaa py/mpconfig: Enable CRYPTOLIB, HASHLIB_MD5, HASHLIB_SHA1 if SSL enabled.
This commit unifies the configuration of MICROPY_PY_CRYPTOLIB,
MICROPY_PY_HASHLIB_MD5 and MICROPY_PY_HASHLIB_SHA1, so they are enabled by
default if MICROPY_PY_SSL is enabled.  This matches the existing
configuration of most of the ports.

With this change, all ports remain the same except:
- reneses-ra now enables MICROPY_PY_CRYPTOLIB, MICROPY_PY_HASHLIB_MD5 and
  MICROPY_PY_HASHLIB_SHA1.
- rp2 now enables MICROPY_PY_HASHLIB_MD5.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-19 21:10:00 +10:00
..
boards py/mpconfig: Enable CRYPTOLIB, HASHLIB_MD5, HASHLIB_SHA1 if SSL enabled. 2025-08-19 21:10:00 +10:00
btstack_inc rp2: Add Bluetooth support via cyw43. 2023-06-14 22:20:20 +10:00
lwip_inc extmod/lwip-include: Factor common lwIP config into lwipopts_common.h. 2025-01-29 12:36:27 +11:00
mbedtls rp2: Integrate RP2350 and use aon_timer instead of rtc API. 2024-10-15 12:07:59 +11:00
modules rp2/rp2_pio: Fix use of PIO2 in prog data structure. 2025-08-01 22:38:00 +10:00
tools_patch rp2: Add temporary workaround for GCC 15.1 build failure. 2025-05-09 18:31:25 +10:00
clocks_extra.c rp2/modmachine: Do not use deprecated XOSC_MHZ and XOSC_KHZ. 2025-07-25 11:25:24 +10:00
clocks_extra.h rp2/clocks_extra: Update runtime_clocks_init based on new pico-sdk. 2024-10-15 12:15:48 +11:00
CMakeLists.txt rp2/CMakeLists.txt: Fix flash size check logic. 2025-08-01 16:20:49 +10:00
cyw43_configport.h rp2,extmod/cyw43: Move the LWIP responder fix into common CYW43 config. 2025-05-08 15:32:05 +10:00
datetime_patch.c rp2/datetime_patch: Fix year and month offset for mktime wrapper. 2024-10-24 11:22:59 +11:00
fatfs_port.c rp2: Integrate RP2350 and use aon_timer instead of rtc API. 2024-10-15 12:07:59 +11:00
help.c ports: Standardise docs link in help text. 2023-06-02 11:48:46 +10:00
libm_extra.c rp2: Switch to locally provided math library. 2023-12-06 14:00:07 +11:00
machine_adc.c rp2/machine_adc: Add ADC support for RP2350B. 2024-10-15 12:16:46 +11:00
machine_bitstream.c rp2/machine_bitstream: Tweak MP_HAL_BITSTREAM_NS_OVERHEAD for RP2350. 2025-01-11 14:23:51 +11:00
machine_i2c.c rp2/machine_i2c: Factor default pin macros to header file. 2025-08-01 23:03:17 +10:00
machine_i2c.h rp2/machine_i2c: Factor default pin macros to header file. 2025-08-01 23:03:17 +10:00
machine_i2c_target.c rp2/machine_i2c_target: Implement I2CTarget class. 2025-08-01 23:03:17 +10:00
machine_i2s.c rp2/machine_i2s: Deinit all active I2S instances on soft reset. 2024-08-07 12:01:34 +10:00
machine_pin.c rp2/machine_pin: Fix simulated open drain with more than 32 GPIOs. 2025-05-22 00:08:27 +10:00
machine_pin.h rp2/machine_pin: Move decl of machine_pin_obj_table to public header. 2024-10-15 12:09:48 +11:00
machine_pin_cyw43.c rp2: Add exception text wrappers. 2025-04-22 11:29:36 +10:00
machine_pwm.c rp2/machine_pwm: Add RP2350 slices to machine.PWM. 2024-10-15 12:19:52 +11:00
machine_rtc.c rp2: Integrate RP2350 and use aon_timer instead of rtc API. 2024-10-15 12:07:59 +11:00
machine_spi.c rp2/machine_spi: Allow MISO to be unspecified. 2025-03-26 17:08:08 +11:00
machine_timer.c rp2/machine_timer: Support hard IRQ timer callbacks. 2025-06-16 12:35:51 +01:00
machine_uart.c rp2/machine_uart: Fix unintended UART buffer allocation on init(). 2025-03-27 11:37:57 +11:00
machine_wdt.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
main.c rp2/machine_i2c_target: Implement I2CTarget class. 2025-08-01 23:03:17 +10:00
Makefile rp2/Makefile: Add deploy target that uses picotool load. 2025-05-09 12:01:50 +10:00
memmap_mp_rp2040.ld rp2: Make FLASH LENGTH match PICO_FLASH_SIZE_BYTES in .ld files. 2025-05-28 11:02:45 +10:00
memmap_mp_rp2350.ld rp2: Make FLASH LENGTH match PICO_FLASH_SIZE_BYTES in .ld files. 2025-05-28 11:02:45 +10:00
modmachine.c rp2/modmachine: Do not use deprecated XOSC_MHZ and XOSC_KHZ. 2025-07-25 11:25:24 +10:00
modmachine.h rp2/machine_uart: Implement a Python UART IRQ handler. 2024-08-29 16:27:43 +10:00
modos.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
modrp2.c rp2/modrp2: Fix rp2.bootsel_button() function for RP2350. 2025-03-13 13:54:43 +11:00
modrp2.h rp2/rp2_dma: Introduce a new rp2.DMA class for control over DMA xfers. 2023-12-22 13:04:51 +11:00
modtime.c extmod/modtime: Move tuple creation to common localtime implementation. 2025-08-15 12:09:13 +10:00
mpbthciport.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
mpbthciport.h rp2: Add Bluetooth support via cyw43. 2023-06-14 22:20:20 +10:00
mpbtstackport.c rp2: Add Bluetooth support via cyw43. 2023-06-14 22:20:20 +10:00
mpconfigport.h py/mpconfig: Enable CRYPTOLIB, HASHLIB_MD5, HASHLIB_SHA1 if SSL enabled. 2025-08-19 21:10:00 +10:00
mphalport.c rp2: Use pico-sdk alarm pool instead of soft timer for sleep. 2025-05-12 16:24:51 +10:00
mphalport.h rp2/machine_pin: Fix simulated open drain with more than 32 GPIOs. 2025-05-22 00:08:27 +10:00
mpnetworkport.c rp2/mpnetworkport: Deregister all sys timeouts when netif is removed. 2025-07-17 13:39:10 +10:00
mpnetworkport.h stm32: Update to use the open-source lib version of cyw43-driver. 2023-03-01 01:27:12 +11:00
mpnimbleport.c rp2/mpbthciport: Rework HCI polling timer to use soft_timer. 2023-11-29 16:23:52 +11:00
mpnimbleport.h rp2: Add support for bluetooth module using NimBLE. 2021-09-19 23:09:59 +10:00
mpthreadport.c rp2/pendsv: Account for PendSV running on both cores, and without CYW43. 2025-03-27 00:07:50 +11:00
mpthreadport.h rp2: Migrate to the new mp_thread_recursive_mutex_t. 2025-02-03 15:02:02 +11:00
msc_disk.c rp2/msc_disk: Allow configuring the USB MSC inquiry response. 2023-09-29 16:36:45 +10:00
mutex_extra.c rp2: Fix power consumption when sleeping with a timeout. 2024-07-23 16:01:42 +10:00
mutex_extra.h rp2: Fix power consumption when sleeping with a timeout. 2024-07-23 16:01:42 +10:00
pendsv.c rp2/pendsv: Account for PendSV running on both cores, and without CYW43. 2025-03-27 00:07:50 +11:00
pendsv.h rp2/pendsv: Account for PendSV running on both cores, and without CYW43. 2025-03-27 00:07:50 +11:00
qstrdefsport.h rp2: Add new port to Raspberry Pi RP2 microcontroller. 2021-01-30 00:42:29 +11:00
README.md rp2/Makefile: Add deploy target that uses picotool load. 2025-05-09 12:01:50 +10:00
rp2_dma.c rp2/rp2_dma: Fix default value used in pack_ctrl on RP2350. 2025-05-09 12:05:04 +10:00
rp2_flash.c rp2/rp2_flash: Add binary info for ROMFS. 2025-08-02 00:36:50 +10:00
rp2_flash.h rp2/rp2_flash: Configure optimal flash timings. 2025-04-08 11:01:14 +10:00
rp2_pio.c rp2/rp2_pio: Fix use of PIO2 in prog data structure. 2025-08-01 22:38:00 +10:00
rp2_psram.c rp2: Add support for PSRAM with auto-detection. 2025-04-08 10:56:59 +10:00
rp2_psram.h rp2: Add support for PSRAM with auto-detection. 2025-04-08 10:56:59 +10:00
uart.c all: Rename mp_keyboard_interrupt to mp_sched_keyboard_interrupt. 2021-04-30 15:13:43 +10:00
uart.h rp2: Add new port to Raspberry Pi RP2 microcontroller. 2021-01-30 00:42:29 +11:00
usbd.c shared/tinyusb: Add a helper for hex string conversion. 2023-11-16 14:59:48 +11:00

The RP2 port

This is a port of MicroPython to the Raspberry Pi RP2 series of microcontrollers. Currently supported features are:

  • REPL over USB VCP, and optionally over UART (on GP0/GP1).
  • Filesystem on the internal flash, using littlefs2.
  • Support for native code generation and inline assembler.
  • time module with sleep, time and ticks functions.
  • os module with VFS support.
  • machine module with the following classes: Pin, ADC, PWM, I2C, SPI, SoftI2C, SoftSPI, Timer, UART, WDT.
  • rp2 module with programmable IO (PIO) support.

See the examples/rp2/ directory for some example code.

Building

The MicroPython cross-compiler must be built first, which will be used to pre-compile (freeze) built-in Python code. This cross-compiler is built and run on the host machine using:

$ make -C mpy-cross

This command should be executed from the root directory of this repository. All other commands below should be executed from the ports/rp2/ directory.

Building of the RP2 firmware is done entirely using CMake, although a simple Makefile is also provided as a convenience. To build the firmware run (from this directory):

$ make submodules
$ make clean
$ make

You can also build the standard CMake way. The final firmware is found in the top-level of the CMake build directory (build by default) and is called firmware.uf2.

If you are using a board other than a Raspberry Pi Pico, you should pass the board name to the build; e.g. for Raspberry Pi Pico W:

$ make BOARD=RPI_PICO_W submodules
$ make BOARD=RPI_PICO_W clean
$ make BOARD=RPI_PICO_W

Deploying firmware to the device

Firmware can be deployed to the device by putting it into bootloader mode (hold down BOOTSEL while powering on or resetting) and then either copying firmware.uf2 to the USB mass storage device that appears, or using picotool load -x firmware.elf. The latter command can be accessed conveniently via make deploy.

If MicroPython is already installed then the bootloader can be entered by executing import machine; machine.bootloader() at the REPL.

Sample code

The following samples can be easily run on the board by entering paste mode with Ctrl-E at the REPL, then cut-and-pasting the sample code to the REPL, then executing the code with Ctrl-D.

Blinky

This blinks the on-board LED on the Pico board at 1.25Hz, using a Timer object with a callback.

from machine import Pin, Timer
led = Pin(25, Pin.OUT)
tim = Timer()
def tick(timer):
    led.toggle()

tim.init(freq=2.5, mode=Timer.PERIODIC, callback=tick)

PIO blinky

This blinks the on-board LED on the Pico board at 1Hz, using a PIO peripheral and PIO assembler to directly toggle the LED at the required rate.

from machine import Pin
import rp2

@rp2.asm_pio(set_init=rp2.PIO.OUT_LOW)
def blink_1hz():
    # Turn on the LED and delay, taking 1000 cycles.
    set(pins, 1)
    set(x, 31)                  [6]
    label("delay_high")
    nop()                       [29]
    jmp(x_dec, "delay_high")

    # Turn off the LED and delay, taking 1000 cycles.
    set(pins, 0)
    set(x, 31)                  [6]
    label("delay_low")
    nop()                       [29]
    jmp(x_dec, "delay_low")

# Create StateMachine(0) with the blink_1hz program, outputting on Pin(25).
sm = rp2.StateMachine(0, blink_1hz, freq=2000, set_base=Pin(25))
sm.active(1)

See the examples/rp2/ directory for further example code.