Skip to main content
Associate III
Oct 10, 2025 12:12 AM UTC
Question

STM32U5 + HAL_FLASH_Program() + DCACHE?

Hi,

I am currently developing a small application with a STM32U5 where I write a few bytes into flash using HAL_FLASH_Program(). All seems to work fine. Except I can only read the data back after I do a reset. I suspect that DCACHE is playing a trick on me? But I am not sure how to invalidate the DCache (preferably only for a small section)

SCB_InvalidateDCache();

Seems to have some problems on the STM32U5? At least, I was unable to include the prober h-file w/o getting tons of errors.

 

What is the new strategy for cache invalidation? 

Thanks,

Juergen 

6 replies

TDK
Oct 10, 2025 12:16 AM UTC

SCB_InvalidateDCache or SCB_InvalidateDCache_by_Addr are the correct ways to invalidate a section of memory. What problems are you running into? Should be able to call those with code generated from an IOC file by STM32CubeMX.

"If you feel a post has answered your question, please click ""Accept as Solution""."
JE_itAuthor
Associate III
Oct 10, 2025 12:24 AM UTC

Thanks for your VERY quick reply.

What file do i need to include?

I tried directly in main.c (code generated from IOC file):

../Core/Src/main.c:385:3: error: implicit declaration of function 'SCB_InvalidateDCache' [-Werror=implicit-function-declaration]
 385 | SCB_InvalidateDCache();
 | ^~~~~~~~~~~~~~~~~~~~

I once used a STM32H7, there everything worked fine. But the STM32U5 and the departure from CMSIS are making things a bit harder :)

 

Thanks,

Juergen

TDK
Oct 10, 2025 1:18 AM UTC

What chip do you have? Are you starting from an IOC file?

 

In a random STM32U5 chip, the compiler has no problem with "SCB_InvalidateDCache" for me.

"If you feel a post has answered your question, please click ""Accept as Solution""."
JE_itAuthor
Associate III
Oct 10, 2025 9:04 AM UTC

Hi,

 

for completion, I figured it out.

 

HAL_StatusTypeDef HAL_DCACHE_InvalidateByAddr(DCACHE_HandleTypeDef *hdcache, const uint32_t *const pAddr, uint32_t dSize)

is the new Api to use. But apparently, if you write to flash Dcache is not the correct cache for that? What works for me is:

HAL_ICACHE_Invalidate();

Apperently Icache is responsible for that (at least AI tells me?).

I had success by removing all Dcache but not for specific memory areas which caught my suspicias/unsatisfied. I expect that beeing not correct.

HAL_DCACHE_Invalidate(&hdcache1);

 Can anybody shed some light here?

Thanks,

Juergen

 

TDK
Oct 10, 2025 4:56 PM UTC

ICACHE isn't relevant unless you are changing instruction code, which is not likely.

Didn't see answers to any of my questions.

"If you feel a post has answered your question, please click ""Accept as Solution""."