summaryrefslogtreecommitdiffstatshomepage
path: root/extmod
Commit message (Collapse)AuthorAge
* extmod/modlwip: Fix crash when calling recv on listening socket.Andrew Leech6 days
| | | | | | | | | | Add check to prevent calling recv on a socket in the listening state. This prevents a crash/hard fault when user code mistakenly tries to recv on the listening socket instead of on the accepted connection. Add corresponding test case to demonstrate the bug. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
* esp8266/modmachine: Use common machine_time_pulse_us implementation.Damien George2025-06-13
| | | | | | | | | | | | Testing shows that for frequencies which the esp8266 can handle -- up to about 1kHz -- `machine.time_pulse_us()` now gives more accurate results. Prior to this commit it would measure on average about 1us lower, but now the average is much closer to the true value. For example a pulse that is 1000us long, it would measure between 998 and 1000us. Now it measures between 999us and 1001us. Signed-off-by: Damien George <damien@micropython.org>
* extmod/machine_pulse: Optimise time_pulse_us for code size.Damien George2025-06-13
| | | | | | | | | | This implementation is based on the esp8266 custom implementation, and further optimised for size and accuracy. Testing on PYBD_SF2 and RPI_PICO2_W shows that it is at least as good as the original implementation in performance. Signed-off-by: Damien George <damien@micropython.org>
* extmod/modre: Use specific error message if regex is too complex.Jeff Epler2025-06-10
| | | | | | | | | If the error reporting mode is at least "normal", report a failure due to a complex regex with a different message. Fixes issue #17150. Signed-off-by: Jeff Epler <jepler@gmail.com>
* extmod/modnetwork: Consolidate definition of common drivers.Andrew Leech2025-06-10
| | | | | | | | | | | | Most extmod network drivers were being defined on a per-port basis, duplicating code and making enabling a driver on a new port harder. This consolidates extmod driver declarations and removes the existing per-port definitions of them. This commit has been verified to be a no-op in terms of firmware change. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
* extmod/modframebuf: Add support for blit'ing read-only data.Damien George2025-06-04
| | | | | | | | | | | | | | | | | | | | | | Currently the `FrameBuffer.blit(buf, x, y)` method requires the `buf` argument to be another `FrameBuffer`, which is quite restrictive because it doesn't allow blit'ing read-only memory/data. This commit extends `blit()` to allow the `buf` argument to be a tuple or list of the form: (buffer, width, height, format[, stride]) where `buffer` can be anything with the buffer protocol and may be read-only, eg `bytes`. Also, the palette argument to `blit()` may be of the same form. The form of this tuple/list was chosen to be the same as the signature of the `FrameBuffer` constructor (that saves quite a bit of code size doing it that way). Signed-off-by: Damien George <damien@micropython.org>
* extmod/modbluetooth: Add timeout to deinit.Andrew Leech2025-06-04
| | | | | | | | | | | If the BLE radio stops responding before deinit is called the function can get stuck waiting for an event that is never received, particularly if the radio is external or on a separate core. This commit adds a timeout, similar to the timeout already used in the init function. Updated for nimble, btstack, esp32 and zephyr bindings. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
* extmod/modlwip: Add optional flags argument for recv and recvfrom.Angus Gratton2025-06-03
| | | | | | | | Implements MSG_PEEK and MSG_DONTWAIT. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* extmod/network_cyw43: Disconnect STA if making inactive.Angus Gratton2025-05-20
| | | | | | | | | esp32 port will disconnect if active(0) is called on a STA interface, but rp2 port stays associated without this change. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* extmod/modjson: Detect unterminated composite entities.Alessandro Gatti2025-05-19
| | | | | | | | | | | | | | | This commit makes the JSON parser raise an exception when handling objects or arrays whose declaration is incomplete, as in missing the closing marker (brace or bracket) and if the missing marker would have been the last non-whitespace character in the incoming string. Since CPython's JSON parser would raise an exception in such a case, unlike MicroPython's, this commit aligns MicroPython's behaviour with CPython. This commit fixes issue #17141. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* extmod/vfs_lfsx: Fix errno value raised from chdir.Damien George2025-05-15
| | | | | | OSError errno values should be positive. Signed-off-by: Damien George <damien@micropython.org>
* esp32/network_ppp: Restructure to match extmod/network_ppp_lwip.Daniël van de Giessen2025-05-15
| | | | | | | | | | | | | | | | | | | | | The ESP32 PPP implementation predates the generic implementation in extmod. The new extmod implementation has a few advantages such as a better deinitialisation procedure (the ESP32 implemementation would not clean up properly and cause crashes if recreated) and using the UART IRQ functionality instead of running a task to read data from the UART. This change restructures the ESP implementation to be much closer to the new extmod version, while also bringing a few tiny improvements from the ESP32 version to the extmod version. The diff between extmod/network_ppp_lwip.c and ports/esp32/network_ppp.c is now a small set of easy to review ESP32 port-specific changes. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
* all: Rename the "NORETURN" macro to "MP_NORETURN".Alessandro Gatti2025-05-13
| | | | | | | | | | | | | | | | This commit renames the NORETURN macro, indicating to the compiler that a function does not return, into MP_NORETURN to maintain the same naming convention of other similar macros. To maintain compaitiblity with existing code NORETURN is aliased to MP_NORETURN, but it is also deprecated for MicroPython v2. This changeset was created using a similar process to decf8e6a8bb940d5829ca3296790631fcece7b21 ("all: Remove the "STATIC" macro and just use "static" instead."), with no documentation or python scripts to change to reflect the new macro name. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* extmod/modlwip: Implement a queue of incoming UDP/raw packets.Damien George2025-05-12
| | | | | | | | | | | | | | | | The bare-metal lwIP socket interface is currently quite limited when used for UDP streams, because it only allows one outstanding incoming UDP packet. If one UDP packet is waiting to be socket.recv'd and another one comes along, then the second one is simply dropped. This commit implements a queue for incoming UDP and raw packets. The queue depth is fixed at compile time, and is currently 4. This allows better use of UDP connections, eg more efficient. It also makes DTLS work better which sometimes has a queue of UDP packets (eg during the connection phase). Signed-off-by: Damien George <damien@micropython.org>
* extmod/moductypes: Refactor string literal as array initializer.Angus Gratton2025-05-09
| | | | | | | | | | | Avoids the new Wunterminated-string-literal when compiled with gcc 15.1. Also split out the duplicate string to a top-level array (probably the duplicate string literal was interned, so unlikely to have any impact.) This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* rp2,extmod/cyw43: Move the LWIP responder fix into common CYW43 config.Angus Gratton2025-05-08
| | | | | | | | | This means the fix from dd1465e7 will also apply to stm32 and mimxrt ports that use CYW43. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* extmod,alif,mimxrt,rp2,stm32: Create common cyw43 driver config header.Angus Gratton2025-05-08
| | | | | | | | | | | This is only a surface level refactor, some deeper refactoring would be possible with (for example) the SDIO interface in mimxrt and stm32, or the BTHCI interface which is is similar on supported ports. But sticking to cases where the macros are the same across all ports. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* lib/littlefs: Reuse existing CRC32 function to save space.Daniël van de Giessen2025-05-07
| | | | | | | Getting this to work required fixing a small issue in `lfs2_util.h`, which has been submitted upstream. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
* extmod/asyncio: Fix early exit of asyncio scheduler.Yoctopuce dev2025-05-07
| | | | | | | | | | | | | | | | | | | | | This commit fixes three open issues related to the asyncio scheduler exiting prematurely when the main task queue is empty, in cases where CPython would not exit (for example, because the main task is not done because it's on a different queue). In the first case, the scheduler exits because running a task via `run_until_complete` did not schedule any dependent tasks. In the other two cases, the scheduler exits because the tasks are queued in an event queue. Tests have been added which reproduce the original issues. These test cases document the unauthorized use of `Event.set()` from a soft IRQ, and are skipped in unsupported environments (webassembly and native emitter). Fixes issues #16759, #16569 and #16318. Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
* drivers/esp-hosted: Rename Bluetooth HCI backend driver.iabdalkader2025-04-22
| | | | | | | Rename `bthci` to `bthci_uart` for consistency with the CYW43 driver and to distinguish it from HCI backends that use a different transport. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
* extmod/modbluetooth: Use newer mp_map_slot_is_filled function.Andrew Leech2025-04-22
| | | | | | Required in MICROPY_PREVIEW_VERSION_2. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
* extmod/machine_usb_device: Add exception text wrappers.Andrew Leech2025-04-22
| | | | | | Required in MICROPY_PREVIEW_VERSION_2. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
* extmod/extmod.mk: Switch from drivers/cyw43/cywbt to lib/cyw43-drivers.Damien George2025-04-08
| | | | | | | | | | | | The cyw43-driver now provides the Bluetooth initialisation code, making `drivers/cyw43/cywbt.c` obsolete. To use the new code a port must enable the `CYW43_ENABLE_BLUETOOTH_OVER_UART` option. Some ports have yet to migrate to the new code, so in the meantime they can explicitly add the old source to their source list and continue to use it without change. Signed-off-by: Damien George <damien@micropython.org>
* extmod/extmod.mk: Add cyw43_spi.c to list of sources.Damien George2025-04-08
| | | | | | | This file is part of the updated cyw43-driver. It will only be used if `CYW43_USE_SPI` is enabled. Signed-off-by: Damien George <damien@micropython.org>
* rp2,esp32,extmod: Implement UPDATE_SUBMODULES in CMake.Angus Gratton2025-03-27
| | | | | | | | | | | | | | | Rather than having Make calling CMake to generate a list of submodules and then run a Make target (which is complex and prone to masking other errors), implement the submodule update logic in CMake itself. Internal CMake-side changes are that GIT_SUBMODULES is now a CMake list, and the trigger variable name is changed from ECHO_SUBMODULES to UPDATE_SUBMODULES. The run is otherwise 100% a normal CMake run now, so most of the other special casing can be removed. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* extmod/vfs_rom: Implement minimal VfsRom.getcwd() method.Damien George2025-03-27
| | | | | | | | | | | This is needed if you chdir to a ROMFS and want to query your current directory. Prior to this change, using `os.getcwd()` when in a ROMFS would raise: AttributeError: 'VfsRom' object has no attribute 'getcwd' Signed-off-by: Damien George <damien@micropython.org>
* extmod/vfs: Return mount table from no-args vfs.mount call.Anson Mansfield2025-03-27
| | | | | | | | This extends the existing `vfs.mount()` function to accept zero arguments, in which case it returns a list of tuples of mounted filesystem objects and their mount location. Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
* extmod/vfs: Refactor mp_vfs_mount to enable no-args mount overload.Anson Mansfield2025-03-27
| | | | Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
* extmod/moddeflate: Keep DeflateIO state consistent on window alloc fail.Damien George2025-03-27
| | | | | | | | | | | Allocation of a large compression window may fail, and in that case keep the `DeflateIO` state consistent so its other methods (such as `close()`) still work. Consistency is kept by only updating the `self->write` member if the window allocation succeeds. Thanks to @jimmo for finding the bug. Signed-off-by: Damien George <damien@micropython.org>
* extmod/network_cyw43: Add WPA3 security constants.Damien George2025-03-12
| | | | | | These are now supported by cyw43-driver. Signed-off-by: Damien George <damien@micropython.org>
* extmod/vfs: Add mp_vfs_mount_romfs_protected() helper.Damien George2025-03-06
| | | | | | | This function will attempt to create a `VfsRom` instance and mount it at location "/rom" in the filesystem. Signed-off-by: Damien George <damien@micropython.org>
* extmod/modvfs: Add vfs.rom_ioctl function and its ioctl constants.Damien George2025-03-06
| | | | | | | This is a generic interface to allow querying and modifying the read-only memory area of a device, if it has such an area. Signed-off-by: Damien George <damien@micropython.org>
* extmod/vfs_rom: Add bounds checking for all filesystem accesses.Damien George2025-02-26
| | | | | | | | | | | | | | | | | | | Testing with ROMFS shows that it is relatively easy to end up with a corrupt filesystem on the device -- eg due to the ROMFS deploy process stopping half way through -- which could lead to hard crashes. Notably, there can be boot loops trying to mount a corrupt filesystem, crashes when importing modules like `os` that first scan the filesystem for `os.py`, and crashing when deploying a new ROMFS in certain cases because the old one is removed while still mounted. The main problem is that `mp_decode_uint()` has an loop that keeps going as long as it reads 0xff byte values, which can happen in the case of erased and unwritten flash. This commit adds full bounds checking in the new `mp_decode_uint_checked()` function, and that makes all ROMFS filesystem accesses robust. Signed-off-by: Damien George <damien@micropython.org>
* all: Upgrade codespell to v2.4.1.Christian Clauss2025-02-25
| | | | | | | This commit upgrades from codespell==2.2.6 to the current codespell==2.4.1, adding emac to the ignore-words-list. Signed-off-by: Christian Clauss <cclauss@me.com>
* extmod/modtls_mbedtls: Wire in support for DTLS.Keenan Johnson2025-02-14
| | | | | | | | | | | | | | | | | | | | | | | | | This commit enables support for DTLS, i.e. TLS over datagram transport protocols like UDP. While support for DTLS is absent in CPython, it is worth supporting it in MicroPython because it is the basis of the ubiquitous CoAP protocol, used in many IoT projects. To select DTLS, a new set of "protocols" are added to SSLContext: - ssl.PROTOCOL_DTLS_CLIENT - ssl.PROTOCOL_DTLS_SERVER If one of these is set, the library assumes that the underlying socket is a datagram-like socket (i.e. UDP or similar). Our own timer callbacks are implemented because the out of the box implementation relies on `gettimeofday()`. This new DTLS feature is enabled on all ports that use mbedTLS. This commit is an update to a previous PR #10062. Addresses issue #5270 which requested DTLS support. Signed-off-by: Keenan Johnson <keenan.johnson@gmail.com>
* extmod/lwip-include: Increase number of lwIP timers when mDNS enabled.Thomas Watson2025-02-14
| | | | | | | | | | | | | | | | | | | | | | | | | | Despite the code comments claiming one is sufficient, the mDNS application is capable of using up to twelve timers. Three per IP protocol are started at once in `mdns_start_multicast_timeouts_ipvX`, then another two per protocol can be started in `mdns_handle_question`. Further timers can be started for two additional callbacks. Having certain timers, such as `MDNS_MULTICAST_TIMEOUT`, fail to start due to none being free will break mDNS forever as the app will never realize it's safe to transmit a packet. Therefore, this commit goes somewhat overkill and allocates the maximal amount of timers; it's uncertain if all can run simultaneously, or how many callback timers are needed. Each timer struct is 16 bytes on standard 32 bit builds. Plus, say, 8 bytes of allocater overhead, that's 288 more bytes of RAM used which shouldn't be too horrible. Users who don't need mDNS can manually disable it to recover the RAM if necessary. This fixes mDNS on W5500_EVB_PICO (among other boards). Before, mDNS would work for a bit after connection until the host's cache expired a minute or two later. Then the board would never respond to further queries. With this patch, all works well. Signed-off-by: Thomas Watson <twatson52@icloud.com>
* extmod/vfs_rom: Remove ability to create VfsRom from an address.Damien George2025-02-11
| | | | | | | | | | It's not necessary to support this, which allows an arbitrary memory address to be specified and potentially allows invalid memory accesses. Requiring an object with the buffer protocol is safer, and also means that the length of the region is always specified. Signed-off-by: Damien George <damien@micropython.org>
* extmod/modmarshal: Add new marshal module.Damien George2025-02-11
| | | | | | | | | | | | | This commit implements a small subset of the CPython `marshal` module. It implements `marshal.dumps()` and `marshal.loads()`, but only supports (un)marshalling code objects at this stage. The semantics match CPython, except that the actual marshalled bytes is not compatible with CPython's marshalled bytes. The module is enabled at the everything level (only on the unix coverage build at this stage). Signed-off-by: Damien George <damien@micropython.org>
* extmod/mbedtls: Try GC before failing to setup socket on esp32, unix.Angus Gratton2025-02-03
| | | | | | | | | | | | | | | | | | | 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>
* extmod/lwip-include: Factor common lwIP config into lwipopts_common.h.Damien George2025-01-29
| | | | | | | | | | | 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>
* extmod/modlwip: Fix incorrect peer address for IPv6.Jared Hancock2025-01-29
| | | | | | | | | | 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>
* lib/mbedtls: Update to mbedtls v3.6.2.Glenn Strauss2025-01-17
| | | | Signed-off-by: Glenn Strauss <gstrauss@gluelogic.com>
* extmod/moddeflate: Add missing size_t cast.Yoctopuce2025-01-02
| | | | | | To prevent compiler warnings. Signed-off-by: Yoctopuce <dev@yoctopuce.com>
* extmod/modsocket: Add missing static in private function definitions.Yoctopuce2025-01-02
| | | | Signed-off-by: Yoctopuce <dev@yoctopuce.com>
* extmod/vfs_reader: Add support for opening a memory-mappable file.Damien George2024-12-23
| | | | | | | | If the file can be memory mapped (because it responds to the buffer protocol) then return a memory-reader that directly references the ROM data of the file. Signed-off-by: Damien George <damien@micropython.org>
* extmod/vfs_rom: Add VfsRom filesystem object.Damien George2024-12-23
| | | | | | | | | | | | | | | | This commit defines a new ROMFS filesystem for storing read-only files that can be memory mapped, and a new VfsRom driver. Files opened from this filesystem support the buffer protocol. This allows naturally getting the memory-mapped address of the file using: - memoryview(file) - uctypes.addressof(file) Furthermore, if these files are .mpy files then their content can be referenced in-place when importing. Such imports take up a lot less RAM than importing from a normal filesystem. This is essentially dynamically frozen .mpy files, building on the revamped v6 .mpy file format. Signed-off-by: Damien George <damien@micropython.org>
* extmod/vfs: Guard mutating fs functions with MICROPY_VFS_WRITABLE.Damien George2024-12-20
| | | | | | | Enabled by default. Useful for ports that need the VFS but don't have any writable filesystems. Signed-off-by: Damien George <damien@micropython.org>
* extmod/moductypes: Fix large return values of addressof and INT_MAYBE.Damien George2024-12-18
| | | | | | | | So they don't return a negative number for an address (prior to this fix they would return negative addresses for values that were larger than the maximum small-int value). Signed-off-by: Damien George <damien@micropython.org>
* extmod/modplatform: Distinguish RISC-V 64 from RISC-V 32.Alessandro Gatti2024-12-10
| | | | | | | This commit lets the platform module report a more accurate architecture name when running on a RISC-V 64 bits platform. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* extmod/extmod.mk: Fix libmetal build prefix.iabdalkader2024-12-10
| | | | | | | | | | | libmetal source files already have the build directory prefix, because they're auto-generated inside the build directory. When they're added to `SRC_THIRDPARTY_C`, another build directory prefix is added resulting in the object files being generated in a nested build directory. This patch strips the build directory prefix before adding libmetal's source files. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>