summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2024-07-26nrf/modules/machine/pin: Disable IRQ with pin.irq(handler=None).robert-hh
Before, the input was still set to `pin.irq()` mode, only the handler was disabled. That prevented switching the pin between input and output mode. Signed-off-by: robert-hh <robert@hammelrath.com>
2024-07-26nrf/modules/machine/soft_pwm: Ensure duty_width is always valid.Andrew Leech
Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-07-26nrf/Makefile: Enable LTO by default only on newer gcc.Andrew Leech
Older gcc/binutils linker does not support lto with wrap. Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-07-26nrf/modules/machine/uart: Support sending data stored in flash.Andrew Leech
Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-07-26nrf: Consolidate all stdio functions.Andrew Leech
Consolidate CDC, UART and NUS stdio interfaces into the one handler. Allows any/all of them to be enabled separately. Updates UART REPL to use similar define to other platforms: `MICROPY_HW_ENABLE_UART_REPL`. USB now uses the shared/tinyusb CDC implementation. Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-07-25tests/multi_net: Fix skipping of SSLContext tests when .der don't exist.Damien George
The `sslcontext_server_client_ciphers.py` test was using stat to test for the .der files after it already tried to open them for reading. That is now fixed. And `sslcontext_server_client.py` is adjusted to use the same pattern for skipping the test. Signed-off-by: Damien George <damien@micropython.org>
2024-07-25github/workflows: Add RISC-V 64 bits Unix port to CI.Alessandro Gatti
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-07-25tests/run-tests.py: Make Windows test skipping more granular.stijn
Signed-off-by: stijn <stijn@ignitron.net>
2024-07-25github/workflows: Improve MSYS2-based CI builds.stijn
Install the mingw variant of Python since it behaves more like a 'real' Windows CPython than the msys2 variant: os.name == 'nt', not 'posix'. Note that os.sep is still '/' though so we don't actually need to skip the import_file test. This way one single Python version can be used both for running run-tests.py and getting the expected test output. Signed-off-by: stijn <stijn@ignitron.net>
2024-07-25py/runtime: Fix self arg passed to classmethod when accessed via super.Damien George
Thanks to @AJMansfield for the original test case. Signed-off-by: Damien George <damien@micropython.org>
2024-07-25py/misc: Fix msvc and C++ compatibility.stijn
Use explicit casts to suppress warnings about implicit conversions, add a workaround for constant expression conditional, and make functions static inline (as is done in the rest of the codebase) to suppress 'warning C4505: unreferenced function with internal linkage has been removed'. (Follow up to fix commit 908ab1ceca15ee6fd0ef82ca4cba770a3ec41894) Signed-off-by: stijn <stijn@ignitron.net>
2024-07-25py/objtype: Validate super() arguments.stijn
This fixes various null dereferencing and out-of-bounds access because super_attr assumes the held obj is effectively an object of the held type, which is now verified. Fixes issue #12830. Signed-off-by: stijn <stijn@ignitron.net>
2024-07-25tests/cpydiff: Add diff for overriding __init__.David Lechner
This adds a CPython diff that explains why calling `super().__init__()` is required in MicroPython when subclassing a native type (because `__new__` and `__init__` are not separate functions). Signed-off-by: David Lechner <david@pybricks.com>
2024-07-25py/objtype: Avoid crash on calling members of uninitialized native type.Laurens Valk
When subclassing a native type, calling native members in `__init__` before `super().__init__()` has been called could cause a crash. In this situation, `self` in `mp_convert_member_lookup` is the `native_base_init_wrapper_obj`. The check added in this commit ensures that an `AttributeError` is raised before this happens, which is consistent with other failed lookups. Also fix a typo in a related comment. Signed-off-by: Laurens Valk <laurens@pybricks.com>
2024-07-25examples/usercmodule/cexample: Add more advanced native class.Laurens Valk
This adds a separate `AdvancedTimer` class that demonstrates a few more advanced concepts usch as custom handlers for printing and attributes. Signed-off-by: Laurens Valk <laurens@pybricks.com>
2024-07-24rp2/lwip_inc: Enable IPv6 per default on rp2 port.Felix Dörre
Having IPv6 support is important, especially for IoT-Devices which might be many, requiring individual IP-addresses. In particular direct access via link-local addresses and having deterministic SLAAC-addresses can be quite convenient. Also in IPv6-only networks or for connecting to IPv6-only services, this is very useful. For the Pico W, there is enough flash and RAM that enabling IPv6 by default is the right choice. Should IPv6 support in a network exist (i.e. there are Router Advertisements), but not provide connectivity, connecting by domain name should not be a problem as DNS will default to return the IPv4-address (if that exists), unless reconfigured at runtime to prefer IPv6. In any case a user can disable obtaining SLAAC-addresses with: <nic>.ipconfig(autoconf6=False) Signed-off-by: Felix Dörre <felix@dogcraft.de>
2024-07-23rp2: Stop machine.idle() blocking indefinitely.Angus Gratton
Updates rp2 port to always resume from idle within 1ms max. When rp2 port went tickless the behaviour of machine.idle() changed as there is no longer a tick interrupt to wake it up every millisecond. On a quiet system it would now block indefinitely. No other port does this. See parent commit for justification of why this change is useful. Also adds a test case that fails without this change. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-07-23docs: Specify that machine.idle() returns at least every 1ms.Angus Gratton
A lot of existing code (i.e. micropython-lib lps22h, lcd160cr sensor drivers, lora sync_modem driver, usb-device-hid) calls machine.idle() inside a tight loop that is polling some condition. This reduces the power usage compared to constantly looping, but can be faster than calling a sleep function. However on a tickless port there's not always an interrupt before the condition they are polling for, so it's difficult to restructure this code if machine.idle() doesn't have any upper limit on execution time. This commit specifies an upper limit of 1ms before machine.idle() resumes execution. This is already the case for all ports except rp2. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-07-23rp2/rp2_pio: Disable correct IRQ for PIO1.Phil Howard
Fix a typo that was disabling PIO0_IRQ_1 instead of PIO1_IRQ_0. Signed-off-by: Phil Howard <phil@gadgetoid.com>
2024-07-23rp2: Fix wakeup from WFE on core1.Angus Gratton
If core1 executes `mp_wfe_or_timeout()` then it needs to receive an interrupt or a SEV to resume execution, but the soft timer interrupt only fires on core 0. This fix adds a SEV to the soft timer interrupt handler. This issue was masked by the issue fixed in the previous commit, as WFE previously wasn't suspending properly. Verified via the existing thread_sleep2 test. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-07-23rp2: Fix power consumption when sleeping with a timeout.Angus Gratton
Fixes a regression introduced in 3af006efb39ad0b7aa7c0401c93329b654bca617 where WFE never blocked in `mp_wfe_or_timeout()` function and would busy-wait instead. This increases power consumption measurably. Root cause is that `mp_wfe_or_timeout()` calls soft timer functions that (after the regression) call `recursive_mutex_enter()` and `recursive_mutex_exit()`. The exit calls `lock_internal_spin_unlock_with_notify()` and the default pico-sdk implementation of this macro issues a SEV which negates the WFE that follows it, meaning the CPU never suspends. See https://forums.raspberrypi.com/viewtopic.php?p=2233908 for more details. The fix in this comment adds a custom "nowait" variant mutex that doesn't do WFE/SEV, and uses this one for PendSV. This will use more power when there's contention for the PendSV mutex as the other core will spin, but this shouldn't happen very often. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-07-23unix/main: Fix GCC builds for RISC-V 64 bits.Alessandro Gatti
This contains a workaround to silence a possibly incorrect warning when building the Unix port with GCC targeting RISC-V 64 bits. Fixes issue #12838. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-07-23esp32/machine_timer: Limit timer numbers for ESP32C3.robert-hh
The ESP32C3 has only two timers in one group. In the code this is reflected as two groups with one timer. Signed-off-by: robert-hh <robert@hammelrath.com>
2024-07-23tests/run-tests.py: Enable thread tests on esp32.Angus Gratton
Before the fix in parent commit, some of these tests hung indefinitely. After, they seem to consistently pass. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-07-23esp32/mpthreadport: Fix uneven GIL allocation between Python threads.Angus Gratton
Explicitly yield each time a thread mutex is unlocked. Key to understanding this bug is that Python threads run at equal RTOS priority, and although ESP-IDF FreeRTOS (and I think vanilla FreeRTOS) scheduler will round-robin equal priority tasks in the ready state it does not make a similar guarantee for tasks moving between ready and waiting. The pathological case of this bug is when one Python thread task is busy (i.e. never blocks) it will hog the CPU more than expected, sometimes for an unbounded amount of time. This happens even though it periodically unlocks the GIL to allow another task to run. Assume T1 is busy and T2 is blocked waiting for the GIL. T1 is executing and hits a condition to yield execution: 1. T1 calls MP_THREAD_GIL_EXIT 2. FreeRTOS sees T2 is waiting for the GIL and moves it to the Ready list (but does not preempt, as T2 is same priority, so T1 keeps running). 3. T1 immediately calls MP_THREAD_GIL_ENTER and re-takes the GIL. 4. Pre-emptive context switch happens, T2 wakes up, sees GIL is not available, and goes on the waiting list for the GIL again. To break this cycle step 4 must happen before step 3, but this may be a very narrow window of time so it may not happen regularly - and quantisation of the timing of the tick interrupt to trigger a context switch may mean it never happens. Yielding at the end of step 2 maximises the chance for another task to run. Adds a test that fails on esp32 before this fix and passes afterwards. Fixes issue #15423. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-07-23extmod/vfs: Fix buffer overflow of string comparison in umount.Junwha
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>
2024-07-23extmod/vfs_fat: Set default volume label on mkfs if it's defined.Terence Stenvold
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.
2024-07-22extmod/moductypes: Validate the descriptor tuple.stijn
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>
2024-07-22extmod/modbtree: Add checks for already-closed database.Michael Vornovitsky
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>
2024-07-20extmod/modos: Include os.sep entry if MICROPY_VFS is enabled.Damien George
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>
2024-07-20extmod/modmachine: Use sys.exit as implementation of machine.soft_reset.Damien George
It does the same thing, raising `SystemExit`. Signed-off-by: Damien George <damien@micropython.org>
2024-07-20shared/runtime/pyexec: Make a raised SystemExit always do a forced exit.Damien George
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>
2024-07-20shared/tinyusb/mp_usbd_cdc: Skip writing to an uninitialized USB device.robert-hh
During execution of `boot.py` the USB device is not yet initialized. Any attempt to write to the CDC (eg calling `print()`) would lock up the device. This commit skips writing when the USB device is not initialized. Any output from `boot.py` is lost, but the device does not lock up. Also removed unnecessary declaration of `tusb_init()`. Signed-off-by: robert-hh <robert@hammelrath.com>
2024-07-19tests/multi_bluetooth/perf_gatt_notify.py: Reduce connection interval.Damien George
To test that the notification ping-pong can be low latency. Signed-off-by: Damien George <damien@micropython.org>
2024-07-19webassembly: Reuse PyProxy objects when they are the same Python object.Damien George
This commit makes it so that PyProxy objects are reused (on the JavaScript side) when they correspond to an existing Python object that is the same object. For example, proxying the same Python function to JavaScript, the same PyProxy instance is now used. This means that if `foo` is a Python function then accessing it on the JavaScript side such as `api.globals().get("foo")` has the property that: api.globals().get("foo") === api.globals().get("foo") Prior to this commit the above was not true because new PyProxy instances were created each time `foo` was accessed. Signed-off-by: Damien George <damien@micropython.org>
2024-07-19py/gc: Remove commented-out functions.Damien George
These are old, unused, and most of them no longer compile. The `gc_test()` function is superseded by the test suite. Signed-off-by: Damien George <damien@micropython.org>
2024-07-18py/sequence: Remove unused len argument from mp_seq_extract_slice.Damien George
Also put this function inside the `MICROPY_PY_BUILTINS_SLICE` guard, because it's only usable when that option is enabled. Signed-off-by: Damien George <damien@micropython.org>
2024-07-18py/lexer: Add static assert that token enum values all fit in a byte.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-07-18py: Remove 5 TODOs in emitbc, objrange and repl.Damien George
These TODOs don't need to be done: - Calling functions with keyword arguments is less common than without them, so adding an extra byte overhead to all calls regardless of whether they use keywords or not would overall increase generated bytecode size. - Restricting `range` objects to machine-sized ints has been adequate for a long time now, so no need to change that and make it more complicated and slower. - Printing spaces in tab completion does not need to be optimised. Signed-off-by: Damien George <damien@micropython.org>
2024-07-18tests/extmod: Make get_event_loop tests compatible with CPython 3.12.Damien George
Follow up to 2e852522b178e6e9b2f0cdb954ba44aa9e7d7c0d: instead of having .exp files for the get_event_loop tests, tweak them so they are compatible with CPython 3.12. This requires calling `asyncio.set_event_loop()` so there is an active event loop and `asyncio.get_event_loop()` succeeds without a warning. Signed-off-by: Damien George <damien@micropython.org>
2024-07-17unix/mpbtstackport_usb: Remove thread detached attribute.Damien George
As in the previous commit, the thread is later joined so can't be detached. Signed-off-by: Damien George <damien@micropython.org>
2024-07-17unix/mpbthciport: Remove thread detached attribute.Leo Chung
A detached thread is not joinable, and the behavior maybe undefined. Signed-off-by: Leo Chung <gewalalb@gmail.com>
2024-07-15unix/modtermios: Add more baudrate options.Lennart
This adds some more baudrate option as they are available in the termios.h header - up to a point that seems reasonable in an embedded context. Signed-off-by: Lennart Schierling <Lennart@binarylabs.dev>
2024-07-15github/workflows: Use macos-latest for unix macos CI.Damien George
macos-11.0 is no longer available. With this change in the macos version, some tests which previously failed now pass, and some different tests now fail. Exclude those that fail from the CI until they can be fixed properly. Signed-off-by: Damien George <damien@micropython.org>
2024-07-15extmod/modre: Rename re_exec to re_exec_helper to avoid clash on BSD.Owen
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
2024-07-12extmod/machine_spi: Support firstbit=LSB for machine.SoftSPI.robert-hh
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>
2024-07-12extmod/network_nina: Fix the AP security mode constants.iabdalkader
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>
2024-07-11extmod/modmachine: Allow more than one argument to machine.freq().robert-hh
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>
2024-07-05tests/stress/bytecode_limit.py: Make test more robust with low memory.Damien George
A target may have enough RAM to run the n=433 test but then run out of RAM on the n=432 test. So allow the test to skip on the n=432 case before it prints any output. Signed-off-by: Damien George <damien@micropython.org>
2024-07-05tests/thread/stress_aes.py: Fix logic waiting for finished threads.Damien George
Because the main thread executes `thread_entry()` it means there's an additional one added to `count`, so the test must wait for the count to reach `n_thread + 1`. Signed-off-by: Damien George <damien@micropython.org>