Hello kind people out there,
I just recently startet using FreeRTOS, therefore I don’t have much experience yet. I also didn’t find any post online of someone having the same problem, so I hope I can get some help here. About the problem:
I’m using a STM32F411 Nucleo Board together with ST’s CubeIDE. I’m using their Firmware Package version 1.26.2 (most recent version at this time). I use CubeMX for configuration and generation of initialization code. However, I don’t use the FreeRTOS implementation provided by CubeMX (I would like to work with the FreeRTOS API directly, not using the CMSIS RTOS API).
Because I would like to continue using CubeMX, I couldn’t start with a demo as its recommended. So i followed the guide on how to add FreeRTOS to an existing project. Im fairly confident that the integration of source- and headerfiles was successfull and error-free. I used the port from GCC/ARM_CM4F and the RTOS_Config.h from the CORTEX_M4F_STM32F407ZG-SK demo.
Upon compiling I now get error messages, stating that the interrupt handlers are defined twice.
c:\st\stm32cubeide_1.7.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_2.0.0.202105311346\tools\arm-none-eabi\bin\ld.exe: ./FreeRTOS/Source/portable/GCC/ARM_CM4F/port.o: in function `SVC_Handler':
F:/STM32Cube/Test_FreeRTOS/Debug/../FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c:249: multiple definition of `SVC_Handler'; ./Core/Src/stm32f4xx_it.o:F:/STM32Cube/Test_FreeRTOS/Debug/../Core/Src/stm32f4xx_it.c:148: first defined here
c:\st\stm32cubeide_1.7.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_2.0.0.202105311346\tools\arm-none-eabi\bin\ld.exe: ./FreeRTOS/Source/portable/GCC/ARM_CM4F/port.o: in function `PendSV_Handler':
F:/STM32Cube/Test_FreeRTOS/Debug/../FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c:443: multiple definition of `PendSV_Handler'; ./Core/Src/stm32f4xx_it.o:F:/STM32Cube/Test_FreeRTOS/Debug/../Core/Src/stm32f4xx_it.c:174: first defined here
c:\st\stm32cubeide_1.7.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_2.0.0.202105311346\tools\arm-none-eabi\bin\ld.exe: ./FreeRTOS/Source/portable/GCC/ARM_CM4F/port.o: in function `SysTick_Handler':
F:/STM32Cube/Test_FreeRTOS/Debug/../FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c:497: multiple definition of `SysTick_Handler'; ./Core/Src/stm32f4xx_it.o:F:/STM32Cube/Test_FreeRTOS/Debug/../Core/Src/stm32f4xx_it.c:187: first defined here
c:\st\stm32cubeide_1.7.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_2.0.0.202105311346\tools\arm-none-eabi\bin\ld.exe: ./FreeRTOS/Source/tasks.o: in function `xTaskIncrementTick':
F:/STM32Cube/Test_FreeRTOS/Debug/../FreeRTOS/Source/tasks.c:2861: undefined reference to `vApplicationTickHook'
c:\st\stm32cubeide_1.7.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_2.0.0.202105311346\tools\arm-none-eabi\bin\ld.exe: F:/STM32Cube/Test_FreeRTOS/Debug/../FreeRTOS/Source/tasks.c:2891: undefined reference to `vApplicationTickHook'
c:\st\stm32cubeide_1.7.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_2.0.0.202105311346\tools\arm-none-eabi\bin\ld.exe: ./FreeRTOS/Source/portable/MemMang/heap_4.o: in function `pvPortMalloc':
F:/STM32Cube/Test_FreeRTOS/Debug/../FreeRTOS/Source/portable/MemMang/heap_4.c:263: undefined reference to `vApplicationMallocFailedHook'
(Please ignore the errors relating to missing hook functions, I didn’t disable those in config yet)
I already found the FAQ entry describing this exact problem (“FreeRTOS FAQ - My application does not run, what could be wrong?” then the “Special note to ARM Cortex-M users” written in red): The three handlers are indeed defined in CMSIS. The problem: Because I’m using CubeMX, adding the __weak attribute to the CMSIS function is overwritten every time I regenerate my code.
What would be the best way to solve this problem?
I tried calling the RTOS-handlers from the respective CMSIS-handlers, but the compiler threw a “implicit declaration” error at me. This makes sense of course, but I couldn’t find the header where SVC_Handler, PendSV_Handler and SysTick_Handler are declared. Is this a valid/good approach after all?
Thanks to everybody reading this and providing help!
PS: Unfortionately I cannot upload my project because I’m a new user, but if someone would like to take a look, I’m sure we can work this out.