Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF52832 Timer Enable Disable Fails Assert and Hard Faults

I am having an issue where i use a GPIO pin to start and stop a timer based on device state and a GPIOE toggle event.  The issue i am seeing is that nrf_drv_timer_enable and nrf_drv_timer_disable randomly fail assert and this is causing a hard fault.  I need this timer to start and stop so that i can get to lowest connected power states when it is not needed.  I cant see a really good reason for this to be happening so any help would be appreciated.  Below is the code.

void MilesWakeHandler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
    uint8_t fret = EXIT_SUCCESS;
    /* Get Pin Value */
    uint32_t sense = nrf_gpio_pin_read(UTA_MILES_WAKE);
    if(sense == 1)
    {
        //NRF_LOG_DEBUG("Miles Wake High");
        nrf_drv_timer_enable(&m_timer1);        //Start Timer
        //TODO request timeslot if needed
    }
    else if (sense == 0)
    {
        nrf_drv_timer_disable(&m_timer1);     //Stop Timer
        nrf_drv_timer_clear(&m_timer1);       //Clear Timer
        //NRF_LOG_DEBUG("Miles Wake Low");
        appMiles_ProcessHits();
        //TODO stop timeslot if needed
        //app_sched_event_put(NULL, 0, (app_sched_event_handler_t)MilesSleep);
    }
    
}

Parents
  • You don't say what the min and max of the timer interval is.  A common mistake is to exercise the timers in ISR's which are inherently delayed and sometime lost if you don't prepare properly for the event in code.

    Since all you do is start and stop a timer based on gpio, you should have all that done in ppi/gpiote instead of pulling it out to an interrrupt.  The ppi/gpiote can be configured such that a pin assert drives timer events.  

    Just remember the min timer time is 2 pclk's. 

Reply
  • You don't say what the min and max of the timer interval is.  A common mistake is to exercise the timers in ISR's which are inherently delayed and sometime lost if you don't prepare properly for the event in code.

    Since all you do is start and stop a timer based on gpio, you should have all that done in ppi/gpiote instead of pulling it out to an interrrupt.  The ppi/gpiote can be configured such that a pin assert drives timer events.  

    Just remember the min timer time is 2 pclk's. 

Children
Related