You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Phil Howard d2e33fe309 rp2/machine_i2s: Deinit all active I2S instances on soft reset. 3 months ago
..
boards rp2/boards/PIMORONI_TINY2040: Add an 8MB variant to Tiny 2040. 3 months ago
btstack_inc rp2: Add Bluetooth support via cyw43. 1 year ago
lwip_inc rp2/lwip_inc: Enable IPv6 per default on rp2 port. 4 months ago
mbedtls rp2/mbedtls: Remove config options that are now in the common settings. 4 months ago
modules ports: Use vfs module instead of os. 9 months ago
CMakeLists.txt rp2/CMakeLists.txt: Add MICROPY_DEF_BOARD to compile definitions. 3 months ago
Makefile ports: Fix handling of paths containing spaces in Makefiles. 10 months ago
README.md rp2/README: Fix typo, improve sentence about building with other boards. 7 months ago
clocks_extra.c rp2/clocks_extra: Implement custom clocks_init function. 5 months ago
clocks_extra.h rp2/clocks_extra: Implement custom clocks_init function. 5 months ago
cyw43_configport.h rp2/cyw43_configport: Make cyw43_delay_ms() a busy loop. 5 months ago
fatfs_port.c rp2/fatfs_port: Fix the modification date of files. 2 years ago
help.c ports: Standardise docs link in help text. 1 year ago
libm_extra.c rp2: Switch to locally provided math library. 11 months ago
machine_adc.c rp2/machine_adc: Initialise ADC GPIO when a Pin is referenced by int. 4 months ago
machine_bitstream.c rp2/machine_bitstream: Implement the machine.bitstream driver. 3 years ago
machine_i2c.c all: Remove the "STATIC" macro and just use "static" instead. 8 months ago
machine_i2s.c rp2/machine_i2s: Deinit all active I2S instances on soft reset. 3 months ago
machine_pin.c all: Remove the "STATIC" macro and just use "static" instead. 8 months ago
machine_pin.h tools/boardgen.py: Add initial implementation of a common make-pins.py. 1 year ago
machine_pin_cyw43.c rp2/machine_pin: Add support for named pins and alternate functions. 2 years ago
machine_pwm.c all: Remove the "STATIC" macro and just use "static" instead. 8 months ago
machine_rtc.c all: Remove the "STATIC" macro and just use "static" instead. 8 months ago
machine_spi.c all: Remove the "STATIC" macro and just use "static" instead. 8 months ago
machine_timer.c all: Remove the "STATIC" macro and just use "static" instead. 8 months ago
machine_uart.c rp2: Replace CMSIS funcs with Pico SDK equivalents. 4 months ago
machine_wdt.c all: Remove the "STATIC" macro and just use "static" instead. 8 months ago
main.c rp2/machine_i2s: Deinit all active I2S instances on soft reset. 3 months ago
memmap_mp.ld rp2/memmap_mp.ld: Lower the minimum GC heap to 32K. 3 months ago
modmachine.c rp2: Stop machine.idle() blocking indefinitely. 4 months ago
modmachine.h rp2/machine_i2s: Deinit all active I2S instances on soft reset. 3 months ago
modos.c all: Remove the "STATIC" macro and just use "static" instead. 8 months ago
modrp2.c all: Remove the "STATIC" macro and just use "static" instead. 8 months ago
modrp2.h rp2/rp2_dma: Introduce a new rp2.DMA class for control over DMA xfers. 11 months ago
modtime.c all: Remove the "STATIC" macro and just use "static" instead. 8 months ago
mpbthciport.c all: Remove the "STATIC" macro and just use "static" instead. 8 months ago
mpbthciport.h rp2: Add Bluetooth support via cyw43. 1 year ago
mpbtstackport.c rp2: Add Bluetooth support via cyw43. 1 year ago
mpconfigport.h rp2: Refactor soft timer to use hardware timer alarm. 5 months ago
mphalport.c rp2: Fix wakeup from WFE on core1. 4 months ago
mphalport.h rp2: Replace CMSIS funcs with Pico SDK equivalents. 4 months ago
mpnetworkport.c rp2: Replace CMSIS funcs with Pico SDK equivalents. 4 months ago
mpnetworkport.h stm32: Update to use the open-source lib version of cyw43-driver. 2 years ago
mpnimbleport.c rp2/mpbthciport: Rework HCI polling timer to use soft_timer. 11 months ago
mpnimbleport.h rp2: Add support for bluetooth module using NimBLE. 3 years ago
mpthreadport.c rp2: Fix wakeup from WFE on core1. 4 months ago
mpthreadport.h rp2: Fix wakeup from WFE on core1. 4 months ago
msc_disk.c rp2/msc_disk: Allow configuring the USB MSC inquiry response. 1 year ago
mutex_extra.c rp2: Fix power consumption when sleeping with a timeout. 4 months ago
mutex_extra.h rp2: Fix power consumption when sleeping with a timeout. 4 months ago
pendsv.c rp2: Fix power consumption when sleeping with a timeout. 4 months ago
pendsv.h rp2: Support calling pendsv_suspend/resume from core 1. 5 months ago
qstrdefsport.h rp2: Add new port to Raspberry Pi RP2 microcontroller. 4 years ago
rp2_dma.c all: Remove the "STATIC" macro and just use "static" instead. 8 months ago
rp2_flash.c all: Remove the "STATIC" macro and just use "static" instead. 8 months ago
rp2_pio.c rp2/rp2_pio: Make PIO IRQ handlers have lazy initialisation. 3 months ago
uart.c all: Rename mp_keyboard_interrupt to mp_sched_keyboard_interrupt. 4 years ago
uart.h rp2: Add new port to Raspberry Pi RP2 microcontroller. 4 years ago
usbd.c shared/tinyusb: Add a helper for hex string conversion. 12 months ago

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 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.