cancel
Showing results for 
Search instead for 
Did you mean: 

When using DMA to read from SPI - Data corrupted on STM32H743VI

Issinski.Anton
Associate II

I trying to use STM32H743VI DMA1 to read from SPI2 MISO RXDR in master mode. 

Allocated memory in the D2 domain at address 0x3000000C for the DMA1 to copy SPI2 RXDR register to, but the resulting data is corrupted. I did not enable any D-cache at leaset manually myself, is it enabled by Atolic runtime or HAL? How to simply turn it all off? Tried to call SCB_DisableDCache() but it causes HardFault right away. __DSB() does not improve data integrity either. Anything else I may be missing?

Similar code for UART worked fine. Not using Cube at all, just the registers directly.

Thanks!

2 REPLIES 2

Ok, you'd want to be a tad more selective.

I think you'd need to use SCB_CleanDCache() before SCB_DisableDCache() otherwise you're likely to destroy stack content, and thus program execution context.

ST's examples use an address scoped cache coherency method for DMA reads

{
            /*
               the SCB_InvalidateDCache_by_Addr() requires a 32-Byte aligned address,
               adjust the address and the D-Cache size to invalidate accordingly.
             */
            uint32_t alignedAddr = (uint32_t)buff & ~0x1F;
            SCB_InvalidateDCache_by_Addr((uint32_t*)alignedAddr, size + ((uint32_t)buff - alignedAddr));
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Issinski.Anton
Associate II

Thank you Clive.  SCB_CleanDCache() also causes HardFault. I call them the very first line in main(). I am leaning more towards disabling the cache for the affecting region so I don't have to invalidate it each time I receive a new byte.