2022-12-21 07:08 AM
I got my SPI5 running the way I want it but now I want to move to DMA. When I do this the SPI lines remain low after sending its data. So I assume my config is off. Using the IOC to make changes I only see the fowling added.
/* SPI5 DMA Init */
/* SPI5_TX Init */
hdma_spi5_tx.Instance = DMA2_Stream3;
hdma_spi5_tx.Init.Request = DMA_REQUEST_SPI5_TX;
hdma_spi5_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
hdma_spi5_tx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_spi5_tx.Init.MemInc = DMA_MINC_ENABLE;
hdma_spi5_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_spi5_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_spi5_tx.Init.Mode = DMA_NORMAL;
hdma_spi5_tx.Init.Priority = DMA_PRIORITY_VERY_HIGH;
hdma_spi5_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
if (HAL_DMA_Init(&hdma_spi5_tx) != HAL_OK)
{
Error_Handler();
}
__HAL_LINKDMA(hspi,hdmatx,hdma_spi5_tx);
/* SPI5_RX Init */
hdma_spi5_rx.Instance = DMA2_Stream0;
hdma_spi5_rx.Init.Request = DMA_REQUEST_SPI5_RX;
hdma_spi5_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_spi5_rx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_spi5_rx.Init.MemInc = DMA_MINC_ENABLE;
hdma_spi5_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_spi5_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_spi5_rx.Init.Mode = DMA_NORMAL;
hdma_spi5_rx.Init.Priority = DMA_PRIORITY_VERY_HIGH;
hdma_spi5_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
if (HAL_DMA_Init(&hdma_spi5_rx) != HAL_OK)
{
Error_Handler();
}
__HAL_LINKDMA(hspi,hdmarx,hdma_spi5_rx);
//added this to dma init
__HAL_RCC_DMA2_CLK_ENABLE();
HAL_NVIC_SetPriority(DMA2_Stream0_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA2_Stream0_IRQn);
HAL_NVIC_SetPriority(DMA2_Stream3_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA2_Stream3_IRQn);
and I did change to
HAL_SPI_TransmitReceive_DMA(&hspi5, (uint8_t*)data_to_send, (uint8_t*)&FromTheADC, sizeof(data_to_send));
but HAL_SPI_TxRxCpltCallback is never called.
if I change my rx to DMA_CIRCULAR it just loop over and over.
In debug I see the call back is set, no errors are given and the call back was not hit.
I'm using the nss and have the int set
HAL_NVIC_SetPriority(SPI5_IRQn, 1, 0);
HAL_NVIC_EnableIRQ(SPI5_IRQn);
nss does come back up but the code is stuck waiting in my while loop.
2022-12-28 05:47 AM
looking back in to this I noticed here that SPI5_IRQHandler is not getting called AND the dmi stream TX irq is ( BUT NOT THE RX). I see the code does hit __HAL_SPI_ENABLE_IT in the HAL_SPI_TransmitReceive_DMA
look thru the code I'm not sure who calls SPI5_IRQHandler, I see no reference of it being called.
2022-12-28 07:52 AM
issue was stream 0, I had to use DMA2_Stream2, I now get the SPi working and send correctly but for some reason the RX data is not making it to memory.
I tried to simplify it with this but still no data.
uint8_t data_to_rec[12];
memset(data_to_rec,0,12);
HAL_SPI_TransmitReceive_DMA(&hspi5, (uint16_t*) &data_to_send, (uint16_t*) &data_to_rec, sizeof(data_to_send));
2022-12-28 09:59 AM
ahhh..
reading online DMA may need the variable to be in a section.
so I tried
with
.dma_buffer :
{
. = ALIGN(4);
*(.dma_buffer)
} >RAM_D2
and that worked