How to use SCB_DisableDCache() correctly?

Hello all,

I'm using a STM32F769 controller with Cortex M7 and FreeRTOS 10.2.0 as OS.

And I will do an SystemReset to restart my system with other Boot settings.

Now, i will keep sure that all my data will not corrupted while the systemReset().

Of that reason, I take SCB_DisableDCache();

The problem that, the os runs in a HardFault, StackoverFlow etc. by calling SCB_DisableDCache().

I think, the reason is that an Interrupt was interrupting SCB_DisableDCache(); and produce the errors.

My question:

How I use SCB_DisableDCache() correctly?

Should I block|stop anything befor entering the function? 

My quick and dirty solution is following:






If anyone has a better solution, please let me know. Thanks.