kopia lustrzana https://github.com/micropython/micropython
stm32/spibdev: Support defining exact flash chip(s) connected.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>pull/12722/head
rodzic
10faa45058
commit
3996913782
|
@ -548,11 +548,9 @@
|
|||
// - MICROPY_HW_BDEV_SPIFLASH - pointer to a spi_bdev_t
|
||||
// - MICROPY_HW_BDEV_SPIFLASH_CONFIG - pointer to an mp_spiflash_config_t
|
||||
// - MICROPY_HW_BDEV_SPIFLASH_SIZE_BYTES - size in bytes of the SPI flash
|
||||
#define MICROPY_HW_BDEV_IOCTL(op, arg) ( \
|
||||
(op) == BDEV_IOCTL_NUM_BLOCKS ? (MICROPY_HW_BDEV_SPIFLASH_SIZE_BYTES / FLASH_BLOCK_SIZE) : \
|
||||
(op) == BDEV_IOCTL_INIT ? spi_bdev_ioctl(MICROPY_HW_BDEV_SPIFLASH, (op), (uint32_t)MICROPY_HW_BDEV_SPIFLASH_CONFIG) : \
|
||||
spi_bdev_ioctl(MICROPY_HW_BDEV_SPIFLASH, (op), (arg)) \
|
||||
)
|
||||
// The board can specify the SPI flash chip(s) being used as comma separated list in:
|
||||
// - MICROPY_HW_SPIFLASH_DEVICES
|
||||
#define MICROPY_HW_BDEV_IOCTL(op, arg) (spi_bdev_ioctl(MICROPY_HW_BDEV_SPIFLASH, (op), (arg)))
|
||||
#define MICROPY_HW_BDEV_READBLOCKS(dest, bl, n) spi_bdev_readblocks(MICROPY_HW_BDEV_SPIFLASH, (dest), (bl), (n))
|
||||
#define MICROPY_HW_BDEV_WRITEBLOCKS(src, bl, n) spi_bdev_writeblocks(MICROPY_HW_BDEV_SPIFLASH, (src), (bl), (n))
|
||||
#endif
|
||||
|
|
|
@ -29,16 +29,33 @@
|
|||
#include "irq.h"
|
||||
#include "led.h"
|
||||
#include "storage.h"
|
||||
#include "drivers/memory/external_flash_device.h"
|
||||
|
||||
#if MICROPY_HW_ENABLE_STORAGE
|
||||
|
||||
int32_t spi_bdev_ioctl(spi_bdev_t *bdev, uint32_t op, uint32_t arg) {
|
||||
switch (op) {
|
||||
case BDEV_IOCTL_INIT:
|
||||
#ifdef MICROPY_HW_BDEV_SPIFLASH_CONFIG
|
||||
if (!arg) {
|
||||
arg = (uint32_t)(MICROPY_HW_BDEV_SPIFLASH_CONFIG);
|
||||
}
|
||||
#endif
|
||||
bdev->spiflash.config = (const mp_spiflash_config_t *)arg;
|
||||
mp_spiflash_init(&bdev->spiflash);
|
||||
int ret = mp_spiflash_init(&bdev->spiflash);
|
||||
bdev->flash_tick_counter_last_write = 0;
|
||||
return 0;
|
||||
return ret;
|
||||
|
||||
case BDEV_IOCTL_NUM_BLOCKS:
|
||||
#if MICROPY_HW_BDEV_SPIFLASH_SIZE_BYTES
|
||||
return MICROPY_HW_BDEV_SPIFLASH_SIZE_BYTES / FLASH_BLOCK_SIZE;
|
||||
#else
|
||||
if (bdev->spiflash.device != NULL) {
|
||||
external_flash_device *flash = (external_flash_device *)bdev->spiflash.device;
|
||||
return flash->total_size / FLASH_BLOCK_SIZE;
|
||||
}
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
case BDEV_IOCTL_IRQ_HANDLER: {
|
||||
int ret = 0;
|
||||
|
|
|
@ -48,11 +48,11 @@ static void storage_systick_callback(uint32_t ticks_ms);
|
|||
|
||||
void storage_init(void) {
|
||||
if (!storage_is_initialised) {
|
||||
storage_is_initialised = true;
|
||||
|
||||
systick_enable_dispatch(SYSTICK_DISPATCH_STORAGE, storage_systick_callback);
|
||||
|
||||
MICROPY_HW_BDEV_IOCTL(BDEV_IOCTL_INIT, 0);
|
||||
if (MICROPY_HW_BDEV_IOCTL(BDEV_IOCTL_INIT, 0) == 0) {
|
||||
storage_is_initialised = true;
|
||||
}
|
||||
|
||||
#if defined(MICROPY_HW_BDEV2_IOCTL)
|
||||
MICROPY_HW_BDEV2_IOCTL(BDEV_IOCTL_INIT, 0);
|
||||
|
|
Ładowanie…
Reference in New Issue