Commit graph

1787 commits

Author SHA1 Message Date
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
87b7a9d734 stm32: Add casts when printing small integers.
All these arguments are of type `mp_{u,}int_t`, but the actual value is
always a small integer.  Cast it so that it can format with the `%d/%u`
formatter.

Before, the compiler plugin produced an error in the PYBD_SF6 build, which
is a nanboxing build with 64-bit ints.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-25 11:01:16 +10:00
7493275918 py/mpconfig,ports: Define new HEX_FMT formatting macro.
Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-25 10:55:28 +10:00
0c8d35b322 ports: Eliminate define of {U,}INT_FMT where redundant.
The default definition in `py/mpconfig.h` for 32-bit architectures is
`%u/%d`, so these can be removed.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-07-25 10:54:27 +10:00
Yoctopuce dev
df05caea6c shared/timeutils: Standardize supported date range on all platforms.
This is code makes sure that time functions work properly on a
reasonable date range, on all platforms, regardless of the epoch.
The suggested minimum range is 1970 to 2099.

In order to reduce code footprint, code to support far away dates
is only enabled specified by the port.

New types are defined to identify timestamps.

The implementation with the smallest code footprint is when
support timerange is limited to 1970-2099 and Epoch is 1970.
This makes it possible to use 32 bit unsigned integers for
all timestamps.

On ARM4F, adding support for dates up to year 3000 adds
460 bytes of code. Supporting dates back to 1600 adds
another 44 bytes of code.

Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
2025-07-09 11:54:21 +10:00
Damien George
99740dbace stm32/stm32.mk: Error out if compiling for cortex-m55 on old gcc.
Signed-off-by: Damien George <damien@micropython.org>
2025-07-08 16:28:58 +10:00
Damien George
50ea398b00 stm32/boards/NUCLEO_N657X0: Add new board definition files.
Signed-off-by: Damien George <damien@micropython.org>
2025-07-08 16:28:58 +10:00
Damien George
3189e49d28 stm32/boards/OPENMV_N6: Add new board definition files.
Signed-off-by: Damien George <damien@micropython.org>
2025-07-08 16:28:58 +10:00
Damien George
7016900fbe stm32/spi: Fail spi_init if pins can't be configured.
Follows the UART and I2C drivers.

Signed-off-by: Damien George <damien@micropython.org>
2025-07-08 16:25:14 +10:00
Damien George
acb294f61a stm32/mboot: Add support for STM32N6xx MCUs.
Works in the usual USB DFU mode, and can program external SPI flash.  It
will enable XSPI memory-mapped mode before jumping to the application
firmware in the external SPI flash.

Signed-off-by: Damien George <damien@micropython.org>
2025-07-08 16:25:14 +10:00
Damien George
96b8f3aebc stm32/boards: Add board support files for N6.
Signed-off-by: Damien George <damien@micropython.org>
2025-07-08 16:25:14 +10:00
Damien George
959e910366 stm32/lwip_inc: Increase lwIP memory on N6.
Signed-off-by: Damien George <damien@micropython.org>
2025-07-08 16:25:14 +10:00
iabdalkader
eaed2518fa stm32/main: Disable D-cache when debugging N6.
See ST Errata ES0620 - Rev 0.2 section 2.1.2.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2025-07-08 16:25:10 +10:00
Damien George
eb3ea9ee13 stm32: Add support for STM32N6xx MCUs.
This commit adds preliminary support for ST's new STM32N6xx MCUs.

Supported features of this MCU so far are:
- basic clock tree initialisation, running at 800MHz
- fully working USB
- XSPI in memory-mapped mode
- machine.Pin
- machine.UART
- RTC and deepsleep support
- SD card
- filesystem
- ROMFS
- WiFi and BLE via cyw43-driver (SDIO backend)

Note that the N6 does not have internal flash, and has some tricky boot
sequence, so using a custom bootloader (mboot) is almost a necessity.

Signed-off-by: Damien George <damien@micropython.org>
2025-07-08 16:24:27 +10:00
Damien George
24fd5f7268 stm32/boards/make-pins.py: Support up to GPIO-O.
Signed-off-by: Damien George <damien@micropython.org>
2025-07-08 16:24:27 +10:00
Yuuki NAGAO
eaffbacb10 stm32/machine_adc: Add machine.ADC implementation for STM32L1.
Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2025-07-08 14:01:41 +10:00
Matt Trentini
42cfa7cdae stm32/dma: Extend STM32H5 DMA use to SPI3 and SPI4.
Attempting to configure SPI3 and SPI4 for the STM32H5 would fail with a
linker error.  This patch resolves that, ensuring that appropriate DMA
channels are assigned to those SPI resources.

Signed-off-by: Matt Trentini <matt.trentini@gmail.com>
2025-07-08 13:57:58 +10:00
Yuuki NAGAO
f3c56c81ea stm32/irq: Change SPI IRQ priority to be higher than DMA IRQ.
On STM32H5/STM32H7, SPI flash cannot use as storage device with DMA.  SPI
interruption may not be genearated even if DMA transfer has been done.
This is due to lower priority of SPI interruption than DMA.

This commit changes SPI interrupt priority more higher than DMA's priority.

Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2025-07-08 13:52:22 +10:00
Damien George
0975255f86 stm32/uart: Suppress additional RX idle IRQs on F4/L1.
These MCUs only clear the RX idle IRQ if the data register is read, which
won't occur if the only IRQ is the RX idle IRQ (because then reading and
discarding the DR may lead to lost data).

To work around this, explicitly suppress the RX idle IRQ so that it's only
passed through to the Python callback once.

Signed-off-by: Damien George <damien@micropython.org>
2025-07-08 13:15:47 +10:00
Damien George
d5246cea61 stm32/machine_adc: Fix internal ADC channel reading on WB MCUs.
Signed-off-by: Damien George <damien@micropython.org>
2025-07-08 13:15:39 +10:00
Damien George
c9adabc25a stm32/adc: Fix core temperature reading on WB55.
It needs a divisor of 100 because the calibration temperatures are 30 and
130 degrees, similar to the H5.

Signed-off-by: Damien George <damien@micropython.org>
2025-07-08 13:15:35 +10:00
Damien George
841439d5fb stm32/adc: Simplify ADC calibration settings.
Combine the common settings for L1/L4/WB with existing G0/G4/H5 settings.

Signed-off-by: Damien George <damien@micropython.org>
2025-07-08 13:14:48 +10:00
Damien George
ea2000b81d stm32/adc: Apply re-read errata for WB55.
Following 17898f8607.

Signed-off-by: Damien George <damien@micropython.org>
2025-07-08 13:14:43 +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
Andrew Leech
fffaf8a41f extmod/modnetwork: Consolidate definition of common drivers.
Most extmod network drivers were being defined on a per-port basis,
duplicating code and making enabling a driver on a new port harder.

This consolidates extmod driver declarations and removes the existing
per-port definitions of them.

This commit has been verified to be a no-op in terms of firmware change.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2025-06-10 11:20:38 +10:00
Andrew Leech
17898f8607 stm32/machine_adc: Enable ADC re-read errata handling for STM32WB55.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2025-06-04 02:11:23 +10:00
Matt Trentini
3e33d0567f ports: Update board.json files for vendor/product consistency.
The vendor and product fields in the `board.json` files were somewhat
inconsistent.  Remove any duplication of the vendor name in the product
field so that `f"{vendor} {product}"` reads well.

In addition to that, update most of the URL's for `board.json` files that
are modified here, and match case and spacing used by the manufacturers for
the vendor and product names.

Signed-off-by: Matt Trentini <matt.trentini@gmail.com>
2025-06-04 01:47:59 +10:00
Herwin Grobben
2dada065ac stm32: Allow QSPI to work on STM32G4.
Adding a QSPI memory chip on a STM32G4 does not work due to some small
issues, which are fixed in this commit:

- Rename QUADSPI1_xxx alt-func names to QUADSPI_xxx, to match the static
  names used in `qspi.c`.

- Enable `mpu.h` macros on G4.

- Don't include I- and D-cache invalidation on G4.

Signed-off-by: Damien George <damien@micropython.org>
2025-05-26 12:40:27 +10:00
Alessandro Gatti
f47e214cdc all: Rename the "NORETURN" macro to "MP_NORETURN".
This commit renames the NORETURN macro, indicating to the compiler
that a function does not return, into MP_NORETURN to maintain the same
naming convention of other similar macros.

To maintain compaitiblity with existing code NORETURN is aliased to
MP_NORETURN, but it is also deprecated for MicroPython v2.

This changeset was created using a similar process to
decf8e6a8b ("all: Remove the "STATIC"
macro and just use "static" instead."), with no documentation or python
scripts to change to reflect the new macro name.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-05-13 10:36:47 +10:00
Angus Gratton
b2cda6c604 extmod,alif,mimxrt,rp2,stm32: Create common cyw43 driver config header.
This is only a surface level refactor, some deeper refactoring would be
possible with (for example) the SDIO interface in mimxrt and stm32, or the
BTHCI interface which is is similar on supported ports. But sticking to
cases where the macros are the same across all ports.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-05-08 15:32:05 +10:00
Malcolm McKellips
288dce26bd docs,ports: Fix SparkFun capitalization.
This is a follow-up to 1e92bdd206 correcting
more of the instances where "Sparkfun" should be "SparkFun".

Signed-off-by: Damien George <damien@micropython.org>
2025-05-07 15:16:55 +10:00
iabdalkader
0f360880aa stm32/cyw43_configport: Update cyw43 config to use new BTHCI UART.
Update the cyw43 configuration to use the new BTHCI UART backend provided
by cyw43-driver.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2025-04-22 12:50:22 +10:00
Andrew Leech
d6c673f28f stm32/main: Replace mp_stack_set calls with new mp_cstack_init_with_top.
Required in MICROPY_PREVIEW_VERSION_2.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2025-04-22 11:29:48 +10:00
Damien George
db85427071 stm32/boards/PYBD_SF6: Support boards with larger SPI flash.
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 <damien@micropython.org>
2025-04-09 22:36:55 +10:00
Damien George
ed4833d495 stm32/modmachine: Add SPI flash size to machine.info dump.
Signed-off-by: Damien George <damien@micropython.org>
2025-04-09 22:36:55 +10:00
Damien George
de08190cb7 stm32/mboot: Allow USB strings to be dynamic.
Signed-off-by: Damien George <damien@micropython.org>
2025-04-09 22:36:55 +10:00
Damien George
aa0945698b stm32/qspi: Allow SPI flash size to be decided at runtime.
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 <damien@micropython.org>
2025-04-09 22:36:55 +10:00
Damien George
1d83c81756 stm32/vfs_rom_ioctl: Allow ROMFS configuration to be dynamic.
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 <damien@micropython.org>
2025-04-09 22:36:55 +10:00
Damien George
2c0240e068 drivers/bus/qspi: Make num_dummy configurable for quad reads.
Signed-off-by: Damien George <damien@micropython.org>
2025-04-09 22:36:55 +10:00
Damien George
a9384c71c5 extmod/extmod.mk: Switch from drivers/cyw43/cywbt to lib/cyw43-drivers.
The cyw43-driver now provides the Bluetooth initialisation code, making
`drivers/cyw43/cywbt.c` obsolete.  To use the new code a port must enable
the `CYW43_ENABLE_BLUETOOTH_OVER_UART` option.

Some ports have yet to migrate to the new code, so in the meantime they can
explicitly add the old source to their source list and continue to use it
without change.

Signed-off-by: Damien George <damien@micropython.org>
2025-04-08 23:52:16 +10:00
Damien George
1660faacf6 stm32/boards/PYBD_SF2: Restart qspi memory-mapped mode during startup.
The PYBD boards use an F7xx which has an errata 2.4.3:

    Memory-mapped read operations may fail when timeout counter is enabled

This is unfortunate because it means that once QSPI memory-mapped flash is
accessed the QSPI peripheral will leave the CS pin active (low) forever,
which increases power consumption of the SPI flash chip (because it's
active and waiting for commands).  The exact amount of power increase
depends on the flash, but the PYBD_SFx increase by about 2.5mA.

Previously this increase in power only happened when QSPI flash was needed,
eg on PYBD_SF2 when mbedtls or nimble libraries were used.  On PYBD_SF6
it's actually never used.

But with the introduction of ROMFS which lives in the QSPI flash, the
memory is always access on start up to see if the ROMFS contains a valid
image (it must read the memory to find out).  That means these boards
always consume about 2.5mA more after starting up (compared to when ROMFS
is disabled).

The fix in this commit is to explicitly restart the QSPI memory mapped mode
during the start up process.  More precisely, the restart is done after
querying the ROMFS and just before trying to execute `boot.py`.  That's the
right location to keep power consumption permanently down if the QSPI is
never used (eg ROMFS image doesn't exist).

Signed-off-by: Damien George <damien@micropython.org>
2025-04-03 16:15:35 +11:00
Damien George
ac1cbef366 stm32/qspi: Add qspi_memory_map_exit and restart.
Signed-off-by: Damien George <damien@micropython.org>
2025-04-03 16:15:35 +11:00