Commit graph

17544 commits

Author SHA1 Message Date
4f3a77638f objint_mpz: Narrow result of 3-arg pow if possible.
Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-08-27 14:12:07 -05:00
decc0c75a7 core: Introduce mp_obj_new_long_ll.
Since #9531 a few ways remained to produce long ints that were
not reduced to small ints.

Explicitly introduce "mp_obj_new_long_from_ll" and make
the "new_int" functions always produce small ints when possible.

At sites where a long int is really intended (or will
eventually be reduced to a small int if the result fits),
the called function is changed to be the new _long_ function.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-08-27 14:12:07 -05:00
c68d8ac358 tests: Test that operations return small ints.
Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-08-27 14:12:07 -05:00
David Schneider
8c47e446bf py/obj: Fix a comment regarding make_new slot.
This was missed as part of the transition to make_new a mp_obj_type_t slot.

See also: 94beeabd2e

Signed-off-by: David Schneider <schneidav81@gmail.com>
2025-08-26 23:16:01 +10:00
Alessandro Gatti
c33a02fe6d tests/run-tests.py: Enable Arm inlineasm FPU tests if possible.
This commits lifts the unconditional restriction on inline assembler FPU
tests for the Qemu platform, and makes said restriction conditional to
the lack of an available floating point unit on the running platform.

The Qemu platform supported only emulated machines that could target up
to a Cortex-M3, so an ArmV7-M target that had no support for floating
point.  With the addition of MPS2_AN500 to the list of emulated targets
the range was extended to cover up to Cortex-M7, so a floating point
unit may possibly be available and thus able to run the FPU inlineasm
tests.

For that, the test runner was changed to detect the running architecture
when checking the target capabilities; if the target reports its
MicroPython architecture to be either "armv7emsp" or "armv7emdp"
(providing single-precision and double-precision floating point unit
support respectively) then the FPU-only inline tests are not put into
the blocked tests list.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-08-26 12:27:21 +10:00
Alessandro Gatti
6c1d1f3ad4 qemu/mcu/arm/mps2.ld: Add .ARM.exidx section to the linkerscript.
This commit fixes a linking issue on certain Arm toolchains where
library code is compiled with exception support.

If a library with exception support is included in the MicroPython
build, the linker had no place to put the stack unwinding tables
necessary to perform exception handling at runtime.  This change adds a
new section to the linkerscript (and therefore the final ELF file) where
that data can be placed into.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-08-26 12:27:21 +10:00
Alessandro Gatti
6650506e06 tools/ci.sh: Extend Arm testing to include hardfp targets.
This commit lets CI extend the testing scope of the QEMU Arm target, by
letting it perform the usual battery of tests (interpreter and natmods)
also on hardfp targets.

The default board for Arm testing lacks hardware floating point support,
so natmods weren't tested in that specific configuration.  With the
introduction of the "MPS_AN500" QEMU target, now this is made possible
as said board emulates a Cortex-M7 machine with a single- and
double-precision floating point unit.

To reduce the impact on build times, the "ci_qemu_build_arm_thumb" CI
step was split in two: "ci_qemu_build_arm_thumb_softfp" and
"ci_qemu_build_arm_thumb_hardfp" - so hopefully those can run in
parallel whenever possible.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-08-26 12:27:21 +10:00
Alessandro Gatti
64cac4690f qemu/mcu/arm/errorhandler: Add ARMv7-M debug registers.
This commit extends the QEMU port's CPU error handler for the Arm target
by printing out in detail the ARMv7-M debug registers if the firmware is
compiled for such a target.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-08-26 12:27:21 +10:00
Alessandro Gatti
19be404ad8 qemu/arm: Add definition for the MPS2_AN500 machine.
This commit introduces a new target for the QEMU port called
"MPS2_AN500", an ARMv7-M machine with a Cortex-M7 CPU and
single-/double-precision floating point unit.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-08-26 12:27:21 +10:00
Alessandro Gatti
87099b5731 qemu/Makefile: Allow overriding floating point mode by boards.
This commit lets board use a different floating point mode rather than
the usual soft-float that was the original default for all QEMU-based
boards.

The configuration options are the same available in the "stm32" port.
Boards can set "MICROPY_FLOAT_IMPL" to either "float", "double", or
"none" to indicate which floating point mode they want, and optionally
"SUPPORTS_HARDWARE_FP_SINGLE" or "SUPPORTS_HARDWARE_FP_DOUBLE" can be
set to 1 to further indicate the hardware capabilities of the hardware
floating point unit, if present.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-08-26 12:27:21 +10:00
Alessandro Gatti
b0fd0079f4 tests/micropython: Make tests behave in low memory condition.
This commit changes the "viper_ptr*_store_boundary" tests to make them
fail more gracefully in low memory conditions.

The original version of the tests compiled viper code blocks on the fly
when it needed them, making them fail at runtime on some boards that do
not come with enough memory for this test.  This clashes with
"run-tests.py"'s ability to look for a particular signature to mark
tests as skipped due to not enough memory.

Now compiled code blocks are generated at the beginning of the test
inside an appropriate exception handler.  In case of a memory error when
pre-compiling a code block, the running test exits reporting a low
memory condition to the test runner.  This allows to have clean test
runs on all platforms when it comes to viper pointer tests.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-08-26 10:47:17 +10:00
Daniël van de Giessen
1df5ee12e8 esp32/network_ppp: Stop polling if PPP was disconnected.
When disconnecting from PPP the modem sends a confirmation. This message
is received, like all messages, through the poll() method. lwIP may then
immediately call our status callback with code PPPERR_USER to indicate
the connection was closed. Our callback then immediately proceeds to
free the PCB. Thus, during each new iteration of the loop in poll() we
must check if we haven't disconnected in the meantime to prevent calling
the pppos_input_tcpip with a PCB that is now NULL.

Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2025-08-25 23:11:33 +10:00
Daniël van de Giessen
72147c02c7 esp32/network_ppp: Stop polling if stream becomes None.
If while a polling operation is active the stream is removed we should
stop polling data from that stream.

This was already the intended behaviour, but implemented incorrectly.

Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2025-08-25 23:11:33 +10:00
Yilin Sun
053aade741 mimxrt/boards: Re-generate MIMXRT1052 clock config files.
These were regenerated by the NXP Config tool for v2.11.

The board_init update was needed to ensure CLOCK_SetMode() is run
at the appropriate time during startup.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2025-08-25 10:48:17 +10:00
Yilin Sun
bd7342d9ec mimxrt: Restructure nxp_sdk to match official mcux-sdk.
The official mcux-sdk follows a slightly different structure to the
current nxp_sdk submodule, with many drivers moved to a common location.

To ease updating the newer versions of the SDK and/or add new families
the nxp_sdk submodule has been updated to follow the structure of
mcux-sdk, just trimmed down to families used here to considerably
reduce the size.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2025-08-25 10:48:16 +10:00
Damien George
a3f9dec788 py/mpconfig: Enable the sys module at all feature levels by default.
This is a pretty fundamental module, and even minimal ports like unix and
zephyr minimal have it enabled.  So, enabled it by default at the lowest
feature level.

Most things in the `sys` module are configurable, and off by default, so it
shouldn't add too much to ports that don't already have it enabled (which
is just the minimal port).

Also note that `sys` is still disabled on the bare-arm port, to keep that
ultra minimal.  It means we now have bare-arm without `sys` and the minimal
port with `sys`.  That will allow different code size comparisons if/when
new `sys` features are added.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-22 13:31:10 +10:00
Damien George
14e9c00cb9 py/builtinimport: Guard code needing sys.path with MICROPY_PY_SYS_PATH.
Signed-off-by: Damien George <damien@micropython.org>
2025-08-22 13:30:46 +10:00
Damien George
b5fcb33eaa py/mpconfig: Enable CRYPTOLIB, HASHLIB_MD5, HASHLIB_SHA1 if SSL enabled.
This commit unifies the configuration of MICROPY_PY_CRYPTOLIB,
MICROPY_PY_HASHLIB_MD5 and MICROPY_PY_HASHLIB_SHA1, so they are enabled by
default if MICROPY_PY_SSL is enabled.  This matches the existing
configuration of most of the ports.

With this change, all ports remain the same except:
- reneses-ra now enables MICROPY_PY_CRYPTOLIB, MICROPY_PY_HASHLIB_MD5 and
  MICROPY_PY_HASHLIB_SHA1.
- rp2 now enables MICROPY_PY_HASHLIB_MD5.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-19 21:10:00 +10:00
Damien George
989abae12c py/mpconfig: Move MICROPY_MODULE___ALL__ option to other module options.
Signed-off-by: Damien George <damien@micropython.org>
2025-08-19 13:00:45 +10:00
Damien George
169d382248 py/mpconfig: Rename MICROPY_PY___FILE__ to MICROPY_MODULE___FILE__.
For consistency with other module-related configuration options.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-19 13:00:45 +10:00
Damien George
3650196682 py/objtype: Use locals_ptr directly instead of getting it from the slot.
This is a very minor code simplification, which reduces code size by about
-8 bytes.  It should have no functional change.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-19 12:58:02 +10:00
Alessandro Gatti
bd413d3d85 py/asmthumb: Fix T3 encoding of conditional branches.
This commit fixes the encoding of conditional branch opcodes emitted for
ARMv7-M targets, when the emitter decides to use the T3 encoding for
said operation.

Fields J1 and J2 are now present in the generated opcode word, along
with correcting some minor issues in bitmasks and shifts computation.

This fixes #17940.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-08-19 12:40:29 +10:00
Angus Gratton
22deeeb8db tests/stress/recursive_iternext: Rewrite to find its own limit.
Necessary on the unix port when running with sanitizers, as the newly
increased stack size can run all tests at N=5000 without raising
RuntimeError, and increasing N to fix this causes issues on other
configurations.

This way the test progressively builds a deeper data structure until it
fails with RuntimeError. This is theoretically slower, but not noticeably
so in reality.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-08-19 10:33:40 +10:00
Angus Gratton
d8672f4cde unix: Increase stack sizes if running with sanitizers.
The specific problem seems to be that the runtime "Python stack frame"
function call is several times more expensive in stack usage when running
with UBSan on older GCC (observed on gcc 11.4 as used in CI, would get
'RuntimeError: maximum recursion depth exceeded' when running some tests
with UBSan enabled.)

Other stack usage (i.e. from pushing things on the stack in Python) stays
the same. Whatever causes the usage seems to be mostly gone in later GCC
versions.

Includes a refactor to apply the same stack size multipliers
for the default thread stack size same as the main stack size.

This goes in a new port-specific header as it depends on macros
in misc.h, so can't be in mpconfigport.h.

A side effect of this is that the default thread stack size is
now doubled on ARM, same as the main stack size.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-08-19 10:33:40 +10:00
Angus Gratton
3faf229853 py/misc: Add a way to detect sanitizer builds.
Clang and gcc>=14 can use __has_feature() to detect if a sanitizer
is enabled, but older GCC has no mechanism - need to set a macro
explicitly for this to be recognised.

Necessary for increasing some resource limits in sanitizer builds.
Important not to use to avoid real issues!

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-08-19 10:33:40 +10:00
Angus Gratton
d81d56cc4d tools/ci: Add UBSan to longlong CI build.
Also rewrite the sanitizer argument variables to not assume a variant.

longlong variant currently fails in this config, due to a bug fixed
in follow-up commit.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-08-19 10:33:40 +10:00
Tico06
020eeba412 stm32/eth_phy: Fix typo in header guard macro.
Typo on line 29 (PYH instead of PHY).

Compilation failing, here is the output:

    eth_phy.h:28: error: header guard 'MICROPY_INCLUDED_STM32_PHY_H'
    followed by '#define' of a different macro [Werror=header-guard]
        28 | #ifndef MICROPY_INCLUDED_STM32_PHY_H
    eth_phy.h:29: note: 'MICROPY_INCLUDED_STM32_PYH_H' is defined here;
    did you mean 'MICROPY_INCLUDED_STM32_PHY_H'?
        29 | #define MICROPY_INCLUDED_STM32_PYH_H

Signed-off-by: Tico06 <e.grammatico@gmail.com>
2025-08-18 14:07:02 +10:00
iabdalkader
c7ddf0c54f stm32/Makefile: Add .gc.blocks.table section to generated binary.
The generated binary file was missing this section, which caused a hard
fault when loading bin or dfu firmware (eg on ARDUINO_GIGA).

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2025-08-18 13:57:30 +10:00
Yuuki NAGAO
365329cd54 stm32/dac: Fix DAC write for MCUs that have D-Cache.
To prevent wrong DAC output, clean D-cache before starting DMA.

For more details, please refer to the following document:
https://www.st.com/resource/en/application_note/DM00272913.pdf

Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2025-08-18 13:20:50 +10:00
Yuuki NAGAO
152a0782e6 stm32/dac: Add support for DAC feature on STM32G0.
DAC.write() and DAC.write_timed() are now available on STM32G0.

Tested on NUCLEO_G0B1RE.

Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2025-08-18 13:17:34 +10:00
Yuuki NAGAO
1b35116c92 stm32/dac: Fix 12-bit DAC issue on STM32H5.
For STM32H5, to use 12-bit DAC, the DMA parameter should set:
- Actual DMA source datawidth to CTR1.
- The length is the amount of data to be transferred from source to
  destination in bytes.

Also, this commit modifies the (dummy) definition of DMA_CIRCULAR for
STM32H5 to prevent conflict with data width specification.

Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2025-08-18 13:11:01 +10:00
dependabot[bot]
1588c455c4 github/workflows: Bump actions/checkout from 4 to 5.
Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-16 18:36:57 +10:00
Maureen Helm
afa7265ffa zephyr: Upgrade to Zephyr v4.2.0.
Updates the Zephyr port build instructions and CI to use the latest
Zephyr release tag.

Tested on max32690fthr and frdm_k64f.

Signed-off-by: Maureen Helm <maureen.helm@analog.com>
2025-08-16 15:10:30 +10:00
Thomas Watson
bba3542018 extmod/modlwip: Remove unused include and functions.
The lwIP includes are now port-specific.

The `sys_arch_{,un}protect` functions are not used according to line 34
of `extmod/lwip-include/lwipopts_common.h`.

Neither have been touched in nearly a decade.

Signed-off-by: Thomas Watson <twatson52@icloud.com>
2025-08-16 14:52:52 +10:00
Damien George
b7cfafc1ee alif/alif.mk: Add MPY_CROSS_FLAGS setting.
The HP and HE CPUs have double-precision hardware floating point, so can
use the armv7emdp architecture.

This allows frozen code to use native/viper/asm_thumb decorators.

Fixes issue #17896.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-15 12:45:33 +10:00
Damien George
f0f5abb7a3 alif/mpconfigport: Enable cryptolib and hashlib.md5/sha1.
They are enabled when SSL/mbedTLS is included in the firmware.  These new
features cost around +1400 bytes of code size.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-15 12:44:39 +10:00
Damien George
f1462448d0 alif/modtime: Implement the rest of the time module.
Adds: `time.time()`, `time.time_ns()`, `time.localtime()`, `time.mktime()`
and `time.gmtime()`.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-15 12:35:24 +10:00
Damien George
326730d8b2 alif/mbedtls: Implement the mbedTLS time function.
Signed-off-by: Damien George <damien@micropython.org>
2025-08-15 12:35:23 +10:00
Damien George
46b366d7b2 alif/fatfs_port: Implement get_fattime.
Signed-off-by: Damien George <damien@micropython.org>
2025-08-15 12:35:21 +10:00
Damien George
0feb4f5ea4 alif/mphalport: Implement mp_hal_time_ns.
Signed-off-by: Damien George <damien@micropython.org>
2025-08-15 12:35:18 +10:00
Damien George
e58848a21e alif/machine_rtc: Implement RTC.datetime to get and set the RTC.
The LPRTC peripheral is a 32-bit counter with a 16-bit prescaler.  It's
configured here to count at 1Hz (to get maximum date range) and then the
prescaler value is used to get 30 microsecond resolution.  That's
essentially a 32+15=47-bit counter.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-15 12:34:28 +10:00
Damien George
b3cd1a355e extmod/modtime: Move tuple creation to common localtime implementation.
This factors code out of the ports and into the common `time.localtime`
implementation in `extmod/modtime.c`.  That helps to reduce code
duplication, prevent errors in implementation, and reduce code size on
some ports (mimxrt and stm32 at least).

Signed-off-by: Damien George <damien@micropython.org>
2025-08-15 12:09:13 +10:00
Damien George
40cc4e4f74 py/objtype: Make mp_obj_new_type a static function.
It's only used once, in the same file it's defined, and making it static
reduces code size.

Along with this, the associated example code comment in `ports/unix/main.c`
has been removed.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-15 11:45:11 +10:00
Damien George
3efbd726eb py/parse: Remove explicit checks for invalid folding operations.
They are instead checked by `binary_op_maybe()`, which catches exceptions
for invalid int/float operations.

This is a follow-up to 69ead7d98e

Signed-off-by: Damien George <damien@micropython.org>
2025-08-15 11:38:20 +10:00
Phil Howard
141f7d0c35 py/mkrules.cmake: Clean genhdr and frozen_mpy dirs.
CMake builds relied upon the parent Makefile removing the entire
build directory to successfully clean build artifacts.

py/mkrules.cmake: Add ADDITIONAL_CLEAN_FILES properties to ensure a
		  "make clean" from within the build directory removes
                  the genhdr and frozen_mpy directories.

Signed-off-by: Phil Howard <github@gadgetoid.com>
2025-08-15 01:24:53 +10:00
0615d13963 py/objringio: Detect incorrect constructor calls.
ringbuffer.size must be at least 2, and is a 16-bit quantity.

This fixes several cases including the one the fuzzer discovered, which
would lead to a fatal signal when accessing the object.

Fixes issue #17847.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-08-15 01:21:25 +10:00
803da9645f extmod/modframebuf: Save code size in setpixel.
There's a slight code size increase paid for by using setpixel_checked for
the last pixel of a line, instead of repeating the checks inline.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-08-15 01:17:00 +10:00
e15219800e extmod/modframebuf: Fix crash in scroll() for large inputs.
If mp_int_t is wider than int, then the tests such as `xend < 0` can fail
even when the amount of scrolling requested is out of range.  This resulted
in a segmentation fault when attempting an out-of-bounds access to the
framebuffer.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-08-15 01:16:24 +10:00
Damien George
2bba507148 tests: Require SSL certificate file to be available for test to run.
Previously, any test needing an SSL certificate file would automatically
skip if the file could not be found.  But that makes it too easy to
accidentally skip tests.

Instead, change it so that the test fails if the certificate file doesn't
exist.  That matches, for example, the fact that the test fails if
networking (LAN, WiFi) is not active.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-15 01:03:00 +10:00
Damien George
a279c64046 tests: Add .native.exp output files for tests that differ with native.
Signed-off-by: Damien George <damien@micropython.org>
2025-08-15 00:36:27 +10:00