cancel
Showing results for 
Search instead for 
Did you mean: 

Memory barrier instructions

Cboe
Associate

Hi!

I have the following code:

uint32_t currentTicks;
do
{
    currentTicks = handle->controlData.ticks; // controlData.ticks is volatile
    // copy a lot of data from handle->controlData
    ...
} while(currentTicks != handle->controlData.ticks);

handle->controlData.ticks (and the other data fields) are regularly updated, triggered by an interrupt, which could happen during copying of this data. The idea is that if the while check is false, just copy all the data again, since during the previous copying of said data new data must have arrived and the copied data would therefore be inconsistent.

We are running on an STM32H7 and the data is in DTCMRAM

For this to work, is a Memory barrier instruction required or could there be any other pitfalls?

1 REPLY 1
TDK
Super User

Declaring it (and the data) as volatile is enough here, no other issues.

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