This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

crashing from _start without even entering into main() function

Hi,

I am using nrf52832 custom board and sdk17.2.0.

My application is a Freertos application. I see that my application is going to hardfault from _start without entering into the main() function.

Attached sdk_config.h , FreeRTOSConfig.h and the screenshot of the hardfault for reference.

Can someone please help me to resolve the issue?

 8358.FreeRTOSConfig.h6215.sdk_config.h

Parents Reply
  • Hi Swetha, I could try to reply to you within 24 hours of your query, 

    swetha Paladugu said:
    yes after disabling NRF_LOG_ENABLED the issue went away

     It looks like the NRF_LOG is taking too much stack and what you are seeing is a possible stack overflow and hence a memory corruption.

    Normally in our examples we let logger run in its own thread so that we can calibrate the stack size it needs explicitly. For example in our SDK\examples\ble_peripheral\ble_app_hrs_freertos\main.c you can see that we create a logger thread.

    #if NRF_LOG_ENABLED
        // Start execution.
        if (pdPASS != xTaskCreate(logger_thread, "LOGGER", 256, NULL, 1, &m_logger_thread))
        {
            APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
        }
    If you have already done it, then try increasing the stack size for both logger thread and "Thread #2" from the screenshot

Children
  • Yes i'm already doing it. 

    the call stack doesn't clearly say which task it is running. 

    and one more thing i have added the log message in the main function itself not in the task before starting scheduler.

    NRF_LOG_INFO("Current RTC time : %u",get_current_time());

    // nrf_sdh_freertos_init(advertising_start, NULL);

    nrf_sdh_freertos_init(NULL, NULL);

    // Activate deep sleep mode.
    SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
    // Start FreeRTOS scheduler.
    vTaskStartScheduler();

  • If increasing the task stack sizes did not help, then I am not sure what is causing this hardfault. if the hardfault_c_handler is not able to give any meaningful address and cause for this hardfault, then it must be a memory corruption that happened that during somewhere in the backend of nrf_log. Try to step through the debugger and try to pin point the exact line where the hardfault is happening. When you understand the context of this hardfault, we might get more hints on how to fix it.

  • but it is not entering into main function itself to step in and debug

  • I see, seeing "Thread #2" in your snapshot made me assume that your device has started into main normally.
    Then something is entirely wrong in your setup. I can see that you have eclipse project. Which startupup files did you add to that project? Is the configuration of the project correct with all the correct preprocessor defines and device files matching nrf52832 device you are using? I do not use eclipse so it is hard for me to understand why your device does not boot properly into main. Seems like a startup issue which mostly point to configuration then.

  • i think i found the issue.

    On calling the below rtc function, that issue is coming.

    The issue is coming from return (mktime(&t1));. If i comment this then i dont see the issue.

    But that is needed. Can you please help?

    uint32_t get_current_time(void)
    {

    rtc_t nowTime;


    get_time(&nowTime);

    struct tm t1 = {.tm_year = RTC_Bcd2ToByte(nowTime.year) + BASE_YEAR,
    .tm_mon = RTC_Bcd2ToByte(nowTime.month) - 1, /* In C, Jan = 0 */
    .tm_mday = RTC_Bcd2ToByte(nowTime.days),
    .tm_wday = RTC_Bcd2ToByte(nowTime.weekDay),
    .tm_hour = RTC_Bcd2ToByte(nowTime.hour),
    .tm_min = RTC_Bcd2ToByte(nowTime.min),
    .tm_sec = RTC_Bcd2ToByte(nowTime.sec)};

    return (mktime(&t1));
    }

Related