本帖最后由 huayuguo 于 2018-12-13 08:25 编辑
原文作者地址:https://www.cnblogs.com/89yanyu/p/7537902.html
想搞搞想到的东西但是,现在手里没有板子!所以想到了之前用过的qemu 嘿嘿就发现这个了,原子看了会不会骂我!
最关键的是这句话 qemu-system-gnuarmeclipse --board STM32F429I-Discovery说明还有其他板子!哈哈所以大家去发现吧,我准备下上班了,回头把具体搭建过程发上来!
QEMU无法仿真Cortex-M4内核基于陈老师提供的Hello_RTOS工程: qemu 2.8.0 arm-none-eabi-gcc 4.8.2 下载工程并编译 1 git clone https://github.com/cbhust/STM32F429_Discovery_FreeRTOS_9.git2 cd STM32F429_Discovery_FreeRTOS_9/Projects/Hello_RTOS/3 make
选用STM32F429I-Discovery为系统板,调用qemu仿真。 1 qemu-system-gnuarmeclipse --board STM32F429I-Discovery -d unimp,guest_errors --image hello_rtos.elf
--board STM32F429I-Discovery 选择系统板
-d unimp,guest_errors 设置需要记录的项目
--image hello_rtos.elf 选择系统镜像
出现如下错误: Attempt to set CP10/11 in SCB->CPACR, but FP is not supported yet. 经查询,这条错误信息是由于qemu不支持硬浮点 可以通过设置编译选项来选择软浮点,还是硬浮点。
将Hello_RTOS拷贝一份,到Qemu_with_M4 修改Makefile中的MCFLAGS,改为: MCFLAGS=-mcpu=cortex-m4 -mthumb -mlittle-endian \-mfpu=fpv4-sp-d16 -mfloat-abi=soft -mthumb-interworkDEFS=-DUSE_STDPERIPH_DRIVER -DSTM32F4XX
再次编译后,仍然出现错误: Error: selected processor does not support `vstmdbeq r0!,{s16-s31}' in Thumb mode
Error: instruction not allowed in IT block -- `stmdb r0!,{r4-r11,r14}'
Error: selected processor does not support `vldmiaeq r0!,{s16-s31}' in Thumb mode
Error: instruction not allowed in IT block -- `msr psp,r0' 查询后发现,这些代码不支持软浮点。 直接查看STM32F429_Discovery_FreeRTOS_9/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c发现: #ifndef __VFP_FP__ #error This port can only be used when the project options are configured to enable hardware floating point support.#endif
代码的确不支持软浮点。 经过多次尝试决定,使用兼容软浮点的接口,并修改部分代码。 阅读代码后发现三处涉及硬浮点的代码: [url=] [/url]
1 /* This is a naked function. */ 2 static void vPortEnableVFP( void ) 3 { 4 __asm volatile 5 ( 6 " ldr.w r0, =0xE000ED88 \n" /* The FPU enable bits are in the CPACR. */ 7 " ldr r1, [r0] \n" 8 " \n" 9 " orr r1, r1, #( 0xf << 20 ) \n" /* Enable CP10 and CP11 coprocessors, then save back. */10 " str r1, [r0] \n"11 " bx r14 "12 );13 }14 /*-----------------------------------------------------------*/[url=] [/url]
第9行就是硬浮点时,仿真出错的位置 实际上是任务在初始化时对浮点处理器的初始化 [url=] [/url]
1 void xPortPendSVHandler( void ) 2 { 3 /* This is a naked function. */ 4 5 __asm volatile 6 ( 7 " mrs r0, psp \n" 8 " isb \n" 9 " \n"10 " ldr r3, pxCurrentTCBConst \n" /* Get the location of the current TCB. */11 " ldr r2, [r3] \n"12 " \n"13 " tst r14, #0x10 \n" /* Is the task using the FPU context? If so, push high vfp registers. */14 " it eq \n"15 " vstmdbeq r0!, {s16-s31} \n"16 " \n"17 " stmdb r0!, {r4-r11, r14} \n" /* Save the core registers. */18 " \n"19 " str r0, [r2] \n" /* Save the new top of stack into the first member of the TCB. */20 " \n"21 " stmdb sp!, {r3} \n"22 " mov r0, %0 \n"23 " msr basepri, r0 \n"24 " dsb \n"25 " isb \n"26 " bl vTaskSwitchContext \n"27 " mov r0, #0 \n"28 " msr basepri, r0 \n"29 " ldmia sp!, {r3} \n"30 " \n"31 " ldr r1, [r3] \n" /* The first item in pxCurrentTCB is the task top of stack. */32 " ldr r0, [r1] \n"33 " \n"34 " ldmia r0!, {r4-r11, r14} \n" /* Pop the core registers. */35 " \n"36 " tst r14, #0x10 \n" /* Is the task using the FPU context? If so, pop the high vfp registers too. */37 " it eq \n"38 " vldmiaeq r0!, {s16-s31} \n"39 " \n"40 " msr psp, r0 \n"41 " isb \n"42 " \n"43 #ifdef WORKAROUND_PMU_CM001 /* XMC4000 specific errata workaround. */44 #if WORKAROUND_PMU_CM001 == 145 " push { r14 } \n"46 " pop { pc } \n"47 #endif48 #endif49 " \n"50 " bx r14 \n"51 " \n"52 " .align 4 \n"53 "pxCurrentTCBConst: .word pxCurrentTCB \n"54 ::"i"(configMAX_SYSCALL_INTERRUPT_PRIORITY)55 );56 }[url=] [/url]
|