gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 15:16:30 25 4
gpt4 key购买 nike

我在为具有 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] 错误 1makefile: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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com