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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
On stm32, the startup code attempts to mount the configured filesystem. If
there is an existing littlefs filesystem that's suitable corrupted it's
possible for the reported blocksize to be incorrect here:
uint32_t block_size = lfs2_fromle32(superblock->block_size);
This `block_size` (which is read from the filesystem iteself) is used to
create the len argument passed to `pyb_flash_make_new()`. In that function
the len arg is validated to be a mutliple of the underlying hardware block
size, as well as not bigger than the physical flash. Any failure is raised
as a ValueError. This exception is not caught currently in main, it flows
up to the high level assert / startup failure.
As this occurs before `boot.py` is run, the users (potentially frozen)
application code doesn't have any opportunity to detect and handle the
issue.
This commit adds a helper function which attempts to create a block device,
and on error returns `None` instead of raising an exception. Using this in
main means that a potentially corrupt filesystem will simply remain
unmounted, and the application can handle the issue safely.
The fix here also handles the case where the littlefs filesystem is valid
but the autodetection code (which detects the filesystem size) does not
work correctly. In that case it will retry mounting the filesystem using
the whole size of the block device.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
stm32's QSPI driver supports memory-mapped mode. The memory-mapped flash
can also be erased/written to. To support both these modes, it switches in
and out of memory-mapped mode during an erase/write.
If the flash is erased/written and then switched back to memory mapped
mode, the cache related to the memory-mapped region that changed must be
invalidated. Otherwise subsequent code may end up reading old data.
That cache invalidation is currently not being done, and this commit fixes
that.
This bug has been around ever since QSPI memory-mapped mode existed, but
it's never really been observed because it's not common to use flash in
memory-mapped mode and also erase/write it. Eg PYBD_SF2 uses the
memory-mapped flash in read-only mode to store additional firmware.
But since the introduction of ROMFS, things changed. The `vfs.rom_ioctl()`
command can erase/write memory-mapped flash.
Signed-off-by: Damien George <damien@micropython.org>
This is necessary for the machine.CAN implementation to use the same
low-level functions.
Includes some refactoring around FIFO selection as there was a footgun
where CAN_FIFO0/1 are 0/1 but FDCAN_RX_FIFO0/1 are not. Added an explicit
type for non-hardware-specific FIFO numbering.
Also moved responsibility for re-enabling CAN receive interrupts into the
higher layer (pyb_can.c layer) after calling can_receive().
Also includes this behaviour change for FDCAN boards:
- Fix for boards with FDCAN not updating error status
counters (num_error_warning, num_error_passive, num_bus_off). These are
now updated the same as on boards with CAN Classic controllers, as
documented.
- Previously FDCAN boards would trigger the RX callback function on error
events instead (passing undocumented irq numbers 3, 4, 5).
This behaviour has been removed in favour of the documented behaviour of
updating the status counters.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Change ROMFS partition configuration variables to use index 0 as the
starting partition number (instead of index 1).
Reasons to do this:
- `vfs.rom_ioctl()` numbers the partitions starting from 0
- `mpremote romfs -p <partition id>` numbers the partitions starting from 0
Signed-off-by: Damien George <damien@micropython.org>
Includes various fixes and improvements to the WLAN driver, in particular:
- Add WPA3 STA and AP support.
- Attempt to reconnect to AP in response to validation error.
- Update 43439 BT firmware for Data Length Extension fix.
Signed-off-by: Damien George <damien@micropython.org>
This commit implements `vfs.rom_ioctl()` to query, erase and write both
internal and external flash, depending on how the board configures its
flash memory.
A board can configure ROM as follows.
To use internal flash memory:
#define MICROPY_HW_ROMFS_ENABLE_INTERNAL_FLASH (1)
To use external flash memory (QSPI memory mapped):
#define MICROPY_HW_ROMFS_ENABLE_EXTERNAL_QSPI (1)
#define MICROPY_HW_ROMFS_QSPI_SPIFLASH_OBJ (&spi_obj)
Then the partition must be defined as symbols in the linker script:
_micropy_hw_romfs_part1_start
_micropy_hw_romfs_part1_size
And finally the partition needs to be enabled:
#define MICROPY_HW_ROMFS_ENABLE_PART1 (1)
There's support for a second, optional partition via:
_micropy_hw_romfs_part2_start
_micropy_hw_romfs_part2_size
#define MICROPY_HW_ROMFS_ENABLE_PART1 (1)
Signed-off-by: Damien George <damien@micropython.org>
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 <angus@redyak.com.au>
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 <angus@redyak.com.au>
Also add the default values of these macros to the respective
`mpconfigport.h` files, to improve discoverability.
Signed-off-by: Angus Gratton <angus@redyak.com.au>