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

SoftDevice and TIMER interrupts

As per this thread: devzone.nordicsemi.com/.../question-regarding-hfclk-control the SD stack takes care of HFCLK, however as fas as I understand HFCLK is also responsible for timers - now, when SD stack is in use/enabled and it takes care for managing the HFCLK - e.g. shutting it down, etc - then what is the safe way to set-up TIMER2 interrupts?

Every time I try to initialize timer2 interrupt my code hangs on either NRF_CLOCK->TASKS_HFCLKSTART = 1; // start external 16HMz crystal oscillator

or

NRF_TIMER2->INTENSET = (TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos);

depending whether I do want to explicitly run the HFCLKSTART or not.

can someone shed some light on this topic please?!

THanks, Marcel

  • Hi Marcel,

    If you have tasks that are very timing critical, you can make sure that the HFCLK is running via these functions in nrf_soc.h:

    
    SVCALL(SD_CLOCK_HFCLK_REQUEST, uint32_t, sd_clock_hfclk_request(void));
    SVCALL(SD_CLOCK_HFCLK_RELEASE, uint32_t, sd_clock_hfclk_release(void));
    SVCALL(SD_CLOCK_HFCLK_IS_RUNNING, uint32_t, sd_clock_hfclk_is_running(uint32_t * p_is_running));
    
    

    sd_clock_hfclk_request() will generate an event "NRF_EVT_HFCLKSTARTED" or you can poll using sd_clock_hfclk_is_running().

    There are a couple of posts already on how to start a timer: devzone.nordicsemi.com/.../setting-timer2-interval

    Regarding "NRF_CLOCK->TASKS_HFCLKSTART = 1;", if you do this after the stack is initialized, you will end up in the hardfault handler, as this is a restricted peripheral (softdevice owns it)

    Best regards Håkon

Related