DW3000_API_DEBUG HardFault_Handler

The model used is the DWM3001CDK EV board.

I downloaded DW3xxx_XR6.0C_24Feb2002.zip from Qorvo’s website

Like it’s written on readme
SES V5.10A and nRF52sdk 17.02 versions are being used.

The build went well without error.

However, when I actually downloaded it to the board, the board didn’t work, so when I debugged it, I found it couldn’t get out of HardFault_Handler() as soon as it started.

I think the source code is aimed at the nrf52840-DK board, so I changed the file

system_nrf52840.c → system_nrf52833.c
ses_startup_nrf52840s → ses_startup52833.s

However, it keeps falling into HardFault_Handler().

Can you suggest what I should do?

Hi @woosangjin!

There are more things to change in the project configuration, you also have to create a custom board header and include it to the project.
I recommend you to use the new DW3_QM33_SDK_1.0.0 instead, the SDK itself has the DWM3001CDK as a target, and if you want to build the driver examples you can copy the DWM3001CDK custom header and other defines from the project folder.

Kind regards!

The processor will jump to HardFault handler vector, generally when a hardware exception happens. You can analyze the exception a little more by extending the handler. Currently the handler is just an instruction branching to itself (infinite loop). You can rewrite that assembly portion , for example by:

 .thumb_func
  .weak   HardFault_Handler
HardFault_Handler:
  TST lr, #4               // Test EXC_RETURN bit 2 to check which stack is in use
  ITE EQ                   // If equal (EXC_RETURN bit 2 = 0), use main stack (MSP)
  MRSEQ r0, MSP            // Load MSP into R0 if using main stack
  MRSNE r0, PSP            // Load PSP into R0 if using process stack
  B hardfault_c_handler    // Branch to C handler, passing stack pointer in R0

with a C handler defined at any place in your code:

#include "core_cm4.h"

// Define the structure of the stack frame pushed during the exception
typedef struct
{
    uint32_t r0;
    uint32_t r1;
    uint32_t r2;
    uint32_t r3;
    uint32_t r12;
    uint32_t lr;
    uint32_t pc;
    uint32_t psr;
} HardFaultStackFrame;

void hardfault_c_handler(HardFaultStackFrame *stackFrame)
{
    // Fault status registers
    uint32_t cfsr = SCB->CFSR;   // Configurable Fault Status Register
    uint32_t hfsr = SCB->HFSR;   // Hard Fault Status Register
    uint32_t mmfar = SCB->MMFAR; // Memory Management Fault Address Register
    uint32_t bfar = SCB->BFAR;   // Bus Fault Address Register
    uint32_t afsr = SCB->AFSR;   // Auxiliary Fault Status Register

    // Optionally, inspect the stacked registers to find the cause
    uint32_t stacked_r0 = stackFrame->r0;
    uint32_t stacked_r1 = stackFrame->r1;
    uint32_t stacked_r2 = stackFrame->r2;
    uint32_t stacked_r3 = stackFrame->r3;
    uint32_t stacked_r12 = stackFrame->r12;
    uint32_t stacked_lr = stackFrame->lr;
    uint32_t stacked_pc = stackFrame->pc;
    uint32_t stacked_psr = stackFrame->psr;

    // Here you can add logic to log or analyze the fault cause, like printing it
    // Example: printing to a debug console, logging the values, or flashing LEDs
    
    // Infinite loop to halt the program for debugging
    while (1);
}

There can be multiple possibilities why the exception is thrown. Try to check the instruction at which it fails in the disassembly window at debug.