summaryrefslogtreecommitdiffstatshomepage
path: root/stmhal/sdcard.c
diff options
context:
space:
mode:
authorTobias Badertscher <python@baerospace.ch>2016-03-22 11:28:35 +0100
committerDamien George <damien.p.george@gmail.com>2016-05-05 14:51:20 +0100
commite64032d6fdeb079de2ace20b64899d1ceb6754f1 (patch)
treec4ce1bb01259371a2eb72fb561dbc43c2e39edde /stmhal/sdcard.c
parenteb54e4d065a7cbc26dc4c8dc2812d1cabdcd0c50 (diff)
downloadmicropython-e64032d6fdeb079de2ace20b64899d1ceb6754f1.tar.gz
micropython-e64032d6fdeb079de2ace20b64899d1ceb6754f1.zip
stmhal: L4: Adapt DMA to be able to support STM32L4 MCU series.
The main thing is to change the DMA code in a way that the structure DMA_Stream_TypeDef (which is similar to DMA_Channel_TypeDef on stm32l4) is no longer used outside of dma.c, as this structure only exists for the F4 series. Therefore I introduced a new structure (dma_descr_t) which handles all DMA specific stuff for configuration. Further the periphery (spi, i2c, sdcard, dac) does not need to know the internals of the dma.
Diffstat (limited to 'stmhal/sdcard.c')
-rw-r--r--stmhal/sdcard.c33
1 files changed, 10 insertions, 23 deletions
diff --git a/stmhal/sdcard.c b/stmhal/sdcard.c
index 59fe3fac82..88969413b2 100644
--- a/stmhal/sdcard.c
+++ b/stmhal/sdcard.c
@@ -63,6 +63,11 @@
#define SDIO_TRANSFER_CLK_DIV SDMMC_TRANSFER_CLK_DIV
+#elif defined(MCU_SERIES_L4)
+
+// The L4 series is not supported
+#error Unsupported Processor
+
#endif
// TODO: Since SDIO is fundamentally half-duplex, we really only need to
@@ -77,22 +82,6 @@
static SD_HandleTypeDef sd_handle;
static DMA_HandleTypeDef sd_rx_dma, sd_tx_dma;
-// Parameters to dma_init() for SDIO tx and rx.
-static const DMA_InitTypeDef dma_init_struct_sdio = {
- .Channel = 0,
- .Direction = 0,
- .PeriphInc = DMA_PINC_DISABLE,
- .MemInc = DMA_MINC_ENABLE,
- .PeriphDataAlignment = DMA_PDATAALIGN_WORD,
- .MemDataAlignment = DMA_MDATAALIGN_WORD,
- .Mode = DMA_PFCTRL,
- .Priority = DMA_PRIORITY_VERY_HIGH,
- .FIFOMode = DMA_FIFOMODE_ENABLE,
- .FIFOThreshold = DMA_FIFO_THRESHOLD_FULL,
- .MemBurst = DMA_MBURST_INC4,
- .PeriphBurst = DMA_PBURST_INC4,
-};
-
void sdcard_init(void) {
GPIO_InitTypeDef GPIO_Init_Structure;
@@ -219,8 +208,7 @@ mp_uint_t sdcard_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_blo
// we must disable USB irqs to prevent MSC contention with SD card
uint32_t basepri = raise_irq_pri(IRQ_PRI_OTG_FS);
- dma_init(&sd_rx_dma, DMA_STREAM_SDIO_RX, &dma_init_struct_sdio,
- DMA_CHANNEL_SDIO_RX, DMA_PERIPH_TO_MEMORY, &sd_handle);
+ dma_init(&sd_rx_dma, &dma_SDIO_0_RX, &sd_handle);
sd_handle.hdmarx = &sd_rx_dma;
err = HAL_SD_ReadBlocks_BlockNumber_DMA(&sd_handle, (uint32_t*)dest, block_num, SDCARD_BLOCK_SIZE, num_blocks);
@@ -229,7 +217,7 @@ mp_uint_t sdcard_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_blo
err = HAL_SD_CheckReadOperation(&sd_handle, 100000000);
}
- dma_deinit(sd_handle.hdmarx);
+ dma_deinit(&dma_SDIO_0_RX);
sd_handle.hdmarx = NULL;
restore_irq_pri(basepri);
@@ -256,9 +244,8 @@ mp_uint_t sdcard_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t n
if (query_irq() == IRQ_STATE_ENABLED) {
// we must disable USB irqs to prevent MSC contention with SD card
uint32_t basepri = raise_irq_pri(IRQ_PRI_OTG_FS);
-
- dma_init(&sd_tx_dma, DMA_STREAM_SDIO_TX, &dma_init_struct_sdio,
- DMA_CHANNEL_SDIO_TX, DMA_MEMORY_TO_PERIPH, &sd_handle);
+\
+ dma_init(&sd_rx_dma, &dma_SDIO_0_TX, &sd_handle);
sd_handle.hdmatx = &sd_tx_dma;
err = HAL_SD_WriteBlocks_BlockNumber_DMA(&sd_handle, (uint32_t*)src, block_num, SDCARD_BLOCK_SIZE, num_blocks);
@@ -266,7 +253,7 @@ mp_uint_t sdcard_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t n
// wait for DMA transfer to finish, with a large timeout
err = HAL_SD_CheckWriteOperation(&sd_handle, 100000000);
}
- dma_deinit(sd_handle.hdmatx);
+ dma_deinit(&dma_SDIO_0_TX);
sd_handle.hdmatx = NULL;
restore_irq_pri(basepri);