背景
CubeMX 可以生成 Makefile 项目,我们可以基于这样的结果来进行QMEU仿真。我们以 STM32F429I-DISC1 为例,刚好在 2边的工具都有这个板子的型号。
仿真原项目
准备项目
1)STM32 CubeMX 选择 以 F429DISC1 作为项目模板。
2)在"Project Manager"中,"Project" - "Toolchain/IDE" 选择 Makefile。
3)根据自己的需求改改其他的东西,"GENERATE CODE"
编译项目
进入项目以后,直接输入:
make
arm-none-eabi-gcc -c -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32F429xx -IInc -IDrivers/STM32F4xx_HAL_Driver/Inc -IDrivers/STM32F4xx_HAL_Driver/Inc/Legacy -IMiddlewares/Third_Party/FreeRTOS/Source/include -IMiddlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS -IMiddlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F -IMiddlewares/ST/STM32_USB_Host_Library/Core/Inc -IMiddlewares/ST/STM32_USB_Host_Library/Class/CDC/Inc -IDrivers/CMSIS/Device/ST/STM32F4xx/Include -IDrivers/CMSIS/Include -IDrivers/CMSIS/Include -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/main.d" -Wa,-a,-ad,-alms=build/main.lst Src/main.c -o build/main.o
...
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/bin/ld: warning: /usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/lib/armv7e-m/fpu/libc_nano.a(lib_a-reent.o) uses 2-byte wchar_t yet the output is to use 4-byte wchar_t; use of wchar_t values across objects may fail
arm-none-eabi-size build/for_stm32f429.elf
text data bss dec hex filename
30548 156 37660 68364 10b0c build/for_stm32f429.elf
arm-none-eabi-objcopy -O ihex build/for_stm32f429.elf build/for_stm32f429.hex
arm-none-eabi-objcopy -O binary -S build/for_stm32f429.elf build/for_stm32f429.bin
仿真
qemu-system-gnuarmeclipse --board STM32F429I-Discovery -d unimp,guest_errors --image build/for_stm32f429.elf
检验
可以看到 界面出现了开发板的样子。可惜还没完。由于 QEMU 不支持硬浮点,导致打印以下的报告:
$ qemu-system-gnuarmeclipse --board STM32F429I-Discovery -d unimp,guest_errors --image build/for_stm32f429.elf
NVIC: Bad read offset 0xd88
qemu-system-gnuarmeclipse: Attempt to set CP10/11 in SCB->CPACR, but FP is not supported yet.
[2] 4796 killed qemu-system-gnuarmeclipse --board STM32F429I-Discovery -d unimp,guest_errors
修改
由于仿真不顺利,我们需要进行修改。
先修改Makefile,将 FLOAT-ABI = -mfloat-abi=hard
改为 FLOAT-ABI = -mfloat-abi=soft
sed -r -i "/FLOAT-ABI = -mfloat-abi=hard/ s/.*/FLOAT-ABI = -mfloat-abi=soft/" Makefile
之后,重新make
,但出现下面的问题:
/tmp/cc5R608O.s: Assembler messages:
/tmp/cc5R608O.s:426: Error: selected processor does not support `vstmdbeq r0!,{s16-s31}' in Thumb mode
/tmp/cc5R608O.s:428: Error: instruction not allowed in IT block -- `stmdb r0!,{r4-r11,r14}'
/tmp/cc5R608O.s:448: Error: selected processor does not support `vldmiaeq r0!,{s16-s31}' in Thumb mode
/tmp/cc5R608O.s:450: Error: instruction not allowed in IT block -- `msr psp,r0'
Makefile:201: recipe for target 'build/port.o' failed
make: *** [build/port.o] Error 1