feat(sdmmc): add dma_burst_size config, fix DMA to PSRAM on esp32p4

FIFOTH.dma_multiple_transaction_size was never programmed and kept its
reset value of 0, which selects 1-byte DMA bursts. On esp32p4 with flash
encryption enabled those bursts do not reach PSRAM.

Add sdmmc_ll_set_dma_burst_size() and a dma_burst_size field in
sd_host_sdmmc_cfg_t, 0 selecting the per-target default. esp32p4
defaults to 16 bytes; esp32 and esp32s3 keep their current 1 byte.
This commit is contained in:
Yogesh Mantri
2026-09-17 16:02:14 +08:00
parent 8438b4b0ca
commit 2e02ed8484
6 changed files with 67 additions and 0 deletions
@@ -88,6 +88,7 @@ extern "C" {
#define SDMMC_LL_HOST_CTLR_NUMS 1U
#define SDMMC_LL_DEFAULT_DIV 2
#define SDMMC_LL_DMA_BURST_SIZE_DEFAULT 1
typedef enum {
SDMMC_LL_DELAY_PHASE_0,
@@ -687,6 +688,20 @@ static inline void sdmmc_ll_init_dma(sdmmc_dev_t *hw)
hw->idinten.ti = 1;
}
/**
* @brief Set the burst size of the internal DMA
*
* @param hw hardware instance address
* @param burst_size burst size in bytes, 1 to disable the data burst,
* otherwise a power of two between 4 and 256
*/
static inline void sdmmc_ll_set_dma_burst_size(sdmmc_dev_t *hw, size_t burst_size)
{
HAL_ASSERT(burst_size == 1 ||
(burst_size >= 4 && burst_size <= 256 && (burst_size & (burst_size - 1)) == 0));
hw->fifoth.dw_dma_mts = (burst_size == 1) ? 0 : (__builtin_ctz(burst_size) - 1);
}
/**
* @brief Enable DMA
*
@@ -96,6 +96,7 @@ extern "C" {
#define SDMMC_LL_SDR50_SUPPORTED 1
#define SDMMC_LL_DEFAULT_DIV 2
#define SDMMC_LL_DMA_BURST_SIZE_DEFAULT 16
/**
* SDMMC delay phase
@@ -876,6 +877,20 @@ static inline void sdmmc_ll_init_dma(sdmmc_dev_t *hw)
hw->idinten.ti = 1;
}
/**
* @brief Set the burst size of the internal DMA
*
* @param hw hardware instance address
* @param burst_size burst size in bytes, 1 to disable the data burst,
* otherwise a power of two between 4 and 256
*/
static inline void sdmmc_ll_set_dma_burst_size(sdmmc_dev_t *hw, size_t burst_size)
{
HAL_ASSERT(burst_size == 1 ||
(burst_size >= 4 && burst_size <= 256 && (burst_size & (burst_size - 1)) == 0));
hw->fifoth.dma_multiple_transaction_size = (burst_size == 1) ? 0 : (__builtin_ctz(burst_size) - 1);
}
/**
* @brief Enable DMA
*
@@ -90,6 +90,7 @@ extern "C" {
#define SDMMC_LL_DELAY_PHASE_SUPPORTED 1
#define SDMMC_LL_DEFAULT_DIV 2
#define SDMMC_LL_DMA_BURST_SIZE_DEFAULT 1
/**
* SDMMC delay phase
@@ -751,6 +752,20 @@ static inline void sdmmc_ll_init_dma(sdmmc_dev_t *hw)
hw->idinten.ti = 1;
}
/**
* @brief Set the burst size of the internal DMA
*
* @param hw hardware instance address
* @param burst_size burst size in bytes, 1 to disable the data burst,
* otherwise a power of two between 4 and 256
*/
static inline void sdmmc_ll_set_dma_burst_size(sdmmc_dev_t *hw, size_t burst_size)
{
HAL_ASSERT(burst_size == 1 ||
(burst_size >= 4 && burst_size <= 256 && (burst_size & (burst_size - 1)) == 0));
hw->fifoth.dw_dma_mts = (burst_size == 1) ? 0 : (__builtin_ctz(burst_size) - 1);
}
/**
* @brief Enable DMA
*
@@ -97,6 +97,7 @@ extern "C" {
#define SDMMC_LL_SDR50_SUPPORTED 1
#define SDMMC_LL_DEFAULT_DIV 8
#define SDMMC_LL_DMA_BURST_SIZE_DEFAULT 64
/**
* SDMMC delay phase
@@ -820,6 +821,20 @@ static inline void sdmmc_ll_init_dma(sdmmc_dev_t *hw)
hw->bmod.bmod_pbl = 0x7;
}
/**
* @brief Set the burst size of the internal DMA
*
* @param hw hardware instance address
* @param burst_size burst size in bytes, 1 to disable the data burst,
* otherwise a power of two between 4 and 256
*/
static inline void sdmmc_ll_set_dma_burst_size(sdmmc_dev_t *hw, size_t burst_size)
{
HAL_ASSERT(burst_size == 1 ||
(burst_size >= 4 && burst_size <= 256 && (burst_size & (burst_size - 1)) == 0));
hw->fifoth.dma_multiple_transaction_size = (burst_size == 1) ? 0 : (__builtin_ctz(burst_size) - 1);
}
/**
* @brief Enable DMA
*