circuitpython/ports/rp2
iabdalkader 309aa26811 rp2/mpconfigport: Switch FATFS LFN to type 2.
LFN type 2 uses the stack to allocate the internal working buffer for LFN,
which is thread-safe and saves about 512 bytes of BSS memory (at the
expense of needing that much memory on the stack).

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-12-10 11:04:49 +11:00
..
boards rp2/boards/RPI_PICO2: Add new RPI_PICO2 board definition. 2024-10-15 12:20:12 +11:00
btstack_inc rp2: Add Bluetooth support via cyw43. 2023-06-14 22:20:20 +10:00
lwip_inc ports: Fix lwIP config setting to disable DHCP ARP check. 2024-09-26 23:00:42 +10:00
mbedtls rp2: Integrate RP2350 and use aon_timer instead of rtc API. 2024-10-15 12:07:59 +11:00
modules rp2/modules: Fix FatFS boot script to detect invalid FAT filesystem. 2024-09-19 13:04:48 +10:00
clocks_extra.c rp2/clocks_extra: Update runtime_clocks_init based on new pico-sdk. 2024-10-15 12:15:48 +11: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: Workaround pico_aon_timer timezone binary size increase. 2024-10-15 12:18:53 +11:00
cyw43_configport.h rp2/cyw43_configport: Define CYW43_PRINTF to mp_printf to get messages. 2024-10-03 12:12:18 +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: Implement bitstream for RISC-V using mcycle. 2024-10-15 12:18:51 +11:00
machine_i2c.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11: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: Generalise gpio_irq handler for pins >32. 2024-10-15 12:14:59 +11: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/machine_pin_cyw43: Include check for CYW43_GPIO. 2024-09-19 12:58:43 +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 all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
machine_timer.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
machine_uart.c rp2/machine_uart: Make it so TX is done only when no longer busy. 2024-10-22 10:17:05 +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/main: Set CPU frequency to default for the MCU. 2024-10-15 12:20:12 +11:00
Makefile rp2/Makefile: Allow CMAKE_ARGS to be set by user. 2024-10-15 12:16:46 +11:00
memmap_mp_rp2040.ld rp2: Update custom linker scripts for new pico-sdk. 2024-10-15 11:51:56 +11:00
memmap_mp_rp2350.ld rp2: Update custom linker scripts for new pico-sdk. 2024-10-15 11:51:56 +11:00
modmachine.c rp2/modmachine: Re-sync time_ns offset when coming out of lightsleep. 2024-10-24 23:24:09 +11: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 all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +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 rp2: Integrate RP2350 and use aon_timer instead of rtc API. 2024-10-15 12:07:59 +11: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 rp2/mpconfigport: Switch FATFS LFN to type 2. 2024-12-10 11:04:49 +11:00
mphalport.c rp2/mphalport: Implement mp_hal_ticks_cpu for RISCV using mcycle. 2024-10-15 12:18:32 +11:00
mphalport.h rp2/mphalport: Implement mp_hal_ticks_cpu for RISCV using mcycle. 2024-10-15 12:18:32 +11:00
mpnetworkport.c rp2: Integrate RP2350 and use aon_timer instead of rtc API. 2024-10-15 12:07:59 +11: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: Fix wakeup from WFE on core1. 2024-07-23 16:02:59 +10:00
mpthreadport.h rp2: Fix wakeup from WFE on core1. 2024-07-23 16:02:59 +10: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: Add support for RP2350 in RISCV mode. 2024-10-15 12:16:46 +11:00
pendsv.h rp2: Support calling pendsv_suspend/resume from core 1. 2024-05-31 16:46:27 +10:00
qstrdefsport.h rp2: Add new port to Raspberry Pi RP2 microcontroller. 2021-01-30 00:42:29 +11:00
README.md rp2/README: Remove redundant global statement from example code. 2024-10-28 11:16:04 +11:00
rp2_dma.c rp2/rp2_dma: Generalise DMA for RP2350. 2024-10-15 11:57:06 +11:00
rp2_flash.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
rp2_pio.c rp2/rp2_pio: Add support for RP2350A/B variants in PIO interface. 2024-10-15 12:09:48 +11: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 copying firmware.uf2 to the USB mass storage device that appears.

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.