[cortex-m0] problem with using sync built-in functions for atomic memory access

Asked by Mallikarjun

Hi,
I want to use sync built-in functions for atomic memory access
fro the target arm cortex-m0.
But i do get error when i use them.

For example:
int main(void)
{
   int x = 2;
   __sync_add_and_fetch(&x, 1);

    return x;
}

I get following error:
undefined reference to `__sync_add_and_fetch_4'

I used following command:
arm-none-eabi-gcc -mcpu=cortex-m0 -mthumb -mfloat-abi=soft -c test.c

Thanks for your help,
Mallikarjuna

Question information

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Solved by:
Terry Guo
Solved:
Last query:
Last reply:
Revision history for this message
Mallikarjun (mallikarjun-gouda) said :
#1

These sync builtin functions are working for cortex-m4.
Are there any alternative to thes functions for cortex-m0?

Please let me know.

Thanks,
Mallikarjuna

Revision history for this message
Terry Guo (terry.guo) said :
#2

These sync builtin functions requires instructions like LDREX which are only present on armv7 and newer targets, so no such builtin for armv6-m based target like cortex-m0. Let me check whether there is alternative.

Revision history for this message
Best Terry Guo (terry.guo) said :
#3

Looks to me that you have to write your own functions to mimic such behaviors. The key point is to disable all interrupt right after STR and then enable all of them right after LDR. And vice versa.

Revision history for this message
Mallikarjun (mallikarjun-gouda) said :
#4

Hi Terry,
Thank you very much for your answer.

//mallikarjuna

Revision history for this message
Mallikarjun (mallikarjun-gouda) said :
#5

Thanks Terry Guo, that solved my question.