Skip to content

Micropython v1.24.1 merge #10417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 507 commits into
base: main
Choose a base branch
from

Conversation

dhalbert
Copy link
Collaborator

Merges MicroPython v1.24.1 into CircuitPython.

  • A few error messages were changed to match the current MicroPython messages. MicroPython had changed some is not to isn't and similar several years ago, but we never picked up these changes. I previously thought we had kept the old messages deliberately, but now I think it was just an oversight. This reduces code differences in some upstream files, and removes some // CIRCUITPY-CHANGE annotations. In most cases, messages were changed directly in the *.po and *.pot files so they won't need to be retranslated.
  • More unused files from upstream were deleted, instead of simply being ignored, especially in examples/ and tests/
  • Some MICROPY_NLR_* macros were predefined in a central place, so we could remove changes we made like if defined(FOO) && FOO
  • MicroPython replace stackctrl.* with new mechanisms in cstack.* for stack overflow checking. For some ports, MicroPython defined a MICROPY_STACK_CHECK_MARGIN that is non-zero, though the default is 0. It is not clear to me how to determine a safe value, but the default 0 I think should be OK.
  • There are some extraneous files in extmod/lwip-include I think we could remove, but I didn't do that yet.

I did some smoke tests and networking tests on various ports. I also did some simple by-hand read/write tests to CIRCUITPY and /sd, because there was some refactoring in the vfs code.

dpgeorge and others added 30 commits August 29, 2024 16:34
These docs now match the code in `extmod/machine_uart.c`.  IRQ trigger
support still need to be updated for each port (to be done in a follow-up
commit).

Signed-off-by: Damien George <[email protected]>
For more ports and trigger options, based on the current state of the code.

Signed-off-by: robert-hh <[email protected]>
The test checks whether the message created by the IRQ handler appears
about at the end of the data sent by UART.

Supported MCUs resp. boards:
- RP2040
- Teensy 4.x
- Adafruit ItsyBitsy M0
- Adafruit ItsyBitsy M4
- NRF52 (Arduino Nano Connect 33 BLE)

Signed-off-by: Damien George <[email protected]>
These all require hardware connections, so live in a different directory.

Except for the IRQ_BREAK test of ESP32 devices a single UART with loopback
is sufficient.

General:
    SAMD21: Due to the limited flash size only SAMD21 devices with external
    flash support uart.irq().

IRQ_BREAK:
    ESP32 needs different UART devices for creating and sensing a break.
    Lacking a second UART the test is skipped for ESP32S2 and ESP32C3.  RP2
    does not pass the test reliable at 115200 baud, reason to be found.
    Thus the upper limit is set to 57600 Baud.

    Coverage:
        esp32  pass when different UART devices are used.
        rp2    pass up to 57600 baud

IRQ_RX:
    SAMD21: Being a slow device it needs data to be sent byte-by-byte at
    9600 baud, since the IRQ callback is scheduled delayed and then the
    flags do not match any more.  The data matches since it is queued in
    the FIFO resp. ringbuffer.

    CC3200: The test cannot be performed since no calls are accepted in the
    IRQ handler like u.read(). Skipped.

    Coverage:
        cc3200 fail due to major differences in the implementation.
        esp32  pass
        nrf    pass
        renesas-ra pass
        samd   pass see the notes.
        stm32  pass

IRQ_RXIDLE:
    STM32: With PyBoard the IRQ is called several times, but only once with
    the flag IRQ_RXIDLE set.

    Coverage:
        esp32    pass
        mimxrt   pass
        renesas-ra pass
        rp2      pass
        samd     pass for both SAMD21 and SAMD51
        stm32    fail. see notes.

Signed-off-by: Damien George <[email protected]>
Signed-off-by: robert-hh <[email protected]>
This updates lwIP from STABLE-2_1_3_RELEASE, which was released in November
2021.  The latest STABLE-2_2_0_RELEASE was released in September 2023.

Signed-off-by: Damien George <[email protected]>
This commit adds a new `network.PPP` interface which works on any port that
has bare-metal lwIP, eg rp2, stm32, mimxrt.

It has been tested on stm32.  A board needs to enable
`MICROPY_PY_NETWORK_PPP_LWIP` and then it can use it as follows:

    import network

    ppp = network.PPP(uart)
    ppp.connect()

    while not ppp.isconnected():
        pass

    # use `socket` module as usual, etc

    ppp.disconnect()

Usually the application must first configure the cellular/etc UART link to
get it connected and in to PPP mode first (eg ATD*99#), before handing over
control to `network.PPP`.

The PPP interface automatically configures the UART IRQ callback to call
PPP.poll() on incoming data.

Signed-off-by: Damien George <[email protected]>
Can be enabled by a board by enabling `MICROPY_PY_NETWORK_PPP_LWIP`.

Signed-off-by: Damien George <[email protected]>
The errcode should be cleared so the caller sees a successful write, even
if it's a short write.

Signed-off-by: Damien George <[email protected]>
When timeout=0 (non-blocking mode) the UART should still wait for each
character to go out.  Otherwise non-blocking mode with CTS enabled is
useless because it can only write one character at a time.

Signed-off-by: Damien George <[email protected]>
This allows enabling lwIP debugging output.  For example, to enable PPP
debugging add the following to `mpconfigboard.h`:

    #define LWIP_DEBUG 1
    #define PPP_DEBUG LWIP_DBG_ON

Signed-off-by: Damien George <[email protected]>
Can be enabled by a board by enabling `MICROPY_PY_NETWORK_PPP_LWIP`.

Signed-off-by: Damien George <[email protected]>
This allows UART RX to function while flash erase/writes operations are
under way, preventing lost serial data so long as it fits in the UART RX
buffer.

This enables (among other things) mpremote to successfully copy files to
boards that use a UART REPL.

Enable via the following option placed in `mpconfigboard.mk`:

    MICROPY_HW_ENABLE_ISR_UART_FLASH_FUNCS_IN_RAM = 1

Signed-off-by: Andrew Leech <[email protected]>
Allows mpremote file transfer to work correctly when mpremote is used over
the ST-link USB/UART REPL port.

Fixes issue adafruit#8386.

Signed-off-by: Andrew Leech <[email protected]>
This was made optional in CPython 3.11.

Signed-off-by: Amirreza Hamzavi <[email protected]>
This was made optional in CPython 3.11.

Signed-off-by: Amirreza Hamzavi <[email protected]>
This was made optional in CPython 3.11.

Signed-off-by: Amirreza Hamzavi <[email protected]>
Regression in 0a11832 in IDF 5.0.x where macro
CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED is not defined.

With this patch, ESP32-S3 still USB Serial/JTAG incorrectly (now on all
ESP-IDF versions).

Closes micropython#15701

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <[email protected]>
This fixes issue of ESP32-S3 switching its config over to USB serial/JTAG
instead of native USB.

The the existing logic was hard to follow, adding this config macro makes
it easier to see which USB is in use and to have board definitions that
enable/disable different USB levels.

This commit also drops (nominal) support for manually setting
CONFIG_ESP_CONSOLE_USB_CDC in sdkconfig. No included board configs use this
and it didn't seem to work (if secondary console was set to the default USB
Serial/JTAG then there is no serial output on any port, and if secondary
console was set to None then linking fails.) Can be re-added if there's a
use case for it.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <[email protected]>
Regression introduced by 5e692d0 now at MICROPY_HW_USB_CDC is set.

The ARDUINO_NANO_ESP32 specifically builds shared/tinyusb/mp_usb_cdc.c
for the 1200bps reset behaviour. However MicroPython esp32 doesn't yet
use the rest of the shared/tinyusb functionality.

Signed-off-by: Angus Gratton <[email protected]>
Workaround for what appears to be an upstream issue:
espressif/esp-idf#14456

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <[email protected]>
The Let's Encrypt root certificate has changed so needs updating in this
test.

Signed-off-by: Damien George <[email protected]>
Now that some ports support multiple architectures (eg esp32 has both
Xtensa and RISC-V CPUs) it's no longer possible to set mpy-cross flags
based on the target, eg `./run-tests.py --target esp32`.  Instead this
commit makes it so the `-march=xxx` argument to mpy-cross is detected
automatically via evaluation of `sys.implementation._mpy`.

Signed-off-by: Damien George <[email protected]>
Currently both the qemu-arm and qemu-riscv ports share a lot of code and
functionality.  This commit merges the qemu-riscv port into the qemu-arm
port.  The only real differences between the two are the toolchains used to
build the code, and the initialisation/startup framework.  Everything else
is pretty much the same, so this brings the following benefits:
- less code duplication
- less burden on maintenance
- generalised qemu port, could in the future support other architectures

A new board `VIRT_RV32` has been added to the qemu-arm port which is the
existing RISC-V board from the qemu-riscv port.  To build it:

    $ make BOARD=VIRT_RV32 repl

To cleanly separate the code for the different architectures, startup code
has been moved to ports/qemu-arm/mcu/<arch>/.

Signed-off-by: Damien George <[email protected]>
agatti and others added 26 commits November 18, 2024 23:27
The PIC16 port didn't catch up with the other ports, so it required a bit
of work to make it build with the latest version of XC16.

Signed-off-by: Alessandro Gatti <[email protected]>
In `deque_subscr()`, if `index_val` equals `self->alloc`, the index
correction `index_val -= self->alloc` does not execute, leading to an
out-of-bounds access in `self->items[index_val]`.

The fix in this commit ensures that the index correction is applied
whenever `index_val >= self->alloc`, preventing access beyond the allocated
buffer size.

Signed-off-by: Jan Sturm <[email protected]>
This was missed in 628abf8.  The the bug
was that, when IPv6 is enabled, the `sizeof(ip_addr_t)` is much larger than
IPv4 size, which is what's needed for IGMP addressing.

Fixes issue micropython#16100.

Signed-off-by: Damien George <[email protected]>
The cleanup in 548babf relies on some functions not available in older
ESP-IDF. Temporarily restore them, until we drop support for ESP-IDF <5.2.

PWM functionality should end up the same regardless of ESP-IDF version, and
also no different from MicroPython V1.23.

Signed-off-by: Angus Gratton <[email protected]>
Seemingly ESP-IDF incorrectly marks RTC FAST memory region
as MALLOC_CAP_EXEC on ESP32-S2 when it isn't. This memory is
the lowest priority, so it only is returned if D/IRAM is exhausted.

Apply this workaround to treat the allocation as failed if it gives us
non-executable RAM back, rather than crashing.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <[email protected]>
mpremote error messages now go to stderr, so make sure stdout is flushed
before printing them.

Also update the test runner to capture error messages.

Signed-off-by: Damien George <[email protected]>
This fixes a regression in db59e55: prior
to that commit `mpremote` supported trailing slashes on the destination of
a normal (non-recursive) copy.

Add back support for that, with the semantics that a trailing slash
requires the destination to be an existing directory.

Also add a test for this.

Signed-off-by: Damien George <[email protected]>
Because the `ai_canonname` field is subsequently used.

ESP32_GENERIC_S3 (at least) crashes with IDF 5.2.3 without this set.

Signed-off-by: Damien George <[email protected]>
Commit f4ab9d9 inadvertently broke some
Python block devices, for example esp32 and stm32 SDCard classes.  Those
classes return a bool from their `readblocks` and `writeblocks` methods
instead of an integer errno code.  With that change, both `False` and
`True` return values are now be interpreted as non-zero and hence the block
device call fails.

The fix in this commit is to allow a bool and explicitly convert `True` to
0 and `False` to `-MP_EIO`.

Signed-off-by: Damien George <[email protected]>
This function is documented to return True if any stations are connected to
the AP. Without this fix it returns True whenever the driver has brought
the AP interface up.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <[email protected]>
The `num_stas` was uninitialised and if it happened to take the value 0
then no results were returned.  It now has the correct maximum value.

Signed-off-by: Damien George <[email protected]>
Configuring the AP for cyw43 writes to some buffers that are only sent to
the modem when the interface is brought up. This means you can't configure
the AP after calling active(True), the new settings seem to be accepted but
the radio doesn't change.

This is different to the WLAN behaviour on other ports. The esp8266 port
requires calling active(True) on the AP before configuring, even.

Fix this by bouncing the AP interface after a config change, if it's
active. Configuring with active(False) still works the same as before.

Adds a static variable to track interface active state, rather than relying
on the LWIP interface state. This is because the interface state is updated
by a driver callback and there's a race: if code calls active(True) and
then config(a=b) then the driver doesn't know it's active yet and the
changes aren't correctly applied.

It is possible this pattern will cause the AP to come up briefly with the
default "PICOabcd" SSID before being reconfigured, however (due to the
aforementioned race condition) it seems like this may not happen at all
before the new config is applied.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <[email protected]>
- Previously the call to esp_wifi_set_channel() would be immediately
  overridden by calling esp_wifi_config(...) with the previous channel set.

- AP interface doesn't seem to need more than esp_wifi_config(...) to work.
  It will automatically configure 40MHz bandwidth and place the secondary
  channel using similar logic to what was being explicitly calculated here.

- However, calling esp_wifi_set_channel() on the STA interface is necessary
  if using this interface with ESP-NOW (without connecting to an AP). So
  the esp_wifi_set_channel() call is kept in for this purpose. Without
  this, tests/multi_espnow/70_channel.py fails.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <[email protected]>
ESP32 has hardware V1 and S2/S3 has V2, and future chips
may have different versions.

This should still compile to the same binary before and after.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <[email protected]>
Closes micropython#13178.

TouchPad confirmed working on both chips, and fixes the the ESP32-S3
reading constant max value. Was unable to reproduce the bug on ESP32-S2 but
this may be due to my test setup, and it still works with the fix.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <[email protected]>
This fixes a bug in FrameBuffer.ellipse where it goes into an infinite loop
if both radii are 0.

This fixes the bug with a simple pre-check to see if both radii are 0, and
in that case sets a single pixel at the center. This is consistent with the
behaviour of the method when called with just one of the radii set to 0,
where it will draw a horizontal or vertical line of 1 pixel width.

The pixel is set with setpixel_checked so it should handle out-of-bounds
drawing correctly.

This fix also includes three new tests: one for the default behaviour, one
for drawing out-of-bounds, and one for when the sector mask is 0.

Fixes issue micropython#16053.

Signed-off-by: Corran Webster <[email protected]>
The micro:bit board (and probably other boards using the music or display
module) locked up on soft reboot.  Reason was a buffer overflow caused by
an index counter, which was not reset on soft_reboot.

That's fixed in this commit.  Tested with a micro:bit board, performing a
series of soft reboots.

Signed-off-by: robert-hh <[email protected]>
Recent MSVC versions have changed the definition of NAN to a non-constant
expression!  This is a bug, C standard says it should be a constant.

Good explanation and workaround at: https://stackoverflow.com/a/79199887

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <[email protected]>
Signed-off-by: Damien George <[email protected]>
tests/ not run yet.
Reduced some differences from upstream by changing some error messages and defining some preprocessor macros.
@dhalbert dhalbert force-pushed the micropython-v1.24.1-merge branch from b6d5415 to 8c7b592 Compare June 13, 2025 03:51
@dhalbert dhalbert requested a review from eightycc June 13, 2025 16:44
@eightycc
Copy link
Collaborator

Review in progress. This might take a while...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.