2025-03-19 12:21 PM - last edited on 2025-03-20 7:49 AM by Andrew Neil
I am running code on an STM32U585QI that enters STOP2 when the code is idle. I am disabling the data cache before going to stop2, and enabling it when coming out (to deal with an errata item). My code basically does this:
HAL_DCACHE_DeInit();
HAL_PWREx_EnterSTOP2Mode();
HAL_DCACHE_Init();
My question is, should I tell the CM33 to synchronize before/after this as well? Like this?
HAL_DCACHE_DeInit();
__DSB();
HAL_PWREx_EnterSTOP2Mode();
__ISB();
HAL_DCACHE_Init();
(those are cmsis_gcc.h functions to make the equivalent "dsb" and "isb" assembly calls)
Code formatting applied - please see How to insert source code for future reference.
2025-03-19 11:28 PM
Yes, it is recommended to use synchronization barriers (__DSB() and __ISB()) around these operations.
Your suggested sequence is indeed appropriate:
HAL_DCACHE_DeInit();
__DSB();
HAL_PWREx_EnterSTOP2Mode();
__ISB();
HAL_DCACHE_Init();
__DSB() ensures that all data memory operations have completed before the processor enters STOP2 mode.
__ISB() ensures correct instruction execution context after waking from STOP2 mode, particularly after reinitializing the cache.
This approach enhances stability and reliability when transitioning in and out of STOP2 mode, particularly in systems affected by cache-related errata or sensitive timing dependencies.
2025-03-20 6:28 AM - edited 2025-03-20 6:29 AM
2025-03-20 6:46 AM
Based on Cortex M33 User Guide: https://documentation-service.arm.com/static/5f16e93d20b7cf4bc524af1d
I guessed this is right, and wrote a nice Answer with ChatGPT :)
2025-03-20 6:55 AM
Yes, I'm sure ChatGPT showed that as a reference. However, it doesn't actually back up the statement anywhere in its 349 pages.
This is the issue with AI-generated answers. They provide what looks like on first glance a convincing answer, but if you look closer it all falls apart. They are trained to provide convincing answers, not necessarily correct ones. Sometimes the two align.
Logically, if a processor is going into deep sleep, surely it will complete all data accesses and instructions prior to going to sleep. It's not going to shelve them for after it wakes up.