We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Using Keil MCBSTM32 (STM32F103RB processor) and uVision3 V3.55a
The goal is to "encapsulate" data in C. To do this I want to create access methods (get/put) that are accessible externally, but the data, being declared static, is not.
I also want to appease those who want faster code so I was attempting to "inline" the methods.
The test code is as follows:
#include counter.h static unsigned int counter; /** Method to get counter. */ __forceinline unsigned int get_counter() { return counter; } /** Method to set counter. */ __forceinline void put_counter( unsigned int val) { counter = val; }
The counter.h contains the following:
__forceinline unsigned int get_counter(void); __forceinline void put_counter( unsigned int val);
(Note: tried the declarations in the .h file with and without the __forceinline)
The main() contains:
static unsigned int opt_test; /*---------------------------------------------------------------------------- MAIN function *----------------------------------------------------------------------------*/ int main (void) { stm32_Init (); // STM32 setup GPIOB->ODR |= (1 << (ledPos+8)); // switch on initial LED position while (1) { // Loop forever opt_test = get_counter(); opt_test++; put_counter( opt_test ); } // end while
(Note: this was just tacked onto the "Timer" project to try things out)
What I get: Build target 'MCBSTM32' assembling STM32F10x.s... creating preprocessor file for STM32_Init.c... compiling STM32_Init.c... creating preprocessor file for Timer.c... compiling Timer.c... creating preprocessor file for optimize.c... compiling optimize.c... linking... .\Obj\Timer.axf: Error: L6218E: Undefined symbol get_counter (referred from timer.o). .\Obj\Timer.axf: Error: L6218E: Undefined symbol put_counter (referred from timer.o). Target not created What I have tried: Compiled with optimization levels of 2 and 3.
Is this functionality actually working? If so, is there anything I should be looking out for that might cause this error?