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
  • Seems like it is happening inside the NRF_LOGs. 

    1. If the function call stack can be trusted, then try to disable the logs to see if the issue goes away.
      1. If it does, then the log buffer might not be enough and we can focus more on looking a bit deeper into this NRF_LOG configuration issue. 
      2. If it does not help, then most likely the stack is corrupt and I wont be trusting this function call stack much.
    2. If this is a stack corruption then could happen because your thread might have caused a stack overflow. Try to increase the stack size significantly for this thread and see if that helps.
  • yes after disabling NRF_LOG_ENABLED the issue went away.

  • 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));
    }

  • you are returning the address of t1 which is allocated from stack and the address is invalid outside the get_current_time scope. Either make t1 static by declaring as below (so that it its memory pointer remains valid outside the get_current_time scope 

    static struct tm t1 = {.tm_year = RTC_Bcd2ToByte(nowTime.year) + BASE_YEAR,

    or declare this struct as global variable so it is allocated in the different section of the memory with memory pointer address valid through the runtime of your application.

  • that didn't solve the issue.

    rtc_t nowTime;

    struct tm t1;

    uint32_t get_current_time(void)
    {
    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)};

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

    return (mktime(&t1));

    }

    And same issue is coming even on calling the below set current time function, with ctime and localtime. With this what i observe is there is some issue using the time.h functions. Do i have to enable any macros or add any paths to the project? 

    void set_current_time(time_t current_time)
    {
    ctime(&current_time);

    struct tm ts = *localtime(&current_time);
    rtc_t time_to_rtc = {.sec = RTC_ByteToBcd2(ts.tm_sec),
    .min = RTC_ByteToBcd2(ts.tm_min),
    .hour = RTC_ByteToBcd2(ts.tm_hour),
    .days = RTC_ByteToBcd2(ts.tm_mday),
    .weekDay = RTC_ByteToBcd2(ts.tm_wday),
    .month = RTC_ByteToBcd2(ts.tm_mon + 1),
    .year = RTC_ByteToBcd2(ts.tm_year - BASE_YEAR)};

    set_time(&time_to_rtc);
    }

Reply
  • that didn't solve the issue.

    rtc_t nowTime;

    struct tm t1;

    uint32_t get_current_time(void)
    {
    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)};

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

    return (mktime(&t1));

    }

    And same issue is coming even on calling the below set current time function, with ctime and localtime. With this what i observe is there is some issue using the time.h functions. Do i have to enable any macros or add any paths to the project? 

    void set_current_time(time_t current_time)
    {
    ctime(&current_time);

    struct tm ts = *localtime(&current_time);
    rtc_t time_to_rtc = {.sec = RTC_ByteToBcd2(ts.tm_sec),
    .min = RTC_ByteToBcd2(ts.tm_min),
    .hour = RTC_ByteToBcd2(ts.tm_hour),
    .days = RTC_ByteToBcd2(ts.tm_mday),
    .weekDay = RTC_ByteToBcd2(ts.tm_wday),
    .month = RTC_ByteToBcd2(ts.tm_mon + 1),
    .year = RTC_ByteToBcd2(ts.tm_year - BASE_YEAR)};

    set_time(&time_to_rtc);
    }

Children
Related