Try "sub" instead of "subs".
Really, the assembler should accept "subs", since the status bits are always updated. But this looks like a quick in the assembler.
But you'll need a #ifdef, to use "sub" on Teensy-LC and "subs" on the others. Yeah, it's messy.
I found that if you look at the disassembly of the asm for delayMicroseconds it uses 'subs'
Code:
00000472 <L_10_delayMicroseconds>:
472: 3b01 subs r3, #1
474: d1fd bne.n 472 <L_10_delayMicroseconds>
476: 4770 bx lr
478: 00027100 .word 0x00027100
I had some issues with this and other instructions that try to set flags for inline assembly.
You can use asm (".syntax unified"); before the subs instruction and then asm (".syntax divided"); after it and it will compile so something like this would compile:The assembler complains with this error
Error: instruction not supported in Thumb16 mode -- `subs r3,#1'
I don't know gcc/gas arm syntax or I'd fix it myself.
Code:
static __inline__ void /* exactly 4 cycles/loop, max 2**32 loops */
_delay_loop_2_x( uint32_t __n )
{ /* cycles per loop */
__asm__ volatile ( /* __n..one zero */
"L_%=__delay_loop_2_x:" "\n\t"
".syntax unified" "\n\t"
"subs %0, #1" "\n\t"
".syntax divided" "\n\t"
// "nop" "\n\t"
"bne L_%=__delay_loop_2_x" "\n"
: "+r" (__n) :
);
}
the disassembly looks good to me:
Code:
00000476 <L_19__delay_loop_2_x>:
476: 3b01 subs r3, #1
478: d1fd bne.n 476 <L_19__delay_loop_2_x>
47a: 4770 bx lr
47c: 00002710 .word 0x00002710