summaryrefslogtreecommitdiffstatshomepage
path: root/extmod
Commit message (Collapse)AuthorAge
* extmod/network_wiznet5k: Add support for IPv6.Jared Hancock2024-08-26
| | | | | | | | This adds support for the WIZNET5K nic to use IPv6 with the LWIP stack. Additionally, if LWIP_IPV6 is disabled, the device is configured to drop all IPv6 packets to reduce load on the MCU. Signed-off-by: Jared Hancock <jared@greezybacon.me>
* extmod/modtls_mbedtls: Optimise the DER certificate parsing fix.Angus Gratton2024-08-26
| | | | | | | | | Small code size and binary size optimisation for the fix merged in 4d6d84983f370e48e81fb05fe31802e0a13fb369. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* py: Add new cstack API for stack checking, with limit margin macro.Angus Gratton2024-08-14
| | | | | | | | | | | | | | | | | | | | Currently the stack limit margin is hard-coded in each port's call to `mp_stack_set_limit()`, but on threaded ports it's fiddlier and can lead to bugs (such as incorrect thread stack margin on esp32). This commit provides a new API to initialise the C Stack in one function call, with a config macro to set the margin. Where possible the new call is inlined to reduce code size in thread-free ports. Intended replacement for `MP_TASK_STACK_LIMIT_MARGIN` on esp32. The previous `stackctrl.h` API is still present and unmodified apart from a deprecation comment. However it's not available when the `MICROPY_PREVIEW_VERSION_2` macro is set. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* extmod/modtls_mbedtls: Fix DER parsing and calculation of key/cert len.Peter Züger2024-08-13
| | | | | | | | | | | | | | | | `mbedtls_pk_parse_key()` expects `key_len` to include the NULL terminator for PEM data but not for DER encoded data. This also applies to `mbedtls_x509_crt_parse()` and `cert_len`. Since all PEM data contains "-----BEGIN" this is used to check if the data is PEM (as per mbedtls code). This can be done for both v2 and v3 of mbedtls since the fundamental behaviour/expectation did not change. What changed is that in v3 the PKCS#8 DER parser now checks that the passed key buffer is fully utilized and no bytes are remaining (all other DER formats still do not check this). Signed-off-by: Peter Züger <zueger.peter@icloud.com>
* extmod/modopenamp: Use mp_event_* functions for poll/wait.iabdalkader2024-08-08
| | | | | | These are the new helper functions to use for polling/waiting. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
* extmod/modopenamp: Fix Endpoint callback required arg.iabdalkader2024-08-08
| | | | | | The callback arg is not actually required. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
* extmod/modopenamp: Add support for building Open-AMP on device side.iabdalkader2024-08-08
| | | | | | Tested with two VMs each running on a different core. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
* extmod/modopenamp_remoteproc: Fix entry point address int overflow.iabdalkader2024-08-08
| | | | Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
* extmod/libmetal: Remove source file listed twice in sources.iabdalkader2024-08-08
| | | | | | This causes multiple definition of symbols on some builds. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
* extmod/vfs: Fix buffer overflow of string comparison in umount.Junwha2024-07-23
| | | | | | | | | The comparison between the given unmount string and existing mount strings were made by the given string, which leads to buffer overflow. Fixes issue #13006. Signed-off-by: Junwha <qbit@unist.ac.kr>
* extmod/vfs_fat: Set default volume label on mkfs if it's defined.Terence Stenvold2024-07-23
| | | | | Using mkfs doesn't set a volume label for FAT filesystems. This commit will set the volume label if `MICROPY_HW_FLASH_FS_LABEL` is defined.
* extmod/moductypes: Validate the descriptor tuple.stijn2024-07-22
| | | | | | | | | | | | | Fixes various null dereferencing, out-of-bounds memory accesses and `assert(0)` failures in the case of an invalid `uctypes` descriptor. By design `uctypes` can crash because it accesses arbitrary memory, but at least describing the descriptor layout should be forced to be correct and not crash. Fixes issue #12702. Signed-off-by: stijn <stijn@ignitron.net>
* extmod/modbtree: Add checks for already-closed database.Michael Vornovitsky2024-07-22
| | | | | | | | | | | | | | | Fixes use-after-free when accessing the database after it is closed with `btree_close`. `btree_close` always succeeds when called with an already-closed database. The new test checks that operations that access the underlying database (get, set, flush, seq) fail with a `ValueError` when the btree is already closed. It also checks that closing and printing the btree succeed when the btree is already closed. Fixes issue #12543. Signed-off-by: Michael Vornovitsky <michaelvornovitskiy@outlook.com>
* extmod/modos: Include os.sep entry if MICROPY_VFS is enabled.Damien George2024-07-20
| | | | | | | | | | | This simplifies configuration by removing the `MICROPY_PY_OS_SEP` option and instead including `os.sep` if `MICROPY_VFS` is enabled. That matches the configuration of all existing ports that enabled `os.sep` (they also had `MICROPY_VFS` enabled), and brings consistency to other ports. Fixes issue #15116. Signed-off-by: Damien George <damien@micropython.org>
* extmod/modmachine: Use sys.exit as implementation of machine.soft_reset.Damien George2024-07-20
| | | | | | It does the same thing, raising `SystemExit`. Signed-off-by: Damien George <damien@micropython.org>
* shared/runtime/pyexec: Make a raised SystemExit always do a forced exit.Damien George2024-07-20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The current situation with SystemExit and soft reset is the following: - `sys.exit()` follows CPython and just raises `SystemExit`. - On the unix port, raising `SystemExit` quits the application/MicroPython, whether at the REPL or in code (this follows CPython behaviour). - On bare-metal ports, raising `SystemExit` at the REPL does nothing, raising it in code will stop the code and drop into the REPL. - `machine.soft_reset()` raises `SystemExit` but with a special flag set, and bare-metal targets check this flag when it propagates to the top-level and do a soft reset when they receive it. The original idea here was that a bare-metal target can't "quit" like the unix port can, and so dropping to the REPL was considered the same as "quit". But this bare-metal behaviour is arguably inconsistent with unix, and "quit" should mean terminate everything, including REPL access. This commit changes the behaviour to the following, which is more consistent: - Raising `SystemExit` on a bare-metal port will do a soft reset (unless the exception is caught by the application). - `machine.soft_reset()` is now equivalent to `sys.exit()`. - unix port behaviour remains unchanged. Tested running the test suite on an stm32 board and everything still passes, in particular tests that skip by raising `SystemExit` still correctly skip. Signed-off-by: Damien George <damien@micropython.org>
* extmod/modre: Rename re_exec to re_exec_helper to avoid clash on BSD.Owen2024-07-15
| | | | | | | | | | | The `re_exec` symbol is the name of a FreeBSD regex function, so needs to be renamed to avoid a clash when building on FreeBSD. (This clash was fixed once before but then accidentally reintroduced by the u-module renaming in 7f5d5c72718af773db751269c6ae14037b9c0727.) Fixes issue #15430. clarify as helper function
* extmod/machine_spi: Support firstbit=LSB for machine.SoftSPI.robert-hh2024-07-12
| | | | | | | | | | | | | | | | Being able to send data out in LSB format can be useful, and having support in the low-level driver is much better than requiring Python code to reorder the bits before sending them / after receiving them. In particular if the hardware does not support the LSB format (eg RP2040) then one needs to use the SoftSPI in LSB mode. For this change a default definition of `MICROPY_PY_MACHINE_SPI_MSB/_LSB` was added to `py/mpconfig.h`, making them available to all ports. The identical defines in `esp32/mpconfigport.h` were deleted. Resolves issues #5340, #11404. Signed-off-by: robert-hh <robert@hammelrath.com>
* extmod/network_nina: Fix the AP security mode constants.iabdalkader2024-07-12
| | | | | | | | | | | The only AP security mode supported is actually WPA/WPA2 not WEP. The firmware command `0x19` starts the AP using `WIFI_AUTH_WPA_WPA2_PSK` mode. There are no functional changes in this commit, it just fixes the constant names and removes the useless sanity checks for WEP. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
* extmod/modmachine: Allow more than one argument to machine.freq().robert-hh2024-07-11
| | | | | | | | | | | The limit is set by a `MICROPY_PY_MACHINE_FREQ_NUM_ARGS_MAX` define, which defaults to 1 and is set for stm32 to 4. For stm32 this fixes a regression introduced in commit e1ec6af654b1c5c4a973b6c6b029ee68bb92eb89 where the maximum number of arguments was changed from 4 to 1. Signed-off-by: robert-hh <robert@hammelrath.com>
* all: Use new mp_obj_new_str_from_cstr() function.Jon Foster2024-07-04
| | | | | | | Use new function mp_obj_new_str_from_cstr() where appropriate. It simplifies the code, and makes it smaller too. Signed-off-by: Jon Foster <jon@jon-foster.co.uk>
* extmod/mbedtls: Enable GCM and ECDHE-RSA in common mbedtls config.Sylvain Zimmer2024-07-02
| | | | | | | | | | | | | | | | | | | Enable support for cipher suites like TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, as suggested in https://github.com/micropython/micropython/issues/14204#issuecomment-2024366349 and https://github.com/micropython/micropython/issues/10485#issuecomment-1396426824 Tests have been run on the top 500 domains from moz.com. Without this patch, 155 out of 500 fail to connect because of TLS issues. This patch fixes them all. And it seems all existing mbedtls flags are needed to get good coverage of those top 500 domains. The `ssl_poll.py` test has the cipher bits increased from 512 to 1024 in its test key/cert so that it can work with ECDHE-RSA which is now the chosen cipher. Signed-off-by: Sylvain Zimmer <sylvain@sylvainzimmer.com> Signed-off-by: Damien George <damien@micropython.org>
* extmod/machine_usb_device: Add USBDevice.remote_wakeup method.Felix Dörre2024-07-02
| | | | | | This simply exposes the TinyUSB function. Signed-off-by: Felix Dörre <felix@dogcraft.de>
* extmod/extmod.mk: Disable maybe-uninitialized warnings in libm_dbl.Damien George2024-06-27
| | | | | | These warnings are emitted by arm-none-eabi-gcc 14.1.0 with -O2 enabled. Signed-off-by: Damien George <damien@micropython.org>
* extmod/modasyncio: Add support for a callback on TaskQueue push.Damien George2024-06-20
| | | | | | | Allows passing in a callback to `TaskQueue()` that is called when something is pushed on to the queue. Signed-off-by: Damien George <damien@micropython.org>
* extmod/modplatform: Add picolibc to the recognised libcs list.Alessandro Gatti2024-06-17
| | | | | | This adds picolibc to the list of the recognised libc options. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* extmod/modlwip: Consolidate socket.accept timeout logic.Damien George2024-06-08
| | | | | | | | This makes the code a bit simpler to understand for the three cases of timeout behaviour (-1, 0, non-zero), and eliminates a dependency on the (slow) `mp_hal_delay_ms(100)` call. Signed-off-by: Damien George <damien@micropython.org>
* extmod/modlwip: Make socket.connect raise ETIMEDOUT on non-zero timeout.Damien George2024-06-08
| | | | | | | | | | | If the socket timeout is 0 then a failed socket.connect() raises EINPROGRESS (which is what the lwIP bindings already did), but if the socket timeout is non-zero then a failed socket.connect() should raise ETIMEDOUT. The latter is fixed in this commit. A test is added for these timeout cases. Signed-off-by: Damien George <damien@micropython.org>
* extmod/network_lwip: Allow using the CIDR notation for addr4.robert-hh2024-06-04
| | | | | | There was a little omisssion in the code. Signed-off-by: robert-hh <robert@hammelrath.com>
* extmod/network_ninaw10: Implement the ipconfig methods for ninaw10.robert-hh2024-06-04
| | | | | | | | | | | | | This implements network.ipconfig() and network.WLAN.ipconfig() when the ninaw10 driver is used for WLAN. Due to a omission in the ninaw10 driver stack, setting the DNS address has no effect. But the interface is kept here just in case it's fixed eventually. dhcp4 and has_dhcp4 are dummy arguments. Ninaw10 seems to always use DHCP. Signed-off-by: robert-hh <robert@hammelrath.com>
* extmod/modos: Only sync FAT filesystems using disk_ioctl.Damien George2024-05-27
| | | | | | | Eventually this needs to be made a generic call to the underlying VFS. But for now this prevents `disk_ioctl()` crashing on non-FAT filesystems. Signed-off-by: Damien George <damien@micropython.org>
* extmod/modlwip: Use Nagle algorithm and add support for TCP_NODELAY.Jared Hancock2024-05-23
| | | | | | | | | | | | | | | | | | | This adds support to use the Nagle algorithm implemented already in lwIP to determine when TCP data should be sent. As currently written, MicroPython will only create packets if there is <25% remaining in the send buffer. Using it, sending a small message of ~50 bytes will not trigger output of the message on the network. So it will remained queued until the TCP interval timer expires, which can be up to 500ms. Using Nagle's algorithm, the first write, no matter how small, will generate a packet on the network. And sending lots of data still makes efficient use of the link. In addition to this, an application designer may choose to always create packets for every write by setting the TCP_NODELAY socket option. That's also implemented in this commit.
* extmod/network_wiznet5k: Properly enable socket buffers for W5100(S).Jared Hancock2024-05-07
| | | | | | | | | | | The W5100 and W5100S only have 4 available sockets and 16kB of socket buffer. Allocating 16kB to either the receive or transmit buffer of a single socket is not allowed, so the current setup does not change the allocation for socket 0 from the reset default. ctlwizchip is returning -1 to indicate the error, but the response isn't being inspected and probably doesn't need to be. Signed-off-by: Jared Hancock <jared@greezybacon.me>
* extmod/modasyncio: Make mp_asyncio_context variable public.Damien George2024-04-24
| | | | | | | So it can be accessed by a port if needed, for example to see if asyncio has been imported. Signed-off-by: Damien George <damien@micropython.org>
* extmod/modopenamp: Use metal logging functions exclusively.iabdalkader2024-03-29
| | | | Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
* extmod/modopenamp: Set a default log handler for ports.iabdalkader2024-03-29
| | | | | | | Use the existing metal log handling mechanism instead of overriding the metal_log, which causes build issues when logging is enabled. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
* extmod/modtls_axtls: Add verify_mode and CERT_NONE constant.Damien George2024-03-28
| | | | | | | Supporting `verify_mode` and `CERT_NONE` is required for the new `ssl.py` code, as well as `requests` to work. Signed-off-by: Damien George <damien@micropython.org>
* examples/natmod/framebuf: Enable FrameBuffer.poly method.Damien George2024-03-28
| | | | Signed-off-by: Damien George <damien@micropython.org>
* extmod: Add interface and security constants at WLAN class level.iabdalkader2024-03-28
| | | | | | | | | | | | | | | | | Other constants such as `machine.Pin.OUT` are defined on the class that uses them, rather than at the module level. This commit makes that the case for WLAN network interfaces, adding IF_xxx and SEC_xxx constants. The SEC_xxx constants are named as such to match the `security` keyword that they are used with. And the IF_xxx constants have IF as a prefix so they are grouped together as names. This scheme of putting constants on the class means that only the available features (eg security configurations) are made available as constants. It also means that different network interfaces (eg WLAN vs LAN) can keep their own specific constants within their class, such as PHY_xxx for LAN. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
* extmod/network_wiznet5k: Properly enable interrupt signal on w5100s.Jared Hancock2024-03-25
| | | | | | | | | | According to the datasheet, the IEN bit to enable the interrupt is in the MR2 register, not the MR register. This is just cleanup as the interrupt appears to be enabled by default after resetting the chip. Tested on W5100S_EVB_PICO.
* extmod/modnetwork: Implement IPv6 API to set and get NIC configuration.Felix Dörre2024-03-19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit implements a new <AbstractNIC>.ipconfig() function for the NIC classes that use lwIP, to set and retrieve network configuration for a NIC. Currently this method supports: - ipconfig("addr4"): obtain a tuple (addr, netmask) of the currently configured ipv4 address - ipconfig("addr6"): obtain a list of tuples (addr, state, prefered_lifetime, valid_lifetime) of all currently active ipv6 addresses; this includes static, slaac and link-local addresses - ipconfig("has_dhcp4"): whether ipv4 dhcp has supplied an address - ipconfig("has_autoconf6"): if there is a valid, non-static ipv6 address - ipconfig(addr4="1.2.3.4/24"): to set the ipv4 address and netmask - ipconfig(addr6="2a01::2"): to set a static ipv6 address; note that this does not configure an interface route, as this does not seem supported by lwIP - ipconfig(autoconf6=True): to enable ipv6 network configuration with slaac - ipconfig(gw4="1.2.3.1"): to set the ipv4 gateway - ipconfig(dhcp4=True): enable ipv4 dhcp; this sets ipv4 address, netmask, gateway and a dns server - ipconfig(dhcp4=False): stops dhcp, releases the ip, and clears the configured ipv4 address. - ipconfig(dhcp6=True): enable stateless dhcpv6 to obtain a dns server There is also a new global configuration function network.ipconfig() that supports the following: - network.ipconfig(dns="2a01::2"): set the primary dns server (can be a ipv4 or ipv6 address) - network.ipconfig(prefer=6): to prefer ipv6 addresses to be returned as dns responses (falling back to ipv4 if the host does not have an ipv6 address); note that this does not flush the dns cache, so if a host is already in the dns cache with its v4 address, subsequent lookups will return that address even if prefer=6 is set This interface replaces NIC.ifconfig() completely, and ifconfig() should be marked as deprecated and removed in a future version. Signed-off-by: Felix Dörre <felix@dogcraft.de>
* all: Update extmod, ports, examples to build with new berkeley-db lib.Damien George2024-03-16
| | | | | | | | | | This provides a MicroPython-specific berkeley-db configuration in extmod/berkeley-db/berkeley_db_config_port.h, and cleans up the include path for this library. Fixes issue #13092. Signed-off-by: Damien George <damien@micropython.org>
* extmod/os_dupterm: Handle exception properly when it occurs in parallel.Felix Dörre2024-03-16
| | | | | | | | | | When an exception is handled and the stream is closed, but while this happens, another exception occurs or dupterm is deactivated for another reason, the initial deactivation crashes, because its dupterm is removed. Co-authored-by: Damien George <damien@micropython.org> Signed-off-by: Felix Dörre <felix@dogcraft.de>
* extmod/modopenamp_remoteproc: Add new OpenAMP RemoteProc class.iabdalkader2024-03-15
| | | | | | | | RemoteProc provides an API to load firmware and control remote processors. Note: port-specific operations must be implemented to support this class. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
* extmod/modopenamp: Add new OpenAMP module.iabdalkader2024-03-15
| | | | | | | | | This module implements OpenAMP's basic initialization and shared resources support, and provides support for OpenAMP's RPMsg component, by providing an `endpoint` type (a logical connection on top of RPMsg channel) which can be used to communicate with the remote core. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
* extmod/libmetal: Add MicroPython platform for libmetal.iabdalkader2024-03-15
| | | | | | | | | Add a MicroPython platform for libmetal, based on the generic platform. The MicroPython platform uses common mp_hal_xxx functions and allows ports to customize default configurations for libmetal. Signed-off-by: Jim Mussared <jim.mussared@gmail.com> Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
* extmod/machine_usb_device: Add support for Python USB devices.Angus Gratton2024-03-15
| | | | | | | | | | | | | This new machine-module driver provides a "USBDevice" singleton object and a shim TinyUSB "runtime" driver that delegates the descriptors and all of the TinyUSB callbacks to Python functions. This allows writing arbitrary USB devices in pure Python. It's also possible to have a base built-in USB device implemented in C (eg CDC, or CDC+MSC) and a Python USB device added on top of that. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* extmod/nimble: Check for active before setting address mode.Daniël van de Giessen2024-03-15
| | | | | | | | `BLE().config(addr_mode=...)` is not safe to call if the NimBLE stack is not yet active (because it tries to acquire mutexes which should be initialized first). Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
* extmod/modmachine: Add MICROPY_PY_MACHINE_RESET configuration option.Damien George2024-03-15
| | | | | | | Disabled by default, but enabled on all boards that previously had `MICROPY_PY_MACHINE_BARE_METAL_FUNCS` enabled. Signed-off-by: Damien George <damien@micropython.org>
* extmod/modmachine: Add MICROPY_PY_MACHINE_MEMX configuration option.Damien George2024-03-15
| | | | | | Enabled by default. Signed-off-by: Damien George <damien@micropython.org>