micropython/ports/rp2
Peter Harper 4af09de19c rp2/boards/make-pins.py: Pass num-gpios/num-ext-gpios into make-pins.
NUM_GPIOS amd NUM_EXT_GPIOS are currently hardcoded in make-pins.py, which
makes it difficult to support SoCs with different pin count.

This commit generalises make-pins.py by passing in the pin count in via the
new arguments `--num-gpios` and `--num-ext-gpios`.  These default to the
current values supported by Pico, namely 30/10.  This can be changed with
PICO_NUM_GPIOS and PICO_NUM_EXT_GPIOS in `mpconfigboard.cmake`.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-15 12:12:04 +11:00
..
boards rp2/boards/make-pins.py: Pass num-gpios/num-ext-gpios into make-pins. 2024-10-15 12:12:04 +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: Implement custom clocks_init function. 2024-06-25 16:25:06 +10:00
clocks_extra.h rp2/clocks_extra: Implement custom clocks_init function. 2024-06-25 16:25:06 +10:00
CMakeLists.txt rp2/boards/make-pins.py: Pass num-gpios/num-ext-gpios into make-pins. 2024-10-15 12:12:04 +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
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: Initialise ADC GPIO when a Pin is referenced by int. 2024-07-04 11:50:28 +10:00
machine_bitstream.c rp2/machine_bitstream: Implement the machine.bitstream driver. 2021-11-17 10:01:15 +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_cyw43.c rp2/machine_pin_cyw43: Include check for CYW43_GPIO. 2024-09-19 12:58:43 +10:00
machine_pin.c rp2/machine_pin: Move decl of machine_pin_obj_table to public header. 2024-10-15 12:09:48 +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_pwm.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +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: Fix dropped UART REPL bytes on soft reset. 2024-09-26 23:43:11 +10: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: Integrate RP2350 and use aon_timer instead of rtc API. 2024-10-15 12:07:59 +11:00
Makefile ports: Fix handling of paths containing spaces in Makefiles. 2024-01-24 10:43:18 +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: Integrate RP2350 and use aon_timer instead of rtc API. 2024-10-15 12:07:59 +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: Set MCU name for RP2350. 2024-10-15 11:51:56 +11:00
mphalport.c rp2: Integrate RP2350 and use aon_timer instead of rtc API. 2024-10-15 12:07:59 +11:00
mphalport.h rp2: Add support for 48-pin RP2350 variant. 2024-10-15 12:08:39 +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: Integrate RP2350 and use aon_timer instead of rtc API. 2024-10-15 12:07:59 +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: Fix typo, improve sentence about building with other boards. 2024-04-22 10:20:54 +10: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):
    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.