Commit graph

17469 commits

Author SHA1 Message Date
cb62a54966 core: Introduce MICROPY_MAP_SPLIT (unfinished).
Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-08-10 14:06:48 -05:00
8bf6e22a2e core: Introduce MP_ROM_TABLE.
Once all ROM tables used in a given port are converted to use this
macro, investigation can commence into alternate memory
representations such as the one proposed by the ROM_TABLE_SEPARATE
macro.

vim command for transforming map entries (split over 2 lines):
```
:'<,'>s/{ MP_ROM_QSTR(\(.*\)), \(MP_[A-Z_]*\)(\(.*\)) },
/((\1, \2, \3))
```

This commit updates all tables used in ports/minimal.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-08-10 11:13:51 -05:00
9dae5b35c0 core: Introduce MP_ROM_TABLE.
Once all ROM tables used in a given port are converted to use this
macro, investigation can commence into alternate memory
representations such as the one proposed by the ROM_TABLE_SEPARATE
macro.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-08-10 10:55:17 -05:00
Angus Gratton
593ae04eeb esp32/machine_timer: Fix machine.Timer() tick frequency on ESP32C2,C6.
Also future-proofs this code for other chips. Apart form C6 and C2, all
currently supported chips use APB clock for GPTIMER_CLK_SRC_DEFAULT.

ESP32-C2 uses 40MHz PLL but APB_CLK_FREQ was 26MHz.
ESP32-C6 uses 80MHz PLL but APB_CLK_FREQ was 40MHz.

Implementation now gets the correct frequency from ESP-IDF.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-08-07 16:55:46 +10:00
Angus Gratton
ce109af712 esp32/machine_timer: Enable timer clock source for ESP32C6.
Otherwise the PLL is not enabled.  These changes are adapted from
`timer_legacy.h` in ESP-IDF.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-08-07 16:55:23 +10:00
Damien George
d5ecda05eb ports: Allow MICROPY_PY_MACHINE_I2C_TARGET to be disabled by board cfg.
Signed-off-by: Damien George <damien@micropython.org>
2025-08-07 10:33:26 +10:00
Damien George
255d74b5a8 renesas-ra/mpconfigport: Enable MICROPY_TIME_SUPPORT_Y1969_AND_BEFORE.
This setting was missed in df05caea6c.  It's
needed for this port to pass its `tests/ports/renesas-ra/modtime.py` test.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-04 10:41:06 +10:00
Damien George
7c8ae78a03 lib/micropython-lib: Update submodule to latest.
This brings in:
- lora: fix SNR value in SX126x received packets
- utop: add initial implementation for ESP32
- utop: print MicroPython memory info
- utop: print IDF heap details
- urllib.urequest: add support for headers to urequest.urlopen
- aiorepl: use blocking reads for raw REPL and raw paste
- errno: add ENOTCONN constant
- logging: allow logging.exception helper to handle tracebacks
- aioble-l2cap: raise correct error if l2cap disconnects during send
- abc: add ABC base class
- aiohttp: fix partial reads by using readexactly
- aiorepl: handle stream shutdown

Signed-off-by: Damien George <damien@micropython.org>
2025-08-04 01:50:32 +10:00
c0252d73c6 py/parse: Fix missing nlr_pop call in complex path of binary_op_maybe.
Reproducer (needs to be run as one compilation unit):

    ans = (-1) ** 2.3
    aa

Fixes issue #17815.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-08-03 08:29:28 +10:00
Damien George
658a2e3dbd github/workflows: Add a CI job to build ESP32-C2 and ESP32-C6 boards.
So that all six supported SoCs are built by CI.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-02 08:53:36 +10:00
Damien George
3c9546ea09 esp32/mpconfigport: Disable I2CTarget on ESP32-C6 to reduce code size.
I2CTarget costs about 8k of flash size on ESP32-S2, and about 11k on
ESP32-C6.  The ESP32-C6 only has about 8k remaining, so disable I2CTarget
on that SoC until more flash can be made available.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-02 08:53:36 +10:00
Phil Howard
e6739fc87e rp2/rp2_flash: Add binary info for ROMFS.
This describes the ROMFS location and size in Pico SDK's binary declaration
format, so it can be read from a .uf2 file for use with various tools.

Signed-off-by: Phil Howard <github@gadgetoid.com>
2025-08-02 00:36:50 +10:00
Jos Verlinde
a9dd741e66 docs/reference/mpremote: Document location of config file.
Signed-off-by: Jos Verlinde <Jos_Verlinde@hotmail.com>
2025-08-02 00:23:21 +10:00
Jos Verlinde
64b3944b01 tools/mpremote: Locate config.py location across different host OSes.
Use `platformdirs.user_config_dir()` (see
https://platformdirs.readthedocs.io/en/latest/api.html#user-config-directory)
to provide portability across many different OSes and configuration styles.

Signed-off-by: Jos Verlinde <Jos_Verlinde@hotmail.com>
2025-08-02 00:22:32 +10:00
Jos Verlinde
026a20da3e tools/mpremote: Add platformdirs dependency to requirements.txt.
Needed to easily find the user configuration file.

Signed-off-by: Jos Verlinde <Jos_Verlinde@hotmail.com>
2025-08-02 00:20:05 +10:00
Angus Gratton
907c5e9976 tests/extmod_hardware: Add basic tests for machine.Counter and Encoder.
These don't test any advanced features, just the basics.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-08-02 00:03:03 +10:00
Jonathan Hogg
641ca2eb06 docs/library/machine: Add docs for Counter and Encoder.
Add documentation for `machine.Counter` and `machine.Encoder` as currently
implemented by the esp32 port, but intended to be implemented by other
ports.

Originally authored by: Ihor Nehrutsa <Ihor.Nehrutsa@gmail.com> and
Jonathan Hogg <me@jonathanhogg.com>.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2025-08-02 00:00:03 +10:00
Jonathan Hogg
327655905e esp32/modules/machine.py: Add Counter and Encoder classes.
Adds a Python override of the `machine` module, which delegates to the
built-in module and adds an implementation of `Counter` and `Encoder`,
based on the `esp32.PCNT` class.

Original implementation by: Jonathan Hogg <me@jonathanhogg.com>

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2025-08-01 23:45:18 +10:00
Jonathan Hogg
e54553c496 docs/esp32: Add documentation for esp32.PCNT.
Document the new `esp32.PCNT` class for hardware pulse counting.

Originally authored by: Jonathan Hogg <me@jonathanhogg.com>

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2025-08-01 23:45:18 +10:00
Jonathan Hogg
c3f3339c87 esp32/modesp32: Add esp32.PCNT class.
Add a new `esp32.PCNT` class that provides complete, low-level support to
the ESP32 PCNT pulse counting hardware units.

This can be used as a building block to implement the higher-level
`machine.Counter` and `machine.Encoder` classes.

This is enabled by default on all OG, S2, S3, C6 boards, but not on C3 (as
the PCNT peripheral is not supported).

Original implementation by: Jonathan Hogg <me@jonathanhogg.com>

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-08-01 23:45:18 +10:00
Damien George
bf6f229cf3 docs/library: Document the new machine.I2CTarget class.
With some working examples that show how to use all the features.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-01 23:03:17 +10:00
Damien George
277b615f26 tests/multi_extmod: Add I2CTarget multi tests.
These require two boards wired together, SCL-SCL and SDA-SDA.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-01 23:03:17 +10:00
Damien George
6558d519a2 tests/extmod_hardware: Add self unittest for I2CTarget.
This test uses a SoftI2C controller wired to an I2CTarget on the one board,
and tests all functionality of the I2CTarget class.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-01 23:03:17 +10:00
Damien George
7bc83afee2 esp32/machine_i2c_target: Implement I2CTarget class.
Only soft IRQs are supported.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-01 23:03:17 +10:00
Damien George
ac5b1bce99 esp32/machine_i2c: Factor default pin macros to header file.
So the implementation of I2CTarget can use them.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-01 23:03:17 +10:00
robert-hh
79d182deb2 samd/machine_i2c_target: Support I2C target mode.
Supporting readfrom_mem*(). writeto_mem() and a set of IRQs.  Enabled by
default for SAMD51 devices and SAMD21 devices with external flash.

Tested with ItsyBitsy M4 and ItsyBitsy M0 with both on-board SoftI2C and a
RP2 Pico as controller.

Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: robert-hh <robert@hammelrath.com>
2025-08-01 23:03:17 +10:00
robert-hh
5c78762c16 mimxrt/machine_i2c_target: Support I2C target mode.
The functionality is similar to the RP2 implementation.  The supported
address size is 7 bit.  In order to achieve a sufficient response, the
target I2C IRQ handler has to run from RAM, causing much more code moved to
RAM than required.

Tested with Teensy 4.1, MIMXRT1021EVK, MIMXRT1011EVK and MIMXRT1170, using
both a On-Board SoftI2C as controller and a RP2 Pico as external
controller.

Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: robert-hh <robert@hammelrath.com>
2025-08-01 23:03:17 +10:00
Damien George
67a442d8fa alif/machine_i2c: Allow changing I2C SCL/SDA pins.
Signed-off-by: Damien George <damien@micropython.org>
2025-08-01 23:03:17 +10:00
Damien George
6e72cae619 alif/machine_i2c_target: Implement I2CTarget class.
Signed-off-by: Damien George <damien@micropython.org>
2025-08-01 23:03:17 +10:00
Damien George
0c50343145 zephyr/machine_i2c_target: Implement I2CTarget class.
Tested and working on rpi_pico and nucleo_wb55rg.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-01 23:03:17 +10:00
Damien George
1839340dda rp2/machine_i2c_target: Implement I2CTarget class.
Signed-off-by: Damien George <damien@micropython.org>
2025-08-01 23:03:17 +10:00
Damien George
56d2b47370 rp2/machine_i2c: Factor default pin macros to header file.
So they can be reused by the I2CTarget implementation.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-01 23:03:17 +10:00
Damien George
01e570a347 stm32/machine_i2c_target: Implement I2CTarget class.
Works, tested on PYBV10, PYBD_SF2 and PYBD_SF6:

    buf = bytearray(16)
    machine.I2CTargetMemory("X", addr=67, mem=buf)

Signed-off-by: Damien George <damien@micropython.org>
2025-08-01 23:03:17 +10:00
Damien George
78d16672e1 stm32/i2cslave: Account for slow addr_match callback.
Signed-off-by: Damien George <damien@micropython.org>
2025-08-01 23:03:17 +10:00
Damien George
2443878bd9 stm32/i2cslave: Support i2c_slave_process_tx_end callback on F4.
The rounds out the F4 implementation to match the other supported MCUs.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-01 23:03:17 +10:00
Damien George
17d0449ac8 stm32/i2cslave: Add functions to read/write I2C data.
Instead of requiring the callback to consume/provide the data.  This allows
the data to be consumed/provided later on, which will stretch the I2C clock
until that occurs.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-01 23:03:17 +10:00
Damien George
a4ca42f094 stm32/i2cslave: Change irq handler name to i2c_slave_irq_handler.
Remove the "ev" part, so this handler can be generalised to also handle
error IRQs.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-01 23:03:17 +10:00
Damien George
9b1778fc77 stm32/i2c: Move I2C IRQ handlers from stm32_it.c to i2c.c.
And add MP_STATIC_ASSERT to statically check that the IRQ names are correct
on the MCU that it's compiled for.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-01 23:03:17 +10:00
Damien George
1b578fe2c0 extmod/machine_i2c_target: Add new machine.I2CTarget class.
This commit implements a generic I2C target/peripheral/"slave" device,
called `machine.I2CTarget`.  It can work in two separate modes:

- A general device with interrupts/events/callbacks for low-level I2C
  operations like address match, read request and stop.

- A memory device that allows reading/writing a specific region of memory
  (or "registers") on the target I2C device.

To make a memory device is very simple:

    from machine import I2CTarget

    mem = bytearray(8)
    i2c = I2CTarget(addr=67, mem=mem)

That's all that's needed to start the I2C target.  From then on it will
respond to any I2C controller on the bus, allowing reads and writes to the
mem bytearray.

It's also possible to register to receive events.  For example to be
notified when the memory is read/written:

    from machine import I2CTarget

    def irq_handler(i2c_target):
        flags = i2c_target.irq().flags()
        if flags & I2CTarget.IRQ_END_READ:
            print("controller read target at addr", i2c_target.memaddr)
        if flags & I2CTarget.IRQ_END_WRITE:
            print("controller wrote target at addr", i2c_target.memaddr)

    mem = bytearray(8)
    i2c = I2CTarget(addr=67, mem=mem)
    i2c.irq(irq_handler)

Instead of a memory device, an arbitrary I2C device can be implemented
using all the events (see docs).

This is based on the discussion in #3935.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-01 23:03:17 +10:00
Koudai Aono
ab7c5a1733 docs/library/btree: Fix method links to explicitly specify class.
So they don't clash with other potential references.

Signed-off-by: Koudai Aono <koxudaxi@gmail.com>
2025-08-01 22:58:26 +10:00
root
769453c750 rp2/rp2_pio: Fix use of PIO2 in prog data structure.
The RP2350 PIO2 State Machines (8, 9, 10, 11) did not work.  The data
structure used to pass the PIO arguments was missing an entry for PIO2,
thus causing the PIO2 instances to write wrong data to wrong locations.

Fixes issue #17509.

Signed-off-by: Matt Westveld <github@intergalacticmicro.com>
2025-08-01 22:38:00 +10:00
Dryw Wade
c9b52b2b7f rp2/CMakeLists.txt: Fix flash size check logic.
Follow up to 6bfb83e30a, if the variable
`PICO_FLASH_SIZE_BYTES` is not a numeric constant, eg "(2 * 1024 * 1024)",
then it won't pass the GREATER check.  So change the if logic to just test
if it's defined.

Signed-off-by: Dryw Wade <dryw.wade@sparkfun.com>
2025-08-01 16:20:49 +10:00
Damien George
a9a606bf5d docs/library/rp2.StateMachine: Add a note about PIO in and jmp pins.
Signed-off-by: Damien George <damien@micropython.org>
2025-08-01 15:10:15 +10:00
Damien George
41987c6cf4 rp2/rp2_pio: Configure jmp_pin for PIO use if it's isolation is set.
Signed-off-by: Damien George <damien@micropython.org>
2025-08-01 15:10:15 +10:00
Jos Verlinde
dea949e860 tools/mpremote: Update ESPxxx detection for USB-CDC ports.
Detection of ESP-XX devices was based on just the names of the USB driver
name, and did not account for the switch of the newer ESP-xx devices to
USB-CDC.  On Windows this caused unwanted/unneeded resets as the DTR/RTS
signals are also used for automatic device reset over USB-CDC.  See
https://github.com/micropython/micropython/issues/9659#issuecomment-3124704572

This commit uses the Espressif registered VID 0x303A to detect USB-CDC
ports, to enable the same DTR/RTS settings as used on the UART-USB
connection.

Also improved the robustness of the code using `getattr()`.

Signed-off-by: Jos Verlinde <Jos_Verlinde@hotmail.com>
2025-08-01 14:58:20 +10:00
Jos Verlinde
4ba626ab5a tools/mpremote: Fix errno.ENOTBLK attribute error on Windows.
Not all errors defined in stdlib errno are available on Windows.
Specifically, errno.ENOTBLK is not.

Fixes issue #17773.

Signed-off-by: Jos Verlinde <Jos_Verlinde@hotmail.com>
2025-08-01 14:52:59 +10:00
Chris Webb
953da2080e tests/micropython: Test that viper offset stores don't clobber base reg.
When running the viper boundary tests, assert that the offset stores don't
clobber the base register, which is saved and temporarily modified on some
architectures.

Signed-off-by: Chris Webb <chris@arachsys.com>
2025-08-01 14:17:49 +10:00
Chris Webb
f39434e9fb py/asmthumb: Don't corrupt base register in large offset store.
asm_thumb_store_reg_reg_offset() modifies the base register when storing
with a large offset which triggers the generic path. If a variable lives
in that register, this corrupts it. Fix this by saving the base register
on the stack before modifying it.

Signed-off-by: Chris Webb <chris@arachsys.com>
2025-08-01 14:15:39 +10:00
Yoctopuce dev
69ead7d98e py/parse: Add support for math module constants and float folding.
Add a new MICROPY_COMP_CONST_FLOAT feature, enabled by in mpy-cross and
when compiling with MICROPY_CONFIG_ROM_LEVEL_CORE_FEATURES.  The new
feature leverages the code of MICROPY_COMP_CONST_FOLDING to support folding
of floating point constants.

If MICROPY_COMP_MODULE_CONST is defined as well, math module constants are
made available at compile time. For example:

    _DEG_TO_GRADIANT = const(math.pi / 180)
    _INVALID_VALUE = const(math.nan)

A few corner cases had to be handled:
- The float const folding code should not fold expressions resulting into
  complex results, as the mpy parser for complex immediates has
  limitations.
- The constant generation code must distinguish between -0.0 and 0.0, which
  are different even if C consider them as ==.

This change removes previous limitations on the use of `const()`
expressions that would result in floating point number, so the test cases
of micropython/const_error have to be updated.

Additional test cases have been added to cover the new repr() code (from a
previous commit).  A few other simple test cases have been added to handle
the use of floats in `const()` expressions, but the float folding code
itself is also tested when running general float test cases, as float
expressions often get resolved at compile-time (with this change).

Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
2025-08-01 13:35:44 +10:00
SiZiOUS
f67a370311 embed/port: Fix alloca include for Windows platforms.
When building the embedded port on MinGW-w64, I receive the following
error:

    fatal error: alloca.h: No such file or directory

MinGW-w64 (used on MSYS2) doesn't include `alloca.h`, but `alloca()` is
provided via `malloc.h` instead.  And this fix is also needed for other
Windows build systems.

Signed-off-by: SiZiOUS <sizious@gmail.com>
2025-08-01 12:01:37 +10:00