Dynamic USB devices, improved webassembly porting, openamp, tls, vfs modules
This version of MicroPython adds support for dynamic USB devices defined in Python, adds new openamp, tls and vfs modules, completely reconfigures webassembly to add a proxy between JavaScript and Python, and implements significant code size optimizations for frozen modules. There are many other enhancements and bug fixes.
After a lot of design, development and testing, MicroPython now fully supports user-defined USB devices. The interface is implemented through the new machine.USBDevice class, which allows users to specify USB descriptors and implement Python callbacks for USB endpoint transfers. With it, any USB device can be implemented in pure Python. While the machine.USBDevice interface is low-level and complete, there is a higher-level USB library in the microython library that makes it easier to implement a variety of devices, such as keyboards, mice, MIDI and serial CDC. This functionality is currently available on rp2 and samd, and will be ported to other hardware in the future.
Support for the OpenAMP (asymmetric multiprocessing) protocol has been added through the new OpenAMP module. This allows MicroPython to control other CPU cores in the system, load and start processes, and communicate with them through the terminal. This functionality is currently available on mimxrt and stm32.
Two new modules have been added: vfs and tls . The vfs module contains all vfs (virtual file system) related functions and classes, such as mount, umount, and VfsFat. These were originally in the os module, but using them in os was incompatible with CPython, so they were moved to their own dedicated module. They are currently still present in the os module, but will eventually be removed from it, so it is recommended to use the vfs module from now on. Similarly, the new tls module is an evolution of the ssl module, so all existing functionality in ssl has been moved to the tls module. This was done because MicroPython's SSL interface is increasingly different from CPython's, and moving SSL/TLS functionality into the new tls module gives it room to grow and gain new features that are useful for embedded applications. Compatibility with normal Python is still retained through the pure Python implementation of the ssl module. One of the new features in the new tls module is the ability to register certificate verification callbacks.
Other additions include more methods on deque objects, making them double-ended and supporting iteration, and support for half-float 'e' formats in struct.pack/struct.unpack. Dynamic native modules have exposed some additional runtime methods, and the .mpy subversion has been increased from v6.2 to v6.3 (native code in .mpy files needs to be recompiled, but bytecode does not, and remains compatible).
Significant code size optimizations have been made for frozen modules. A new internal mp_proto_fun_t type has been defined that allows bytecode functions (as opposed to native code) to be stored in frozen code without any additional overhead of mp_raw_code_t descriptor structures. All firmware built with frozen modules will be significantly smaller in size. Code size has also been further improved for very small targets by adding an option to remove the qstr hash bytes.
Inside the source code, the "STATIC" macro definition has been removed. Code should now only use "static". If you have C/C++ code that uses "STATIC", then replace it with "STATIC", or provide your own #define defining "STATIC" to "STATIC". See for more information .
Mbedtls has been updated to version 3.5.1. Network interface constants, such as IF_STA and SEC_WPA2, have now been merged across ports, so they are all at the WLAN class level, e.g. network.WLAN.SEC_WPA2 (the existing constants at the network module level have been retained for backward compatibility, but the new constants should be used in preference from now on).
esp32 Some important bug fixes were found in the BLE component to deinitialize without crashing, and to increase the size of the BLE task stack. This port also uses the new I2S IDF driver, and supports IDF 5.0.5 and 5.2. For esp32-C3/S2/S3 devices, support for entering the bootloader via machine.bootloader(), as well as esp32.mcu_temperature().
The rp2 port has added a new machine.USBDevice dynamic USB driver and applied firmware performance optimizations to key parts of the runtime and virtual machine, resulting in a performance improvement of about 10%. Direct access to the memory of PIO and SPI FIFOs is now possible through proxy arrays, and bugs with threads, lightsleep, and UART IRQ delays have been fixed.
The stm32 port has integrated support for the new openamp module, which is enabled on all Arduino boards. The firmware for Arduino boards is now frozen in additional Arduino-specific library code. Internal flash writes on STM32H5 and STM32H7 MCUs have been fixed (bank selection and last word in write buffer), an important fix for SPI DMA cache errors, an I2C clock fix for I2C4 on STM32F7 MCUs, and a fix for FDCAN source clock frequency on STM32G4 MCUs have been added. Mboot has added support for a new raw file system to allow simpler and more robust firmware updates.
The webassembly port has been significantly overhauled in structure and is now built as a JavaScript .mjs module, exporting a user-friendly JavaScript level API inspired by the API provided by Pyodide (which is a version of CPython that runs in the browser). This change was motivated by the need to use MicroPython as an engine in Pyscript, a platform for Python in the browser. New features in the webassembly port include object proxies between Python and JavaScript, a js module to interface with JavaScript namespaces, a jsffi module for various proxy helpers, top-level asynchronous code, JavaScript-driven async support, automatic growth of the Python heap, integration of JavaScript and Python finalization for global memory management, more time module functions, and support for build variants (following the unix port).
The changes in code size of the various ports since the last release are (absolute and percentage changes in the text section):
bare-arm: -220 -0.383%
minimal x86: -341 -0.184%
unix x64: +20168 +2.527%
stm32: -1692 -0.430%
cc3200: +256 +0.139%
esp8266: -8880 -1.260%
esp32: -3328 -0.194%
mimxrt: -408 -0.112%
renesas-ra: -464 -0.074%
nrf: -640 -0.341%
rp2: +5380 +1.626%
samd: +3224 +1.229%
The main reasons for these code size changes are:
- bare-arm, minimal: disable qstr hashing
- unix: Update mbedtls to version 3.5.1
- stm32: optimize size of frozen modules
- cc3200: added new vfs module, and fixed bugs in VM and array types
- esp8266: disable unused MICROPY_DEBUG_PRINTERS and optimize frozen modules
- esp32, mimxrt, renesasra, nrf: optimize frozen modules
- rp2: add machine.USBDevice, enable -O2 optimization
- samd: add machine.USBDevice
The performance of all ports is effectively unchanged since the last release, with the exception of the rp2 port, which has seen a performance improvement of about 10%.
Thanks to everyone who contributed to this release: Amirreza Hamzavi, Andrew Leech, Angus Gratton, Brian Pugh, Carlosgg, Christian Walther, Damien George, Danil van de Giessen, darc, Dash Peters, David Lechner, Felix Drre, iabdalkader, Ihor Nehrutsa, Iksas, J. Neuschfer, Jared Hancock, Jim Lipsey, Jim Mussared, Jochen Sprickerhof, Joey232, Jos Verlinde, Kwabena W. Agyeman, Maarten van der Schreck, Matt Trentini, Matthias Urlichs, Michia iel W. Beijen, Mike Teachman, Nicko van Someren, Olivier Lenoir, Phil Howard, Rick Sorensen, robert hh, Sebastian Romero, Simon Wood, Stanislav Ponomarev, stijn, Takahashi Takeo, Trent Piepho, Trent Warlaven, Vonasmic, YAMAMOTO Takashi, Yoctopuce.
MicroPython is a global open source project with contributions from the following time zones: 0800, 0700, 0600, -0500, -0300, +0000, +0100, +0200, +0330, +0400, +0900, +1000, +1100.
The work for this release was funded in part by GitHub Sponsors and in part by George Robotics, Espressif, Anaconda, Arduino, LEGO Education, OpenMV, and Planet Innovation.
|