使用qemu-system-ARM.exe模拟ARM Cortex-M7



我使用的是基于Eclipse的CubeIDE和QEMU调试插件。我在汇编程序中工作,可以在STM32Cortex M7板(STM32H750DK(上调试简单的项目(在寄存器中添加两个数字(。现在我想使用QEMU做同样的事情,但有问题,因为我找不到合适的通用Cortex M7机器。我试过mps2-an500,但它不起作用。

我已经在STM32F407板上的qemu-system-gnuarmeclipse.exe下做了类似的操作,它甚至在视觉上得到了支持(板上的图片(,我可以看到LED二极管在闪烁。

对于皮质M7板,我只需要简单的模拟(而不是视觉(就足够了。

有没有人做过类似的事情或任何其他建议来正确地做到这一点?

谢谢。

我认为您应该显示一些代码,说明在Stackoverflow上提问时所做的尝试。在您的情况下,这可能是您尝试使用mps2-an500 QEMU虚拟机的一个最小、可重复的示例。

话虽如此,使用QEMU构建和调试程序并以mps2-an500虚拟机为目标的过程可以是:

  1. 下载适用于Windows的QEMU 7.10,并将其安装到\opt\QEMU-7.1.0目录中-您必须创建它
  2. 下载arm-gnu-toolchain-11.3.rel1-ming-w64-i686-arm-none-eabi工具链,并安装到\opt\arm\11目录中-您必须创建它

在您选择的目录中,创建以下文件:

build.cmd:

@set CROSS_COMPILE=optarm11arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabibinarm-none-eabi-
@set CC=%CROSS_COMPILE%gcc
@set OBJDUMP=%CROSS_COMPILE%objdump
@set GDB=%CROSS_COMPILE%gdb
@set QEMU_SYSTEM_ARM=optqemu-7.1.0qemu-system-arm
@%CC%  -g -mthumb -mtune=cortex-m7 -nostdlib -nostartfiles -ffreestanding -Wl,-Ttext,0x00000000 -o mps2-an500.elf startup.s 
@%OBJDUMP% -d mps2-an500.elf > mps2-an500.objdump
@echo QEMU/GDB commands:
@echo %QEMU_SYSTEM_ARM% -m 16M  -nographic -machine mps2-an500 -S -cpu cortex-m7 -gdb tcp::2345,ipv4 -kernel mps2-an500.elf
@echo %GDB%

startup.s:

.file    "startup.s"
.arch    armv7-a
.fpu     vfpv3-d16
.thumb
.syntax  unified
.equ    __StackTop, 0x21000000
.global  _start
.align   2
.long    __StackTop
.long   _start    
_start:
mov     r0,#3
mov     r1,#5
add     r2, r0, r1
wait:    b       wait
.size    _start, .-_start
.end

执行build.cmd批处理过程,它将创建mps2-an500.elfmps2-an500.lst,并显示用于调试(非常(基本示例的QEMU和GDB命令:

build.cmd
QEMU/GDB commands:
optqemu-7.1.0qemu-system-arm -m 16M  -nographic -machine mps2-an500 -S -cpu cortex-m7 -gdb tcp::2345,ipv4 -kernel mps2-an500.elf
optarm11arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabibinarm-none-eabi-gdb

在一个控制台模式会话中,执行:

optqemu-7.1.0qemu-system-arm -m 16M  -nographic -machine mps2-an500 -S -cpu cortex-m7 -gdb tcp::2345,ipv4 -kernel mps2-an500.elf

在另一种情况下,执行GDB命令:

optarm11arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabibinarm-none-eabi-gdb --command=mps2-an500.gdb

在GDB会话中,按顺序执行以下命令:

target remote localhost:2345
file mps2-an500.elf
break _start
break wait
set $sp = 0x21000000
set $pc = _start 
stepi
stepi
stepi
info registers

GDB会议的记录应该如下所示:

optarm11arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabibinarm-none-eabi-gdb
GNU gdb (Arm GNU Toolchain 11.3.Rel1) 12.1.90.20220802-git
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=i686-w64-mingw32 --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://bugs.linaro.org/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) target remote localhost:2345
Remote debugging using localhost:2345
warning: No executable has been specified and target does not support
determining executable automatically.  Try using the "file" command.
0x00000014 in ?? ()
(gdb) file mps2-an500.elf
A program is being debugged already.
Are you sure you want to change the file? (y or n) y
Reading symbols from mps2-an500.elf...
(gdb) break _start
Breakpoint 1 at 0x8: file startup.s, line 12.
(gdb) break wait
Breakpoint 2 at 0x14: file startup.s, line 15.
(gdb) set $sp = 0x21000000
(gdb) set $pc = _start
(gdb) stepi
13               mov     r1,#5
(gdb) stepi
14               add     r2, r0, r1
(gdb) stepi
Breakpoint 2, _start () at startup.s:15
15      wait:    b       wait
(gdb) info registers
r0             0x3                 3
r1             0x5                 5
r2             0x8                 8
r3             0x0                 0
r4             0x0                 0
r5             0x0                 0
r6             0x0                 0
r7             0x0                 0
r8             0x0                 0
r9             0x0                 0
r10            0x0                 0
r11            0x0                 0
r12            0x0                 0
sp             0x21000000          0x21000000
lr             0xfffffff9          -7
pc             0x14                0x14 <_start+12>
xpsr           0x41000003          1090519043
fpscr          0x0                 0
(gdb)

最新更新