2018-08-06 10:40 AM
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...
2018-08-06 11:29 AM
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
2018-08-06 01:09 PM
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
2018-08-06 02:48 PM
The Two of you have provided a working solution, thank you!
2018-08-06 06:00 PM
Yes