0
votes

I am facing compilation error for FreeRTOS compilation on STM32 using Truestudio.

/home/dd/Atollic/TrueSTUDIO/STM32_workspace_9.0/STM32L071KZ_RTOS/Debug/../Src/main.c:236: undefined reference to `HAL_SYSTICK_Config'
/home/dd/Atollic/TrueSTUDIO/STM32_workspace_9.0/STM32L071KZ_RTOS/Debug/../Src/main.c:240: undefined reference to `HAL_SYSTICK_CLKSourceConfig'
/home/dd/Atollic/TrueSTUDIO/STM32_workspace_9.0/STM32L071KZ_RTOS/Debug/../Src/main.c:243: undefined reference to `HAL_NVIC_SetPriority'
Src/main.o: In function `main':
/home/dd/Atollic/TrueSTUDIO/STM32_workspace_9.0/STM32L071KZ_RTOS/Debug/../Src/main.c:107: undefined reference to `HAL_Init'
Src/main.o: In function `MX_GPIO_Init':
Src/main.o: In function `main':
/home/dd/Atollic/TrueSTUDIO/STM32_workspace_9.0/STM32L071KZ_RTOS/Debug/../Src/main.c:147: undefined reference to `osThreadCreate'
/home/dd/Atollic/TrueSTUDIO/STM32_workspace_9.0/STM32L071KZ_RTOS/Debug/../Src/main.c:151: undefined reference to `osThreadCreate'
/home/dd/Atollic/TrueSTUDIO/STM32_workspace_9.0/STM32L071KZ_RTOS/Debug/../Src/main.c:155: undefined reference to `osThreadCreate'
/home/dd/Atollic/TrueSTUDIO/STM32_workspace_9.0/STM32L071KZ_RTOS/Debug/../Src/main.c:167: undefined reference to `osKernelStart'

Any idea on how to resolve this?

1
your project is not correctly set up. You need to add all the include paths, add the .c files to your project, and eventually all the libraries0___________

1 Answers

2
votes

"Undefined reference" is a linker error, which in your case likely means you didn't compile all the necessary files or the required functions were "disabled" by preprocessor directive. However seeing how your linker complains about HAL_Init missing - which isn't surrounded by any #if, #ifdef or similar - means that your problem is probably due to source files not being compiled at all. This also isn't a missing static library issue, as HAL is delivered in the form of source code.

To solve your problem, do the following:

  • Make sure the corresponding source files (not headers) are included to your project. For example, HAL_Init is located in stm32f7xx_hal.c (for STM32F7, F4 etc. have a similar file, depending on what you use). In Eclipse / Truestudio the easiest way to do so is to through the Top menu -> Navigate -> Open Resource... (CTRL+Shift+R) and type in the file name. If it's not there - the file is not added to your project and at this point you should add it.

  • If you did open the file, that doesn't necessarily mean it's being build, as it may be excluded. Depending how you've added a directory, Eclipse may sometimes decide to disable it as a whole by default. Go to the file in your Project Explorer (if you have the file still open in the editor from the previous step, you can click the two arrows icon to nagivate to the file: https://i.imgur.com/mGf0lHf.png). The file - and likely the whole directory it's in - should not be greyed-out / strikethrough. Rightclick on the file and select Resource Configurations -> Exclude from Build.... Make sure it's NOT checked for the project configuration you're trying to build.

To further ensure you've done everything correctly and the needed files do indeed get compiled, rightclick on it (e.g. stm32f7xx_hal.c) and select Build Selected File(s). What you should see is a compiler command line and its output, e.g. arm-none-eabi-.... If the file is excluded from build, you'll only see Info: Internal Builder is used for build followed by hh:mm:ss Build Finished (took Xs.YYYms) but no line with compiler's command line arguments. Try doing so on a file in your project that's know to compile (main.c from what you've posted does get compiled) and compare the results.