原子不要骂我哈!分享一个stm32之qemu仿真开发板

2019-07-20 04:36发布

本帖最后由 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不支持硬浮点https://sourceforge.net/p/gnuarmeclipse/bugs/159/可以通过设置编译选项来选择软浮点,还是硬浮点。 http://blog.csdn.net/gujintong1110/article/details/23038217
将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'
查询后发现,这些代码不支持软浮点。https://sourceforge.net/p/freertos/discussion/382005/thread/9abf4160/直接查看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         " /* The FPU enable bits are in the CPACR. */ 7         "    ldr r1, [r0]                " 8         "                                 " 9         "    orr r1, r1, #( 0xf << 20 )    " /* Enable CP10 and CP11 coprocessors, then save back. */10         "    str r1, [r0]                "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                         " 8     "    isb                                  " 9     "                                        "10     "    ldr    r3, pxCurrentTCBConst         " /* Get the location of the current TCB. */11     "    ldr    r2, [r3]                      "12     "                                        "13     "    tst r14, #0x10                      " /* Is the task using the FPU context?  If so, push high vfp registers. */14     "    it eq                               "15     "    vstmdbeq r0!, {s16-s31}             "16     "                                        "17     "    stmdb r0!, {r4-r11, r14}             " /* Save the core registers. */18     "                                        "19     "    str r0, [r2]                         " /* Save the new top of stack into the first member of the TCB. */20     "                                        "21     "    stmdb sp!, {r3}                      "22     "    mov r0, %0                           "23     "    msr basepri, r0                      "24     "    dsb                                  "25     "    isb                                  "26     "    bl vTaskSwitchContext                "27     "    mov r0, #0                           "28     "    msr basepri, r0                      "29     "    ldmia sp!, {r3}                      "30     "                                        "31     "    ldr r1, [r3]                         " /* The first item in pxCurrentTCB is the task top of stack. */32     "    ldr r0, [r1]                         "33     "                                        "34     "    ldmia r0!, {r4-r11, r14}             " /* Pop the core registers. */35     "                                        "36     "    tst r14, #0x10                      " /* Is the task using the FPU context?  If so, pop the high vfp registers too. */37     "    it eq                               "38     "    vldmiaeq r0!, {s16-s31}             "39     "                                        "40     "    msr psp, r0                         "41     "    isb                                  "42     "                                        "43     #ifdef WORKAROUND_PMU_CM001 /* XMC4000 specific errata workaround. */44         #if WORKAROUND_PMU_CM001 == 145     "            push { r14 }                "46     "            pop { pc }                   "47         #endif48     #endif49     "                                        "50     "    bx r14                               "51     "                                        "52     "    .align 4                            "53     "pxCurrentTCBConst: .word pxCurrentTCB    "54     ::"i"(configMAX_SYSCALL_INTERRUPT_PRIORITY)55     );56 }[url=][/url]




友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。