drivers: spi: stm32 spi instance of stm32H7 mcu

A generic function is used to give the register address to the DMA.
The SPI of the stm32H7 serie has two data registers for Tx and Rx
When the DMA is getting the address it differs between Rx and Tx.
As the stm32cube/stm32h7xx/drivers/include/stm32h7xx_ll_spi.h
has no such LL functions, the register address is get direclty.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
This commit is contained in:
Francois Ramu 2022-01-05 19:17:09 +01:00 committed by Maureen Helm
parent 0ce796398a
commit ca3c2cf1f9
2 changed files with 20 additions and 2 deletions

View file

@ -121,7 +121,7 @@ static int spi_stm32_dma_tx_load(const struct device *dev, const uint8_t *buf,
}
}
blk_cfg->dest_address = (uint32_t)LL_SPI_DMA_GetRegAddr(cfg->spi);
blk_cfg->dest_address = ll_func_dma_get_reg_addr(cfg->spi, SPI_STM32_DMA_TX);
/* fifo mode NOT USED there */
if (data->dma_tx.dst_addr_increment) {
blk_cfg->dest_addr_adj = DMA_ADDR_ADJ_INCREMENT;
@ -180,7 +180,7 @@ static int spi_stm32_dma_rx_load(const struct device *dev, uint8_t *buf,
}
}
blk_cfg->source_address = (uint32_t)LL_SPI_DMA_GetRegAddr(cfg->spi);
blk_cfg->source_address = ll_func_dma_get_reg_addr(cfg->spi, SPI_STM32_DMA_RX);
if (data->dma_rx.src_addr_increment) {
blk_cfg->source_addr_adj = DMA_ADDR_ADJ_INCREMENT;
} else {

View file

@ -31,6 +31,9 @@ struct spi_stm32_config {
#define SPI_STM32_DMA_DONE_FLAG \
(SPI_STM32_DMA_RX_DONE_FLAG | SPI_STM32_DMA_TX_DONE_FLAG)
#define SPI_STM32_DMA_TX 0x01
#define SPI_STM32_DMA_RX 0x02
struct stream {
const struct device *dma_dev;
uint32_t channel; /* stores the channel for dma or mux */
@ -54,6 +57,21 @@ struct spi_stm32_data {
};
#ifdef CONFIG_SPI_STM32_DMA
static inline uint32_t ll_func_dma_get_reg_addr(SPI_TypeDef *spi, uint32_t location)
{
#if defined(CONFIG_SOC_SERIES_STM32H7X)
if (location == SPI_STM32_DMA_TX) {
/* use direct register location until the LL_SPI_DMA_GetTxRegAddr exists */
return (uint32_t)&(spi->TXDR);
}
/* use direct register location until the LL_SPI_DMA_GetRxRegAddr exists */
return (uint32_t)&(spi->RXDR);
#else
ARG_UNUSED(location);
return (uint32_t)LL_SPI_DMA_GetRegAddr(spi);
#endif /* CONFIG_SOC_SERIES_STM32H7X */
}
/* checks that DMA Tx packet is fully transmitted over the SPI */
static inline uint32_t ll_func_spi_dma_busy(SPI_TypeDef *spi)
{