Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Hardfault in FreeRTOS button code

Hello All,

I have taken usbd_ble_uart_freertos example and modified it for USB MIDI example (taken from Github) for nRF5 SDK and modified it to use nRF52833 SoC.

I am using Segger Embedded Studio on Windows 10 PC and EVK of ublox having NINA-B406 MCU.

USB MIDI is working fine until I press any button on the EVK. Code executes for button event and MIDI message is sent to PC Music application over USB and I can see the change accordingly in PC Music application. But after that the code resets - I can see in device manager is refreshed whenever I press any of the two buttons configured in the code.

Below is the part of code for UBS thread:

// Enter main loop.
for (;;)
{
    /* Waiting for event */
    UNUSED_RETURN_VALUE(ulTaskNotifyTake(pdTRUE, USB_THREAD_MAX_BLOCK_TIME));
    while (app_usbd_event_queue_process())
    {
        /* Nothing to do */
        NRF_LOG_INFO ("USB event processed");
    }
}

I debugged the code and found that app_usbd_event_queue_process () is completed successfully when button is pressed, but after that when it goes  to execute

   UNUSED_RETURN_VALUE(ulTaskNotifyTake(pdTRUE, USB_THREAD_MAX_BLOCK_TIME));

line. In this function when 

   taskEXIT_CRITICAL();

instruction is executed after that the debug shows "Unknown function at 0x00000A06".

After that it shows Hardfault error.

for Button, I have used below code:

   ret = bsp_init(BSP_INIT_BUTTONS, bsp_event_handler);

   UNUSED_RETURN_VALUE(bsp_event_to_button_action_assign(BSP_BOARD_BUTTON_0,
   BSP_BUTTON_ACTION_RELEASE,
   BTN_MIDI_KEY_0_RELEASE));

Button press event is detected and it goes to execute bsp_event_handler

Any help / guide to resolve this crash?

Or is there any example of button with FreeRTOS? it will also be helpful as a starting point.

Regards.

Parents
  • What is the priority of the button interrupt handler you have? (Check NRFX_GPIOTE_CONFIG_IRQ_PRIORITY in sdk_config.h file)

    You are seeing an assert inside the softdevice at address at 0XA06. This normally should forward this handling to the application app_error_fault_handler (second argument to sd_softdevice_enable) function. If you are using the default fault handler from the SDK, it should throw out some more information regarding the assert on the log output (depending on whether you have enabled logs and built the code with DEBUG macro enabled)

  • Thanks Susheel for your reply.

    button interrupt priority is set as below (in sdk_config.h)

    #ifndef NRFX_GPIOTE_CONFIG_IRQ_PRIORITY
    #define NRFX_GPIOTE_CONFIG_IRQ_PRIORITY 6
    #endif

    By the way, there is one good news. Earlier I have added USB MIDI functionality and then modified for buttons. Now, I have started again. In that, I have first checked button functionality in usbd_ble_uart_freertos example and found working. After that I have modified the main.c file for USB MIDI related changes and found that two buttons are working as expected.

    Next I was changing the name of project, solution, project and folders. I have changed all at once and to my surprise, the code has same behavior (not working) as mentioned in my first (main) post.

    So, I changed again and kept all the names same as earlier and found working again when checked. So, I changed the names one by one, and found that when I changed the project name from "usbd_ble_uart_freertos_pca10056_s140.emProject" to some other, the code was not working. So, for now, I have kept the project name as default.

    What can be the reason? There should not be project name dependency, right?

    One more thing, when I gave my code to my colleague, the same code is not working. He has Segger version 5.50b and I have 5.50d.

    Is there any dependency? What can be the reason?

Reply
  • Thanks Susheel for your reply.

    button interrupt priority is set as below (in sdk_config.h)

    #ifndef NRFX_GPIOTE_CONFIG_IRQ_PRIORITY
    #define NRFX_GPIOTE_CONFIG_IRQ_PRIORITY 6
    #endif

    By the way, there is one good news. Earlier I have added USB MIDI functionality and then modified for buttons. Now, I have started again. In that, I have first checked button functionality in usbd_ble_uart_freertos example and found working. After that I have modified the main.c file for USB MIDI related changes and found that two buttons are working as expected.

    Next I was changing the name of project, solution, project and folders. I have changed all at once and to my surprise, the code has same behavior (not working) as mentioned in my first (main) post.

    So, I changed again and kept all the names same as earlier and found working again when checked. So, I changed the names one by one, and found that when I changed the project name from "usbd_ble_uart_freertos_pca10056_s140.emProject" to some other, the code was not working. So, for now, I have kept the project name as default.

    What can be the reason? There should not be project name dependency, right?

    One more thing, when I gave my code to my colleague, the same code is not working. He has Segger version 5.50b and I have 5.50d.

    Is there any dependency? What can be the reason?

Children
Related