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

  • Those API are working quite fine on my end with the nRF5_SDK_17.0.2_d674dde\examples\ble_peripheral\experimental\ble_app_cgms example.

    FreeRTOS should not have any role in this behavior except the stack sizes I mentioned before. So I am not sure what causes the issue you are seeing.

Related