cancel
Showing results for 
Search instead for 
Did you mean: 

Is the word(uint32_t) access atomic in shared memory in dual core STM32H7

yhplx
Associate II

Hi Friends,

In STM32H7 MCU, both M7 and M4 can access shared memory, such as D3 SRAM4. I am going to use a D3 SRAM4 address as a place to share some status information between M7 and M4. If a 32bits word is defined shown as below,  can the access from both sides(M7 and M4) be guaranteed atomic?  Does it need HSEM?

-----

Code example:

volatile uint32_t *status_ptr = (status4_7 *)0x38000000;

In M4 side,  *status_ptr = 0x1234abcd;

In M7 side, uint32_t status = *status4to7_ptr;

I know a 32bits word access is atomic in single core STM32 MCU. 

Thank you in advance.

 

 

 

5 REPLIES 5
TDK
Guru

Yes, it's atomic. It won't read intermediate values.

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

It's dual-ported, writes are buffered and potentially cached. Assume RMW actions will NOT be atomic

>>I know a 32-bits word access is atomic in single core STM32 MCU.

That's a bit sweeping. An aligned write can be a single bus transaction. Peripherals should generally be treated as operating independently and concurrently.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
SofLit
ST Employee

Hello,

If you mean by "atomic" to protect a variable from RW operations by the other core while performing a RW operation in the first core, I say yes, you need to use HSEM to lock/unlock RW operations. And you need also to define that memory region as Sharable region using MPU to prevent any data incoherency between CM7 and CM4 while using cache in CM7.

 

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.

Thank you, SoftLit.

What if it is only written(W) in M4 side, and only read(R) in M7 side, can it be safe without using HSEM lock/unlock

It can't be safe if one core reads and the other writes as the operations are asynchronous. How could guarantee the consistency of the data between the cores? think about race conditions .. if the race condition doesn't matter in your application, you can do the operations without semaphore.

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.