SPIM with DMA Problem?

Hi, when debugging, I'm encountering this problem where relevant SPI registers (likely status registers) signaled a successful read before the actual data could be pulled into the memory.

Elaborating it a bit further: when using library function nrf_drv_spi_transfer, the function will return with a success code, albeit the data not having been updated into the designated memory area.

If I set a breakpoint somewhere before the function call, chances are everything will work normally, and it feels almost as if the memory update lagged a good several clock cycles behind.

This is my speculation and I cannot fully confirm this, but with previous experiences regard DMA and external interface, this is actually quite frequent occurrence.

uint32 dwt_read32bitoffsetreg(int regFileID,int regOffset)
{
    uint32  regval = DWT_ERROR ;
    int     j ;
    uint8   buffer[4] = {0} ;
		
RDA:    int result = dwt_readfromdevice(regFileID,regOffset,4,buffer); // Read 4 bytes (32-bits) register into buffer 
		
		if(result == DWT_SUCCESS)
    {
			regval = *((uint32_t*)buffer);
		  if((regval==0x00)||		(regval==0xFFFFFFFF))
        goto RDA;
			else 
				return regval ;
	  }
   goto RDA;

    

} 

Note that this is such a problem I had to add in goto directives to "fend off" all 1 and all 0 reads (0xFFFFFFFF or 0x00000000).

So my questions are:

1. Is this caused by DMA or improper configuration of the SPI interface, or something else?

2. Is it possible to disable DMA and get everything to be processed by the core?

Parents Reply
  • Hello Haakonsh, I have found the problem.

    I believe the status (most likely) register would trigger SPI's library read+write function to return the result once data is detected on the SPI bus, even though the data hasn't been updated to the designated buffer area.

    This is particularly noticeable when the transmission speed is 125K.

    I put a 2ms (yes, that much) delay in the function and it fixed the problem.

    So basically, after that library function returned, I wait for 2ms for the data to "actually" be updated to the buffer in the memory.

    Cheers.

Children
Related