The problem is the "ldrb ...strb" sequence which is not atomic. M0 cores do not have strex/ldrex , they require an interrupt disable around the protected operation (mrs + cpsid + msr).
I believe gcc shouldn't silently generate a non-atomic sequence like this !
Hi, /answers. launchpad. net/gcc- arm-embedded/ +question/ 265649 .
this is mostly a rehash of https:/
Here's the essential:
Compiling the following code with "arm-none-eabi-gcc -save-temps -mcpu=cortex-m0 -mthumb -fverbose-asm at.c"
**** at.c ****
#include <stdatomic.h>
atomic_flag aflag = ATOMIC_FLAG_INIT;
int main(void) { flag_test_ and_set( &aflag)); flag_clear( &aflag);
while (1) {
while (atomic_
atomic_
}
return 0;
}
*********
gives the following intermediate assembly :
********* at.s (excerpt) **** flag_test_ and_set( &aflag)); flag_test_ and_set( &aflag)); flag_test_ and_set( &aflag));
main:
push {r7, lr} @
add r7, sp, #0 @,,
.L3:
@ t1.c:16: while (atomic_
nop
.L2:
@ t1.c:16: while (atomic_
ldr r3, .L4 @ tmp114,
ldrb r2, [r3] @ tmp115,
movs r1, #1 @ tmp116,
strb r1, [r3] @ tmp117,
uxtb r3, r2 @ _1, tmp115
@ t1.c:16: while (atomic_
cmp r3, #0 @ _1,
bne .L2 @,
........
**********
The problem is the "ldrb ...strb" sequence which is not atomic. M0 cores do not have strex/ldrex , they require an interrupt disable around the protected operation (mrs + cpsid + msr).
I believe gcc shouldn't silently generate a non-atomic sequence like this !