Newbie struggling with .c .h and linking
Hello all
I'm a hobbyist with experience as a java programmer and with simple embedded C and C++ experience who's working on a project for the Elektor Magazine STM32 contest and I'm finding myself in over my head and I'm wondering if any of you might be able to point me in the right direction.
I'm building up a project that uses several of the capabilities of the STM32WB5MM-DK board that I'm working with. I decided to built it up step by step so I can understand what I'm doing.
I began with a project that just reads the temperature sensor and outputs the data on the USART1 serial terminal. This was my first success. The next thing I'd like to add is the ability to use the RGB LED. I see that code is in stm32wb5mm_dk.c in one of the demo projects. So I put a copy of stm32wb5mm_dk.c into Core/Src and I put the corresponding .h file in Core/Inc. Since both Core/Src and Core/Inc already contain files that are part of the project, I assumed that I didn't need to change the build settings. Was this wrong?
I was not able to call functions in the stm32wb5mm_dk.c file until I added #include "stm32wb5mm_dk.h" to main.c but then the related errors in main.c disappeared. I have a feeling that this isn't the right way to do this. Is there a better way to get access to those functions?
However, errors appeared in the stm32wb5mm_dk.c file and this is what I'm going in circles to try to fix. There are only two functions that are a problem: HAL_TIM_Base_Init() and HAL_TIM_Base_Start() - the error is "undefined reference". I googled that and it suggests that this is a 'linker problem' - this may be confirmed by searching for the declaration of these functions which only turns up a stub in stm32wbxx_hal_tim.h (rather than a real declaration of code). The thing is, stm32wbxx_hal_tim.c is already in the project by default (in Drivers/STM32WBxx_HAL_Driver/Src/) and the corresponding .h is in Drivers/STM32WBxx_HAL_Driver/Inc. So, somehow, eclipse isn't seeing this .c file.
If I look in the properties for this project and Paths and Symbols and then Includes, I see
Core/Inc
Drivers/STM32WBxx_HAL_Driver/Inc
Drivers/STM32WBxx_HAL_Driver/Inc/Legacy
Drivers/CMSIS/Device/ST/STM32WBxx/Include
Drivers/CMSIS/Include
- so it looks like the files should be seen.
It seems like there's something really simple I'm missing but while my grasp of .c vs .h and what the linker does is slowly coming into focus, I'm really at sea as to how to make eclipse do what I want. It feels like it has something to do with how you tell the compiler/linker to put all the pieces together but that part is really fuzzy for me. So please excuse my ignorance but any suggestions would help.
This may really be an eclipse question but I'm afraid that if I ask an eclipse forum they'll tell me they don't know what I'm referring to with the file and function names etc.
thanks to all.
Brian
