Commit graph

170 commits

Author SHA1 Message Date
Dan Halbert
5fb3f960ca MicroPython v1.25.0 merge 2025-06-20 14:26:24 -04:00
Dan Halbert
1381e17320 wip: initial merge; no compilation yet 2025-06-08 19:23:05 -04:00
eightycc
1cca6916c2 Revert PR #10301, obsoleted by PR #10325. 2025-05-10 16:26:00 -07:00
eightycc
1f5ce96139 Durable fix for RISC-V interpreter crash. 2025-05-02 22:58:32 -07:00
eightycc
e35b1e9865 Workaround Risc-V code gen problem causing Python interpreter crash. 2025-04-30 18:52:05 -07:00
Scott Shawcroft
04622e7c03
Update broadcom compiler and shrink stm boards 2025-03-31 11:35:31 -07:00
iabdalkader
f187c77da8 shared/runtime/pyexec: Add helper function to execute a vstr.
Add `pyexec_vstr()` to execute Python code from a vstr source.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2025-03-14 17:10:35 +11:00
8da339e2f8 context_manager_helpers: Comment on what default enter & exit obj are 2025-02-07 20:49:29 -06:00
8aa1969c61 add, use a default exit object
This just delegates to .deinit().

Also, change default __enter__ to a macro that reuses the
identically-beving "identity_obj", and harmonize a few sites so that
the naming s consistent.

Saves about 800 bytes on metro rp2350.
2025-02-07 15:10:58 -06:00
Scott Shawcroft
7f0cc9e7b4
Add Zephyr port
This port is meant to grow to encompass all existing boards. For
now, it is a port while we transition over.

It is named `zephyr-cp` to differentiate it from the MicroPython
`zephyr` port. They are separate implementations.
2025-02-04 11:24:13 -08:00
Yoctopuce
3dd605e7de shared/timeutils: Add missing mp_uint_t casts.
To prevent compiler warnings.

Signed-off-by: Yoctopuce <dev@yoctopuce.com>
2025-01-02 13:28:01 +11:00
Alessandro Gatti
5784714f73 shared/runtime/gchelper_generic: Fix AArch32 build on Clang.
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-10 12:03:34 +11:00
iabdalkader
c55202dd63 shared/tinyusb: Set MSC max endpoint size based on device speed.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-12-10 10:26:27 +11:00
Damien George
43bd57f94b shared/timeutils: Document the range of year/month/day etc input values.
These differ to, eg, the standard `mktime()` function.

Signed-off-by: Damien George <damien@micropython.org>
2024-10-24 11:22:22 +11:00
Andrew Leech
548f88d2bd shared/tinyusb: Wake main task if needed at end of USB ISR.
Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-10-07 11:06:57 +11:00
Andrew Leech
5ae622ef7b esp32: Add automatic bootloader handling for S2 and S3.
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-07 11:06:57 +11:00
Andrew Leech
641f60045f shared/tinyusb: Remove MICROPY_HW_USB_EXTERNAL_TINYUSB.
No longer needed as shared tinyusb is now used by the esp32 port.

Signed-off-by: Andrew Leech <andrew@alelec.net>
2024-10-07 11:06:57 +11:00
Alessandro Gatti
e39bd3ae9d shared/runtime/gchelper_rv64i: Fix opcode sw/sd typo.
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-10-03 11:40:10 +10:00
Damien George
b0ba151102 shared/tinyusb: Use new persistent-tx-fifo configure interface.
The old configuration option has been removed from TinyUSB.

Signed-off-by: Damien George <damien@micropython.org>
2024-09-26 23:13:50 +10:00
Damien George
067ef81cd0 all: Remove tinytest component.
With the recent qemu (d9a0fdda9a and
0426934969) and zephyr
(05cad7b56f) 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-19 13:31:36 +10:00
Angus Gratton
5d8878b582 shared/tinyusb: Only run TinyUSB on the main thread if GIL is disabled.
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-19 13:17:01 +10:00
Dan Halbert
1f68fffa13 merge from main 2024-09-10 16:36:32 -04:00
Dan Halbert
ffaabeb933 shared/runtime/pyexec.c: fix merge error 2024-09-09 19:13:07 -04:00
Dan Halbert
bc6f065447 working on compilation errors 2024-09-06 23:10:41 -04:00
timdechant
455415b1e1 shared/runtime/sys_stdio_mphal: Fix printed type for stdio streams.
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-09-06 17:00:35 +10:00
Dan Halbert
7812695281 non-conflict merge changes 2024-09-05 14:54:18 -04:00
timdechant
c6c4c79330 shared/runtime/sys_stdio_mphal: Fix docstring for stdio.
Signed-off-by: timdechant <timdechant.git@gmail.com>
2024-09-03 22:41:34 -04:00
Dan Halbert
1e1a8000a8 change remaining STATIC to static 2024-09-03 17:40:07 -04:00
Dan Halbert
ac7e15f88a (only) reserve merge conflicts 2024-08-28 16:31:37 -04:00
Damien George
1090f1a60c shared/runtime/semihosting_arm: Add mp_semihosting_exit.
Signed-off-by: Damien George <damien@micropython.org>
2024-08-28 11:52:08 +10:00
Damien George
70a6791b09 shared/runtime/semihosting_arm: Add mp_semihosting_rx_chars.
Signed-off-by: Damien George <damien@micropython.org>
2024-08-28 11:52:08 +10:00
Damien George
9f9c283ef4 shared/runtime/semihosting_arm: Support semihosting on non-Thumb ARM.
Signed-off-by: Damien George <damien@micropython.org>
2024-08-28 11:52:08 +10:00
iabdalkader
706e09dff3 shared/tinyusb: Allow ports to define CDC TX/RX buffer sizes.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-08-26 12:42:09 +10:00
timdechant
2c9212ad1e Fix docstring for stdout.buffer
Earlier commit changed stdio docstring/type to StringIO and included
stdio_buffer_obj in that.  Reviewing history for that object,
it is intended to implement (e.g.) stdout.buffer, which is a
binary stream.  Revert back to FileIO for that docstring/type.
2024-08-23 08:58:10 -04:00
Dan Halbert
e5e9c5ca84
Merge pull request #9469 from dhalbert/merge-from-micropython-v1.22.2
Merge from micropython v1.22.2
2024-08-21 18:11:19 -04:00
Tim DeChant
e499614161
fix: Docstring for stdio indicates binary #9543
Docstring for stdio indicates "FileIO", which is a binary IO stream. As detailed in #553, stdio is not binary by design; its docstring should indicate "StringIO".
2024-08-21 09:58:21 -04:00
Dan Halbert
a2bdf57f08 pyexec.c: fix pyexec_frozen_module 2024-08-20 21:58:12 -04:00
Alessandro Gatti
55b2720687 shared/runtime/gchelper: Add RISC-V RV64I native gchelper.
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-08-07 16:23:21 +10:00
Dan Halbert
be6fa2af21 merge from main 2024-07-29 17:41:46 -04:00
Dan Halbert
c11f2af3e7 wip: blink works on trinket M0 2024-07-27 08:06:20 -04:00
Dan Halbert
71f17b08fb wip: fixing compilation 2024-07-26 18:38:46 -04:00
Dan Halbert
69b667406b MPy v1.22 merge: initial merge; not compiled yet 2024-07-25 15:16:24 -04:00
Damien George
69c25ea865 shared/runtime/pyexec: Make a raised SystemExit always do a forced exit.
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-20 12:13:14 +10:00
robert-hh
a734ee9057 shared/tinyusb/mp_usbd_cdc: Skip writing to an uninitialized USB device.
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-20 00:27:58 +10:00
Damien George
880f7bc040 shared/tinyusb/mp_usbd_cdc: Fix short CDC TX timeouts.
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-26 14:50:42 +10:00
Peter Harper
9111fa5831 shared/tinyusb/mp_usbd_runtime: Fix pointer comparison in assert.
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-26 13:57:45 +10:00
Alessandro Gatti
ace08c3978 shared/runtime/semihosting: Add RISC-V semihosting support.
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-06 12:55:21 +10:00
Alessandro Gatti
90d50ce918 shared/runtime/semihosting: Rename ARM semihosting files.
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-06 12:55:15 +10:00
Alessandro Gatti
de0e13a9a8 shared/runtime/gchelper: Add RISC-V RV32I native gchelper.
Add native gchelper support for 32 bits RISC-V RV32I targets.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-06-06 12:01:00 +10:00
Andrew Leech
8809ae7161 shared/tinyusb: Buffer startup CDC data to send to host on connection.
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-04 17:49:19 +10:00