Skip to content

Commit d79d337

Browse files
committed
stm32/boards/STM32F469DISC: Configure QSPI flash as a secondary flash file system device.
1 parent 15d5575 commit d79d337

3 files changed

Lines changed: 93 additions & 70 deletions

File tree

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,45 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2025 Mike Tolkachev <contact@miketolkachev.dev>
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
127
#include "storage.h"
228
#include "qspi.h"
329

4-
// External SPI flash uses standard SPI interface
5-
6-
STATIC mp_spiflash_cache_t spi_bdev_cache;
7-
8-
#ifdef MICROPY_F469DISC_USE_SOFTSPI
9-
10-
STATIC const mp_soft_spi_obj_t soft_spi_bus = {
11-
.delay_half = MICROPY_HW_SOFTSPI_MIN_DELAY,
12-
.polarity = 0,
13-
.phase = 0,
14-
.sck = MICROPY_HW_SPIFLASH_SCK,
15-
.mosi = MICROPY_HW_SPIFLASH_MOSI,
16-
.miso = MICROPY_HW_SPIFLASH_MISO,
17-
};
18-
19-
const mp_spiflash_config_t spiflash_config = {
20-
.bus_kind = MP_SPIFLASH_BUS_SPI,
21-
.bus.u_spi.cs = MICROPY_HW_SPIFLASH_CS,
22-
.bus.u_spi.data = (void *)&soft_spi_bus,
23-
.bus.u_spi.proto = &mp_soft_spi_proto,
24-
.cache = &spi_bdev_cache,
25-
};
26-
27-
#else // MICROPY_F469DISC_USE_SOFTSPI
30+
#if MICROPY_HW_SPIFLASH_ENABLE_CACHE
31+
static mp_spiflash_cache_t spi_bdev_cache;
32+
#endif
2833

34+
// External SPI flash uses QSPI interface
2935
const mp_spiflash_config_t spiflash_config = {
3036
.bus_kind = MP_SPIFLASH_BUS_QSPI,
3137
.bus.u_qspi.data = NULL,
3238
.bus.u_qspi.proto = &qspi_proto,
39+
#if MICROPY_HW_SPIFLASH_ENABLE_CACHE
3340
.cache = &spi_bdev_cache,
41+
#endif
3442
};
3543

36-
#endif // MICROPY_F469DISC_USE_SOFTSPI
37-
44+
// SPI flash device instance
3845
spi_bdev_t spi_bdev;

ports/stm32/boards/STM32F469DISC/board_init.c

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,44 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2025 Mike Tolkachev <contact@miketolkachev.dev>
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
127
#include "py/mphal.h"
228
#include "storage.h"
29+
#include "boardctrl.h"
30+
#include "qspi.h"
331

4-
#ifdef MICROPY_F469DISC_USE_SOFTSPI
5-
6-
// SPI flash WP and HOLD pins on STM32F469I-DISCO
7-
#define SPIFLASH_WP (pin_F7)
8-
#define SPIFLASH_HOLD (pin_F6)
32+
// Micron N25Q128A13EF840F of original STM32F469I-DISCO board
33+
static const mp_spiflash_chip_params_t chip_params_n25q128a13ef840f = {
34+
.jedec_id = 0, // Not used for detection
35+
.memory_size_bytes_log2 = MICROPY_HW_QSPIFLASH_SIZE_BITS_LOG2,
36+
.qspi_prescaler = MICROPY_HW_QSPI_PRESCALER,
37+
.qread_num_dummy = MICROPY_HW_QSPIFLASH_DUMMY_CYCLES
38+
};
939

40+
// Early board initialization hook called before file system is mounted
1041
void STM32F469DISC_board_early_init(void) {
11-
// set SPI flash WP and HOLD pins high
12-
mp_hal_pin_output(SPIFLASH_WP);
13-
mp_hal_pin_output(SPIFLASH_HOLD);
14-
mp_hal_pin_write(SPIFLASH_WP, 1);
15-
mp_hal_pin_write(SPIFLASH_HOLD, 1);
42+
// Initialize QSPI flash device parameters
43+
spi_bdev.spiflash.chip_params = &chip_params_n25q128a13ef840f;
1644
}
17-
18-
#else // MICROPY_F469DISC_USE_SOFTSPI
19-
20-
void STM32F469DISC_board_early_init(void) {
21-
}
22-
23-
#endif // MICROPY_F469DISC_USE_SOFTSPI

ports/stm32/boards/STM32F469DISC/mpconfigboard.h

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
#define MICROPY_BOARD_EARLY_INIT STM32F469DISC_board_early_init
33
void STM32F469DISC_board_early_init(void);
44

5-
// TODO: Software SPI not needed anymore, remove after testing
6-
// #define MICROPY_F469DISC_USE_SOFTSPI // Temporary, enables software 1-bit SPI
7-
85
#define MICROPY_HW_BOARD_NAME "F469DISC"
96
#define MICROPY_HW_MCU_NAME "STM32F469"
107

@@ -17,34 +14,32 @@ void STM32F469DISC_board_early_init(void);
1714
#define MICROPY_HW_ENABLE_SDCARD (1)
1815
#define MICROPY_PY_UCRYPTOLIB_CONSTS (1)
1916

20-
// use external SPI flash for storage
21-
#define MICROPY_HW_SPIFLASH_SIZE_BITS (128 * 1024 * 1024)
22-
23-
#ifdef MICROPY_F469DISC_USE_SOFTSPI
24-
25-
#define MICROPY_HW_SPIFLASH_CS (pin_B6)
26-
#define MICROPY_HW_SPIFLASH_SCK (pin_F10)
27-
#define MICROPY_HW_SPIFLASH_MOSI (pin_F8)
28-
#define MICROPY_HW_SPIFLASH_MISO (pin_F9)
29-
30-
#else // MICROPY_F469DISC_USE_SOFTSPI
31-
17+
// QSPI flash storage configuration
18+
#if !BUILDING_MBOOT
19+
#define MICROPY_HW_SPIFLASH_ENABLE_CACHE (1)
20+
#endif
21+
#define MICROPY_HW_SPIFLASH_SOFT_RESET (1)
22+
#define MICROPY_HW_SPIFLASH_SIZE_BITS (128 * 1024 * 1024)
23+
#define MICROPY_HW_SPIFLASH_CHIP_PARAMS (1) // enable extended parameters
3224
#define MICROPY_HW_QSPI_PRESCALER (3)
33-
#define MICROPY_HW_QSPI_C4READ_DUMMY_CYCLES (8)
25+
#define MICROPY_HW_QSPIFLASH_DUMMY_CYCLES (4)
3426
#define MICROPY_HW_QSPIFLASH_SIZE_BITS_LOG2 (27)
35-
#define MICROPY_HW_QSPIFLASH_CS (pyb_pin_QSPI_CS)
36-
#define MICROPY_HW_QSPIFLASH_SCK (pyb_pin_QSPI_CLK)
37-
#define MICROPY_HW_QSPIFLASH_IO0 (pyb_pin_QSPI_D0)
38-
#define MICROPY_HW_QSPIFLASH_IO1 (pyb_pin_QSPI_D1)
39-
#define MICROPY_HW_QSPIFLASH_IO2 (pyb_pin_QSPI_D2)
40-
#define MICROPY_HW_QSPIFLASH_IO3 (pyb_pin_QSPI_D3)
41-
42-
#endif // MICROPY_F469DISC_USE_SOFTSPI
43-
44-
// block device config for SPI flash
27+
#define MICROPY_HW_QSPIFLASH_CS (pyb_pin_QSPI_CS)
28+
#define MICROPY_HW_QSPIFLASH_SCK (pyb_pin_QSPI_CLK)
29+
#define MICROPY_HW_QSPIFLASH_IO0 (pyb_pin_QSPI_D0)
30+
#define MICROPY_HW_QSPIFLASH_IO1 (pyb_pin_QSPI_D1)
31+
#define MICROPY_HW_QSPIFLASH_IO2 (pyb_pin_QSPI_D2)
32+
#define MICROPY_HW_QSPIFLASH_IO3 (pyb_pin_QSPI_D3)
33+
34+
// QSPI flash block device configuration
4535
extern const struct _mp_spiflash_config_t spiflash_config;
4636
extern struct _spi_bdev_t spi_bdev;
47-
#define MICROPY_HW_SPIFLASH_ENABLE_CACHE (1)
37+
//#define MICROPY_HW_BDEV_SPIFLASH (&spi_bdev)
38+
//#define MICROPY_HW_BDEV_SPIFLASH_CONFIG (&spiflash_config)
39+
//#define MICROPY_HW_BDEV_SPIFLASH_SIZE_BYTES (MICROPY_HW_SPIFLASH_SIZE_BITS / 8)
40+
//#define MICROPY_HW_BDEV_SPIFLASH_EXTENDED (&spi_bdev) // for extended block protocol
41+
42+
// Block device 2 is the QSPI flash, used for the second filesystem
4843
#define MICROPY_HW_BDEV2_IOCTL(op, arg) ( \
4944
(op) == BDEV_IOCTL_NUM_BLOCKS ? (MICROPY_HW_SPIFLASH_SIZE_BITS / 8 / FLASH_BLOCK_SIZE) : \
5045
(op) == BDEV_IOCTL_INIT ? spi_bdev_ioctl(&spi_bdev, (op), (uint32_t)&spiflash_config) : \

0 commit comments

Comments
 (0)