micropython/ports/rp2
iabdalkader f21c565583 rp2/machine_uart: Handle and clear UART RX timeout IRQ.
The pico-sdk 1.3.0 update in 97a7cc243b
introduced a change that broke RP2 Bluetooth UART, and possibly UART in
general, which stops working right after UART is initialized.  The commit
raspberrypi/pico-sdk@2622e9b enables the UART receive timeout (RTIM) IRQ,
which is asserted when the receive FIFO is not empty, and no more
characters are received for a period of time.

This commit makes sure the RTIM IRQ is handled and cleared in
uart_service_interrupt.
2021-12-14 14:59:39 +11:00
..
boards rp2/boards: Add PYBSTICK26 RP2040 board definition. 2021-11-25 21:05:21 +11:00
modules rp2/rp2_pio: Support exec with sideset. 2021-11-19 13:35:28 +11:00
CMakeLists.txt rp2/machine_bitstream: Implement the machine.bitstream driver. 2021-11-17 10:01:15 +11:00
Makefile rp2/Makefile: Add "submodules" target, to match other ports. 2021-08-19 22:54:57 +10:00
README.md rp2/Makefile: Add "submodules" target, to match other ports. 2021-08-19 22:54:57 +10:00
fatfs_port.c
machine_adc.c
machine_bitstream.c rp2/machine_bitstream: Implement the machine.bitstream driver. 2021-11-17 10:01:15 +11:00
machine_i2c.c
machine_i2s.c rp2/machine_i2s: Add I2S protocol support. 2021-11-13 12:27:42 +11:00
machine_pin.c
machine_pwm.c extmod/machine_pwm: Factor out machine.PWM bindings to common code. 2021-09-04 16:31:17 +10:00
machine_rtc.c
machine_spi.c
machine_timer.c
machine_uart.c rp2/machine_uart: Handle and clear UART RX timeout IRQ. 2021-12-14 14:59:39 +11:00
machine_wdt.c
main.c rp2/machine_i2s: Add I2S protocol support. 2021-11-13 12:27:42 +11:00
memmap_mp.ld
modmachine.c rp2/machine_bitstream: Implement the machine.bitstream driver. 2021-11-17 10:01:15 +11:00
modmachine.h rp2/machine_i2s: Add I2S protocol support. 2021-11-13 12:27:42 +11:00
modrp2.c
modrp2.h
moduos.c
modutime.c
mpbthciport.c rp2: Add support for bluetooth module using NimBLE. 2021-09-19 23:09:59 +10:00
mpbthciport.h rp2: Add support for bluetooth module using NimBLE. 2021-09-19 23:09:59 +10:00
mpconfigport.h rp2/machine_bitstream: Implement the machine.bitstream driver. 2021-11-17 10:01:15 +11:00
mphalport.c
mphalport.h rp2/machine_bitstream: Implement the machine.bitstream driver. 2021-11-17 10:01:15 +11: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
mpthreadport.h
qstrdefsport.h
rp2_flash.c rp2/rp2_flash: Disable IRQs while calling flash_erase/program. 2021-08-29 12:15:01 +10:00
rp2_pio.c rp2/rp2_pio: Support exec with sideset. 2021-11-19 13:35:28 +11:00
tusb_config.h
tusb_port.c
uart.c
uart.h

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.

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.