EFM8

How to fix Keil EFM8 Warning C280: unreferenced local variable

Problem:

You have a C function like

int myfunc(int value) {
  return 0;
}

but you see a Keil compiler warning like

*** WARNING C280 IN LINE 7 OF C:\Users\uli\MyProject\src\main.c: 'value': unreferenced local variable

Solution:

'value': unreferenced local variable means that you don’t use that variable value in any way.

In the function shown above, you can see that value is the argument of myfunc but myfunc never actually uses the variable.

Do you think that variable should be used in this function?

You need to check your function for typos – the variable is never used at all. Possibly you are using the wrong variable or your function is missing some part of its logic.

Don’t want to use that variable at all?

Usually you can tell the compiler that you don’t want to use that variable by using

(void)value;

but that will produce an expression with possibly no effect warning.

*** WARNING C275 IN LINE 7 OF C:\Users\uli\MyProject\src\main.c: expression with possibly no effect

You can use this hack to avoid this warning:

r = r; // Avoid unused local variable

 

Posted by Uli Köhler in C/C++, EFM8

How to fix Keil EFM8 ERROR C267 ‘SLAB_ASSERT’: requires ANSI-style prototype

Problem:

You want to compile your EFM8 application but you see these error messages:

*** WARNING C206 IN LINE 86 OF C:\SiliconLabs\SimplicityStudio\v4\developer\sdks\8051\v4.1.7\Device\EFM8BB3\peripheral_driver\src\adc_0.c: 'SLAB_ASSERT': missing function-prototype
*** ERROR C267 IN LINE 86 OF C:\SiliconLabs\SimplicityStudio\v4\developer\sdks\8051\v4.1.7\Device\EFM8BB3\peripheral_driver\src\adc_0.c: 'SLAB_ASSERT': requires ANSI-style prototype

Solution:

Go into your Project properties (by right-clicking on your project on the top left and clicking “Properties”) -> C/C++ Build -> Project Modules

There, select 8051 -> EFM8 and check the Assert checkbox to include the assertion module. Now recompile your module.

Posted by Uli Köhler in EFM8, Embedded

How to fix Keil error C129: “missing ‘;'” without any missing semicolon (EFM8)

Problem:

You have source code like

uint16_t convert(uint16_t input) {
   return input * 2;
}

that you want to compile using EFM8

// *** ERROR C129 IN LINE 1 OF C:\Users\user\TestProject\src\Test.c: missing ';' before 'convert'

Solution:

Keil doesn’t know what the uint16_t before the declaration of convert().

#include <stdint.h>

stdint.h contains declarations for several standard integer types like uint8_t, uint16_t, uint32_t, int16_t etc.

The final code should look like this:

#include <stdint.h>

uint16_t convert(uint16_t input) {
    return input * 2;
}

 

Posted by Uli Köhler in EFM8

What does SCON0_TI = 1 mean for the EFM8?

SCON0 is the UART0 serial port control register (Serial CONtrol 0). The TI bit enables the Transmit Interrupt, i.e. when the transmission of a byte is finished, the CPU will be interrupted.

Setting

SCON0_TI = 1;

is neccessary for some of the EFM8 UART libraries (like the STDIO UART library) so they initialize properly. Although this is a simplification, the library needs to know that there is no UART transmission going on at the moment.

Also, don’t forget to enable global interrupts using

IE_EA = 1;

else, the UART0 transmit interrupt will never be run.

Posted by Uli Köhler in EFM8, Embedded