2024-04-01 12:31 PM
2024-04-22 05:01 AM
Hello @IIvan.22,
In the context of the STM32H7 series, when the D-cache is disabled, the CPU writes directly to the SRAM, and the data is immediately visible to all bus masters, including the interrupt handlers. Therefore, if the D-cache is disabled, there is no need for special synchronization steps such as calling DMB instruction.
In your specific case with the D-cache disabled, if the STR instruction has been completed before the exception occurs, the interrupt handler should see the updated value of 'X' as '0x1'
as you may know, the ARM Cortex-M7 processor has a write-through cache policy as one of the options for memory attributes. When a memory region is configured as write-through, writes are immediately visible to all bus masters, but reads may fetch data from the cache. This can be configured using the MPU.
>>Any official statement about it in the documentation?
I would recommend The ARM Cortex-M7 Devices Generic User Guide
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2024-04-22 06:29 AM - edited 2024-04-22 06:38 AM
In single-core STM32H7, there's no other CPU, so the ISR running on the same CPU sees the same cache as the thread code. So, the ISR will immediately see memory writes by the thread code - with or without any cache or buffering, no MPU tricks needed.
But the compiler can delay the write or move it around, so DMB would be appropriate. The shared variables can be declared volatile, though precise meaning of volatile became complicated these days.
For dual core H7, if one CPU writes and another reads, I don't know. A DSB won't harm.
2024-04-22 10:07 AM - edited 2024-04-22 10:38 AM
Hi Sarra,
To summarize your answer:
(1) If D-cache is disabled or configured as write-through, no need for extra steps to synchronize.
(2) If D-cache is enabled, but not in the write-through mode (read cache), then synchronization may be needed?
If synchronization between thread and interrupt not required, then I don't understand why DMB instruction exists? (there are separate instructions to clear and invalidate the cache).
Lets say it is a single-core MCU. We configure some areas as no-cache for use with DMA, and some areas as read cache, to exchange information between threads and interrupts. Do we need DMB for cached areas then? There is no answer on this question in device documentation, but we need it for ISO design quality certification.
Thank you.
2024-04-22 10:27 AM
Hello Pavel,
Lets say we use assembler language, so volatile is out of question. Processor can re-arrange memory writes, but it is not clear then when the DMB instruction should be used at all? No DMA involved for the clarity. Won't harm will be quite a scary answer.
2024-04-22 02:00 PM
Writes are queued/buffered, but completion of read/write should always occur in program order.
I don't think you need any fencing instruction for your top-post example to work
2024-04-22 03:25 PM - edited 2024-04-22 03:29 PM
@IIvan.22 If you write in assembly then indeed everything C related (volatile, CMSIS) is not useful. I apologize about the DMB as well, it is overkill in your case of single core. /* In C, a compiler barrier will suffice, and the DMB intrinsic has side effect of compiler barrier */
The DSB is even more overkill for single core. As assembly programmer, you know of course the difference between dmb and dsb.
> Won't harm will be quite a scary answer.
Not more scary than developing for a multicore STM32 )) Fortunately you don't ))
Regards,
P.