Wykres commitów

15852 Commity (master)

Autor SHA1 Wiadomość Data
Damien George e60e8079a7 nrf/mpconfigport: Enable MICROPY_NLR_THUMB_USE_LONG_JUMP on nRF51xx.
Signed-off-by: Damien George <damien@micropython.org>
2024-04-26 11:15:59 +10:00
J. Neuschäfer 7b050b366b py/nlrthumb: Make non-Thumb2 long-jump workaround opt-in.
Although the original motivation given for the workaround[1] is correct,
nlr.o and nlrthumb.o are linked with a small enough distance that the
problem does not occur, and the workaround isn't necessary. The distance
between the b instruction and its target (nlr_push_tail) is just 64
bytes[2], well within the ±2046 byte range addressable by an
unconditional branch instruction in Thumb mode.

The workaround induces a relocation in the text section (textrel), which
isn't supported everywhere, notably not on musl-libc[3], where it causes
a crash on start-up. With the workaround removed, micropython works on an
ARMv5T Linux system built with musl-libc.

This commit changes nlrthumb.c to use a direct jump by default, but
leaves the long jump workaround as an option for those cases where it's
actually needed.

[1]: commit dd376a239d

Author: Damien George <damien.p.george@gmail.com>
Date:   Fri Sep 1 15:25:29 2017 +1000

    py/nlrthumb: Get working again on standard Thumb arch (ie not Thumb2).

    "b" on Thumb might not be long enough for the jump to nlr_push_tail so
    it must be done indirectly.

[2]: Excerpt from objdump -d micropython:

000095c4 <nlr_push_tail>:
    95c4:       b510            push    {r4, lr}
    95c6:       0004            movs    r4, r0
    95c8:       f02d fd42       bl      37050 <mp_thread_get_state>
    95cc:       6943            ldr     r3, [r0, #20]
    95ce:       6023            str     r3, [r4, #0]
    95d0:       6144            str     r4, [r0, #20]
    95d2:       2000            movs    r0, #0
    95d4:       bd10            pop     {r4, pc}

000095d6 <nlr_pop>:
    95d6:       b510            push    {r4, lr}
    95d8:       f02d fd3a       bl      37050 <mp_thread_get_state>
    95dc:       6943            ldr     r3, [r0, #20]
    95de:       681b            ldr     r3, [r3, #0]
    95e0:       6143            str     r3, [r0, #20]
    95e2:       bd10            pop     {r4, pc}

000095e4 <nlr_push>:
    95e4:       60c4            str     r4, [r0, #12]
    95e6:       6105            str     r5, [r0, #16]
    95e8:       6146            str     r6, [r0, #20]
    95ea:       6187            str     r7, [r0, #24]
    95ec:       4641            mov     r1, r8
    95ee:       61c1            str     r1, [r0, #28]
    95f0:       4649            mov     r1, r9
    95f2:       6201            str     r1, [r0, #32]
    95f4:       4651            mov     r1, sl
    95f6:       6241            str     r1, [r0, #36]   @ 0x24
    95f8:       4659            mov     r1, fp
    95fa:       6281            str     r1, [r0, #40]   @ 0x28
    95fc:       4669            mov     r1, sp
    95fe:       62c1            str     r1, [r0, #44]   @ 0x2c
    9600:       4671            mov     r1, lr
    9602:       6081            str     r1, [r0, #8]
    9604:       e7de            b.n     95c4 <nlr_push_tail>

[3]: https://www.openwall.com/lists/musl/2020/09/25/4

Signed-off-by: J. Neuschäfer <j.ne@posteo.net>
2024-04-25 16:06:28 +10:00
Damien George 49af8cad49 webassembly/api: Inject asyncio.run if needed by the script.
This allows a simple way to run the existing asyncio tests under the
webassembly port, which doesn't support `asyncio.run()`.

Signed-off-by: Damien George <damien@micropython.org>
2024-04-24 16:24:00 +10:00
Damien George 8a3546b3bd webassembly: Add JavaScript-based asyncio support.
This commit adds a significant portion of the existing MicroPython asyncio
module to the webassembly port, using parts of the existing asyncio code
and some custom JavaScript parts.

The key difference to the standard asyncio is that this version uses the
JavaScript runtime to do the actual scheduling and waiting on events, eg
Promise fulfillment, timeouts, fetching URLs.

This implementation does not include asyncio.run(). Instead one just uses
asyncio.create_task(..) to start tasks and then returns to the JavaScript.
Then JavaScript will run the tasks.

The implementation here tries to reuse as much existing asyncio code as
possible, and gets all the semantics correct for things like cancellation
and asyncio.wait_for.  An alternative approach would reimplement Task,
Event, etc using JavaScript Promise's.  That approach is very difficult to
get right when trying to implement cancellation (because it's not possible
to cancel a JavaScript Promise).

Signed-off-by: Damien George <damien@micropython.org>
2024-04-24 16:24:00 +10:00
Damien George 84d6f8e8cb webassembly/modjsffi: Add jsffi.async_timeout_ms.
This function exposes `setTimeout()` as an async function.

Signed-off-by: Damien George <damien@micropython.org>
2024-04-24 16:24:00 +10:00
Damien George 967ad38ac7 extmod/modasyncio: Make mp_asyncio_context variable public.
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>
2024-04-24 16:23:59 +10:00
Damien George d998ca78c8 webassembly/proxy_c: Fix then-continue to convert reason to throw value.
When a Promise is rejected on the JavaScript side, the reject reason should
be thrown into the encapsulating generator on the Python side.

Signed-off-by: Damien George <damien@micropython.org>
2024-04-24 16:23:42 +10:00
Damien George 92b3b69648 webassembly/proxy_c: Fix proxy then reject handling.
An exception on the Python side should be passed to the Promise reject
callback on the JavaScript side.

Signed-off-by: Damien George <damien@micropython.org>
2024-04-24 16:14:17 +10:00
Damien George 4c3f5f552b webassembly/objjsproxy: Fix handling of thrown value into JS generator.
Signed-off-by: Damien George <damien@micropython.org>
2024-04-24 16:07:00 +10:00
Damien George 9c7f0659e2 webassembly/api: Allocate code data on C heap when running Python code.
Otherwise Emscripten allocates it on the Emscripten C stack, which will
overflow for large amounts of code.

Fixes issue #14307.

Signed-off-by: Damien George <damien@micropython.org>
2024-04-24 13:15:54 +10:00
Damien George 45848f77ca webassembly/api: Fix waiting for Emscripten module to be loaded.
In modularize mode, the `_createMicroPythonModule()` constructor must be
await'ed on, before `Module` is ready to use.

Signed-off-by: Damien George <damien@micropython.org>
2024-04-24 13:15:54 +10:00
Damien George 49ce7a6075 github/workflows: Run code size workflow on shared or port code changes.
To get more insight to firmware size changes when code changes.

Signed-off-by: Damien George <damien@micropython.org>
2024-04-22 12:38:29 +10:00
Angus Gratton 6877987002 tests/cpydiff: Add a note about risk of resizing memoryview targets.
This a stop-gap until there is a proper fix for this.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-04-22 11:51:18 +10:00
Angus Gratton 4bed614e70 py/objarray: Fix use-after-free if extending a bytearray from itself.
Two cases, one assigning to a slice.
Closes https://github.com/micropython/micropython/issues/13283

Second is extending a slice from itself, similar logic.

In both cases the problem occurs when m_renew causes realloc to move the
buffer, leaving a dangling pointer behind.

There are more complex and hard to fix cases when either argument is a
memoryview into the buffer, currently resizing to a new address breaks
memoryviews into that object.

Reproducing this bug and confirming the fix was done by running the unix
port under valgrind with GC-aware extensions.

Note in default configurations with GIL this bug exists but has no impact
(the free buffer won't be reused while the function is still executing, and
is no longer referenced after it returns).

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-04-22 11:50:52 +10:00
Vonasmic ce491ab0d1 py/obj: Fix initialiser order in MP_DEFINE_CONST_OBJ_TYPE_NARGS_ macros.
This commit swaps the order of the `flags` and `name` struct initialisers
for `mp_obj_type_t`, to fix an incompatibility with C++.  The original
order of the initialiser didn't match the definition of the type, and
although that's still legal C, it's not legal C++.

Signed-off-by: Vonasmic <kasarkal123@gmail.com>
2024-04-22 11:10:23 +10:00
stijn 40f7e9ce20 py/objfun: Fix C++ compatibility with casting in inline functions.
Explicit casts are needed.

Fixes recent changes from 648a7578da and
9400229766.

Signed-off-by: stijn <stijn@ignitron.net>
2024-04-22 10:34:01 +10:00
Michiel W. Beijen 3129b69e0f rp2/README: Fix typo, improve sentence about building with other boards.
Signed-off-by: Michiel W. Beijen <mb@x14.nl>
2024-04-22 10:20:54 +10:00
Simon Wood 19844b4983 rp2/modmachine: Prevent lock-up when lightsleep() called within thread.
When `lightsleep()` is called from within a thread the interrupts may not
be enabled on current core, and thus the call to `lightsleep()` never
completes.

Fixes issue #14092.

Signed-off-by: Simon Wood <simon@mungewell.org>
2024-04-22 10:09:30 +10:00
J. Neuschäfer f76cf29402 github/workflows: Update coverage workflow to codecov-action@v4.
Fixes: https://github.com/micropython/micropython/issues/14340

Signed-off-by: J. Neuschäfer <j.ne@posteo.net>
2024-04-20 19:43:50 +02:00
Angus Gratton d11ca092f7 shared/tinyusb: Fix dynamic USB control callbacks for wLength==0.
In the case where an OUT control transfer triggers with wLength==0 (i.e.
all data sent in the SETUP phase, and no additional data phase) the
callbacks were previously implemented to return b"" (i.e. an empty buffer
for the data phase).

However this didn't actually work as intended because b"" can't provide a
RW buffer (needed for OUT transfers with a data phase to write data into),
so actually the endpoint would stall.

The symptom was often that the device process the request (if processing
it in the SETUP phase when all information was already available), but the
host sees the endpoint stall and eventually returns an error.

This commit changes the behaviour so returning True from the SETUP phase of
a control transfer queues a zero length status response.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-04-17 12:39:47 +10:00
iabdalkader 53d0050255 lib/arduino-lib: Update submodule to the latest.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-04-11 17:04:10 +02:00
Damien George 5114f2c1ea webassembly/proxy_js: Allow a Python proxy of a function to be undone.
This optimises the case where a Python function is, for example, stored to
a JavaScript attribute and then later retrieved from Python.  The Python
function no longer needs to be a proxy with double proxying needed for the
call from Python -> JavaScript -> Python.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-30 13:13:51 +11:00
Damien George 7c62fbe3f2 webassembly/proxy_js: Promote Python thenable to a Promise.
Signed-off-by: Damien George <damien@micropython.org>
2024-03-30 13:13:51 +11:00
Damien George 3997532186 webassembly/proxy_c: Ensure return value of async fun is passed to JS.
Signed-off-by: Damien George <damien@micropython.org>
2024-03-30 13:13:51 +11:00
iabdalkader 87d821ab49 mimxrt: Add support for OpenAMP.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-03-29 17:59:29 +11:00
iabdalkader 23d7a915c1 stm32/mpremoteprocport: Use metal logging functions.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-03-29 17:59:18 +11:00
iabdalkader 8936d3af46 extmod/modopenamp: Use metal logging functions exclusively.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-03-29 17:59:04 +11:00
iabdalkader aa0f3ebe93 extmod/modopenamp: Set a default log handler for ports.
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>
2024-03-29 17:58:18 +11:00
Damien George b829450359 samd/mcu: Guard static function with appropriate #if.
Signed-off-by: Damien George <damien@micropython.org>
2024-03-29 17:48:06 +11:00
Damien George 20a86eff53 tests/net_inet: Add simpler tls sites test, and skip existing on axtls.
Ports that use axtls cannot run the `test_tls_sites.py` test because the
sites it connects to use advanced ciphers.  So skip this test on such
ports, and add a new, simpler test that doesn't require certificate
verification and works with axtls.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-29 10:46:09 +11:00
Damien George c3e37d1fac extmod/modtls_axtls: Add verify_mode and CERT_NONE constant.
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>
2024-03-28 17:36:13 +11:00
Damien George 628a37e6cf docs/reference/mpyfiles: Document change in .mpy sub-version.
Signed-off-by: Damien George <damien@micropython.org>
2024-03-28 16:21:35 +11:00
Damien George bdbc869f9e py/persistentcode: Bump .mpy sub-version to 6.3.
This is required because the .mpy native ABI was changed by the
introduction of `mp_proto_fun_t`, see commits:
- 416465d81e
- 5e3006f117
- e2ff00e811

And three `mp_binary` functions were added to `mp_fun_table` in
commit d2276f0d41.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-28 16:18:26 +11:00
Damien George 8b0efde927 examples/natmod/framebuf: Enable FrameBuffer.poly method.
Signed-off-by: Damien George <damien@micropython.org>
2024-03-28 16:18:09 +11:00
Damien George d2276f0d41 py/dynruntime: Add mp_binary_get_size/get_val_array/set_val_array.
These are needed to read/write array.array objects, which is useful in
native code to provide fast extensions that work with big arrays of data.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-28 16:18:09 +11:00
robert-hh 4662a71f44 drivers/memory: Add IS25LPWP064D chip to list of external flash devices.
Confirguration provided by by @ironss-iotec.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-03-28 15:52:40 +11:00
robert-hh d9b9e88899 samd/samd_qspiflash: Avoid reading status byte 2 when not available.
Change provided by @ironss-iotec.

Tested with Adafruit, SEEED and MiniFig boards for non-interference.

Fixes issue #14190.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-03-28 15:52:40 +11:00
robert-hh 3980b36173 samd/samd_spiflash: Allow configuring the flash SPI baudrate.
Using a define for MICROPY_HW_SPIFLASH_BAUDRATE in mpconfigboard.h.  If not
defined the default is 24MHz.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-03-28 15:52:28 +11:00
robert-hh e8e9a39a6d samd/mcu: Update clock config after changes to USB.
For all MCUs: run the test for USB clock recovery mode fallback after USB
has been started.

For samd21: change DFLL48 config from the open loop mode variant to sync
with the XOSC32KULP.  Matches better the 48MHz value.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-03-28 15:49:41 +11:00
robert-hh b41360d119 samd/boards: Enable MICROPY_HW_DFLL_USB_SYNC on appropriate boards.
For the boards ADAFRUIT_TRINKET_M0 and MINISAM_M4.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-03-28 15:37:01 +11:00
robert-hh 328b6df058 samd/README: Fix incorrect port directory name.
At a single place, STM32 was used instead of SAMD.

Signed-off-by: robert-hh <robert@hammelrath.com>
2024-03-28 15:36:26 +11:00
iabdalkader e8dd519e2d esp32/network_wlan: Add interface and security WLAN constants.
Following the same change to extmod network interfaces.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-03-28 13:01:55 +11:00
iabdalkader 81dff08bf2 esp8266/network_wlan: Add interface and security WLAN constants.
Following the same change to extmod network interfaces.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-03-28 13:01:55 +11:00
iabdalkader 7753045a8f extmod: Add interface and security constants at WLAN class level.
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>
2024-03-28 12:52:28 +11:00
iabdalkader 5a7d78c732 mimxrt,stm32: Set the security mode for the default WiFi AP.
The default CYW43 WiFi AP settings were missing the security mode, leaving
the AP in open mode by default.  That's changed by this commit to use
WPA/WPA2 by default.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-03-28 12:51:50 +11:00
Matt Trentini db1b5df16c stm32/README: Update list of supported STM32 series.
Signed-off-by: Matt Trentini <matt.trentini@gmail.com>
2024-03-28 12:34:46 +11:00
Damien George 35e8d184b1 shared/tinyusb: Increase default string descr max length to 40 chars.
When defining custom USB devices, longer strings may be needed.  Eventually
the memory for string descriptors can be allocated on demand, but for now
this bigger value should be reasonable.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-27 23:57:57 +11:00
Angus Gratton 0f16ae92c0 shared/tinyusb: Update some code comments for runtime USB.
Updates a few code comments that were out of date or poorly worded. No code
changes.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-03-27 23:55:41 +11:00
Angus Gratton 935f5391b5 shared/tinyusb: Don't disconnect on soft reset unless USB was active.
Previously, constructing the singleton USBDevice object was enough to
trigger a USB disconnect on soft reset. Now it also has to be active.

The only case where this changes the behaviour is if the USBDevice object
has been constructed but never set to active (no more disconnect in this
case). Otherwise, behaviour is the same.

This change was requested by hippy on the raspberrypi forums.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-03-27 23:54:12 +11:00
Damien George 79edaddf50 rp2/CMakeLists: Apply O2 optimisation to map, mpz and vm source code.
Enabling this optimisation increases the RPI_PICO firmware by +3344 bytes.

Performace change is:

diff of scores (higher is better)
N=100 M=100             rpi-base -> rpi-opt      diff      diff% (error%)
bm_chaos.py               196.56 ->  215.26 :  +18.70 =  +9.514% (+/-0.05%)
bm_fannkuch.py             52.47 ->   54.37 :   +1.90 =  +3.621% (+/-0.05%)
bm_fft.py                1476.74 -> 1530.06 :  +53.32 =  +3.611% (+/-0.01%)
bm_float.py              2305.65 -> 2444.11 : +138.46 =  +6.005% (+/-0.08%)
bm_hexiom.py               32.83 ->   35.09 :   +2.26 =  +6.884% (+/-0.05%)
bm_nqueens.py            2335.85 -> 2259.78 :  -76.07 =  -3.257% (+/-0.06%)
bm_pidigits.py            366.23 ->  465.81 :  +99.58 = +27.191% (+/-0.04%)
bm_wordcount.py            41.20 ->   41.87 :   +0.67 =  +1.626% (+/-0.01%)
core_import_mpy_multi.py  327.44 ->  335.24 :   +7.80 =  +2.382% (+/-0.08%)
core_import_mpy_single.py  63.41 ->   64.98 :   +1.57 =  +2.476% (+/-0.21%)
core_locals.py             27.24 ->   29.19 :   +1.95 =  +7.159% (+/-0.01%)
core_qstr.py              137.31 ->  140.84 :   +3.53 =  +2.571% (+/-0.03%)
core_str.py                18.44 ->   18.10 :   -0.34 =  -1.844% (+/-0.03%)
core_yield_from.py        221.69 ->  211.72 :   -9.97 =  -4.497% (+/-0.01%)
misc_aes.py               303.38 ->  308.72 :   +5.34 =  +1.760% (+/-0.02%)
misc_mandel.py           1501.00 -> 1746.60 : +245.60 = +16.362% (+/-0.04%)
misc_pystone.py          1348.22 -> 1456.75 : +108.53 =  +8.050% (+/-0.07%)
misc_raytrace.py          223.81 ->  246.16 :  +22.35 =  +9.986% (+/-0.07%)
viper_call0.py            331.05 ->  331.10 :   +0.05 =  +0.015% (+/-0.00%)
viper_call1a.py           323.34 ->  323.39 :   +0.05 =  +0.015% (+/-0.00%)
viper_call1b.py           241.01 ->  241.04 :   +0.03 =  +0.012% (+/-0.00%)
viper_call1c.py           242.88 ->  242.92 :   +0.04 =  +0.016% (+/-0.00%)
viper_call2a.py           318.41 ->  318.46 :   +0.05 =  +0.016% (+/-0.00%)
viper_call2b.py           211.27 ->  211.30 :   +0.03 =  +0.014% (+/-0.00%)

And the test `tests/basics/builtin_pow3_intbig.py` now passes (it uses a
lot of mpz code and previously took longer than 10 seconds to run on
RPI_PICO, which would lead to a timeout in the test runner).

Signed-off-by: Damien George <damien@micropython.org>
2024-03-27 12:16:30 +11:00