2017-12-12 06:32 PM
Hi,
I'm trying to implement SPI Tx and Rx with LL API. In stripped down code, I have these in my initialization function:
LL_SPI_EnableDMAReq_RX
LL_SPI_EnableDMAReq_TX
LL_DMA_ConfigTransfer(DmaInstanceT, DmaStreamT,LL_DMA_DIRECTION_MEMORY_TO_PERIPH | LL_DMA_PRIORITY_VERYHIGH | LL_DMA_MODE_NORMAL |
LL_DMA_PERIPH_NOINCREMENT | LL_DMA_MEMORY_INCREMENT | LL_DMA_PDATAALIGN_BYTE | LL_DMA_MDATAALIGN_BYTE);
LL_DMA_ConfigTransfer(DmaInstanceR, DmaStreamR,LL_DMA_DIRECTION_PERIPH_TO_MEMORY | LL_DMA_PRIORITY_VERYHIGH | LL_DMA_MODE_NORMAL |
LL_DMA_PERIPH_NOINCREMENT | LL_DMA_MEMORY_INCREMENT | LL_DMA_PDATAALIGN_BYTE | LL_DMA_MDATAALIGN_BYTE);
LL_DMA_EnableIT_TC(DmaInstanceR, DmaStreamR);
LL_DMA_EnableIT_TE(DmaInstanceR, DmaStreamR);
LL_SPI_Enable(hspi->Instance);
Then, for SPI Tx and Rx, I made another function which goes something like:
LL_DMA_ConfigAddresses(DmaInstanceT, DmaStreamT, (uint32_t)aTxBuffer, LL_SPI_DMA_GetRegAddr(hspi->Instance), LL_DMA_GetDataTransferDirection(DmaInstanceT, DmaStreamT));
LL_DMA_SetDataLength(DmaInstanceT, DmaStreamT, Size);
LL_DMA_ConfigAddresses(DmaInstanceR, DmaStreamR, LL_SPI_DMA_GetRegAddr(hspi->Instance), (uint32_t)aRxBuffer, LL_DMA_GetDataTransferDirection(DmaInstanceR, DmaStreamR));
LL_DMA_SetDataLength(DmaInstanceR, DmaStreamR, Size);
LL_DMA_EnableStream(DmaInstanceR, DmaStreamR);
LL_DMA_EnableStream(DmaInstanceT, DmaStreamT);
I set the callback
void DMA1_Stream3_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Stream3_IRQn 0 */
HB_SPI_TxRxCpltCallback(&hdma_spi2_rx);
}
void HB_SPI_TxRxCpltCallback(DMA_HandleTypeDef *hdma)
{
if(LL_DMA_IsActiveFlag_TC3(DMA1))
{
LL_DMA_ClearFlag_TC3(DMA1);
}
if(LL_DMA_IsActiveFlag_TE3(DMA1))
{
LL_DMA_ClearFlag_TE3(DMA1);
}
SPI_HandleTypeDef* hspi = ( SPI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
DMA_TypeDef* DmaInstanceT;
DMA_TypeDef* DmaInstanceR;
uint32_t DmaStreamT;
uint32_t DmaStreamR;
DmaInstanceT = __LL_DMA_GET_INSTANCE(hspi->hdmatx->Instance);
DmaStreamT = __LL_DMA_GET_STREAM(hspi->hdmatx->Instance);
DmaInstanceR = __LL_DMA_GET_INSTANCE(hspi->hdmarx->Instance);
DmaStreamR = __LL_DMA_GET_STREAM(hspi->hdmarx->Instance);
/* Disable DMA2 Rx Channel */
LL_DMA_DisableStream(DmaInstanceR, DmaStreamR);
/* Disable DMA2 Tx Channel */
LL_DMA_DisableStream(DmaInstanceT, DmaStreamT);
StartFrametransfer(); //This calls the SPI TxRx function
}
The problem is that this callback gets called only once. I can't figure out why.
#stm32-f4 #ll-drivers #callback #spi-write-and-read