This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

When call the app_timer_start(),return error_code = 0x08,NRF_ERROR_INVALID_STATE?

At the start of programm, I create a timer_id used the follow code: app_timer_create(&m_sec_req_timer_id,APP_TIMER_MODE_SINGLE_SHOT,sec_req_timeout_handler);

when the device peered the iphone(ancs),send the QQ message to the iphone,the device could respond,then disconnected the device, after a time,connect the device,the device would call the function app_timer_start(m_sec_req_timer_id,SECURITY_REQUEST_DELAY,NULL),it will generate the error_code = 0x0000008.

So I trace this error_code,it stopped at the line about 1095 in file app_timer.c,it displayed mp_nodes[timer_id].state = STATE_FREE. I have created the timer_id at the start of programm,why it displayed STATE_FREE. How to solve this problem?Thank you.

image description image description

Parents
  • FormerMember
    0 FormerMember

    From the code in app_timer_start(..), it will return NRF_ERROR_INVALID_STATE if the timer_id is not properly initialized or if there is no timeout handler:

    uint32_t app_timer_start(app_timer_id_t timer_id, uint32_t timeout_ticks, void * p_context)
    {
    uint32_t timeout_periodic;
    timer_node_t * p_node = (timer_node_t*)timer_id;
    
    // Check state and parameters
    VERIFY_MODULE_INITIALIZED();
    
    if (timer_id == 0)
    {
        return NRF_ERROR_INVALID_STATE;
    }
    if (timeout_ticks < APP_TIMER_MIN_TIMEOUT_TICKS)
    {
        return NRF_ERROR_INVALID_PARAM;
    }
    if (p_node->p_timeout_handler == NULL)
    {
        return NRF_ERROR_INVALID_STATE;
    }
    
    // Schedule timer start operation
    timeout_periodic = (p_node->mode == APP_TIMER_MODE_REPEATED) ? timeout_ticks : 0;
    
    return timer_start_op_schedule(p_node,
                                   timeout_ticks,
                                   timeout_periodic,
                                   p_context);
    }
    

    Could you run the chip in debug mode and set a breakpoint in app_timer_start(..) when your device is about to re-connect to the iPhone? When the program hits app_timer_start(..), you can see why it fails.

  • FormerMember
    0 FormerMember in reply to FormerMember

    When the timer is being created, it's added to mp_nodes with the state "STATE_ALLOCATED". When starting the timer, app_timer checks mp_nodes, to check if the given timer has state "STATE_ALLOCATED". When you call app_timer_start(..), does timer_id matches the id given in app_timer_create(..)?

Reply
  • FormerMember
    0 FormerMember in reply to FormerMember

    When the timer is being created, it's added to mp_nodes with the state "STATE_ALLOCATED". When starting the timer, app_timer checks mp_nodes, to check if the given timer has state "STATE_ALLOCATED". When you call app_timer_start(..), does timer_id matches the id given in app_timer_create(..)?

Children
No Data
Related