stm32/sdcard: Use only a single DMA stream for both SDIO TX/RX.
No need to be wasteful on DMA resources.
This commit is contained in:
parent
d7e2ac4a6a
commit
e4f7001d9c
@ -224,25 +224,25 @@ const dma_descr_t dma_I2C_1_TX = { DMA1_Stream6, DMA_CHANNEL_1, dma_id_6, &dma
|
||||
|
||||
// DMA2 streams
|
||||
#if defined(STM32F7) && defined(SDMMC2) && MICROPY_HW_HAS_SDCARD
|
||||
const dma_descr_t dma_SDMMC_2_RX= { DMA2_Stream0, DMA_CHANNEL_11, dma_id_8, &dma_init_struct_sdio };
|
||||
const dma_descr_t dma_SDMMC_2 = { DMA2_Stream0, DMA_CHANNEL_11, dma_id_8, &dma_init_struct_sdio };
|
||||
#endif
|
||||
const dma_descr_t dma_SPI_1_RX = { DMA2_Stream2, DMA_CHANNEL_3, dma_id_10, &dma_init_struct_spi_i2c };
|
||||
const dma_descr_t dma_SPI_5_RX = { DMA2_Stream3, DMA_CHANNEL_2, dma_id_11, &dma_init_struct_spi_i2c };
|
||||
#if defined(MICROPY_HW_HAS_SDCARD) && MICROPY_HW_HAS_SDCARD
|
||||
const dma_descr_t dma_SDIO_0_RX= { DMA2_Stream3, DMA_CHANNEL_4, dma_id_11, &dma_init_struct_sdio };
|
||||
const dma_descr_t dma_SDIO_0 = { DMA2_Stream3, DMA_CHANNEL_4, dma_id_11, &dma_init_struct_sdio };
|
||||
#endif
|
||||
const dma_descr_t dma_SPI_4_RX = { DMA2_Stream3, DMA_CHANNEL_5, dma_id_11, &dma_init_struct_spi_i2c };
|
||||
const dma_descr_t dma_SPI_5_TX = { DMA2_Stream4, DMA_CHANNEL_2, dma_id_12, &dma_init_struct_spi_i2c };
|
||||
const dma_descr_t dma_SPI_4_TX = { DMA2_Stream4, DMA_CHANNEL_5, dma_id_12, &dma_init_struct_spi_i2c };
|
||||
const dma_descr_t dma_SPI_6_TX = { DMA2_Stream5, DMA_CHANNEL_1, dma_id_13, &dma_init_struct_spi_i2c };
|
||||
const dma_descr_t dma_SPI_1_TX = { DMA2_Stream5, DMA_CHANNEL_3, dma_id_13, &dma_init_struct_spi_i2c };
|
||||
#if defined(STM32F7) && defined(SDMMC2) && MICROPY_HW_HAS_SDCARD
|
||||
const dma_descr_t dma_SDMMC_2_TX= { DMA2_Stream5, DMA_CHANNEL_11, dma_id_13, &dma_init_struct_sdio };
|
||||
#endif
|
||||
//#if defined(STM32F7) && defined(SDMMC2) && MICROPY_HW_HAS_SDCARD
|
||||
//const dma_descr_t dma_SDMMC_2 = { DMA2_Stream5, DMA_CHANNEL_11, dma_id_13, &dma_init_struct_sdio };
|
||||
//#endif
|
||||
const dma_descr_t dma_SPI_6_RX = { DMA2_Stream6, DMA_CHANNEL_1, dma_id_14, &dma_init_struct_spi_i2c };
|
||||
#if defined(MICROPY_HW_HAS_SDCARD) && MICROPY_HW_HAS_SDCARD
|
||||
const dma_descr_t dma_SDIO_0_TX= { DMA2_Stream6, DMA_CHANNEL_4, dma_id_14, &dma_init_struct_sdio };
|
||||
#endif
|
||||
//#if defined(MICROPY_HW_HAS_SDCARD) && MICROPY_HW_HAS_SDCARD
|
||||
//const dma_descr_t dma_SDIO_0 = { DMA2_Stream6, DMA_CHANNEL_4, dma_id_14, &dma_init_struct_sdio };
|
||||
//#endif
|
||||
/* not preferred streams
|
||||
const dma_descr_t dma_SPI_1_TX = { DMA2_Stream3, DMA_CHANNEL_3, dma_id_11, &dma_init_struct_spi_i2c };
|
||||
const dma_descr_t dma_SPI_1_RX = { DMA2_Stream0, DMA_CHANNEL_3, dma_id_8, &dma_init_struct_spi_i2c };
|
||||
@ -317,9 +317,7 @@ const dma_descr_t dma_DAC_1_TX = { DMA2_Channel4, DMA_REQUEST_3, dma_id_10, &dm
|
||||
const dma_descr_t dma_SPI_1_TX = { DMA2_Channel4, DMA_REQUEST_4, dma_id_10, &dma_init_struct_spi_i2c };
|
||||
*/
|
||||
#if defined(MICROPY_HW_HAS_SDCARD) && MICROPY_HW_HAS_SDCARD
|
||||
// defined twice as L4 HAL only needs one channel and can correctly switch direction but sdcard.c needs two channels
|
||||
const dma_descr_t dma_SDIO_0_TX= { DMA2_Channel4, DMA_REQUEST_7, dma_id_10, &dma_init_struct_sdio };
|
||||
const dma_descr_t dma_SDIO_0_RX= { DMA2_Channel4, DMA_REQUEST_7, dma_id_10, &dma_init_struct_sdio };
|
||||
const dma_descr_t dma_SDIO_0 = { DMA2_Channel4, DMA_REQUEST_7, dma_id_10, &dma_init_struct_sdio };
|
||||
#endif
|
||||
/* not preferred streams
|
||||
const dma_descr_t dma_ADC_3_RX = { DMA2_Channel5, DMA_REQUEST_0, dma_id_11, NULL };
|
||||
|
@ -44,18 +44,18 @@ extern const dma_descr_t dma_DAC_2_TX;
|
||||
extern const dma_descr_t dma_SPI_3_TX;
|
||||
extern const dma_descr_t dma_I2C_1_TX;
|
||||
extern const dma_descr_t dma_I2C_2_TX;
|
||||
extern const dma_descr_t dma_SDMMC_2_RX;
|
||||
extern const dma_descr_t dma_SDMMC_2;
|
||||
extern const dma_descr_t dma_SPI_1_RX;
|
||||
extern const dma_descr_t dma_SPI_5_RX;
|
||||
extern const dma_descr_t dma_SDIO_0_RX;
|
||||
extern const dma_descr_t dma_SDIO_0;
|
||||
extern const dma_descr_t dma_SPI_4_RX;
|
||||
extern const dma_descr_t dma_SPI_5_TX;
|
||||
extern const dma_descr_t dma_SPI_4_TX;
|
||||
extern const dma_descr_t dma_SPI_6_TX;
|
||||
extern const dma_descr_t dma_SPI_1_TX;
|
||||
extern const dma_descr_t dma_SDMMC_2_TX;
|
||||
extern const dma_descr_t dma_SDMMC_2;
|
||||
extern const dma_descr_t dma_SPI_6_RX;
|
||||
extern const dma_descr_t dma_SDIO_0_TX;
|
||||
extern const dma_descr_t dma_SDIO_0;
|
||||
|
||||
#elif defined(STM32L4)
|
||||
|
||||
@ -76,8 +76,7 @@ extern const dma_descr_t dma_I2C_1_TX;
|
||||
extern const dma_descr_t dma_I2C_1_RX;
|
||||
extern const dma_descr_t dma_SPI_3_RX;
|
||||
extern const dma_descr_t dma_SPI_3_TX;
|
||||
extern const dma_descr_t dma_SDIO_0_TX;
|
||||
extern const dma_descr_t dma_SDIO_0_RX;
|
||||
extern const dma_descr_t dma_SDIO_0;
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -51,15 +51,13 @@
|
||||
#define SDMMC_CLK_ENABLE() __HAL_RCC_SDMMC2_CLK_ENABLE()
|
||||
#define SDMMC_CLK_DISABLE() __HAL_RCC_SDMMC2_CLK_DISABLE()
|
||||
#define SDMMC_IRQn SDMMC2_IRQn
|
||||
#define SDMMC_TX_DMA dma_SDMMC_2_TX
|
||||
#define SDMMC_RX_DMA dma_SDMMC_2_RX
|
||||
#define SDMMC_DMA dma_SDMMC_2
|
||||
#else
|
||||
#define SDIO SDMMC1
|
||||
#define SDMMC_CLK_ENABLE() __HAL_RCC_SDMMC1_CLK_ENABLE()
|
||||
#define SDMMC_CLK_DISABLE() __HAL_RCC_SDMMC1_CLK_DISABLE()
|
||||
#define SDMMC_IRQn SDMMC1_IRQn
|
||||
#define SDMMC_TX_DMA dma_SDIO_0_TX
|
||||
#define SDMMC_RX_DMA dma_SDIO_0_RX
|
||||
#define SDMMC_DMA dma_SDIO_0
|
||||
#define STATIC_AF_SDMMC_CK STATIC_AF_SDMMC1_CK
|
||||
#define STATIC_AF_SDMMC_CMD STATIC_AF_SDMMC1_CMD
|
||||
#define STATIC_AF_SDMMC_D0 STATIC_AF_SDMMC1_D0
|
||||
@ -104,8 +102,7 @@
|
||||
#define SDMMC_CLK_ENABLE() __SDIO_CLK_ENABLE()
|
||||
#define SDMMC_CLK_DISABLE() __SDIO_CLK_DISABLE()
|
||||
#define SDMMC_IRQn SDIO_IRQn
|
||||
#define SDMMC_TX_DMA dma_SDIO_0_TX
|
||||
#define SDMMC_RX_DMA dma_SDIO_0_RX
|
||||
#define SDMMC_DMA dma_SDIO_0
|
||||
#define SDIO_USE_GPDMA 1
|
||||
#define STATIC_AF_SDMMC_CK STATIC_AF_SDIO_CK
|
||||
#define STATIC_AF_SDMMC_CMD STATIC_AF_SDIO_CMD
|
||||
@ -128,12 +125,6 @@
|
||||
|
||||
#endif
|
||||
|
||||
// TODO: Since SDIO is fundamentally half-duplex, we really only need to
|
||||
// tie up one DMA channel. However, the HAL DMA API doesn't
|
||||
// seem to provide a convenient way to change the direction. I believe that
|
||||
// its as simple as changing the CR register and the Init.Direction field
|
||||
// and make DMA_SetConfig public.
|
||||
|
||||
// TODO: I think that as an optimization, we can allocate these dynamically
|
||||
// if an sd card is detected. This will save approx 260 bytes of RAM
|
||||
// when no sdcard was being used.
|
||||
@ -343,7 +334,7 @@ mp_uint_t sdcard_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_blo
|
||||
uint32_t basepri = raise_irq_pri(IRQ_PRI_OTG_FS);
|
||||
|
||||
#if SDIO_USE_GPDMA
|
||||
dma_init(&sd_rx_dma, &SDMMC_RX_DMA, DMA_PERIPH_TO_MEMORY, &sd_handle);
|
||||
dma_init(&sd_rx_dma, &SDMMC_DMA, DMA_PERIPH_TO_MEMORY, &sd_handle);
|
||||
sd_handle.hdmarx = &sd_rx_dma;
|
||||
#endif
|
||||
|
||||
@ -357,7 +348,7 @@ mp_uint_t sdcard_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_blo
|
||||
}
|
||||
|
||||
#if SDIO_USE_GPDMA
|
||||
dma_deinit(&SDMMC_RX_DMA);
|
||||
dma_deinit(&SDMMC_DMA);
|
||||
sd_handle.hdmarx = NULL;
|
||||
#endif
|
||||
|
||||
@ -409,7 +400,7 @@ mp_uint_t sdcard_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t n
|
||||
uint32_t basepri = raise_irq_pri(IRQ_PRI_OTG_FS);
|
||||
|
||||
#if SDIO_USE_GPDMA
|
||||
dma_init(&sd_tx_dma, &SDMMC_TX_DMA, DMA_MEMORY_TO_PERIPH, &sd_handle);
|
||||
dma_init(&sd_tx_dma, &SDMMC_DMA, DMA_MEMORY_TO_PERIPH, &sd_handle);
|
||||
sd_handle.hdmatx = &sd_tx_dma;
|
||||
#endif
|
||||
|
||||
@ -422,7 +413,7 @@ mp_uint_t sdcard_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t n
|
||||
}
|
||||
|
||||
#if SDIO_USE_GPDMA
|
||||
dma_deinit(&SDMMC_TX_DMA);
|
||||
dma_deinit(&SDMMC_DMA);
|
||||
sd_handle.hdmatx = NULL;
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user