cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to adapt a library, getting a syntax error,

MThat
Associate II

Good day, everyone.

This is the library I'm trying to us with the STM32f103.

https://github.com/rogerdahl/stm32-tm1637

Most all of the work was already done as this IS an stm32 library.

I am however getting this error:

compiling main.c...
..\libraries\stm32-tm1637-master\stm32-tm1637-master\stm32_tm1637.c(143): error:  #130: expected a "{"
              __asm__ __volatile__("nop\n\t":::"memory");
..\libraries\stm32-tm1637-master\stm32-tm1637-master\stm32_tm1637.c(143): error:  #18: expected a ")"

The code snippet that this piece is complaining:

void _tm1637DelayUsec(unsigned int i)
{
    for (; i>0; i--) {
        for (int j = 0; j < 10; ++j) {
            __asm__ __volatile__("nop\n\t":::"memory"); // This is LINE 143
        }
    }
}

 I'm not sure where exactly those brackets are supposed to go. This is a level of programming outside of my basic understanding of... making an led blink...

4 REPLIES 4

A less clumsy and more portable implementation would look like

void _tm1637DelayUsec(unsigned int i)
{
  volatile unsigned int j;
  while(i--)
  {
    for(j=0; j<10; j++)
    {
      __NOP();
    }
  }
}

Using in-line assembler has tool-chain specific limitations. You don't specify what you're using, guessing Keil. But __NOP is a CMSIS compliant form.

Volatile is used so the compiler doesn't optimize out a pointless looping construct.

With such loops you'd likely need to calibrate the loop iterations as this is code and chip speed specific. ie Toggle a GPIO pin and scope

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

Clive, isn't it __NOP() ?

The inline assembler from the original post may be gcc-specific, the error messages don't seem to be gcc.

In STM32s, it may perhaps be easier to implement us-granularity loopdelay using timers (maybe even systick).

JW

MThat
Associate II

The Two of you have provided a working solution, thank you!

Yes

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