drivers: dma: stm32 dma source and dest data size must be equal

It raises an error in case the source data width differs
from the dest data width.
The dma_stm32_width_config function is no more useful: removed.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
This commit is contained in:
Francois Ramu
2020-11-18 11:10:52 +01:00
committed by Carles Cufí
parent 80123899c1
commit e7f222a3b6

View File

@@ -135,33 +135,6 @@ static void dma_stm32_shared_irq_handler(const struct device *dev)
#endif /* CONFIG_DMA_STM32_SHARED_IRQS */
static int dma_stm32_width_config(struct dma_config *config,
bool source_periph,
DMA_TypeDef *dma,
LL_DMA_InitTypeDef *DMA_InitStruct,
uint32_t id)
{
uint32_t periph, memory;
uint32_t m_size = 0, p_size = 0;
if (source_periph) {
periph = config->source_data_size;
memory = config->dest_data_size;
} else {
periph = config->dest_data_size;
memory = config->source_data_size;
}
int index = find_lsb_set(config->source_data_size) - 1;
m_size = table_m_size[index];
index = find_lsb_set(config->dest_data_size) - 1;
p_size = table_p_size[index];
DMA_InitStruct->PeriphOrM2MSrcDataSize = p_size;
DMA_InitStruct->MemoryOrM2MDstDataSize = m_size;
return 0;
}
static int dma_stm32_get_priority(uint8_t priority, uint32_t *ll_priority)
{
switch (priority) {
@@ -273,7 +246,6 @@ DMA_STM32_EXPORT_API int dma_stm32_configure(const struct device *dev,
&dev_config->streams[id - STREAM_OFFSET];
DMA_TypeDef *dma = (DMA_TypeDef *)dev_config->base;
LL_DMA_InitTypeDef DMA_InitStruct;
uint32_t msize;
int ret;
/* give channel from index 0 */
@@ -311,19 +283,17 @@ DMA_STM32_EXPORT_API int dma_stm32_configure(const struct device *dev,
}
#endif /* CONFIG_DMA_STM32_V1 */
if (config->source_data_size != 4U &&
config->source_data_size != 2U &&
config->source_data_size != 1U) {
LOG_ERR("Source unit size error, %d",
config->source_data_size);
/* support only the same data width for source and dest */
if ((config->dest_data_size != config->source_data_size)) {
LOG_ERR("source and dest data size differ.");
return -EINVAL;
}
if (config->dest_data_size != 4U &&
config->dest_data_size != 2U &&
config->dest_data_size != 1U) {
LOG_ERR("Dest unit size error, %d",
config->dest_data_size);
if (config->source_data_size != 4U &&
config->source_data_size != 2U &&
config->source_data_size != 1U) {
LOG_ERR("source and dest unit size error, %d",
config->source_data_size);
return -EINVAL;
}
@@ -415,12 +385,12 @@ DMA_STM32_EXPORT_API int dma_stm32_configure(const struct device *dev,
}
stream->source_periph = stream->direction == MEMORY_TO_PERIPHERAL;
ret = dma_stm32_width_config(config, stream->source_periph, dma,
&DMA_InitStruct, id);
if (ret < 0) {
return ret;
}
msize = DMA_InitStruct.MemoryOrM2MDstDataSize;
/* set the data width, when source_data_size equals dest_data_size */
int index = find_lsb_set(config->source_data_size) - 1;
DMA_InitStruct.PeriphOrM2MSrcDataSize = table_p_size[index];
index = find_lsb_set(config->dest_data_size) - 1;
DMA_InitStruct.MemoryOrM2MDstDataSize = table_m_size[index];
#if defined(CONFIG_DMA_STM32_V1)
DMA_InitStruct.MemBurst = stm32_dma_get_mburst(config,