stm32/spibdev: Convert to use multiple block read/write interface.
The spiflash driver now supports read/write of multiple blocks at a time.
This commit is contained in:
parent
861080aa3d
commit
8bd0a51ca9
|
@ -105,26 +105,26 @@ void spi_bdev_flush(void) {
|
|||
}
|
||||
}
|
||||
|
||||
bool spi_bdev_readblock(uint8_t *dest, uint32_t block) {
|
||||
int spi_bdev_readblocks(uint8_t *dest, uint32_t block_num, uint32_t num_blocks) {
|
||||
// we must disable USB irqs to prevent MSC contention with SPI flash
|
||||
uint32_t basepri = raise_irq_pri(IRQ_PRI_OTG_FS);
|
||||
mp_spiflash_read(&spiflash, block * FLASH_BLOCK_SIZE, FLASH_BLOCK_SIZE, dest);
|
||||
mp_spiflash_read(&spiflash, block_num * FLASH_BLOCK_SIZE, num_blocks * FLASH_BLOCK_SIZE, dest);
|
||||
restore_irq_pri(basepri);
|
||||
|
||||
return true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool spi_bdev_writeblock(const uint8_t *src, uint32_t block) {
|
||||
int spi_bdev_writeblocks(const uint8_t *src, uint32_t block_num, uint32_t num_blocks) {
|
||||
// we must disable USB irqs to prevent MSC contention with SPI flash
|
||||
uint32_t basepri = raise_irq_pri(IRQ_PRI_OTG_FS);
|
||||
int ret = mp_spiflash_write(&spiflash, block * FLASH_BLOCK_SIZE, FLASH_BLOCK_SIZE, src);
|
||||
int ret = mp_spiflash_write(&spiflash, block_num * FLASH_BLOCK_SIZE, num_blocks * FLASH_BLOCK_SIZE, src);
|
||||
if (spiflash.flags & 1) {
|
||||
led_state(PYB_LED_RED, 1); // indicate a dirty cache with LED on
|
||||
flash_tick_counter_last_write = HAL_GetTick();
|
||||
}
|
||||
restore_irq_pri(basepri);
|
||||
|
||||
return ret == 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif // defined(MICROPY_HW_SPIFLASH_SIZE_BITS)
|
||||
|
|
|
@ -41,8 +41,8 @@
|
|||
#define BDEV_INIT spi_bdev_init
|
||||
#define BDEV_IRQ_HANDLER spi_bdev_irq_handler
|
||||
#define BDEV_FLUSH spi_bdev_flush
|
||||
#define BDEV_READBLOCK spi_bdev_readblock
|
||||
#define BDEV_WRITEBLOCK spi_bdev_writeblock
|
||||
#define BDEV_READBLOCKS spi_bdev_readblocks
|
||||
#define BDEV_WRITEBLOCKS spi_bdev_writeblocks
|
||||
|
||||
#else
|
||||
|
||||
|
|
|
@ -53,8 +53,8 @@ bool flash_bdev_writeblock(const uint8_t *src, uint32_t block);
|
|||
void spi_bdev_init(void);
|
||||
void spi_bdev_irq_handler(void);
|
||||
void spi_bdev_flush(void);
|
||||
bool spi_bdev_readblock(uint8_t *dest, uint32_t block);
|
||||
bool spi_bdev_writeblock(const uint8_t *src, uint32_t block);
|
||||
int spi_bdev_readblocks(uint8_t *dest, uint32_t block_num, uint32_t num_blocks);
|
||||
int spi_bdev_writeblocks(const uint8_t *src, uint32_t block_num, uint32_t num_blocks);
|
||||
|
||||
extern const struct _mp_obj_type_t pyb_flash_type;
|
||||
|
||||
|
|
Loading…
Reference in New Issue