summaryrefslogtreecommitdiff
path: root/shared
AgeCommit message (Collapse)Author
3 daysshared/runtime/pyexec: Set PYEXEC_FORCED_EXIT flag for SystemExit.HEADorigin/masterorigin/HEADmasterAndrew Leech
When `MICROPY_PYEXEC_ENABLE_EXIT_CODE_HANDLING` is enabled, `SystemExit` now sets the `PYEXEC_FORCED_EXIT` flag in addition to the exit code. This allows the REPL to properly detect and exit when SystemExit is raised, while still preserving the exit code in the lower bits. Fixes `repl_lock.py` test which expects REPL to exit on `SystemExit`. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
3 daysunix: Enable exit code handling for sys.exit().Andrew Leech
Enable `MICROPY_PYEXEC_ENABLE_EXIT_CODE_HANDLING` to propagate `sys.exit()` exit codes properly. Update `convert_pyexec_result()` to handle return values where pyexec returns the exit code with `PYEXEC_FORCED_EXIT` flag set for `SystemExit`. Extract the exit code from the lower 8 bits when the flag is set, otherwise return as-is (0 for success, 1 for exception). Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
3 daysshared/runtime/pyexec: Call mp_hal_stdio_mode_orig/raw as appropriate.Damien George
This ensures that ctrl-C works on the unix port when executing code at the REPL. Signed-off-by: Damien George <damien@micropython.org>
3 daysshared/runtime/pyexec: Provide support for compile-only mode.Andrew Leech
When `MICROPY_PYEXEC_COMPILE_ONLY` is enabled and the global `mp_compile_only` is True, code is compiled but not executed. Also add comprehensive tests for compile-only functionality covering both successful compilation and syntax error detection. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
3 daysshared/runtime/pyexec: Set __file__ for file input when enabled.Andrew Leech
When `MICROPY_MODULE___FILE__` is enabled and parsing file input, set the global `__file__` variable to the source filename. This matches the behavior of the unix port and provides the current filename to the executing script. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
3 daysunix/main: Use standard pyexec REPL for unix and windows ports.Andrew Leech
This improves REPL usage consistency across ports, by utilizing the pyexec code for the unix REPL. Only enabled when MICROPY_USE_READLINE == 1 (the default). Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
6 daysshared/tinyusb/mp_usbd: Reorder the mp_usbd_init/deinit functions.Angus Gratton
Not a functional change, but makes it easier to see that mp_usbd_init() is available regardless of whether MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE is set. Also adds a no-op inline mp_usbd_deinit() implementation, which means both a port's calls to mp_usbd_init()/deinit() can both be guarded on the same MICROPY_HW_ENABLE_USBDEV. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-11-04shared/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>
2025-10-31shared/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>