2022-02-10 01:26 PM
...
arm-none-eabi-g++ "C:/Users/../wheel/nucleo_demo_y4/Src/main.cpp" -mcpu=cortex-m4 -std=gnu++14 -g3 -DDEBUG -DARM_MATH_CM4 -DUSE_HAL_DRIVER -DSTM32F302x8 -c -I../../Inc -I../../Drivers/STM32F3xx_HAL_Driver/Inc -I../../Drivers/STM32F3xx_HAL_Driver/Inc/Legacy -I../../MCSDK_v5.Y.4-Full/MotorControl/MCSDK/MCLib/Any/Inc -I../../MCSDK_v5.Y.4-Full/MotorControl/MCSDK/MCLib/F3xx/Inc -I../../Drivers/CMSIS/Device/ST/STM32F3xx/Include -I../../Drivers/CMSIS/Include -I../../Middlewares/Third_Party/FreeRTOS/Source/include -I../../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS -I../../Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F -I../../Drivers/CMSIS/DSP/Include -O0 -ffunction-sections -fdata-sections -fno-exceptions -fno-rtti -fno-use-cxa-atexit -Wall -fstack-usage -MMD -MP -MF"Application/User/main.d" -MT"Application/User/main.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Application/User/main.o"
In file included from C:/Users/dustin/repos/wheel/nucleo_demo_y4/Src/main.cpp:21:
C:/Users/dustin/repos/wheel/nucleo_demo_y4/Src/main.cpp: In function 'int main()':
C:/Users/dustin/repos/wheel/nucleo_demo_y4/Src/main.cpp:141:82: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
141 | osThreadDef(mediumFrequency, startMediumFrequencyTask, osPriorityNormal, 0, 128);
| ^
../../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.h:416:4: note: in definition of macro 'osThreadDef'
416 | { #name, (thread), (priority), (instances), (stacksz), NULL, NULL }
| ^~~~
C:/Users/.../wheel/nucleo_demo_y4/Src/main.cpp:145:69: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
145 | osThreadDef(safety, StartSafetyTask, osPriorityAboveNormal, 0, 128);
| ^
../../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.h:416:4: note: in definition of macro 'osThreadDef'
416 | { #name, (thread), (priority), (instances), (stacksz), NULL, NULL }
| ^~~~
C:/Users/.../wheel/nucleo_demo_y4/Src/main.cpp:149:69: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
149 | osThreadDef(wheelCtrl, startWheelControl, osPriorityNormal, 0, 128);
| ^
../../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.h:416:4: note: in definition of macro 'osThreadDef'
416 | { #name, (thread), (priority), (instances), (stacksz), NULL, NULL }
| ^~~~
....
arm-none-eabi-g++ -o "nucleo_demo_y4.elf" @"objects.list" -mcpu=cortex-m4 -T"C:\Users\...\wheel\nucleo_demo_y4\STM32CubeIDE\STM32F302R8TX_FLASH.ld" -Wl,-Map="nucleo_demo_y4.map" -Wl,--gc-sections -static --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -Wl,--start-group -lc -lm -lstdc++ -lsupc++ -Wl,--end-group
c:\st\stm32cubeide_1.8.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: ./Application/User/main.o:(.rodata+0x44): undefined reference to `StartSafetyTask(void const*)'
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:82: nucleo_demo_y4.elf] Error 1
make: Target 'all' not remade because of errors.
"make -k all" terminated with exit code 2. Build might be incomplete.
13:18:12 Build Failed. 3 errors, 3 warnings. (took 51s.983ms)
Having issues with undefined reference when switching to C++ using the MC SDK.
My guess would be that g++ doesn't like the way tasks are created.. Anyone else sucessfully convert to C++ project?
2022-02-10 02:28 PM
So changing char * -> const char * fixes the compile warnings, but not linking issues.
/// Thread Definition structure contains startup information of a thread.
/// \note CAN BE CHANGED: \b os_thread_def is implementation specific in every CMSIS-RTOS.
typedef struct os_thread_def {
const char *name; ///< Thread name
os_pthread pthread; ///< start address of thread function
osPriority tpriority; ///< initial thread priority
uint32_t instances; ///< maximum number of instances of that thread function
uint32_t stacksize; ///< stack size requirements in bytes; 0 is default stack size
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
uint32_t *buffer; ///< stack buffer for static allocation; NULL for dynamic allocation
osStaticThreadDef_t *controlblock; ///< control block to hold thread's data for static allocation; NULL for dynamic allocation
#endif
} osThreadDef_t;
2022-02-10 07:36 PM
Found the answer.
g++ doesn't want to look for "extern void StartSafetyTask(void const * argument);" in main.cpp, I moved it to main.h and linked fine.
Hope that helps other people use MC SDK + FreeRTOS using C++