summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2025-02-03py: Add optional support for recursive mutexes, use for gc mutex.Angus Gratton
Enabled by default if using threading and no GIL This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-02-03py/gc: Allow gc_free from inside a gc_sweep finalizer.Angus Gratton
Do this by tracking being inside gc collection with a separate flag, GC_COLLECT_FLAG. In gc_free(), ignore this flag when determining if the heap is locked. * For finalisers calling gc_free() when heap is otherwise unlocked, this allows memory to be immediately freed (potentially avoiding a MemoryError). * Hard IRQs still can't call gc_free(), as heap will be locked via gc_lock(). * If finalisers are disabled then all of this code can be compiled out to save some code size. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-02-03py/gc: Split out running finalizers to a separate pass.Angus Gratton
Currently a finalizer may run and access memory which has already been freed. (This happens mostly during gc_sweep_all() but could happen during any garbage collection pass.) Includes some speed improvement tweaks to skip empty FTB blocks. These help compensate for the inherent slowdown of having to walk the heap twice. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-02-03unix: Use the bare metal mbedTLS config in the coverage buiid.Angus Gratton
This allows coverage to test MicroPython-specific features such as the tracked alloc cleanups added in the parent commit. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-02-03extmod/mbedtls: Try GC before failing to setup socket on esp32, unix.Angus Gratton
On mbedTLS ports with non-baremetal configs (mostly esp32, technically also unix port), mbedTLS memory is allocated from the libc heap. This means an old SSL socket may be holding large SSL buffers and preventing a new SSL socket from being allocated. As a workaround, trigger a GC pass and retry before failing outright. This was originally implemented as a global mbedTLS calloc function, but there is complexity around the possibility of C user modules calling into mbedTLS without holding the GIL. It would be interesting to try making a generic version for any malloc which fails, but this would require checking for a Python thread and probably making the GIL recursive. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-02-03tests: Add a test for SSL socket memory leaks.Angus Gratton
Test is for an issue reported on the micropython-lib Discord as effecting the rp2 port umqtt.simple interface when reconnecting with TLS, however it's a more generic problem. Currently this test fails on RPI_PICO_W and ESP32_GENERIC_C3 (and no doubt others). Fixes are in the subsequent commits. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-01-29py/parsenumbase: Favor clarity of code over manual optimisation.Jeff Epler
Follow up to 13b13d1fdd05549d504eeded0b5aa8871d5e5dcf, based on some testing on godbolt, the manual code optimisation seems unnecessary for code size, at least on gcc x86_64 and ARM, and it's definitely not good for clarity. Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-01-29extmod/lwip-include: Factor common lwIP config into lwipopts_common.h.Damien George
This lwIP configuration file has options that are common to all ports, and the ports are updated to use this file. This change is a no-op, the lwIP configuration remains the same for the four ports using this common file. This reduces code duplication, keeps the ports in sync, and makes it easier to update the configuration for all ports at once. Signed-off-by: Damien George <damien@micropython.org>
2025-01-29py/mkrules: Add GIT_SUBMODULES_FAIL_IF_EMPTY flag for CMake ports.Angus Gratton
The way CMake gathers the submodule list, it can quietly be empty if the previous step fails. This makes it an explicit error. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-01-29esp32: Don't add TinyUSB files to an ECHO_SUBMODULES build.Angus Gratton
Similar to other places, CMake will error out if this file doesn't exist yet but we don't want this if we're only getting the list of submodules. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-01-29esp32: Disable component manager when running 'make submodules'.Angus Gratton
- ECHO_SUBMODULES=1 exits CMake early. With idf_component_manager 1.x this seems to leave the managed_components directory in a state that causes later builds to fail. - Looks like the component manager isn't needed for this step, so disable it. This invocation logs a warning (not visible in normal output) but completes successfully and returns the correct list of submodules. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-01-29extmod/modlwip: Fix incorrect peer address for IPv6.Jared Hancock
For IPv6 connections, the peer address was previously defined as only the first four bytes of the IP address. For IPv6 addresses, this resulted in an incorrect IPv4 address. For instance, receiving a packet via `::recvfrom` from `'fe80::87:e7ff:fe48:629a'` is returned as having a peer address of `'254.128.0.0'` Signed-off-by: Jared Hancock <jared.hancock@centeredsolutions.com>
2025-01-29tools/mpremote: Introduce timeout_overall for read_until().Hans Maerki
And use it in `enter_raw_repl()`. This prevents waiting forever for a serial device that does not respond to the Ctrl-C/Ctrl-D/etc commands and is constantly outputting data. Signed-off-by: Hans Maerki <buhtig.hans.maerki@ergoinfo.ch>
2025-01-27tools/mpremote: Avoid initial blocking read in read_until().Hans Maerki
If the target does not return any data then `read_until()` will block indefinitely. Fix this by making the initial read part of the general read look, which always checks `inWaiting() > 0` before reading from the serial device. Also added the UART timeout to the constructor. This is not currently used but may be used as an additional safeguard. Signed-off-by: Hans Maerki <buhtig.hans.maerki@ergoinfo.ch>
2025-01-26py/emitnative: Optimise Viper immediate offset load/stores on Xtensa.Alessandro Gatti
This commit introduces the ability to emit optimised code paths on Xtensa for load/store operations indexed via an immediate offset. If an immediate offset for a load/store operation is within a certain range that allows it to be embedded into an available opcode then said opcode is emitted instead of the generic code sequence. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-01-26py/emitnative: Emit shorter exception handler entry code on RV32.Alessandro Gatti
This commit improves the RV32 code sequence that is emitted if a function needs to set up an exception handler as its prologue. The old code would clear a temporary register and then copy that value to places that needed to be initialised with zero values. On RV32 there's a dedicated register that's hardwired to be equal to zero, which allows us to bypass the extra register clear and use the zero register to initialise values. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-01-26py/emitnative: Optimise Viper register offset load/stores on Xtensa.Alessandro Gatti
This commit improves the emitted code sequences for address generation in the Viper subsystem when loading/storing 16 and 32 bit values via a register offset. The Xtensa opcodes ADDX2 and ADDX4 are used to avoid performing the extra shifts to align the final operation offset. Those opcodes are available on both xtensa and xtensawin MicroPython architectures. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-01-26py/parsenum: Throw an exception for invalid int literals like "01".Jeff Epler
This includes making int("01") parse in base 10 like standard Python. When a base of 0 is specified it means auto-detect based on the prefix, and literals begining with 0 (except when the literal is all 0's) like "01" are then invalid and now throw an exception. The new error message is different from CPython. It says e.g., `SyntaxError: invalid syntax for integer with base 0: '09'` Additional test cases were added to cover the changed & added code. Co-authored-by: Damien George <damien@micropython.org> Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-01-26tests/basics/nanbox_smallint.py: Fix incorrect use of int() in test.Jeff Epler
The literal is in base 16 but int()'s default radix in CPython is 10, not 0. Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-01-24py/persistentcode: Initialize prelude_ptr to prevent compiler warning.IhorNehrutsa
The esp32 IDF toolchain can give a "may be used uninitialized" warning, at least for ESP32-S3 with gcc 14.2.0. Silence that warning by initializing the variable with NULL. Co-authored-by: Daniel van de Giessen <daniel@dvdgiessen.nl> Signed-off-by: IhorNehrutsa <Ihor.Nehrutsa@gmail.com>
2025-01-24esp32: Add support for IDF v5.4.IhorNehrutsa
Add WIFI_AUTH_WPA3_ENTERPRISE and WIFI_AUTH_WPA2_WPA3_ENTERPRISE, and update PPP callback signature for latest lwIP. Co-authored-by: Daniel van de Giessen <daniel@dvdgiessen.nl> Signed-off-by: IhorNehrutsa <Ihor.Nehrutsa@gmail.com>
2025-01-23samd/samd_qspiflash: Correct QSPI baud calculation.I. Tomita
The QSPI baud is derived from the AHB clock, not from the APB (peripheral) clock. Datasheet: The QSPI Baud rate clock is generated by dividing the module clock (CLK_QSPI_AHB) by a value between 1 and 255. As previously implemented, all baudrates are 2.5 times greater than expected. Signed-off-by: I. Tomita <ziceva@me.com>
2025-01-23samd/machine_dac: Fix SAMD51 DAC for two channels.Graeme Winter
Improvements to DAC support for SAMD51: - properly validate DAC id - correctly use dac_init flag, as a 2-ple for A0, A1 channels - disable DAC before adjusting settings, see SAMD5x data sheet ยง47.6.2.3 Co-authored-by: robert-hh <robert@hammelrath.com> Signed-off-by: Graeme Winter <graeme.winter@gmail.com>
2025-01-22LICENSE,docs: Update copyright year range to include 2025.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2025-01-22esp8266/Makefile: Fix local toolchain builds on recent Linux systems.Alessandro Gatti
This commit fixes compilation for the ESP8266 port when using a local toolchain on relatively recent Linux systems. The documentation asks the user to delete the esptool instance that comes with the toolchain, in favour of using the one provided by the system. On Linux systems that are at least two years old (looking at the CI Ubuntu image as an example), the version of esptool installed with the package manager isn't called `esptool.py` but just `esptool`. The Makefile didn't take that into account and used `esptool.py` without checking if such a command exists, making builds fail. Now preference is given to the `esptool` command, falling back to `esptool.py` only if the former command does not exist or it is not available to the current user, to maintain compatibility with old setups. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-01-19qemu/boards: Change boards to use a subdirectory like other ports.Damien George
This commit moves `<board>.mk` to `<board>/mpconfigboard.mk` for all qemu boards, making it the same as other bare-metal ports. Signed-off-by: Damien George <damien@micropython.org>
2025-01-17py/mkrules.mk: Move comment about partial clones outside make rule.Damien George
Otherwise the comment is printed each time the rule is run. Follow up to fdd606dd5395d9c474775945fa4458a27199653b. Signed-off-by: Damien George <damien@micropython.org>
2025-01-17docs/esp32: Defer to the download page for flashing steps.Angus Gratton
The user already has it open, and its customised for their particular board. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-01-17esp32/boards: Update the product name for some UM boards.Angus Gratton
The previous deploy.md refactors revealed that these boards had a different "product" entry in boards.json compared to the name given in the board.md file. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-01-17docs/esp32: Update tutorial flashing steps to match deploy.md.Angus Gratton
Includes fixing the flashing address for newer SoCs, as reported in discussion https://github.com/orgs/micropython/discussions/16417 Also removes some redundant or out of date information, and adds links to the Espressif esptool docs which are quite comprehensive. Information about ESP32_GENERIC variants is moved to the board page, as it only applies to that board. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-01-17tools/autobuild,esp32: Template the generation of esp32 port deploy.md.Angus Gratton
Allows two source files (ports/esp32/boards/deploy.md and deploy_nativeusb.md for boards with only native USB) for all esp32 installation steps, with templated chip name and flash offset inserted via string formatting. The new files add more text to explain the esptool.py port auto-detection, remove the unnecessary -z feature (already enabled by default), and add a bit of troubleshooting and port detection info. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-01-17stm32/boards: Update Arduino boards to reserve timers and fix USB PID.iabdalkader
Reserve timers used for the camera, and fix USB PID because 0x055F is reserved for MicroPython. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2025-01-17stm32/boards/ARDUINO_NICLA_VISION: Fix CAN pin assignment.Angus Gratton
The only STM32H747 pins with CAN function that are also broken out on the board are PB8 and PB9. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-01-17stm32/fdcan: Fix extended CAN ID filtering for stm32g4.Angus Gratton
The memory bank addresses used for these are independent, can (and must) enable both. Also looks like no need to shrink these if FDCAN2 is added, the Reference Manual is a bit unclear but looks like the peripheral's RAM multiplies out for each additional controller. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-01-17stm32/can: Fix clearing filters on CAN3 (bxCAN).Angus Gratton
HAL argument is ignored for CAN1, CAN2 but needed for CAN3. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-01-17stm32/pyb_can: Include requested CAN baudrate in matching error.Angus Gratton
This is redundant for bxCAN, but for CAN-FD with BRS it's otherwise unclear which set of parameters (baudrate & sample_point or brs_baudrate & brs_sample_point) failed to match. This makes finding a valid combination extra annoying. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-01-17stm32/pyb_can: Make pyb.CAN baud calculation a little more forgiving.Angus Gratton
Not every baudrate or sample point combination has an exact match, but getting within 1% on sample point and .1% on baud rate should always be good enough. Because the search goes from shorter bit periods (lowest brp) and increases, the first match which meets this criteria should still mostly be the best available. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-01-17stm32/pyb_can: Fix CAN-FD BRS baud initialisation.Angus Gratton
Was initialising using the Classic CAN bs1/bs2 value, incorrectly. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-01-17stm32/boards: Support 'FDCAN' in board pin CSVs.Angus Gratton
Previously micros with the 'FDCAN' peripheral (as opposed to the older 'CAN' peripheral) needed to rename these pins in the CSVs for the CAN driver to work. The following CSVs in MicroPython still had FDCAN in them: $ rg -t csv -l FDCAN boards boards/stm32h7b3_af.csv boards/stm32h743_af.csv boards/stm32h573_af.csv boards/stm32h723_af.csv boards/stm32g0b1_af.csv Confirmed that this allows CAN to work on NUCLEO_H723ZG board, and that at least one board based on each of the other chips can still compile. Some of these boards could possibly have MICROPY_HW_ENABLE_CAN set and work, now. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-01-17lib/mbedtls: Update to mbedtls v3.6.2.Glenn Strauss
Signed-off-by: Glenn Strauss <gstrauss@gluelogic.com>
2025-01-16docs/reference/isr_rules: Describe issue with hard ISRs and globals.peterhinch
Signed-off-by: Damien George <damien@micropython.org>
2025-01-16stm32/boards: Reserve SPI bus when it's used for external flash storage.iabdalkader
Reserve SPI flash bus used for storage or XIP. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2025-01-16stm32/spi: Retain the state of special SPI buses on soft reboot.iabdalkader
Reserved and static SPI buses must remain initialized during a soft reboot as they may be used for SPI flash storage or XIP. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2025-01-16stm32/mpconfigboard_common: Add MICROPY_HW_SPI_IS_STATIC macro.iabdalkader
A board should make this return true if the specified SPI instances should not be deinitialized on soft-reboot. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2025-01-16qemu/boards/SABRELITE.mk: Remove exception for omitted tests.Alessandro Gatti
This commit re-introduces `tests/extmod/vfs_rom.py` and `tests/float/math_domain.py` to the test suite, as the issues that made them fail have now been addressed. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-01-16py/asmarm: Fix halfword loads with larger offsets.Alessandro Gatti
This commit fixes code generation for loading halfwords using an offset greater than 255. The old code blindly encoded the offset into a `LDRH Rd, [Rn, #imm]` opcode, but only the lowest 8 bits would be put into the opcode itself. This commit instead generates a two-opcodes sequence, a constant load into R8, and then `LDRH Rd, [Rn, R8]`. This fixes `tests/extmod/vfs_rom.py` for the qemu/SABRELITE board. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-01-16py/asmarm: Fix locals address loading code generation with large imm.Alessandro Gatti
This commit fixes code generation for loading a local's address if its index is greater than 63. The old code blindly encoded the offset into an `ADD Rd, Rn, #imm` opcode, but only the lowest 8 bits would be put into the opcode itself. This commit instead generates a two-opcodes sequence, a constant load into R8, and then an `ADD Rd, Rn, R8` opcode. This fixes `tests/float/math_domain.py` for the qemu/SABRELITE board. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-01-16qemu/Makefile: Increase GC heap size to 140KiB.Alessandro Gatti
This commit increases the GC heap size from 120KiB to 140KiB, as it is needed to make the full test suite pass on SABRELITE when ran through the armv6 native emitter. This is needed as the code output by the armv6 native emitter is limited to 4-bytes opcodes and thus takes more space than other ARM emitters. To keep things aligned, the RV32 port also got its heap size increased even though it is not needed on that platform right now. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-01-16qemu: Disable native emitter for the MICROBIT board.Alessandro Gatti
The Micro:Bit machine definition in Qemu has soft MMU support enabled, which is currently not compatible with the way MicroPython generates code that needs to call back into non-emitted code. As a stop-gap solution, the native code emitter for the MICROBIT board is turned off. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-01-16qemu/mcu/arm: Dump exception cause and registers on machine error.Alessandro Gatti
When a CPU exception is raised when emulating a Thumb-capable processor, the default exception handler would simply enter in an endless loop without providing any further information. This commit adds a more complete exception handler that dumps to STDOUT the exception cause and the status of the registers at the moment of the exception. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>