nrf5-calendar-example SOFTDEVICE: INVALID MEMORY ACCESS

I try to integrate https://github.com/NordicPlayground/nrf5-calendar-example into Keil project. But the following error messages shown when accessing NRF_CLOCK.

error messages

nrf5-calendar-example SOFTDEVICE: INVALID MEMORY ACCESS

source code

int main(void) {
    _initVariables();
    

    // Initialize.
    log_init(); // Power_saving
    uart_init(); // Power_saving
    //_showInfo();
    fstorageInit();
    batteryVoltageInit();
    timerInit();
    button_events_init();
    scheduler_init();
    power_management_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();
    db_discovery_init();
    services_init();
    advertising_init();
    conn_params_init();
    timerPeriodStart();
    timerStart();
    

    //  SOFTDEVICE: INVALID MEMORY ACCESS occurred when running the following code
    NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_HFCLKSTART = 1;
    while(NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);
    
     nrf_cal_init();
     nrf_cal_set_callback(calendar_updated, 4);

}

  • Thanks for your great support! Time is correct after changing nrf_cal_set_time() as follows.

    void nrf_cal_set_time(uint32_t year, uint32_t month, uint32_t day, uint32_t hour, uint32_t minute, uint32_t second) {
        NRF_LOG_DEBUG("nrf_cal_set_time(%u, %u, %u, %u, %u, %u) e\n", year, month, day, hour, minute, second);
        static time_t uncal_difftime, difftime, newtime;
        time_struct.tm_year = year - 1900;
        time_struct.tm_mon  = month - 1;
        time_struct.tm_mday = day;
        time_struct.tm_hour = hour;
        time_struct.tm_min  = minute;
        time_struct.tm_sec  = second;   
        newtime = mktime(&time_struct);
      
        CAL_RTC->TASKS_CLEAR = 1;  
        
        // Calculate the calibration offset
        if (m_last_calibrate_time != 0) {
            difftime = newtime - m_last_calibrate_time;
            uncal_difftime = m_time - m_last_calibrate_time;
            m_calibrate_factor = (float)difftime / (float)uncal_difftime;
        }
        
        // Assign the new time to the local time variables
        m_time = m_last_calibrate_time = newtime;
        //_nrf_cal_print_time_t(newtime);
        gCalTimeSet = true;
        NRF_LOG_DEBUG("nrf_cal_set_time(%u, %u, %u, %u, %u, %u) x\n", year, month, day, hour, minute, second);
    }   

    Log messages.

     <debug> app: nrf_cal_set_time(2022, 6, 29, 9, 24, 49) x
     0>
     0> <info> app:
     0>
     0> <debug> app: Uncalibrated time:    06/29/22 - 09:24:49
     0>
     0> <debug> app: Calibrated time:    06/29/22 - 09:24:49

Related