简体   繁体   English

在ARM Cortex-M0 +上调试硬故障(使用CMSIS DSP库)

[英]Debugging Hard Fault on ARM Cortex-M0+ (using CMSIS DSP library)

I'm using the CMSIS DSP library on a Cortex-M0+. 我正在Cortex-M0 +上使用CMSIS DSP库。 Some functions, such as sqrt and FFT, are resulting in hard faults. 一些功能(例如sqrt和FFT)会导致硬故障。

The arm_sqrt_f32 function calls sqrtf : arm_sqrt_f32函数调用sqrtf

 arm_sqrt_f32(
 float32_t in,
 float32_t * pOut)
 [...]
 *pOut = sqrtf(in);

part of the generated code: 生成的代码的一部分:

0x00003914:   bl 0x49e8 <sqrtf>
0x00003918:   adds r2, r0, #0
0x0000391a:   ldr r3, [r7, #0]
0x0000391c:   str r2, [r3, #0]

The hard fault happens on the str instruction at address 0x0000391c. 硬故障发生在地址为0x0000391c的str指令上。 When at this line, the registers are: 在此行时,寄存器为:

$r1 0x0 
$r2 0x40000000  
$r3 0x0 
$r4 0x0 
$r5 0x200017fc  
$r6 0x0 
$r7 0x200017e0  
$r8 0xfff7ffff  
$r9 0xefbffffe  
$r10    0xff7fffff  
$r11    0x0 
$r12    0x0 

the SP register is 0x200017e0, an address containing 0. SP寄存器为0x200017e0,该地址包含0。

I can't figure out why I'm getting this hard fault. 我不知道为什么我会遇到这个困难。 What should I do? 我该怎么办?

Thanks! 谢谢!

If the Cortex-M0 fault mechanism is the same as the Cortex-M3/4/7 fault mechanism, then the following page provides detailed information on how to decode the fault stack, giving you the address of the faulting instruction, as well as the register values at the time. 如果Cortex-M0故障机制与Cortex-M3 / 4/7故障机制相同,则下一页将提供有关如何解码故障堆栈的详细信息,并提供故障指令的地址以及当时注册值。 http://www.freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.html http://www.freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.html

Lets look at exactly what your str call is doing by looking at this page your str call is doing str r2,[r3, #0] which translates to (if i'm not mistaken) : 通过查看此页面上的str调用正在执行str r2,[r3,#0]来确切地了解您的str调用正在做什么,这将转换为(如果我没有记错的话):

store r2 in the address r3 offset by #0 将r2存储在偏移#0的地址r3中

Looking at those register values, you are trying to put 0x40000000 into location 0x0 offset by 0, so 0x0 still. 查看这些寄存器的值,您尝试将0x40000000放入位置0x0偏移0的位置,因此仍为0x0。 It is the equivalent of a segmentation fault, you are trying to access memory that is not avaliable to you thus causing the hard fault. 这等效于分段错误,您正在尝试访问不可用的内存,从而导致硬故障。

Seeing as how that code is generated, I'm assuming you are giving it a faulty pOut pointer. 看到代码是如何生成的,我假设您给它提供了错误的pOut指针。

Make sure you aren't calling the function by doing arm_sqrt_f32(float32_t foo, float32_t* pOut) , you'll want to call it by doing arm_sqrt_f32(float32_t foo, float32_t &pOut) where pOut may be delcared as float32_t pOut = bar; 确保您没有通过执行arm_sqrt_f32(float32_t foo, float32_t* pOut)来调用函数arm_sqrt_f32(float32_t foo, float32_t* pOut)要通过执行arm_sqrt_f32(float32_t foo, float32_t &pOut)来调用此arm_sqrt_f32(float32_t foo, float32_t &pOut)其中pOut可能被视为float32_t pOut = bar; since, as a pointer arguement, its looking for an address 因为,作为指针的争论,它寻找一个地址

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM