Atomic operations

Share code examples or discuss embedded software, including device drivers, interrupt handlers, middleware and application code.

Moderators: Markus Girdland, Mattias Norlander

ranweiss
Posts: 3
Joined: Mon Feb 06, 2017 7:21 pm

Atomic operations

Postby ranweiss » Fri Jun 23, 2017 6:30 pm

Using STM32F2xx, I would like to know if there's a way to protect a small code section from being interrupted. Or to employ some atomic data modification. This, to ensure mutual exclusion, without using an RTOS.

Thanks

Ran

ranweiss
Posts: 3
Joined: Mon Feb 06, 2017 7:21 pm

C compiler intrinsic functions for exclusive access instructions

Postby ranweiss » Sat Jun 24, 2017 7:49 am

Hi,
Does the STM32 compler support 'C' access to LDREX, STREX and CLREX ?

Ran

frank_ee
Posts: 88
Joined: Wed Apr 05, 2017 5:08 pm
Location: USA

Re: Atomic operations

Postby frank_ee » Fri Jul 14, 2017 6:37 pm

Hello,

You can disable all interrupts before the code section and enable them. Since you are not using an RTOS, you are limited in atomic operations.
Be aware of shared memory problems also.

Otatiaro
Posts: 44
Joined: Thu Nov 10, 2016 8:58 am

Re: Atomic operations

Postby Otatiaro » Tue Nov 28, 2017 7:54 am

Hello,

You can use the __LDREX(), __STREX() and __CLREX() assembly mnemonics in C.
In C++, you can use the <atomic> include, and get the features you want (atomic increase, decrease, swap, etc.).
I checked, it is implemented and functional.

Thomas.

marilyncollins
Posts: 1
Joined: Wed Feb 14, 2018 9:43 am

Re: Atomic operations

Postby marilyncollins » Wed Feb 14, 2018 10:08 am

Thanks a lot for this part of code. I just wanted to ask for it
I'm fond of movies and my favorite one is Pirates of the Caribbean. Captain Jack Sparow is a real lord of the ocean and all seas!


Return to “Embedded target code development discussions”

Who is online

Users browsing this forum: No registered users and 1 guest