micropython/ports/rp2
Jim Mussared 203dae41fb all: Update all manifest.py files to use new features.
Changes in this commit:
- Manifest include's now use the directory path where possible (no longer
  necessary to include the manifest.py file explicitly).
- Add manifest.py for all drivers and components that are referenced by
  port/board manifests.
- Replace all uses of freeze() with package()/module(), except for port and
  board modules.
- Use opt=3 everywhere, for consistency and to reduce code size.
- Use require() instead of include() for all micropython-lib references.
- Remove support for optional board-level manifest.py in mimxrt port, to
  make it behave the same as other ports (the board must set
  FROZEN_MANIFEST to a custom manifest.py, which can optionally include the
  default, port-level manifest).
- Also reinstates modules that were accidentally removed from the esp8266
  512k build in fbe9417b90.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Damien George <damien@micropython.org>
2022-09-05 18:43:18 +10:00
..
boards all: Update all manifest.py files to use new features. 2022-09-05 18:43:18 +10:00
lwip_inc rp2/lwip_inc: Enable lwIP status callback. 2022-06-30 16:03:21 +10:00
mbedtls rp2/mbedtls: Fix missing time.h include. 2022-08-31 00:22:34 +10:00
modules rp2: Add USB MSC support. 2022-03-09 00:38:07 +11:00
CMakeLists.txt rp2: Correctly determine path to arm-none-eabi-size. 2022-08-11 14:23:28 +10:00
Makefile rp2/Makefile: Always use cmake to discover submodules. 2022-08-03 00:05:54 +10:00
README.md rp2: Integrate CYW43xx WiFi driver. 2022-06-30 17:03:51 +10:00
cyw43_configport.h rp2/cyw43_configport: Add event hook into cyw43_delay_ms. 2022-07-27 13:42:21 +10:00
fatfs_port.c rp2: Enable VfsFat class for FAT filesystem support. 2021-03-11 17:56:21 +11:00
machine_adc.c all: Use mp_obj_malloc everywhere it's applicable. 2022-05-03 22:28:14 +10:00
machine_bitstream.c rp2/machine_bitstream: Implement the machine.bitstream driver. 2021-11-17 10:01:15 +11:00
machine_i2c.c rp2/machine_i2c: Use soft I2C only for len=0, and increase timeout. 2022-01-21 15:10:29 +11:00
machine_i2s.c rp2: Use MP_REGISTER_ROOT_POINTER(). 2022-07-18 13:50:34 +10:00
machine_pin.c rp2: Use MP_REGISTER_ROOT_POINTER(). 2022-07-18 13:50:34 +10:00
machine_pwm.c rp2/machine_pwm: Keep duty value when changing the frequency. 2022-01-06 13:52:45 +11:00
machine_rtc.c all: Update to point to files in new shared/ directory. 2021-07-12 17:08:10 +10:00
machine_spi.c rp2/machine_spi: Add mp_hal_get_spi_obj helper function. 2022-08-10 14:05:02 +10:00
machine_timer.c rp2: Add new port to Raspberry Pi RP2 microcontroller. 2021-01-30 00:42:29 +11:00
machine_uart.c rp2/machine_uart: Implement uart.flush() and uart.txdone(). 2022-08-31 00:17:54 +10:00
machine_wdt.c rp2/machine_wdt: Check for the maximum timeout value of watchdog. 2022-08-23 16:26:29 +10:00
main.c rp2: Mark gc_heap NOLOAD for faster boot. 2022-08-11 14:16:29 +10:00
memmap_mp.ld rp2: Mark gc_heap NOLOAD for faster boot. 2022-08-11 14:16:29 +10:00
modmachine.c rp2/modmachine: Implement lightsleep() with optional sleep period. 2022-06-30 11:40:17 +10:00
modmachine.h rp2/modmachine: Allow boards to provide custom bootloader code. 2022-06-17 13:38:21 +10:00
modrp2.c rp2: Integrate CYW43xx WiFi driver. 2022-06-30 17:03:51 +10:00
modrp2.h rp2: Add new port to Raspberry Pi RP2 microcontroller. 2021-01-30 00:42:29 +11:00
moduos.c py/objstr: Split mp_obj_str_from_vstr into bytes/str versions. 2022-08-26 16:43:55 +10:00
modutime.c all: Remove third argument to MP_REGISTER_MODULE. 2022-06-02 16:31:37 +10:00
mpbthciport.c rp2/mpbthciport: Remove mp_bthci_uart from set of root pointers. 2022-07-21 16:19:42 +10:00
mpbthciport.h rp2: Add support for bluetooth module using NimBLE. 2021-09-19 23:09:59 +10:00
mpconfigport.h ports: Remove unused mp_type_{fileio/textio} macros in mpconfigport.h. 2022-07-26 18:07:22 +10:00
mphalport.c rp2/mphalport: Fix missing storage_read_blocks symbol in debug build. 2022-07-12 16:56:38 +10:00
mphalport.h rp2/machine_spi: Add mp_hal_get_spi_obj helper function. 2022-08-10 14:05:02 +10:00
mpnetworkport.c rp2: Integrate CYW43xx WiFi driver. 2022-06-30 17:03:51 +10:00
mpnimbleport.c rp2: Add support for bluetooth module using NimBLE. 2021-09-19 23:09:59 +10:00
mpnimbleport.h rp2: Add support for bluetooth module using NimBLE. 2021-09-19 23:09:59 +10:00
mpthreadport.c rp2: Make atomic sections suspend the other core (if active). 2022-07-12 16:20:21 +10:00
mpthreadport.h rp2/mpthreadport: Add mp_thread_deinit to reset core1 on soft reset. 2021-05-09 00:08:30 +10:00
msc_disk.c rp2: Add USB MSC support. 2022-03-09 00:38:07 +11:00
pendsv.c rp2: Integrate CYW43xx WiFi driver. 2022-06-30 17:03:51 +10:00
pendsv.h rp2: Integrate CYW43xx WiFi driver. 2022-06-30 17:03:51 +10:00
qstrdefsport.h rp2: Add new port to Raspberry Pi RP2 microcontroller. 2021-01-30 00:42:29 +11:00
rp2_flash.c rp2/rp2_flash: Add asserts for size of flash filesystem partition. 2022-06-30 16:03:21 +10:00
rp2_pio.c rp2/rp2_pio: Fix StateMachine.restart when PIO program is shared. 2022-07-26 02:00:01 +10:00
tusb_config.h rp2: Add USB MSC support. 2022-03-09 00:38:07 +11:00
tusb_port.c rp2: Add USB MSC support. 2022-03-09 00:38:07 +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

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.
  • utime module with sleep, time and ticks functions.
  • uos 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=PICO_W submodules
$ make BOARD=PICO_W clean
$ make BOARD=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.