Patch release for mpremote, rp2 IGMP, esp32 PWM, SDCard, and AP channel
This is a patch release containing the following commits:
- tools/mpremote: fix UnboundLocalError in Transport.fs_writefile()
- esp32/machine_pwm: use IDF functions to calculate resolution correctly
- pic16bit: make it build with recent XC16 versions
- py/objdeque: fix buffer overflow in deque_subscr
- extmod/modlwip: fix IGMP address type when IPv6 is enabled
- esp32/machine_pwm: restore PWM support for ESP-IDF v5.0.x and v5.1.x
- esp32: workaround native code execution crash on ESP32-S2
- tools/mpremote: make sure stdout and stderr output appear in order
- tools/mpremote: add test for forced copy
- tools/mpremote: support trailing slash on dest for non-recursive copy
- esp32/modsocket: fix getaddrinfo hints to set AI_CANONNAME
- extmod/vfs_blockdev: support bool return from Python read/write blocks
- extmod/network_cyw43: fix isconnected() result on AP interface
- extmod/network_cyw43: fix uninitialised variable in status('stations')
- extmod/network_cyw43: allow configuring active AP interface
- esp32: fix setting WLAN channel in AP mode
- esp32: use hardware version for touchpad macro defines
- esp32: fix machine.TouchPad startup on ESP32-S2 and S3
- extmod/modframebuf: fix 0 radius bug in FrameBuffer.ellipse
- nrf/drivers/ticker: reset slow ticker callback count on soft reboot
- py/objfloat: workaround non-constant NAN definition on Windows MSVC
# Conflicts:
# .github/workflows/code_formatting.yml
# .github/workflows/code_size.yml
# .github/workflows/commit_formatting.yml
# .github/workflows/docs.yml
# .github/workflows/examples.yml
# .github/workflows/mpremote.yml
# .github/workflows/mpy_format.yml
# .github/workflows/ports.yml
# .github/workflows/ports_cc3200.yml
# .github/workflows/ports_esp32.yml
# .github/workflows/ports_esp8266.yml
# .github/workflows/ports_mimxrt.yml
# .github/workflows/ports_nrf.yml
# .github/workflows/ports_powerpc.yml
# .github/workflows/ports_renesas-ra.yml
# .github/workflows/ports_rp2.yml
# .github/workflows/ports_samd.yml
# .github/workflows/ports_stm32.yml
# .github/workflows/ports_unix.yml
# .github/workflows/ports_webassembly.yml
# .github/workflows/ports_windows.yml
# .github/workflows/ports_zephyr.yml
# README.md
# extmod/extmod.mk
# ports/esp32/.gitignore
# ports/esp32/CMakeLists.txt
# ports/esp32/boards/ESP32_GENERIC/mpconfigboard.cmake
# ports/esp32/boards/sdkconfig.base
# ports/esp32/main.c
# ports/esp32/main/CMakeLists.txt
# ports/stm32/Makefile
# ports/stm32/boards/STM32F7DISC/mpconfigboard.mk
# ports/stm32/boards/manifest.py
# ports/stm32/boards/stm32f7xx_hal_conf_base.h
# ports/unix/Makefile
# ports/unix/variants/manifest.py
# ports/unix/variants/mpconfigvariant_common.h
# ports/windows/mpconfigport.h
# py/makeqstrdata.py
# py/qstr.c
# py/qstr.h
# tools/ci.sh
# tools/makemanifest.py
# tools/mpy-tool.py
3.6 KiB
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.
timemodule with sleep, time and ticks functions.osmodule with VFS support.machinemodule with the following classes:Pin,ADC,PWM,I2C,SPI,SoftI2C,SoftSPI,Timer,UART,WDT.rp2module 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.
Troubleshooting
If you experience unstable behaviour, it is worth checking the value of MICROPY_HW_FLASH_STORAGE_BASE against the value of __flash_binary_end from the firmware.elf.map file. If the storage base is lower than the binary end, parts of the firmware will be overwritten when the micro- python filesystem is initialised.