Skip to main content
harinath
Associate III
December 19, 2012
Question

Microseconds delay assembler inline routine IAR EWARM 6.3

  • December 19, 2012
  • 6 replies
  • 1705 views
Posted on December 19, 2012 at 07:19

I needprecise microseconds delay routine in myapplication ( uses STM32F103RE)

I saw

https://github.com/leaflabs/libmaple/blob/master/libmaple/include/libmaple/delay.h

for microseconds delay routine. It has the following:

static
inline
void
delay_us(uint32 us) {
us *= STM32_DELAY_US_MULT;
/* fudge for function call overhead */
us--;
asm 
volatile
(
'' mov r0, %[us] \n\t''
''1: subs r0, #1 \n\t''
'' bhi 1b \n\t''
:
: [us] 
''r''
(us)
: 
''r0''
);
}

I'm trying to rewrite this routing in IAR EWARM 6.3 I would like to write the same function in IAR EWARM 6.3 I get the following error if I use the same code: Error[Og006]: Syntax error in inline assembly: ''Error[41]: Bad label''

Anyone who hasexperience in writing code using IAR embedded workbech, suggestions pleas

    This topic has been closed for replies.

    6 replies

    frankmeyer9
    Associate III
    December 19, 2012
    Posted on December 19, 2012 at 17:35

    I think it is nothing else than a disguised assembler version of

    while (delay_us--);

    And I bet there is no 1:1 relation between the contents of

    delay_us

    , and the time spent there in microseconds...
    harinath
    harinathAuthor
    Associate III
    December 20, 2012
    Posted on December 20, 2012 at 02:08

    Thank you for pointing out c version. But I prefer assembly version to check out which one works closer to 1 microsecond.

    Tesla DeLorean
    Guru
    December 20, 2012
    Posted on December 20, 2012 at 02:43

    static void delay_us(uint32_t us)
    {
    us *= STM32_DELAY_US_MULT;
    us--;
    asm('' mov r0, us 
    ''
    ''loop: subs r0, #1 
    ''
    '' bhi loop 
    '');
    }

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    harinath
    harinathAuthor
    Associate III
    December 21, 2012
    Posted on December 21, 2012 at 06:42

    Sorry for the late reply.

    0690X000006052VQAQ.png

    The following errors are shown when compiled. Do we need to activate any settings in IDE ?

    0690X000006052QQAQ.png

    The following link may help us to resolve:

    http://supp.iar.com/Support/?note=31237&%3bfrom=search+result

    Thank you
    frankmeyer9
    Associate III
    December 21, 2012
    Posted on December 21, 2012 at 10:58

    Don't know the IAR toolchain in detail, but C level variables usually get prepended by a '_' in the assembler/linker stage. I would try '_us' instead.

    And I'm not sure, lacking the IAR detailled knowledge, how you tell the compiler that the variable 'us' is manipulated in assembler code.

    Tesla DeLorean
    Guru
    December 21, 2012
    Posted on December 21, 2012 at 13:31

    I used IAR EWARM 6.40.3.4115, worked there. Why not just put it in startup.s in straight assembler?

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..