Commit graph

17256 commits

Author SHA1 Message Date
a0786d92a1 ci: Enable format checking in many builds.
Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-05 16:05:42 +01:00
28e461aa35 mpprint: Rework integer vararg handling.
This adds support for %llx (needed by XINT_FMT for printing cell
objects) and incidentally support for capitalized output of %P.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-05 15:59:00 +01:00
dab2a2d6b4 micropython_checks: Add compiler plugin.
Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-05 15:59:00 +01:00
5c0e313372 coverage: Avoid type checking an invalid string.
we still want this not to crash a runtime but the
new static checker wouldn't like it.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-05 15:59:00 +01:00
69ae83d2b1 objcell: Fix printing cell ID.
On the nanbox build, `o->obj` is a 64-bit type but `%p` formats
a 32-bit type, leading to undefined behavior.

Print the cell's ID as an integer instead.

It can't be printed in hex because the '%llx' format specifier is not
supported in mp_printf.

This location was found using an experimental gcc plugin for mp_printf
error checking.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-05 15:55:54 +01:00
05a2996e5c coverage: Cast values to int for printing.
During the coverage test, all the values encountered are within the
range of %d.

These locations were found using an experimental gcc plugin
for mp_printf error checking.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-05 09:23:16 +01:00
5888b9b6a5 examplemodule: Cast arguments to printf.
These locations were found using an experimental gcc plugin
for mp_printf error checking.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-05 09:21:55 +01:00
31b62f25a4 core: Fix mp_printf integer size mismatches.
The type of the argument must match the format string. Add
casts to ensure that they do.

It's possible that casting from `size_t` to `unsigned` loses
the correct values by masking off upper bits, but it seems likely
that the quantities involved in practice are small enough that
the %u formatter (32 bits on most platforms, 16 on pic16bit) will
in fact hold the correct value.

The alternative, casting to a wider type, adds code size.

These locations were found using an experimental gcc plugin
for mp_printf error checking, cross-building for x64 windows
on Linux.

In one case there was already a cast, but it was written
incorrectly and did not have the intended effect.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-05 09:21:42 +01:00
1f3a21b3f8 coverage: Provide argmuents of expected types.
Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-04 15:49:35 +01:00
fb061dfde6 coverage: Cast type names to qstr explicitly.
Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-04 15:47:45 +01:00
fb10ccf93c core: Cast type names to qstr explicitly.
The name field of type objects is of type uint16_t for efficiency,
but when the type is passed to mp_printf it must be cast explicitly
to type qstr.

These locations were found using an experimental gcc plugin
for mp_printf error checking, cross-building for x64 windows
on Linux.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-04 15:45:23 +01:00
dbd87a9d02 runtime: Initialize bool field idiomatically.
Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-04 14:33:22 +01:00
8d1205c61c objcode: Fully parenthesize macro expansion.
as requested in code review.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-04 14:33:22 +01:00
bfe333772a ci: Use Python 3.11 for coverage testing.
This removes the need for the `sys_settrace_features.py.exp` file.

This means that people testing locally will also need to install
Python 3.11 in some way, such as with pyenv or uv, and use it
during `make VARIANT=coverage test`, or they will get failures.

When using python from GitHub actions/setup-python, pip3 can't
be wrapped by sudo, because this invokes the operating system python
instead.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-04 14:33:22 +01:00
5b00f0f1ff tests: Increase test timeout in coverage build.
The additional overhead of the settrace profiler means that the
`aes_stress.py` test was running too slowly on GitHub CI.
Double the timeout to 60 seconds.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-04 14:33:22 +01:00
1ab8fb08e0 ci: Remove the "settrace" build.
This becomes redundant when the main coverage build includes
settrace.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-04 14:20:12 +01:00
9994b4335f profile: Fix printing frame objects.
The argument corresponding to a `%q` specifier must be of type
`qstr`, not a narrower type like `int16_t`. Not ensuring this
caused an assertion error on one Windows x64 build.

The argument corresponding to a `%d` specifier must be of type
`int`, not a potentially-wider type like `mp_uint_t`. Not ensuring
this prevented the function name from being printed on the
unix nanbox build.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-04 14:20:12 +01:00
73f03f2e4a coverage: Initialize more code_state fields.
When MICROPY_PY_SYS_SETTRACE was enabled, a crash was seen in
the qemu_mips build. It seems likely that this was due to these
added fields not being initialized.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-04 14:20:12 +01:00
01287870ad runtime: Initialize fields in mp_thread_init_state.
If the fields added for MICROPY_PY_SYS_SETTRACE are not
initialized properly, their value in a thread is
indeterminate. In particular, if the callback is not NULL,
it will be invoked as a function.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-04 14:20:12 +01:00
f25c1cdc9d sys_settrace_features: Add expected output.
This side-steps the problem where the output does not match when the
host python version is 3.12.x (as it is on unix ci today).

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-04 14:20:12 +01:00
cf944864ef tests: Improve test coverage of py/profile.c.
Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-04 14:20:12 +01:00
989b0be60f coverage: Enable sys.settrace.
Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-04 14:20:12 +01:00
Alessandro Gatti
2ab06b61b3 py/emitnative: Let emitters know the compiled entity's name.
This commit introduces an optional feature to provide to native emitters
the fully qualified name of the entity they are compiling.

This is achieved by altering the generic ASM API to provide a third
argument to the entry function, containing the name of the entity being
compiled.  Currently only the debug emitter uses this feature, as it is
not really useful for other emitters for the time being; in fact the
macros in question just strip the name away.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-07-04 16:07:04 +10:00
Andrew Leech
3a97175f5f tools/mpremote: Fix disconnect handling on Windows and Linux.
Changes in this commit:
- Handle SerialException on Windows when device disconnects.
- Print clean 'device disconnected' message instead of stack trace.
- Fix terminal formatting issues on Linux after disconnect.
- Return disconnected state after console cleanup to avoid terminal issues.

This ensures proper disconnect messages on both platforms without showing
confusing error traces to users.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2025-07-04 15:51:47 +10:00
Andrea Giammarchi
e33a0f4682 webassembly/objpyproxy: Avoid throwing on symbol or iterator has-check.
JavaScript code uses "Symbol in object" to brand check its own proxies, and
such checks should also work on the Python side.

Signed-off-by: Andrea Giammarchi <andrea.giammarchi@gmail.com>
2025-07-04 15:08:03 +10:00
iabdalkader
16f9d7fdc3 alif/machine_spi: Improve transfer function to poll events.
Poll events during SPI transfer (USB fails during long transfers
otherwise).  And add a timeout for the blocking transfer.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2025-07-03 21:43:10 +10:00
iabdalkader
4a1edc4866 alif/machine_pin: Add support for machine.Pin IRQ.
Matches existing `Pin.irq()` API.  Both rising and falling edge work.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2025-07-03 21:26:27 +10:00
Alessandro Gatti
1b0cdc0794 py/asmthumb: Clean up integer-indexed load/store emitters.
This commit cleans up the single entry point integer-indexed load/store
emitters that have been built by merging the single operand type
load/store functions in 1f5ba6998b.

To follow the same convention found in RV32 and Xtensa emitters, the
function operand size is not named after the left shift amount to apply
to the initial offset to get its true byte offset, but by a generic
"operand size".

Also, those functions were updated to use the new MP_FIT_UNSIGNED macros
to perform bit width checks when figuring out which opcode encoding is
the best one to use.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-07-01 15:43:17 +10:00
Alessandro Gatti
6fd7422a8e tests/run-tests.py: Allow injected code customisation.
This commit introduces a mechanism to customise the code that is
injected to the board when performing a test file upload and execution.

A new argument, --begin", is added so regular Python code can be
inserted in the injected fragment between the module file creation and
the effective file import.  This is needed for running larger tests
(usually ones that have been pre-compiled with
"--via-mpy --emit native") on ESP8266, as that board does not have
enough memory to fit certain blocks of code unless additional
configuration is performed.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-07-01 15:43:17 +10:00
Alessandro Gatti
0d435959e0 tests/micropython: Improve viper ptr boundary tests.
This commit reworks the Viper pointer boundary tests in order to make
them more accurate and easier to extend.

The tests are now easier to reason about in their output, using easier
to read values, and bit thresholds are now more configurable.  If a new
conditional code sequence is introduced, adding a new bit threshold is
just a matter of adding a value into a tuple at the beginning of the
relevant test file.

Load tests have also been made more accurate, with better function
templates to test register-indexed operations.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-07-01 15:43:02 +10:00
Alessandro Gatti
c8c8b04569 py/asmx64: Implement the full set of Viper load/store operations.
This commit expands the implementation of Viper load/store operations
that are optimised for the x86 platform.

Like x86, x64 already implemented all necessary functions and all it
took to expose these to Viper after the infrastructure refactoring
was to add a few defines.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-07-01 15:34:29 +10:00
Alessandro Gatti
a8dd393eee py/asmx86: Implement the full set of Viper load/store operations.
This commit expands the implementation of Viper load/store operations
that are optimised for the x86 platform.

Unlike other platforms, x86 already implemented all necessary
functions and all it took to expose these to Viper after the
infrastructure refactoring was to add a few defines.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-07-01 15:34:29 +10:00
Alessandro Gatti
7bb5f2da9d py/asmthumb: Remove redundant load/store opcode implementations.
This commit removes load/store opcode implementations that have been
made redundant in 1f5ba6998b.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-07-01 15:34:29 +10:00
Alessandro Gatti
12f36cc13c py/asmxtensa: Implement the full set of Viper load/store operations.
This commit expands the implementation of Viper load/store operations
that are optimised for the Xtensa platform.

Now both load and store emitters should generate the shortest possible
sequence in all cases.  Redundant specialised operation emitters have
been aliased to the general case implementation - this was the case of
integer-indexed load/store operations with a fixed offset of zero.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-07-01 15:34:29 +10:00
Alessandro Gatti
cd1b921bf2 py/asmarm: Implement the full set of Viper load/store operations.
This commit expands the implementation of Viper load/store operations
that are optimised for the Arm platform.

Now both load and store emitters should generate the shortest possible
sequence in all cases.  Redundant specialised operation emitters have
been folded into the general case implementation - this was the case of
integer-indexed load/store operations with a fixed offset of zero.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-07-01 15:34:29 +10:00
Alessandro Gatti
a8e0369826 py/asmrv32: Implement the full set of Viper load/store operations.
This commit expands the implementation of Viper load/store operations
that are optimised for the RV32 platform.

Given the way opcodes are encoded, all value sizes are implemented with
only two functions - one for loads and one for stores.  This should
reduce duplication with existing operations and should, in theory, save
space as some code is removed.  Both load and store emitters will
generate the shortest possible sequence (as long as the stack pointer is
not involved), using compressed opcodes when possible.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-07-01 15:34:29 +10:00
Alessandro Gatti
703d5acbad py/misc: Introduce macros to check values' bits size.
This commit adds two macros that lets check whether a given value can
fit an arbitrary number of bits, either as a signed or as an unsigned
number.

The native emitter code backends perform a lot of bit size checks to see
if a particular code sequence can be emitted instead of a generic one,
and each platform backend has its own ad-hoc macros (usually one per bit
count and signedness).

With these macros there's a single way to perform those checks, plus
there's no more chance for off-by-one mask length errors when dealing
with signed numbers.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-07-01 15:34:29 +10:00
1eb27e11f3 unix/README: Add some small documentation about sanitizers.
Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-01 15:19:07 +10:00
07c3bf21f2 tools/ci.sh: Disable "stack use after return" in ASan build.
This check, runtime-enabled by default in gcc 13 (and existing at least
since gcc 12, but runtime-disabled) changes the stack layout in ways that
are not compatible with assumptions spread across the core code (nlr, gc,
and stack checking).

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-01 15:18:29 +10:00
9a5cf0e3db github/workflows: Run the address sanitizer (ASan) build during CI.
Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-01 15:18:21 +10:00
Damien George
4bd99260dc alif/Makefile: Allow specifying a custom build directory.
Signed-off-by: Damien George <damien@micropython.org>
2025-06-26 14:22:13 +10:00
iabdalkader
9b38cf9f82 alif/README: Update README with build instructions.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2025-06-26 13:28:18 +10:00
iabdalkader
8cd8e146a4 alif/boards/ALIF_ENSEMBLE: Add board.json and deploy instructions.
The firmware for this board will now be built and available automatically.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2025-06-26 13:25:40 +10:00
Damien George
77c454829f tools/autobuild: Build alif boards as part of auto-build.
Signed-off-by: Damien George <damien@micropython.org>
2025-06-26 13:25:37 +10:00
Damien George
74a4cce6d1 alif/Makefile: Create firmware.zip with files needed for deploying.
The resulting `firmware.zip` file is self contained with everything needed
to deploy the firmware, eg over SE UART.

Signed-off-by: Damien George <damien@micropython.org>
2025-06-26 13:25:02 +10:00
Andrew Leech
2f04381aeb extmod/modlwip: Fix crash when calling recv on listening socket.
Add check to prevent calling recv on a socket in the listening state.  This
prevents a crash/hard fault when user code mistakenly tries to recv on the
listening socket instead of on the accepted connection.

Add corresponding test case to demonstrate the bug.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2025-06-26 12:46:45 +10:00
ennyKey
2a46759fe8 stm32/uart: Enable UART FIFO for H7 MCUs.
The H7 has a hardware UART FIFO, so it's worth enabling it, to reduce the
chance of missed incoming characters.  Note that `HAL_UART_Init(&huart)`
does not activate the FIFO, it must be done explicitly by calling
`HAL_UARTEx_EnableFifoMode(&huart)`.

Signed-off-by: ennyKey <ennyKey@fn.de>
2025-06-26 12:36:04 +10:00
iabdalkader
5c6da11799 stm32/boards/ARDUINO_GIGA: Define additional GC blocks in SDRAM.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2025-06-26 12:10:04 +10:00
iabdalkader
cbe50635e8 stm32/main: Add support for additional GC blocks.
Add support for defining additional GC blocks via linker scripts.  A board
would need to define `_gc_blocks_table_start` and `_gc_blocks_table_end`
and within that region have pairs of (address, length) for each GC block
to add.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2025-06-26 12:10:04 +10:00
iabdalkader
0815b45479 stm32/boards/ARDUINO_PORTENTA_H7: Free reserved timer.
This pin is used for the camera clock on Portenta carrier, and vision
shield but it doesn't need to be reserved.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2025-06-26 10:49:51 +10:00