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

}

Parents
  • Hello,

    The app does not have write access to the CLOCK peripheral when the Softdevice is enabled, hence the assert (See Hardware peripherals). Instead you have to access it via the provided Softdevice APIs such as sd_clock_hfclk_request().

    However, it should not be necessary to start HF crystal oscillator for the calendar library, so my suggestion would be to simply not include this code:

        NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
        NRF_CLOCK->TASKS_HFCLKSTART = 1;
        while(NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);

    Best regards,

    Vidar

  • Thanks for your reply! I have changed above code to the following code.

    const ret_code_t errCode = sd_clock_hfclk_request();
        if (errCode != NRF_SUCCESS) {
            NRF_LOG_WARNING("sd_clock_hfclk_request() failed\n");
        }    

        uint32_t hfclkIsRunning = 0;

        while (!hfclkIsRunning) {
            APP_ERROR_CHECK(sd_clock_hfclk_is_running(&hfclkIsRunning) );
        }

    Now it hangs at nrf_cal_init() as the following error messages.

    <debug> app: nrf_cal_init() e
     0>
     0> <error> app: SOFTDEVICE: INVALID MEMORY ACCESS

    void nrf_cal_init(void) {
        NRF_LOG_DEBUG("nrf_cal_init() e\n");
        // Select the 32 kHz crystal and start the 32 kHz clock
        NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos;
        NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
        NRF_CLOCK->TASKS_LFCLKSTART = 1;
        while(NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);
        NRF_LOG_DEBUG("1\n");
        
        // Configure the RTC for 1 minute wakeup (default)
        CAL_RTC->PRESCALER = 0xFFF;
        CAL_RTC->EVTENSET = RTC_EVTENSET_COMPARE0_Msk;
        CAL_RTC->INTENSET = RTC_INTENSET_COMPARE0_Msk;
        CAL_RTC->CC[0] = m_rtc_increment * 8;
        CAL_RTC->TASKS_START = 1;

    }

Reply
  • Thanks for your reply! I have changed above code to the following code.

    const ret_code_t errCode = sd_clock_hfclk_request();
        if (errCode != NRF_SUCCESS) {
            NRF_LOG_WARNING("sd_clock_hfclk_request() failed\n");
        }    

        uint32_t hfclkIsRunning = 0;

        while (!hfclkIsRunning) {
            APP_ERROR_CHECK(sd_clock_hfclk_is_running(&hfclkIsRunning) );
        }

    Now it hangs at nrf_cal_init() as the following error messages.

    <debug> app: nrf_cal_init() e
     0>
     0> <error> app: SOFTDEVICE: INVALID MEMORY ACCESS

    void nrf_cal_init(void) {
        NRF_LOG_DEBUG("nrf_cal_init() e\n");
        // Select the 32 kHz crystal and start the 32 kHz clock
        NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos;
        NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
        NRF_CLOCK->TASKS_LFCLKSTART = 1;
        while(NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);
        NRF_LOG_DEBUG("1\n");
        
        // Configure the RTC for 1 minute wakeup (default)
        CAL_RTC->PRESCALER = 0xFFF;
        CAL_RTC->EVTENSET = RTC_EVTENSET_COMPARE0_Msk;
        CAL_RTC->INTENSET = RTC_INTENSET_COMPARE0_Msk;
        CAL_RTC->CC[0] = m_rtc_increment * 8;
        CAL_RTC->TASKS_START = 1;

    }

Children
Related