SCB_InvalidateDCache() hangs
I'm using a Nucleo-H437ZI2 board. Set up a simple project in STM32CubeIDE with the latest firmware for H7. I enabled both Icache and Dcache, no MPU
I create a uint16_t array of 12,900 elements as a buffer for an ADC conversion using DMA transfer into the bus. Since the Dcache is active, after the ADC/DMA conversion completes, I want to invalidate the cache, to ensure coherency between what the DMA transferred and what the CPU sees.
So, after having read all the available L1 documents (AN4839) and some examples, I added SCB_InvalidateDCache() right after the DMA completes, and before accessing the array. But the execution hangs, and if I interrupt the execution, I see that it loops forever in the code below in core_cm7.h
__STATIC_INLINE void SCB_InvalidateDCache (void)
{
#if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U)
uint32_t ccsidr;
uint32_t sets;
uint32_t ways;
SCB->CSSELR = 0U; /*(0U << 1U) | 0U;*/ /* Level 1 data cache */
__DSB();
ccsidr = SCB->CCSIDR;
/* invalidate D-Cache */
sets = (uint32_t)(CCSIDR_SETS(ccsidr));
do {
ways = (uint32_t)(CCSIDR_WAYS(ccsidr));
do {
SCB->DCISW = (((sets << SCB_DCISW_SET_Pos) & SCB_DCISW_SET_Msk) |
((ways << SCB_DCISW_WAY_Pos) & SCB_DCISW_WAY_Msk) );
#if defined ( __CC_ARM )
__schedule_barrier();
#endif
} while (ways-- != 0U);
} while(sets-- != 0U);
__DSB();
__ISB();
#endif
}sets starts from 127, decreases to 126, then jumps to 4294967294 and loops forever.
If instead I use the following SCB_InvalidateDCache_by_Addr((uint32_t *) &aADCxConvertedData[0], ADC_CONVERTED_DATA_BUFFER_SIZE * 2);, the memory used by the array is then read properly
I know I should probably disable Dcache for the memory used by DMA transfers (per the notes in AN4839), but only a small portion of my code relies on DMA, then there's an extensive set of operations on the data array, so I was thinking of disabling Dcache before the DMA section, perform all the ADC conversions, then re-enable Dcache
The problem is that SCB_DisableDCache(); also hangs, because before disabling the cache it will force an InvalidateDCache-like loop, and also loop forever. Same for SCB_EnableDCache();.
What I don't understand is why SCB_EnableDCache(); works fine when invoked at the beginning the the code (before HAL_Init()), but fails in the main loop. I'm sure I'm missing something
Any pointer?
