使用stm32与C++进行程序编写,根据网络上的教程一开始能进行程序编写,但是我添加freertos发现多个文件报错,经过一番折腾之后终于是解决了这个问题
出错信息
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26compiling heap_4.c...
../Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c(193): error: #513: a value of type "void *" cannot be assigned to an entity of type "BlockLink_t *"
pxNewBlockLink = ( void * ) ( ( ( uint8_t * ) pxBlock ) + xWantedSize );
../Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c(275): error: #513: a value of type "void *" cannot be assigned to an entity of type "BlockLink_t *"
pxLink = ( void * ) puc;
../Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c(350): error: #513: a value of type "void *" cannot be assigned to an entity of type "A_BLOCK_LINK *"
xStart.pxNextFreeBlock = ( void * ) pucAlignedHeap;
../Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c(358): error: #513: a value of type "void *" cannot be assigned to an entity of type "BlockLink_t *"
pxEnd = ( void * ) uxAddress;
../Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c(364): error: #513: a value of type "void *" cannot be assigned to an entity of type "BlockLink_t *"
pxFirstFreeBlock = ( void * ) pucAlignedHeap;
../Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c: 0 warnings, 5 errors
compiling cmsis_os2.c...
../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c(661): error: #513: a value of type "void *" cannot be assigned to an entity of type "TaskStatus_t *"
task = pvPortMalloc (count * sizeof(TaskStatus_t));
../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c(887): error: #513: a value of type "void *" cannot be assigned to an entity of type "TimerCallback_t *"
callb = pvPortMalloc (sizeof(TimerCallback_t));
../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c(1062): error: #167: argument of type "void *" is incompatible with parameter of type "StaticEventGroup_t *"
hEventGroup = xEventGroupCreateStatic (attr->cb_mem);
../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c(1254): error: #167: argument of type "void *" is incompatible with parameter of type "StaticQueue_t *"
hMutex = xSemaphoreCreateRecursiveMutexStatic (attr->cb_mem);
../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c(1257): error: #167: argument of type "void *" is incompatible with parameter of type "StaticQueue_t *"
hMutex = xSemaphoreCreateMutexStatic (attr->cb_mem);
../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c(1613): error: #167: argument of type "void *" is incompatible with parameter of type "std::uint8_t *"
hQueue = xQueueCreateStatic (msg_count, msg_size, attr->mq_mem, attr->cb_mem);
../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c(1613): error: #167: argument of type "void *" is incompatible with parameter of type "StaticQueue_t *"这里只贴了一部分,根据信息可以知道是C++的类型转换不允许(void *)转换,所以第一直觉是直接改变类型
在我改变类型之后,的确不会报错,但是一运行就进入SVC_Handler中断,进入的位置1
2
3
4
5
6
7
8
9
10
11
12
13
14
15__asm void vPortSVCHandler( void )
{
PRESERVE8
ldr r3, =pxCurrentTCB /* Restore the context. */
ldr r1, [r3] /* Use pxCurrentTCBConst to get the pxCurrentTCB address. */
ldr r0, [r1] /* The first item in pxCurrentTCB is the task top of stack. */
ldmia r0!, {r4-r11} /* Pop the registers that are not automatically saved on exception entry and the critical nesting count. */
msr psp, r0 /* Restore the task stack pointer. */
isb
mov r0, #0
msr basepri, r0
orr r14, #0xd
bx r14
}解决办法
在找解决办法的时候,发现网友说可以在keil中改变文件类型,对单独的文件使用C++编译;这就是解决办法
但是每次使用cubemx更新文件之后,需要再次设置文件属性。- 不要改变option/c/c++中的设置
- 右键main.c,在options for file中改变‘file type’,选择‘C++ source file’
- 同样改变freertos.c文件
- 添加自己的CPP文件(注意后缀)
编译一下,就大功告成了