c - 硬故障处理 - Arm Cortex-M0

标签 c assembly arm cortex-m

我在为具有 ARM CortexM0 的 NRF51 创建硬故障处理程序时遇到一些困难。

(注意:以下代码是从互联网上的不同来源组合而来的) 这是我到目前为止所拥有的:

    static void hard_fault_handler_c(unsigned int * hardfault_args)
{
    unsigned int stacked_r0;
    unsigned int stacked_r1;
    unsigned int stacked_r2;
    unsigned int stacked_r3;
    unsigned int stacked_r12;
    unsigned int stacked_lr;
    unsigned int stacked_pc;
    unsigned int stacked_psr;

    stacked_r0 = ((unsigned long) hardfault_args[0]);
    stacked_r1 = ((unsigned long) hardfault_args[1]);
    stacked_r2 = ((unsigned long) hardfault_args[2]);
    stacked_r3 = ((unsigned long) hardfault_args[3]);

    stacked_r12 = ((unsigned long) hardfault_args[4]);
    stacked_lr = ((unsigned long) hardfault_args[5]);
    stacked_pc = ((unsigned long) hardfault_args[6]);
    stacked_psr = ((unsigned long) hardfault_args[7]);

    for(;;);
}

void HardFault_Handler(void)
{
    asm volatile(  
        "movs r0, #4\t\n"  
        "mov  r1, lr\t\n"  
        "tst  r0, r1\t\n" /* Check EXC_RETURN[2] */  
        "beq 1f\t\n"  
        "mrs r0, psp\t\n"  
        "ldr r1,=hard_fault_handler_c\t\n"  
        "bx r1\t\n"  
        "1:mrs r0,msp\t\n"  
        "ldr r1,=hard_fault_handler_c\t\n"  
        : /* no output */  
        : /* no input */  
        : "r0" /* clobber */  
    );  
}

编译时出现错误如下: 构建目标:project.elf 调用:跨ARM C++链接器 C:\Users\Steven\AppData\Local\Temp\ccuAgDyP.ltrans9.ltrans.o:在函数 HardFault_Handler': <artificial>:(.text.HardFault_Handler+0x18): undefined reference to 中硬故障处理程序c' collect2.exe:错误:ld 返回 1 退出状态 make: *** [FruityMesh.elf] 错误 1 makefile:65: 目标“project.elf”的配方失败

总之,链接器似乎无法找到 Hard_fault_handler_c 函数的地址。我认为我需要编写程序集来导入或包含此函数的路径,但这只是我的建议。我无法为 M0 编写汇编来进行编译。

谢谢

最佳答案

我建议升级到version 11 NRF SDK 的版本,它添加了对硬故障处理程序的内置支持(请参阅 nRF5_SDK_11.0.0_89a8197/components/libraries/hardfault)。

关于c - 硬故障处理 - Arm Cortex-M0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33045201/

相关文章:

java - 如何使用 EVP_Sign 函数计算签名

c - 在malloc C/C++之前,malloc无需类型转换即可工作

c - 给定 Assembly,翻译成 C

ARM M3 重定位代码 -> 故障

c - "Use"h2ph 从 C 头文件生成的 Perl 文件?

c - 将 int 转换为 short 并截断后,如何确定新值?

linux - 在汇编中使用 printf 会导致管道输出为空,但在终端上有效

assembly - 转换十六进制/十进制数 (Assembly-TASM)

xcode - ARM NEON 汇编程序错误 : "instruction cannot be conditional"

security - 使用 ARM TrustZone 防止从非安全世界访问内存区域