3. Analyzing Hard-Fault

In this section we see to track a hard-fault in DA1453x,DA1458x project step by step.

3.1. Configuration

  1. We have to connect User LED on jumper of development kits before we proceed. By default those jumpers are connected. Check on DA14585 Devkitp , DA14531 Devkitp or DA1453x Devkipt. You may need to review Devkitp Getting started guides for example here , please have a look at Getting Started with the Pro-Development Kits for User LED.

USB kit

On Renesas BLE USB kits User LED is connected to the chip directly.

  1. Open ../target_apps/ble_examples/ble_app_peripheral/Keil_5/\ble_app_peripheral.uvprojx

  2. In user_custs1_impl.c replace with the following code in function user_svc1_led_wr_ind_handler. Just after else if block finishes ,add:

*(uint32_t*)0x07F00000 = 0x90;

So the block code will look like:

void user_svc1_led_wr_ind_handler(ke_msg_id_t const msgid,
                             struct custs1_val_write_ind const *param,
                             ke_task_id_t const dest_id,
                             ke_task_id_t const src_id)
{
uint8_t val = 0;
memcpy(&val, &param->value[0], param->length);

if (val == CUSTS1_LED_ON)
        {
        GPIO_SetActive(GPIO_LED_PORT, GPIO_LED_PIN);
        }
else if (val == CUSTS1_LED_OFF)
        {
        GPIO_SetInactive(GPIO_LED_PORT, GPIO_LED_PIN);
        }
// test
*(uint32_t*)0x07F00000 = 0x90;
}

This line,purposefully creates a hard-fault which we aim to trap.

  1. Build the project for your target (here Da14531).

  2. After the code is successfully built, press on the Start/Stop Debugging button in Task Bar.

_images/Image11.PNG
  1. After the debugging session is started, press Run button to start the execution of code.

_images/Image12.PNG
  1. Open iOS Light-Blue - you will find your device is advertising.

  2. Connect to your device using Light-Blue.

  3. Find - LED State characteristics and press on it.

  4. Find - write new value - and press on it.

_images/ble_connected.PNG
  1. Write 1 and press Done

  2. You will see the Light-Blue shows disconnection alert message.

_images/ble_disconnected.PNG
  1. Go to Keil IDE you will see a hard-fault is trapped.

_images/Image2.PNG

At this point there are 2 options to debug hard-fault:

Option 1: When call stack is generated:
  1. Open KEIL IDE call stack from:

    [View->Call stack window]

  2. Press right button mouse on HardFault_HandlerC and choose Show Caller Code option

    _images/Image3.PNG
  3. You will see in disassembly window that where exactly the hardfault has occurred. You can see the hardfault in code window too.

    _images/Image4.PNG
Option 2: When call stack is not generated
  1. Open KEIL IDE call stack from

    [View->Register window]

  2. Open KEIL IDE call stack from

    [View->Memory window->Memory 1]

  3. In Registers window find out:

    • Stack pointer (SP) for this study the address is 07FC5400

    • Program counter (PC) for this study the address is 0x07FC0288

    • Main stack pointer (MSP) for this study the address is 0x07FC5400

    _images/Image5.PNG
  4. Copy Main stack pointer (MSP) in this study the address is 0x07FC5400 Paste in Address of Memory 1 window. Then create the memory address as instructed below:

    In this study it is 0x07FC32A6
    _images/Image6.PNG
  5. Right click on [Disassembly window] and Select [Show Disassembly at Address…]

    _images/Image7.PNG
  6. Paste the address 0x07FC32A6 in [Show code at address window] and press [Go To] button.

    _images/Image8.PNG
  7. Check the disassembly window.

    _images/Image9.PNG
  8. Check the cursor position in [code window].

_images/Image10.PNG