alexcekay opened a new pull request, #18787:
URL: https://github.com/apache/nuttx/pull/18787

   ## Summary
   
   In sporadic cases it is possible that a SPI exchange returns stale RX data 
from the DCACHE.
   
   This occurs when:
   - DCACHE is enabled
   - DMA is used
   
   The impact of this can be hard to debug and vanishes when the timing even 
changes minimally.
   
   This is caused by the DCACHE being invalidated before the actual DMA 
transaction starts which violates the recommendations from AN4839 and also does 
not match the implementation of other drivers of the STM32H7/STM32F7.
   
   Fixed by invalidating the DCACHE right before the actual read, which matches 
the implementation of the STM32F7 SPI driver.
   
   
   ## Testing
   
   Tested on a Pixhawk v6x. Validated by setting a breakpoint in a driver 
running on SPI3 that checks if the current RX data returned by a SPI transfer 
matches the data format of another driver running on SPI3. Without the fix it 
is visible that stale data is present that vanishes as soon as the cache is 
invalidated.
   
   ```
   $11 = {
     spidev = {
       ops = 0x81f05e0 <g_sp3iops>
     },
     spibase = 1073757184,
     spiclock = 96000000,
     spiirq = 67 'C',
     rxresult = 176 '\260',
     txresult = 128 '\200',
     rxch = 573,
     txch = 574,
     rxbuf = 0x24015240 <g_spi3_rxbuf> "",
     txbuf = 0x24015640 <g_spi3_txbuf> "\277",
     buflen = 1024,
     rxdma = 0x240007e0 <g_dmach+160>,
     txdma = 0x240007f0 <g_dmach+176>,
     rxsem = taken (0),
     txsem = taken (0),
     txccr = 1088,
     rxccr = 1024,
     initialized = true,
     exclsem = available (1i),
     frequency = 10000000,
     actual = 6000000,
     nbits = 8 '\b',
     mode = 3 '\003',
     config = FULL_DUPLEX
   }
   ```
   
   ```
   (gdb) x/8xw 0x24015240
   0x24015240 <g_spi3_rxbuf>:   0x001c0000      0x04000a84      0x84055d00      
0x00080012
   0x24015250 <g_spi3_rxbuf+16>:        0x08840562      0x66000500      
0x000e8405      0x055a0005
   
   (gdb) call up_invalidate_dcache(0x24015240, 0x24015260)
   
   (gdb) x/8xw 0x24015240
   0x24015240 <g_spi3_rxbuf>:   0xdc002aff      0x9c0012ff      0x00000aff      
0x2a009200
   0x24015250 <g_spi3_rxbuf+16>:        0x9effee00      0xaa0008ff      
0xd0fffeff      0x050064ff
   ```
   
   After applying the fix the breakpoint is not hit anymore and the high-level 
problem (gyroscope reading accelerometer data) does not happen anymore.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to