I'm having some difficulty creating a hard fault handler for the NRF51 which has an ARM CortexM0.
(note: the following code has been combined from different sources on the internet) Here's what I have so far:
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, #4tn"
"mov r1, lrtn"
"tst r0, r1tn" /* Check EXC_RETURN[2] */
"beq 1ftn"
"mrs r0, psptn"
"ldr r1,=hard_fault_handler_ctn"
"bx r1tn"
"1:mrs r0,msptn"
"ldr r1,=hard_fault_handler_ctn"
: /* no output */
: /* no input */
: "r0" /* clobber */
);
}
The error during compilation is the following:
Building target: project.elf
Invoking: Cross ARM C++ Linker
C:UsersStevenAppDataLocalTempccuAgDyP.ltrans9.ltrans.o: In function HardFault_Handler':
<artificial>:(.text.HardFault_Handler+0x18): undefined reference to
hard_fault_handler_c'
collect2.exe: error: ld returned 1 exit status
make: *** [FruityMesh.elf] Error 1
makefile:65: recipe for target 'project.elf' failed
In summary, it looks like the linker is having trouble finding the address for hard_fault_handler_c function. I would think that i would need to write assembly to import or include the path to this function but, this is just my suggestion. I haven't been able to write assembly for the M0 that compiles to do so.
Thank you
Aucun commentaire:
Enregistrer un commentaire