c - Qemu: fatal: Lockup: cant escalate 3 to Hardfault (Current Priority -1) 错误-Core Dumped

标签 c linux embedded stm32 qemu

我正在尝试在 QEMU 上使用 cortex M4 处理器模拟 STM32F407XX Controller 。我写的 .ld 文件如下:

ENTRY(_Reset)

MEMORY
{
  FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = 512K
  RAM (xrw)       : ORIGIN = 0x20000000, LENGTH = 128K
  CCMRAM (rw)     : ORIGIN = 0x10000000, LENGTH = 64K
  PERIPHERALS(rw) : ORIGIN = 0x40000000, LENGTH = 128K
}

SECTIONS
{

 .startup . : { stm32.o(.text) } >FLASH
 .text : { *(.text) } 
 .data : { *(.data) } >RAM AT> FLASH
 .bss : { *(.bss COMMON) } >RAM
 . = ALIGN(4);
 . = . + 0x400; /* required amount of stack */
 stack_top = 0x20020000;
}

当我生成 .elf 文件并运行代码时,出现错误

Qemu: fatal: Lockup: cant escalate 3 to Hardfault (Current Priority -1) error.
Aborted (Core Dumped)

我感觉是内存问题。我究竟做错了什么? 我已经按照STM32F407的引用手册要求分配了flash、RAM内存。

为什么首先会出现此错误?我该如何解决此错误? 谢谢。

最佳答案

将 vector 表放在正确的位置解决了这个问题。我在上面的评论中遵循了@peter Maydell 的所有说明。我在这里添加它们。

You can turn on some of the debug logging options of QEMU with -d ('in_asm,int,exec,cpu,guest_errors,unimp' are probably a good set to start with), which will tell you what your guest code is doing. I would start by checking that your ELF file has a vector table in it at the place where QEMU expects to find it. Otherwise QEMU will hard fault immediately out of reset (which is what the hardware does).

The core dump is expected: QEMU goes into lockup, but we don't emulate lockup correctly (strictly speaking QEMU should just sit there doing nothing like the real hardware does), so we print a register dump and abort(). As I said in my previous comment, your problem is almost certainly that your binary doesn't have a vector table.

The main thing you must have in your vector table is the entries for the initial PC and stack pointer. The interrupt and exception entries are worth putting in but will only be needed if there is an interrupt or exception. If you put in debugging handlers for the other faults you'll at least know when you get a fault due to a bug in the rest of your program, though

关于c - Qemu: fatal: Lockup: cant escalate 3 to Hardfault (Current Priority -1) 错误-Core Dumped,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55220313/

相关文章:

c - 读取文本文件并比较每一行

linux - OpenCV安装cuda9错误: Makefile:160: recipe for target 'all' failed make: *** [all] Error 2

c - 在 stringbuffer 对象中手动分配

linux - 删除带空格文件的 Shell 脚本

c - 将链接器脚本文件链接到源代码

c - 如何使用 Atmel Studio 中的调试器来使用 scanf?

c - SDL 将窗口保存为 BMP

无法在 C 中的 TXT 文件中单独写入

c - 当格式字符串末尾有换行符时,为什么 scanf 会要求输入两次?

linux - Bash - Awk sort -n 不排序