summaryrefslogtreecommitdiff
path: root/shared
AgeCommit message (Collapse)Author
7 daysshared/runtime: Set exit code according to the SystemExit exception.John Smith
Add abort setup code `nlr_set_abort` to the standard runtime executor. This makes the standard runtime respond to abort signal without any further modifications. - When aborted, the program exits with 137 exit code (configurable, same as posix sig abort), to differentiate from a normal shutdown. - When exited by exception/crash, the program will exit with exit code 1 (configurable). - When exited by exception KeyboardInterrupt, the program will exit with exit code 130 (configurable, same as posix sig int). - When exited with a exit code (from Python environment), this code is propagated. When a different object is passed, exit code is set to 1 and the value printed, to be consistent with Python docs: https://python.readthedocs.io/en/latest/library/exceptions.html#SystemExit Signed-off-by: John Smith <jsmith@jsmith.cz>
11 daysshared/runtime/pyexec: Remove legacy USB IRQ enable code.Andrew Leech
It's very STM32 USB stack specific and doesn't generalise well to other ports. So remove it. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2025-10-02all: Use "static inline" consistently in function definitions.Jeff Epler
Signed-off-by: Jeff Epler <jepler@unpythonic.net>
2025-09-25shared/runtime/mpirq: Check separate hard IRQ stack correctly.Chris Webb
On the zephyr port, hard IRQ handlers run with a separate stack on a different thread, so each call to mp_irq_dispatch() and mp_irq_handler() has to be wrapped with adjustments to the stack-limit checker. Move these adjustments into the shared mp_irq_dispatch(), introducing MICROPY_STACK_SIZE_HARD_IRQ which a port can define to non-zero if it uses a separate stack for hard IRQ handlers. We only need wrap the hard dispatch case. This should reduce binary size on zephyr without affecting other ports. Signed-off-by: Chris Webb <chris@arachsys.com>
2025-09-25shared/runtime/softtimer: Add support for hard callbacks.Chris Webb
Add a flag SOFT_TIMER_HARD_CALLBACK to request that a soft timer's python callback is run directly from the IRQ handler with the scheduler and heap locked, instead of being scheduled via mp_sched_schedule(). Signed-off-by: Chris Webb <chris@arachsys.com>
2025-09-25shared/runtime/mpirq: Factor out mp_irq_dispatch() and use it.Chris Webb
Separate out a routine to call an arbitrary function with arbitrary argument either directly as a hard-IRQ handler or scheduled as a soft-IRQ handler, adjusting mp_irq_handler() to wrap this. This can then be used to implement other hard/soft callbacks, such as for machine.Timer. Signed-off-by: Chris Webb <chris@arachsys.com>
2025-09-15ports: Remove unneeded future imports.Jeff Epler
Signed-off-by: Jeff Epler <jepler@unpythonic.net>
2025-09-10shared/tinyusb/mp_usbd_cdc: Rewrite USB CDC TX loop.Angus Gratton
This is related to the previous commit (where due to the new config flag this loop could end up stuck indefinitely if the USB host was disconnected). The previous loop could maybe still get stuck if the low-level USB state and the high-level USB state got out of sync. (Not clearly possible, but hard to say definitely not possible.) To be "belts and braces" careful: - Always run mp_usbd_task() each time around the loop to progress the state. - Always evaluate the timeout if we fail to write anything to the FIFO. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-09-10shared/tinyusb: Fix hang from new tx_overwritabe_if_not_connected flag.Angus Gratton
This flag is in the main branch of TinyUSB, included in Espressif since their v0.18.0~3 component release (but it's not actually in TinyUSB v0.18.0 release). Setting the flag is needed for the USB device not to block waiting for space in the FIFO if the host is disconnected. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-09-09shared/tinyusb: Fix build errors with CDC support disabled.Alessandro Gatti
This commit makes possible building MicroPython with USB CDC support disabled. The original code does support such a configuration but missed a few spots where build errors would arise. These changes fix the remaining issues, fixing also warnings caused by the changes needed to make the build succeed. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-09-02shared/runtime/pyexec: Unconditionally reset lock depth.Jeff Epler
Saves code size for the same functionality. Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-25shared/netutils: Cast the ticks value before printing.Jeff Epler
Before, the compiler plugin produced an error in the PYBD_SF6 build, which is a nanboxing build with 64-bit ints. I made the decision here to cast the value even though some significant bits might be lost after 49.7 days. However, the format used is "% 8d", which produces a consistent width output for small ticks values (up to about 1.1 days). I judged that it was more valuable to preserve the fixed width display than to accurately represent long time periods. Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-09shared/timeutils: Standardize supported date range on all platforms.Yoctopuce dev
This is code makes sure that time functions work properly on a reasonable date range, on all platforms, regardless of the epoch. The suggested minimum range is 1970 to 2099. In order to reduce code footprint, code to support far away dates is only enabled specified by the port. New types are defined to identify timestamps. The implementation with the smallest code footprint is when support timerange is limited to 1970-2099 and Epoch is 1970. This makes it possible to use 32 bit unsigned integers for all timestamps. On ARM4F, adding support for dates up to year 3000 adds 460 bytes of code. Supporting dates back to 1600 adds another 44 bytes of code. Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
2025-05-26shared/tinyusb: Use device event hook to schedule USB task.Angus Gratton
Previously MicroPython ports would linker-wrap dcd_event_handler in order to schedule the USB task callback to run when needed. TinyUSB 0.16 added proper support for an event hook to do the same thing without the hacky linker wrapping. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-05-13all: Rename the "NORETURN" macro to "MP_NORETURN".Alessandro Gatti
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>
2025-03-14shared/runtime/pyexec: Add helper function to execute a vstr.iabdalkader
Add `pyexec_vstr()` to execute Python code from a vstr source. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2025-01-02shared/timeutils: Add missing mp_uint_t casts.Yoctopuce
To prevent compiler warnings. Signed-off-by: Yoctopuce <dev@yoctopuce.com>
2024-12-10shared/runtime/gchelper_generic: Fix AArch32 build on Clang.Alessandro Gatti
This commit fixes a compile error happening on Clang when building the generic gchelper code for AArch32. Clang would raise a warning regarding undefined variable access when aliasing a variable to an existing CPU register. The fix is pretty crude but it works - it simply disables the warning in question for the AArch32 gchelper collection function. Care was taken to make sure the code would also compile on GCC without warnings of sorts. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-12-10shared/tinyusb: Set MSC max endpoint size based on device speed.iabdalkader
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-10-24shared/timeutils: Document the range of year/month/day etc input values.Damien George
These differ to, eg, the standard `mktime()` function. Signed-off-by: Damien George <damien@micropython.org>
2024-10-07shared/tinyusb: Wake main task if needed at end of USB ISR.Andrew Leech
Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-10-07esp32: Add automatic bootloader handling for S2 and S3.Andrew Leech
Enables support for the ESP standard DTR/RTS based reboot to bootloader. Switches from OTG to Serial/Jtag mode to workaround issue discussed in: https://github.com/espressif/arduino-esp32/issues/6762 Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-10-07shared/tinyusb: Remove MICROPY_HW_USB_EXTERNAL_TINYUSB.Andrew Leech
No longer needed as shared tinyusb is now used by the esp32 port. Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-10-03shared/runtime/gchelper_rv64i: Fix opcode sw/sd typo.Alessandro Gatti
The version of the assembly code for the GC helper that was committed ended up being a version that had an opcode typo in. The code was tested and working, but an undo operation too many when cleaning up the file before committing checked in the wrong version. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-09-26shared/tinyusb: Use new persistent-tx-fifo configure interface.Damien George
The old configuration option has been removed from TinyUSB. Signed-off-by: Damien George <damien@micropython.org>
2024-09-19all: Remove tinytest component.Damien George
With the recent qemu (d9a0fdda9a7b0db55c1115b55bb1b83cd5ce739c and 0426934969d06aa649ba903f5408cb331b5b9c2d) and zephyr (05cad7b56f5d460db26a468a05bfdeabe4a656db) changes to how their tests are run, two things became unused: - The tinytest framework, which embedded a set of tests and their expected output within firmware, so these tests could be run stand-alone. - The `--write-exp` and `--list-tests` options to `tests/run-tests.py`, which were needed primarily to generated the expected test output for tinytest (also the associated `tests/run-tests-exp.py/.sh` scripts are now unused). This commit removes the tinytest component and all its helper code. This eliminates a maintenance burden. Signed-off-by: Damien George <damien@micropython.org>
2024-09-19shared/tinyusb: Only run TinyUSB on the main thread if GIL is disabled.Angus Gratton
If GIL is disabled then there's threat of a race condition if some other code specifically requests USB processing (i.e. to unblock stdio), while a scheduled TinyUSB callback is already running on another thread. Relies on the change in the parent commit, where scheduler is restricted to main thread if GIL is disabled. Fixes #15390 - "TinyUSB callback can't recurse" exceptions on rp2 when using _thread module and USB serial I/O. Adds a unit test for stdin functioning correctly in threads (fails on rp2 port without this fix). This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-09-06shared/runtime/sys_stdio_mphal: Fix printed type for stdio streams.timdechant
The printed type for stdio streams indicates "FileIO", which is a binary IO stream. Stdio is not binary by design, and its printed type should indicate a text stream. "TextIOWrapper" suits that purpose, and is used by VfsPosix files. Signed-off-by: timdechant <timdechant.git@gmail.com>
2024-08-28shared/runtime/semihosting_arm: Add mp_semihosting_exit.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-08-28shared/runtime/semihosting_arm: Add mp_semihosting_rx_chars.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-08-28shared/runtime/semihosting_arm: Support semihosting on non-Thumb ARM.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-08-26shared/tinyusb: Allow ports to define CDC TX/RX buffer sizes.iabdalkader
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-08-07shared/runtime/gchelper: Add RISC-V RV64I native gchelper.Alessandro Gatti
Add native gchelper support for 64 bits RISC-V RV64I targets. Now that RV64 is under CI, this also enables platform-specific ghelper in the Unix port. Also changes the data type holding the register contents to something more appropriate, so in the remote eventuality somebody wants to use this with RV128 all they have to do is update the `__riscv_xlen` check. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
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-06-26shared/tinyusb/mp_usbd_cdc: Fix short CDC TX timeouts.Damien George
The `mp_event_wait_ms()` function may return earlier than the requested timeout, and if that happens repeatedly (eg due to lots of USB data and IRQs) then the loop waiting for CDC TX FIFO space to become available may exit much earlier than MICROPY_HW_USB_CDC_TX_TIMEOUT, even when there is no space. Fix this by using `mp_hal_ticks_ms()` to compute a more accurate timeout. The `basics/int_big_mul.py` test fails on RPI_PICO without this fix. Signed-off-by: Damien George <damien@micropython.org>
2024-06-26shared/tinyusb/mp_usbd_runtime: Fix pointer comparison in assert.Peter Harper
Addresses build warning "comparison of distinct pointer types lacks a cast". Fixes issue #15276. Signed-off-by: Peter Harper <peter.harper@raspberrypi.com>
2024-06-06shared/runtime/semihosting: Add RISC-V semihosting support.Alessandro Gatti
This adds a RISC-V RV32 semihosting implementation, with all defined system calls exposed to the user. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-06-06shared/runtime/semihosting: Rename ARM semihosting files.Alessandro Gatti
Make room for RISC-V semihosting code, by renaming the existing `semihosting.[ch]` files into `semihosting_arm.[ch]`. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-06-06shared/runtime/gchelper: Add RISC-V RV32I native gchelper.Alessandro Gatti
Add native gchelper support for 32 bits RISC-V RV32I targets. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-06-04shared/tinyusb: Buffer startup CDC data to send to host on connection.Andrew Leech
At startup, buffer initial stdout / MicroyPthon banner so that it can be sent to the host on initial connection of the USB serial port. This buffering also works for when the CDC becomes disconnected and the device is still printing to stdout, and when CDC is reconnected the most recent part of stdout (depending on how big the internal USB FIFO is) is flushed to the host. This change is most obvious when you've first plugged in a MicroPython device (or hit reset), when it's a board that uses USB (CDC) serial in the chip itself for the REPL interface. This doesn't apply to UART going via a separate USB-serial chip. The stm32 port already has this buffering behaviour (it doesn't use TinyUSB) and this commit extends such behaviour to rp2, mimxrt, samd and renesas-ra ports, which do use TinyUSB. Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-06-04extmod/network_ninaw10: Implement the ipconfig methods for ninaw10.robert-hh
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>
2024-06-02shared/tinyusb: Allow ports to use 1200bps-touch without other CDC code.Damien George
This fixes the build for some esp32 and nrf boards (for example `ARDUINO_NANO_33_BLE_SENSE` and `ARDUINO_NANO_ESP32`) due to commit c98789a6d8e05acb608afe4b30cf3ca563419b2d. Changes are: - Allow the CDC TX/RX functions in `mp_usbd_cdc.c` to be enabled separately to those needed for `MICROPY_HW_USB_CDC_1200BPS_TOUCH`. - Add `MICROPY_EXCLUDE_SHARED_TINYUSB_USBD_CDC` option as a temporary workaround for the nrf port to use. - Declare `mp_usbd_line_state_cb()` in a header as a public function. - Fix warning with type cast of `.callback_line_state_changed`. Signed-off-by: Damien George <damien@micropython.org>
2024-05-31shared/tinyusb: Add common CDC TX/RX functions.Andrew Leech
There are a few TinyUSB CDC functions used for stdio that are currently replicated across a number of ports. Not surprisingly in a couple of cases these have started to diverge slightly, with additional features added to one of them. This commit consolidates a couple of key shared functions used directly by TinyUSB based ports, and makes those functions available to all. Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-05-31rp2: Refactor to not use pico-sdk alarm pool functions for sleeping.Angus Gratton
The best_effort_wfe_or_timeout() and sleep_us() pico-sdk functions use the pico-sdk alarm pool internally, and that has a bug. Some usages inside pico-sdk (notably multicore_lockout_start_blocking()) will still end up calling best_effort_wfe_or_timeout(), although usually with "end_of_time" as the timeout value so it should avoid any alarm pool race conditions. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-05-31rp2: Refactor soft timer to use hardware timer alarm.Angus Gratton
Progress towards removing pico-sdk alarm pool, due to a known issue. This work was funded through GitHub Sponsors. 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-04-17shared/tinyusb: Fix dynamic USB control callbacks for wLength==0.Angus Gratton
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-03-27shared/tinyusb: Increase default string descr max length to 40 chars.Damien George
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-27shared/tinyusb: Update some code comments for runtime USB.Angus Gratton
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>