diff options
| author | Damien George <damien@micropython.org> | 2024-06-18 17:46:21 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2025-07-08 16:24:27 +1000 |
| commit | eb3ea9ee13093d81053f5d07b8c96e4fc0e1383d (patch) | |
| tree | 07f7bb3e3f9c6fb1f4204c531d3c18a29c3cb189 /ports/stm32/spibdev.c | |
| parent | 24fd5f72682922664c0bcf70d6e3631a6d5b8d2b (diff) | |
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>
Diffstat (limited to 'ports/stm32/spibdev.c')
| -rw-r--r-- | ports/stm32/spibdev.c | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/ports/stm32/spibdev.c b/ports/stm32/spibdev.c index fecd4a991..d7a75ed24 100644 --- a/ports/stm32/spibdev.c +++ b/ports/stm32/spibdev.c @@ -32,6 +32,16 @@ #if MICROPY_HW_ENABLE_STORAGE +#if MICROPY_HW_RUNS_FROM_EXT_FLASH +// Disable all interrupts. +#define FLASH_WRITE_ENTER uint32_t atomic_state = MICROPY_BEGIN_ATOMIC_SECTION() +#define FLASH_WRITE_EXIT MICROPY_END_ATOMIC_SECTION(atomic_state) +#else +// Prevent cache flushing and USB access. +#define FLASH_WRITE_ENTER uint32_t basepri = raise_irq_pri(IRQ_PRI_FLASH) +#define FLASH_WRITE_EXIT restore_irq_pri(basepri) +#endif + int32_t spi_bdev_ioctl(spi_bdev_t *bdev, uint32_t op, uint32_t arg) { switch (op) { case BDEV_IOCTL_INIT: @@ -68,6 +78,7 @@ int32_t spi_bdev_ioctl(spi_bdev_t *bdev, uint32_t op, uint32_t arg) { } #if MICROPY_HW_SPIFLASH_ENABLE_CACHE + int spi_bdev_readblocks(spi_bdev_t *bdev, uint8_t *dest, uint32_t block_num, uint32_t num_blocks) { uint32_t basepri = raise_irq_pri(IRQ_PRI_FLASH); // prevent cache flushing and USB access int ret = mp_spiflash_cached_read(&bdev->spiflash, block_num * FLASH_BLOCK_SIZE, num_blocks * FLASH_BLOCK_SIZE, dest); @@ -87,20 +98,36 @@ int spi_bdev_writeblocks(spi_bdev_t *bdev, const uint8_t *src, uint32_t block_nu return ret; } + +#elif FLASH_BLOCK_SIZE == MP_SPIFLASH_ERASE_BLOCK_SIZE + +int spi_bdev_readblocks(spi_bdev_t *bdev, uint8_t *dest, uint32_t block_num, uint32_t num_blocks) { + int ret = spi_bdev_readblocks_raw(bdev, dest, block_num, 0, num_blocks * FLASH_BLOCK_SIZE); + return ret; +} + +int spi_bdev_writeblocks(spi_bdev_t *bdev, const uint8_t *src, uint32_t block_num, uint32_t num_blocks) { + int ret = spi_bdev_eraseblocks_raw(bdev, block_num, num_blocks * FLASH_BLOCK_SIZE); + if (ret == 0) { + ret = spi_bdev_writeblocks_raw(bdev, src, block_num, 0, num_blocks * FLASH_BLOCK_SIZE); + } + return ret; +} + #endif // MICROPY_HW_SPIFLASH_ENABLE_CACHE int spi_bdev_readblocks_raw(spi_bdev_t *bdev, uint8_t *dest, uint32_t block_num, uint32_t block_offset, uint32_t num_bytes) { - uint32_t basepri = raise_irq_pri(IRQ_PRI_FLASH); // prevent cache flushing and USB access + FLASH_WRITE_ENTER; int ret = mp_spiflash_read(&bdev->spiflash, block_num * MP_SPIFLASH_ERASE_BLOCK_SIZE + block_offset, num_bytes, dest); - restore_irq_pri(basepri); + FLASH_WRITE_EXIT; return ret; } int spi_bdev_writeblocks_raw(spi_bdev_t *bdev, const uint8_t *src, uint32_t block_num, uint32_t block_offset, uint32_t num_bytes) { - uint32_t basepri = raise_irq_pri(IRQ_PRI_FLASH); // prevent cache flushing and USB access + FLASH_WRITE_ENTER; int ret = mp_spiflash_write(&bdev->spiflash, block_num * MP_SPIFLASH_ERASE_BLOCK_SIZE + block_offset, num_bytes, src); - restore_irq_pri(basepri); + FLASH_WRITE_EXIT; return ret; } @@ -108,9 +135,9 @@ int spi_bdev_writeblocks_raw(spi_bdev_t *bdev, const uint8_t *src, uint32_t bloc int spi_bdev_eraseblocks_raw(spi_bdev_t *bdev, uint32_t block_num, uint32_t num_bytes) { int ret = 0; while (num_bytes >= MP_SPIFLASH_ERASE_BLOCK_SIZE) { - uint32_t basepri = raise_irq_pri(IRQ_PRI_FLASH); // prevent cache flushing and USB access + FLASH_WRITE_ENTER; ret = mp_spiflash_erase_block(&bdev->spiflash, block_num * MP_SPIFLASH_ERASE_BLOCK_SIZE); - restore_irq_pri(basepri); + FLASH_WRITE_EXIT; if (ret) { break; } |
