Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Merge MicroPython v1.25.0 #10437

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

Merged
merged 548 commits into from
Jun 21, 2025
Merged

Conversation

dhalbert
Copy link
Collaborator

Merge MicroPython v1.25.0 into CircuitPython.

  • Remove extmod/virtpin.*: not used in CircuitPython.
  • Change some #if defined(FOO) && FOO changes we made back to just #if FOO, and define those cpp macros elsewhere if necessary. This reduces code differences.

Initial simple smoke testing: SAMD21, SAMD51, ESP32-S3 (wifitest), RP2040.

I'll make it not a draft once the build is successful.

iabdalkader and others added 30 commits February 14, 2025 12:08
The linker scripts for most of these microcontrollers contain a
non-contiguous flash section for the ID code that results in big binary
files, which exceed the flash size.  This commit removes the ID code
section from the main firmware binary, and outputs it to a separate binary,
which can be deployed manually if ID code is enabled.

Signed-off-by: iabdalkader <[email protected]>
Despite the code comments claiming one is sufficient, the mDNS application
is capable of using up to twelve timers.  Three per IP protocol are started
at once in `mdns_start_multicast_timeouts_ipvX`, then another two per
protocol can be started in `mdns_handle_question`.  Further timers can be
started for two additional callbacks.

Having certain timers, such as `MDNS_MULTICAST_TIMEOUT`, fail to start due
to none being free will break mDNS forever as the app will never realize
it's safe to transmit a packet.  Therefore, this commit goes somewhat
overkill and allocates the maximal amount of timers; it's uncertain if all
can run simultaneously, or how many callback timers are needed.

Each timer struct is 16 bytes on standard 32 bit builds.  Plus, say, 8
bytes of allocater overhead, that's 288 more bytes of RAM used which
shouldn't be too horrible.  Users who don't need mDNS can manually disable
it to recover the RAM if necessary.

This fixes mDNS on W5500_EVB_PICO (among other boards).  Before, mDNS would
work for a bit after connection until the host's cache expired a minute or
two later.  Then the board would never respond to further queries.  With
this patch, all works well.

Signed-off-by: Thomas Watson <[email protected]>
This commit enables support for DTLS, i.e. TLS over datagram transport
protocols like UDP.  While support for DTLS is absent in CPython, it is
worth supporting it in MicroPython because it is the basis of the
ubiquitous CoAP protocol, used in many IoT projects.

To select DTLS, a new set of "protocols" are added to SSLContext:
- ssl.PROTOCOL_DTLS_CLIENT
- ssl.PROTOCOL_DTLS_SERVER

If one of these is set, the library assumes that the underlying socket is a
datagram-like socket (i.e. UDP or similar).

Our own timer callbacks are implemented because the out of the box
implementation relies on `gettimeofday()`.

This new DTLS feature is enabled on all ports that use mbedTLS.

This commit is an update to a previous PR adafruit#10062.

Addresses issue adafruit#5270 which requested DTLS support.

Signed-off-by: Keenan Johnson <[email protected]>
This adds a multi-test for DTLS server and client behaviour.  It works on
all ports that enable this feature (eg unix, esp32, rp2, stm32), but
bare-metal ports that use lwIP are not reliable as the DTLS server because
the lwIP bindings only support queuing one UDP packet at a time (that needs
to be fixed).

Also, to properly implement a DTLS server sockets need to support
`socket.recvfrom(n, MSG_PEEK)`.  That can be implemented in the future.

Signed-off-by: Damien George <[email protected]>
Regression in 3af006e meant that pendsv.c no longer compiled if threads
were disabled in the build config. Add an implementation based on the
earlier one (simple counter) for the non-threads case.

It seems like with the current usage patterns there's no need for the
counter to be incremented/decremented atomically on a single core config.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <[email protected]>
This works similarly to the existing support in "bare metal" make ports,
with the caveat that CMake will only set this value on a clean build and
will reuse the previous value otherwise.

This is slightly different to the CMake built-in support for CFLAGS,
as this variable is used when evaluating source files for qstr
generation, etc.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <[email protected]>
Serves as a build test for a config we don't otherwise support.

Signed-off-by: Angus Gratton <[email protected]>
This commit removes "memory.h" from the ESP32 port tree, as it is no
longer needed with recent ESP-IDF versions.

Signed-off-by: Alessandro Gatti <[email protected]>
It was set to 133Mhz, but that is not stable.  Reduce to 100MHz.

The UF2 bootloader runs at 100MHz, so no need for a change of the
bootloader.

Signed-off-by: robert-hh <[email protected]>
URLs in `package.json` may now be specified relative to the base URL of the
`package.json` file.

Relative URLs wil work for `package.json` files installed from the web as
well as local file paths.

Docs: update `docs/reference/packages.rst` to add documentation for:

- Installing packages from local filesystems (PR micropython#12476); and
- Using relative URLs in the `package.json` file (PR micropython#12477);
- Update the packaging example to encourage relative URLs as the default
  in `package.json`.

Add `tools/mpremote/tests/test_mip_local_install.sh` to test the
installation of a package from local files using relative URLs in the
`package.json`.

Signed-off-by: Glenn Moloney <[email protected]>
For GitHub Actions, ubuntu-20.04 is deprecated and will be removed by 1st
April 2025.  See announcement at
actions/runner-images#11101

This commit changes actions that use ubuntu-20.04 to a newer image.

Signed-off-by: Damien George <[email protected]>
Changing runner OS can change Python version, and ESP-IDF installs are
keyed on ESP-IDF and Python version together.

Signed-off-by: Angus Gratton <[email protected]>
This commit upgrades from codespell==2.2.6 to the current codespell==2.4.1,
adding emac to the ignore-words-list.

Signed-off-by: Christian Clauss <[email protected]>
Signed-off-by: Christian Clauss <[email protected]>
Found by codespell.

Signed-off-by: Christian Clauss <[email protected]>
Manifests as `readblocks(-1, buf)` failing.  The ST HAL does a bounds
check, but it checks `(block_num + num_blocks)` is within bounds, so if
these values overflow then it allows the read which seems to hang some SD
Cards (but not all).

Fix by explicitly testing for overflow in our layer of the driver.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <[email protected]>
60 seconds is long enough that the USB serial connection drops out before
it times out (at least on my computer).

Also refactor out the timeout argument from sdcard_wait_finished, to try
and save a little code size.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <[email protected]>
Testing with ROMFS shows that it is relatively easy to end up with a
corrupt filesystem on the device -- eg due to the ROMFS deploy process
stopping half way through -- which could lead to hard crashes.  Notably,
there can be boot loops trying to mount a corrupt filesystem, crashes when
importing modules like `os` that first scan the filesystem for `os.py`, and
crashing when deploying a new ROMFS in certain cases because the old one is
removed while still mounted.

The main problem is that `mp_decode_uint()` has an loop that keeps going as
long as it reads 0xff byte values, which can happen in the case of erased
and unwritten flash.

This commit adds full bounds checking in the new `mp_decode_uint_checked()`
function, and that makes all ROMFS filesystem accesses robust.

Signed-off-by: Damien George <[email protected]>
This commit fixes a compilation warning (turned error) about a
potentially uninitialised variable being used.  The warning can be
ignored as the variable in question is always written to, but the code
has been changed to silence that warning.

Signed-off-by: Alessandro Gatti <[email protected]>
This commit introduces a few changes aimed at reducing the amount of
space taken by the inline assembler once compiled:

* The register string table uses 2 bytes for each qstr rather than the
  usual 4
* The opcode table uses 2 bytes for each qstr rather than the usual 4
* Opcode masks are not embedded in each opcode entry but looked up via
  an additional smaller table, reducing the number of bytes taken by
  an opcode's masks from 12 to 2 (with a fixed overhead of 24 bytes for
  the the masks themselves stored elsewhere)
* Some error messages had a trailing period, now removed
* Error messages have been parameterised when possible, and the overall
  text length is smaller.

Signed-off-by: Alessandro Gatti <[email protected]>
This commit changes the Xtensa inline assembly parser to use a slightly
simpler (and probably a tiny bit more efficient) way to look up register
names when decoding instruction parameters.

Signed-off-by: Alessandro Gatti <[email protected]>
The mantissa parsing code uses a floating point variable to accumulate
digits.  Using an `mp_float_uint_t` variable instead and casting to
`mp_float_t` at the very end reduces code size.  In some cases, it also
improves the rounding behaviour as extra digits are taken into account
by the int-to-float conversion code.

An extra test case handles the special case where mantissa overflow occurs
while processing deferred trailing zeros.

Signed-off-by: Yoctopuce dev <[email protected]>
This significantly speeds up readline on files opened directly from an
mpremote mount.

Signed-off-by: Andrew Leech <[email protected]>
dpgeorge and others added 19 commits April 9, 2025 00:22
This test is not intended to be run automatically and does not have a
corresponding .exp file.

Signed-off-by: Damien George <[email protected]>
mpremote now supports `mpremote rm -r`.

Addresses adafruit#9802 and micropython#16845.

Signed-off-by: Jos Verlinde <[email protected]>
This commit allows the user of this driver to dynamically configure the SPI
flash chip parameters.  For this, enable `MICROPY_HW_SPIFLASH_CHIP_PARAMS`
and then set the `mp_spiflash_t::chip_params` element to point to a valid
`mp_spiflash_chip_params_t` struct.

Signed-off-by: Damien George <[email protected]>
This commit allows the user of this driver to intercept the SPI flash
initialisation routine and possibly take some action based on the JEDEC id,
for example change the `mp_spiflash_t::chip_params` element.

To do this, enable `MICROPY_HW_SPIFLASH_DETECT_DEVICE` and define a
function called `mp_spiflash_detect()`.

Signed-off-by: Damien George <[email protected]>
Options for a board to configure ROMFS are:

- Leave ROMFS disabled, do nothing.

- Enable by defining `MICROPY_HW_ROMFS_ENABLE_PARTx` to 1 and then in the
  linker script define `_micropy_hw_romfs_partX_start` and
  `_micropy_hw_romfs_partX_size`.

- Enable by defining `MICROPY_HW_ROMFS_ENABLE_PARTx` to 1 and also define
  `MICROPY_HW_ROMFS_PARTx_START` and `MICROPY_HW_ROMFS_PARTx_SIZE` which
  can be arbitrary expressions (not necessarily static)

Signed-off-by: Damien George <[email protected]>
Allows `MICROPY_HW_QSPIFLASH_SIZE_BITS_LOG2` and
`MICROPY_HW_QSPI_MPU_REGION_SIZE` to be arbitrary expressions, eg function
calls.

The `storage.h` header needs to be included in case access to `spi_bdev_t`
is needed by the macros.

Signed-off-by: Damien George <[email protected]>
There are some newer PYBD_SF6 being produced which have a larger flash,
namely two of 8MiB (instead of the older ones with two of 2MiB).

This commit adds support for these boards.  The idea is to have the same
PYBD_SF6 firmware run on both old and new boards.  That means autodetecting
the flash at start-up and configuring all the relevant SPI/QSPI parameters,
including for ROMFS and mboot.

Signed-off-by: Damien George <[email protected]>
Prior to this fix the following would fail:

    $ make build-TEENSY40/flexram_config.s

because it didn't create the build directory before generating the file.

Also, make `hal/resethandler_MIMXRT10xx.S` have an explicit dependency on
`flexram_config.s` rather than the latter just being forced to be built
before everything else.

Signed-off-by: Damien George <[email protected]>
Otherwise, when compiling on 16-bit systems (where `mp_uint_t` is 16 bits
wide) the compiler warns about "left shift count >= width of type", from
the static inline functions that have RV32_ENCODE_TYPE_xxx macros which
do a lot of bit shifting.

Signed-off-by: Damien George <[email protected]>
This brings in:
- requests: do not leak header modifications when calling request
- mip: allow relative URLs in package.json
- mip: make mip.install() skip /rom*/lib directories
- umqtt.simple: restore legacy ssl/ssl_params arguments
- nrf24l01: increase startup delay
- nrf24l01: properly handle timeout
- nrf24l01: optimize status reading
- lora-sx126x: fix invert_iq_rx / invert_iq_tx behaviour
- unix-ffi/json: accept both str and bytes as arg for json.loads()
- unix-ffi/machine: use libc if librt is not present
- requests: use the host in the redirect url, not the one in headers
- aiohttp: fix header case sensitivity
- aiohttp: allow headers to be passed to a WebSocketClient
- usb-device-cdc: optimise writing small data so it doesn't require alloc
- inspect: fix isgenerator logic
- inspect: implement iscoroutinefunction and iscoroutine

Signed-off-by: Damien George <[email protected]>
Signed-off-by: Damien George <[email protected]>
@dhalbert dhalbert force-pushed the merge-micropython-v1.25.0 branch from e1eda27 to 1263d11 Compare June 20, 2025 21:25
@dhalbert dhalbert force-pushed the merge-micropython-v1.25.0 branch from fb5d521 to b874e04 Compare June 21, 2025 15:25
@dhalbert dhalbert requested a review from eightycc June 21, 2025 17:23
@dhalbert dhalbert marked this pull request as ready for review June 21, 2025 17:24
Copy link
Collaborator

@eightycc eightycc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Did not test, but will re-base my work and test with this.

Note that we should look into updating CP's old version 2 of mbedtls to the current major version 3.

@eightycc eightycc merged commit 751c766 into adafruit:main Jun 21, 2025
17 checks passed
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.