micropython/ports/rp2
Damien George 807c25d05a rp2: Change machine.I2S and rp2.DMA to use shared DMA IRQ handlers.
These separate drivers must share the DMA resource with each other.

Fixes issue #13380.

Signed-off-by: Damien George <damien@micropython.org>
2024-01-30 12:44:22 +11:00
..
boards ports: Add LED pin aliases for all Arduino boards. 2024-01-26 14:11:42 +11:00
btstack_inc
lwip_inc
mbedtls all: Update bindings, ports and tests for mbedtls v3.5.1. 2024-01-30 11:08:46 +11:00
modules all: Update Python formatting to ruff-format. 2023-11-03 13:30:41 +11:00
CMakeLists.txt rp2: Change machine.I2S and rp2.DMA to use shared DMA IRQ handlers. 2024-01-30 12:44:22 +11:00
Makefile ports: Fix handling of paths containing spaces in Makefiles. 2024-01-24 10:43:18 +11:00
README.md
cyw43_configport.h rp2: Switch rp2 and drivers to use new event functions. 2023-12-08 12:49:43 +11:00
fatfs_port.c
help.c
libm_extra.c rp2: Switch to locally provided math library. 2023-12-06 14:00:07 +11:00
machine_adc.c rp2/machine_adc: Refactor channel/pin validation code. 2023-11-03 18:20:31 +11:00
machine_bitstream.c
machine_i2c.c rp2: Add new NO_DEFAULT_PINS config options for i2c, spi, and uart. 2023-12-18 14:07:03 +11:00
machine_i2s.c rp2: Change machine.I2S and rp2.DMA to use shared DMA IRQ handlers. 2024-01-30 12:44:22 +11:00
machine_pin.c tools/boardgen.py: Add initial implementation of a common make-pins.py. 2023-11-03 14:06:27 +11:00
machine_pin.h tools/boardgen.py: Add initial implementation of a common make-pins.py. 2023-11-03 14:06:27 +11:00
machine_pin_cyw43.c
machine_pwm.c
machine_rtc.c extmod/modmachine: Clean up decls of machine types to use common ones. 2023-10-26 16:20:53 +11:00
machine_spi.c rp2: Provide direct memory access to PIO and SPI FIFOs via proxy arrays. 2024-01-07 18:27:01 +11:00
machine_timer.c
machine_uart.c rp2/machine_uart: Fix potential race condition in interrupt handling. 2024-01-23 13:11:53 +11:00
machine_wdt.c
main.c rp2/rp2_dma: Introduce a new rp2.DMA class for control over DMA xfers. 2023-12-22 13:04:51 +11:00
memmap_mp.ld
modmachine.c extmod/modmachine: Provide common implementation of disable/enable_irq. 2023-11-30 16:11:11 +11:00
modmachine.h extmod/modmachine: Provide common Python bindings for bootloader(). 2023-11-30 16:11:11 +11:00
modos.c
modrp2.c rp2/rp2_dma: Introduce a new rp2.DMA class for control over DMA xfers. 2023-12-22 13:04:51 +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
mpbthciport.c rp2/mpbthciport: Rework HCI polling timer to use soft_timer. 2023-11-29 16:23:52 +11:00
mpbthciport.h
mpbtstackport.c
mpconfigport.h rp2/mpconfigport: Allow MICROPY_PY_THREAD to be disabled by a board. 2024-01-16 11:42:47 +11:00
mphalport.c ports: Fix sys.stdout.buffer.write() return value. 2023-12-22 10:32:46 +11:00
mphalport.h rp2/mpconfigport: Allow MICROPY_PY_THREAD to be disabled by a board. 2024-01-16 11:42:47 +11:00
mpnetworkport.c rp2/mpnetworkport: Rework lwIP polling to use soft_timer. 2023-11-29 16:25:20 +11:00
mpnetworkport.h
mpnimbleport.c rp2/mpbthciport: Rework HCI polling timer to use soft_timer. 2023-11-29 16:23:52 +11:00
mpnimbleport.h
mpthreadport.c rp2/mpthreadport: Make result of thread.get_ident() a non-zero integer. 2024-01-17 08:02:16 +11:00
mpthreadport.h
msc_disk.c
mutex_extra.c rp2/mutex_extra: Implement additional mutex functions. 2024-01-03 15:59:02 +11:00
mutex_extra.h rp2/mutex_extra: Implement additional mutex functions. 2024-01-03 15:59:02 +11:00
pendsv.c
pendsv.h rp2/mpnetworkport: Rework lwIP polling to use soft_timer. 2023-11-29 16:25:20 +11:00
qstrdefsport.h
rp2_dma.c rp2: Change machine.I2S and rp2.DMA to use shared DMA IRQ handlers. 2024-01-30 12:44:22 +11:00
rp2_flash.c rp2/rp2_flash: Lockout second core only when doing flash erase/write. 2024-01-03 15:58:39 +11:00
rp2_pio.c rp2: Provide direct memory access to PIO and SPI FIFOs via proxy arrays. 2024-01-07 18:27:01 +11:00
uart.c
uart.h
usbd.c shared/tinyusb: Add a helper for hex string conversion. 2023-11-16 14:59:48 +11:00

README.md

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 different board other than a Rasoberry Pi Pico, then 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):
    global led
    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.