diff options
author | Damien George <damien.p.george@gmail.com> | 2014-07-07 07:29:52 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-07-07 07:29:52 +0100 |
commit | 42b6419056a67a0ea8e28eaf27e51f53bc65eec2 (patch) | |
tree | 682ad0fcb9aad754f951880493827c438143b8e6 | |
parent | 5fa5ca40e67c3c4bfce116a70c3a88b52b718928 (diff) | |
parent | 594699bc88f1293496e178c76567d2d608a005d8 (diff) | |
download | micropython-42b6419056a67a0ea8e28eaf27e51f53bc65eec2.tar.gz micropython-42b6419056a67a0ea8e28eaf27e51f53bc65eec2.zip |
Merge branch 'dhylands-fix-sdcard-read'
-rw-r--r-- | stmhal/sdcard.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/stmhal/sdcard.c b/stmhal/sdcard.c index 204dbe3b46..2993773fab 100644 --- a/stmhal/sdcard.c +++ b/stmhal/sdcard.c @@ -144,7 +144,14 @@ bool sdcard_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_blocks) return false; } - if (HAL_SD_ReadBlocks(&sd_handle, (uint32_t*)dest, block_num * SDCARD_BLOCK_SIZE, SDCARD_BLOCK_SIZE, num_blocks) != SD_OK) { + // We must disable IRQs because the SDIO peripheral has a small FIFO + // buffer and we can't let it fill up in the middle of a read. + // This will not be needed when SD uses DMA for transfer. + __disable_irq(); + HAL_SD_ErrorTypedef err = HAL_SD_ReadBlocks(&sd_handle, (uint32_t*)dest, block_num * SDCARD_BLOCK_SIZE, SDCARD_BLOCK_SIZE, num_blocks); + __enable_irq(); + + if (err != SD_OK) { return false; } @@ -162,7 +169,14 @@ bool sdcard_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t num_bl return false; } - if (HAL_SD_WriteBlocks(&sd_handle, (uint32_t*)src, block_num * SDCARD_BLOCK_SIZE, SDCARD_BLOCK_SIZE, num_blocks) != SD_OK) { + // We must disable IRQs because the SDIO peripheral has a small FIFO + // buffer and we can't let it drain to empty in the middle of a write. + // This will not be needed when SD uses DMA for transfer. + __disable_irq(); + HAL_SD_ErrorTypedef err = HAL_SD_WriteBlocks(&sd_handle, (uint32_t*)src, block_num * SDCARD_BLOCK_SIZE, SDCARD_BLOCK_SIZE, num_blocks); + __enable_irq(); + + if (err != SD_OK) { return false; } |