summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2024-05-16webassembly/proxy_c: Return undefined if dict lookup failed on JS side.Damien George
Instead of raising KeyError. These semantics match JavaScript behaviour and make it much more seamless to pass Python dicts through to JavaScript as though they were JavaScript {} objects. Signed-off-by: Damien George <damien@micropython.org>
2024-05-16webassembly/proxy_js: Create a special "undefined" type for Python.Damien George
This adds a new undefined singleton to Python, that corresponds directly to JavaScript `undefined`. It's accessible via `js.undefined`. Signed-off-by: Damien George <damien@micropython.org>
2024-05-16webassembly/proxy_js: Revert back to converting Py None to JS null.Damien George
This reverts part of commit fa23e4b093f81f03a24187c7ea0c928a9b4a661b, to make it so that Python `None` converts to JavaScript `null` (and JavaScript `null` already converts to Python `None`). That's consistent with how the `json` module converts these values back and forth. Signed-off-by: Damien George <damien@micropython.org>
2024-05-16esp32/panichandler: Print support information on panic.Daniël van de Giessen
When a fatal error occurs it's important to know which precise version it occurred on in order to be able to decode the crash dump information such as the backtrace. By wrapping around the built-in IDF panic handler we can print some extra information whenever a fatal error occurs. The message links to a new wiki page which contains additional information on how to debug ESP32 issues, and links to the bug reporting issue template. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2024-05-15stm32/pyb_can: Fix STM32G4 FDCAN source clock frequency.Angus Gratton
Fixes automatic baudrate calculation results. Default clock source on this SoC is HSE not PCLK1. We could fix this by switching to PCLK1 instead, but two extra complications: - PCLK1 on this board is a 42.5MHz and the Pyboard CAN sample_point calculation requires an exact match, which is harder to hit with this source frequency. - Would be a breaking change for any existing Python code on this board, i.e. specifying brp, bs1, bs2 to initialise CAN. In the future it might be worth looking switching to the PLL source on this SoC instead, as this is a much higher frequency that would give higher quality BRS bitrate matches (probably too high without using the second divider going into the CAN peripheral though, so more code changes needed also). This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-05-15examples/usb: Add README that points out the alternative usb modules.Angus Gratton
If someone starts from this directory then they won't know they exist, otherwise. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-05-15docs/library/asyncio: Document that ThreadSafeFlag now works on unix.Damien George
ThreadSafeFlag works on the unix port since commit df08c38c286561c08d5ac354428074817eb0c163. Signed-off-by: Damien George <damien@micropython.org>
2024-05-15docs/reference: Document how to mip install packages from GitLab.Olivier Lenoir
Signed-off-by: Olivier Lenoir <olivier.len02@gmail.com>
2024-05-15tools/mpremote: Add support to mip install from GitLab.Olivier Lenoir
Changes are: - main.py: Add gitlab:org/repo, gitlab:org/repo@branch. - mip.py: Implement install from GitLab. - README.md: Add mip install gitlab:org/repo@branch example. Signed-off-by: Olivier Lenoir <olivier.len02@gmail.com>
2024-05-14tests/micropython/import_mpy_invalid.py: Skip if target cant import mpy.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-05-14webassembly/mpconfigport: Enable importing of .mpy files.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-05-13webassembly/proxy_js: Convert JS undefined and JS null to Py None.Damien George
And change Py None conversion so it converts to JS undefined. The semantics for conversion of these objects are then: - Python None -> JavaScript undefined - JavaScript undefined -> Python None - JavaScript null -> Python None This follows Pyodide: https://pyodide.org/en/stable/usage/type-conversions.html Signed-off-by: Damien George <damien@micropython.org>
2024-05-13webassembly/proxy_c: Ensure objs thrown into generators are exceptions.Damien George
This commit defines a new `JsException` exception type which is used on the Python side to wrap JavaScript errors. That's then used when a JavaScript Promise is rejected, and the reason is then converted to a `JsException` for the Python side to handle. This new exception is exposed as `jsffi.JsException`. Signed-off-by: Damien George <damien@micropython.org>
2024-05-13webassembly/asyncio: Fix case where a Promise is resolved with no arg.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-05-13webassembly/proxy_c: Support more than 4 args when JS calls Py func.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-05-13examples/network: Add example of HTTPS client using non-blocking socket.Damien George
Non-blocking SSL streams can be difficult to get right, so provide a working example, of a HTTPS client. Signed-off-by: Damien George <damien@micropython.org>
2024-05-13examples/network: Rename SSL examples to start with https.Damien George
It's better for discoverability to have these examples named `https_xxx.py` rather than `http_xxx_ssl.py`. Signed-off-by: Damien George <damien@micropython.org>
2024-05-13examples/usb: Add a USBDevice example implementing the DFU protocol.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-05-13examples/usb: Add a very simple USBDevice example with host.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-05-09docs/library/machine.USBDevice: Update note about packages in mp-lib.Angus Gratton
Also fix a small typo. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-05-09shared/tinyusb: Stall the CDC IN endpoint while disconnecting.Angus Gratton
Only when dynamic USB devices are enabled. The issue here is that when the USB reset triggers, the dynamic USB device reset callback is called from inside the TinyUSB task. If that callback tries to print something then it'll call through to tud_cdc_write_flush(), but TinyUSB hasn't finished updating state yet to know it's no longer configured. Subsequently it may try to queue a transfer and then the low-level DCD layer panics. By explicitly stalling the endpoint first, usbd_edpt_claim() will fail and tud_cdc_write_flush() returns immediately. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-05-07extmod/network_wiznet5k: Properly enable socket buffers for W5100(S).Jared Hancock
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>
2024-05-07esp32/modesp32: Add mcu_temperature() function for C3/S2/S3 devices.Rick Sorensen
For ESP32C3/S2/S3 IDFv5 exposes new internal temperature API which is different to the base ESP32, IDFv4. Thanks to @robert-hh for cleaner code and testing sensor capability in these devices. See discussion #10443. Signed-off-by: Rick Sorensen <rick.sorensen@gmail.com>
2024-05-07docs/esp32/quickref: Add note about different ESP32 varieties.Rick Sorensen
Signed-off-by: Rick Sorensen <rick.sorensen@gmail.com>
2024-05-07webassembly/api: Resolve thenables returned from runPythonAsync.Damien George
JavaScript semantics are such that the caller of an async function does not need to await that function for it to run to completion. This commit makes that behaviour also apply to top-level async Python code run via `runPythonAsync()`. Signed-off-by: Damien George <damien@micropython.org>
2024-05-07webassembly/objpyproxy: Implement JS iterator protocol for Py iterables.Damien George
This allows using JavaScript for..of on Python iterables. Signed-off-by: Damien George <damien@micropython.org>
2024-05-06webassembly/objjsproxy: Fix proxying in arguments to JS new function.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-05-06webassembly/proxy_c: Only proxy across resolve/reject funs when needed.Damien George
To improve efficiency. Signed-off-by: Damien George <damien@micropython.org>
2024-05-06webassembly/proxy_c: Reject promises with a PythonError instance.Damien George
The `reason` in a rejected promise should be an instance of `Error`. That leads to better error messages on the JavaScript side. Signed-off-by: Damien George <damien@micropython.org>
2024-05-06webassembly/api: Fix importing micropython.mjs module from node REPL.Damien George
Fixes issue #14363. Signed-off-by: Damien George <damien@micropython.org>
2024-05-03stm32/i2c: Fix clock enable for I2C4 on STM32F7 MCUs.Damien George
This was broken by 5aec051f9f0e1be9750ca4f08478275f298087a3 when adding support for I2C4 on H7 MCUs. Signed-off-by: Damien George <damien@micropython.org>
2024-05-01stm32/mboot: Buffer the correct amount of bytes for a flash write.Damien George
Different MCUs have different requirements for the minimum number of bytes that can be written to internal flash. Signed-off-by: Damien George <damien@micropython.org>
2024-05-01stm32/flash: Fix writing final words to flash on H5 and H7 MCUs.Damien George
The calculations `num_word32 / 4` and `num_word32 / 8` were rounding down the number of words to program to flash, and therefore possibly truncating the data (eg mboot could miss writing the final few words of the firmware). That's fixed in this commit by adding extra logic to program any remaining words. And the logic for H5 and H7 is combined. Signed-off-by: Damien George <damien@micropython.org>
2024-05-01stm32/boards/LEGO_HUB_NO7: Add robust update logic to mboot.Damien George
Following change in 899592ac341ed9f10ee554424f964f6880fc8c48 Signed-off-by: Damien George <damien@micropython.org>
2024-05-01stm32/boards/LEGO_HUB_NO6: Write key after writing elements.Damien George
In case there is a power failure after during this operation, the key must be the last thing that is written, to indicate valid data. Signed-off-by: Damien George <damien@micropython.org>
2024-04-29docs/develop/optimizations: Fix typo identified in issue 14391.Matt Trentini
Signed-off-by: Matt Trentini <matt.trentini@gmail.com>
2024-04-26nrf/mpconfigport: Enable MICROPY_NLR_THUMB_USE_LONG_JUMP on nRF51xx.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-04-25py/nlrthumb: Make non-Thumb2 long-jump workaround opt-in.J. Neuschäfer
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 dd376a239dc4f47b0ee7866810fcda151f3cf6dd 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-24webassembly/api: Inject asyncio.run if needed by the script.Damien George
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-24webassembly: Add JavaScript-based asyncio support.Damien George
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-24webassembly/modjsffi: Add jsffi.async_timeout_ms.Damien George
This function exposes `setTimeout()` as an async function. Signed-off-by: Damien George <damien@micropython.org>
2024-04-24extmod/modasyncio: Make mp_asyncio_context variable public.Damien George
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-24webassembly/proxy_c: Fix then-continue to convert reason to throw value.Damien George
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-24webassembly/proxy_c: Fix proxy then reject handling.Damien George
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-24webassembly/objjsproxy: Fix handling of thrown value into JS generator.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-04-24webassembly/api: Allocate code data on C heap when running Python code.Damien George
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-24webassembly/api: Fix waiting for Emscripten module to be loaded.Damien George
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-22github/workflows: Run code size workflow on shared or port code changes.Damien George
To get more insight to firmware size changes when code changes. Signed-off-by: Damien George <damien@micropython.org>
2024-04-22tests/cpydiff: Add a note about risk of resizing memoryview targets.Angus Gratton
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-22py/objarray: Fix use-after-free if extending a bytearray from itself.Angus Gratton
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>