Skip to main content
dominik
Senior
Feb 3, 2021 1:12 PM UTC
Solved

HAL_SPI_TransmitReceive_DMA read before write

Hi

I'm using the HAL_SPI_TransmitReceive_DMA to write to an external Flash. On a delte command for the external flash I need to wait for until the busy flag of the flash is zero. So I use this function to check the busy flag.

 spi_read(&command, sizeof (command), &SPI_RX_BUFFER, 2);
 
 if ((SPI_RX_BUFFER[1] & 1) == 0)
 return true;
 else
 return false;
void spi_read(const void *txdata, size_t txsize, void *rxdata, size_t rxsize)
{
 HAL_GPIO_WritePin(Flash_NSS_GPIO_Port, Flash_NSS_Pin, GPIO_PIN_RESET);
 //reset the TX_RX complete Indication
 SPI_TXRX_Complete (true, false);
 SPI_TXRX_Status_Complete (true, false);
 
 HAL_SPI_TransmitReceive_DMA (&hspi3, (uint8_t *)txdata, (uint8_t *)rxdata, rxsize);
}

The problem is, that the RX of the DMA is not ready when I check the busy flag:

SPI_RX_BUFFER[1] & 1

How can I fix this issue?

This topic has been closed for replies.
dominik
dominikBest answer
Senior
Feb 4, 2021 6:58 AM UTC

It's running, problem was that with high optimization debugger I got wrong and inpossible results. I changed the icf file to a bigger range ange disabled the optimization, now it works like it should.

4 replies

waclawek.jan
Super User
Feb 3, 2021 7:38 PM UTC

Observe the communication on the SPI pins using logic analyzer.

JW

dominik
dominikAuthorBest answer
Senior
Feb 4, 2021 6:58 AM UTC

It's running, problem was that with high optimization debugger I got wrong and inpossible results. I changed the icf file to a bigger range ange disabled the optimization, now it works like it should.

KnarfB
Super User
Feb 5, 2021 2:06 PM UTC

If your MCU has a data cache, the observed behaviour at high optimzation could be due to cache incoherency.

dominik
dominikAuthor
Senior
Feb 5, 2021 3:07 PM UTC

I changed my icf file to a 1 image Debug config, now I can debug without optimization