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

app_timer has crashed on running

Hello,

My code( I add a source code lower ) has error on bold line printing NRF_ERROR_INVALID_STATE. The program uses three timers and init by "MAX_TIMERS = 6" and "OP_QUEUE_SIZE = 5".

Because of NRF_ERROR_INVALID_STATE, I create new timer before start timer(bold line!) but in that case, app_timer_create() is crashed by NRF_ERROR_NO_MEM. Before I said, the program not use timers over "MAX_TIMERS = 6". Even I increase values of "APP_TIMER_MAX_TIMERS" and "APP_TIMER_OP_QUEUE_SIZE" but same problem occurs.

I don't know that what is wrong on my code.

Thanks.


int main() {
timers_init();
ble_start();

for (;;)
    {
        uint8_t CurFrm[MAX_BLE_DATA_LENGTH] = {0,};
        
        NVIC_DisableIRQ(UART0_IRQn);
        popFrmQueue(CurFrm);
        NVIC_EnableIRQ(UART0_IRQn);
        
        if ( CurFrm[RF_TYPE_IND] == RFTYPE_RF) {
            ble_stop();
            RF_init(addr); 
            memcpy(packet,(CurFrm+1), MAX_BLE_DATA_LENGTH-1);
            RF_send();
            ble_start();
            
        } else if ( CurFrm[RF_TYPE_IND] == RFTYPE_BLE ) {
            
            if ( BLE_CONN_FLAG == true ) {
                err_code = app_timer_start(m_data_send_timer_id, DATA_SEND_INTERVAL, NULL);
                APP_ERROR_CHECK(err_code);
            }
            
            
            TIMEOUT_FLAG = false; // timeout flag init
            **err_code = app_timer_start(m_wait_timer_id, BLE_TX_COMPLTE_WAIT_INTERVAL, NULL);**
            APP_ERROR_CHECK(err_code);
            
            while (BLE_TX_COMPLETE_FLAG != true && BLE_CONN_FLAG == true && TIMEOUT_FLAG != true) { 
                err_code = sd_app_event_wait();
                APP_ERROR_CHECK(err_code);
            }
            err_code = app_timer_stop(m_wait_timer_id);
            APP_ERROR_CHECK(err_code);
            
            TIMEOUT_FLAG = false; // timeout flag init
            simple_uart_putstring((const uint8_t *)"ble tx complete end\r\n");
            if ( BLE_TX_COMPLETE_FLAG == true ) {
                err_code = app_timer_stop(m_data_send_timer_id);
                APP_ERROR_CHECK(err_code);
                BLE_TX_COMPLETE_FLAG = false;
            }
        }
return 0;
}

Parents
  • The only cases in which app_timer_start can return invalid state should be if the module isn't initialized or if the timer_id_t you try to start isn't actually created. I therefore suspect that the error is in your timers_init() function, either in that the APP_TIMER_INIT() is done incorrectly or that the m_wait_timer_id isn't created properly.

    Remember that you can see the source code of all the app_ modules, which makes it easier to find errors like this. The relevant checks of app_timer_start are like this:

    
    if (mp_nodes == NULL)
    {
        return NRF_ERROR_INVALID_STATE;
    }
    if ((timer_id >= m_node_array_size) || (timeout_ticks < APP_TIMER_MIN_TIMEOUT_TICKS))
    {
        return NRF_ERROR_INVALID_PARAM;
    }
    if (mp_nodes[timer_id].state != STATE_ALLOCATED)
    {
        return NRF_ERROR_INVALID_STATE;
    }
    
    
  • Sorry for replying late. I don't know you comment additionally. I think notification tap doesn't alarm about comment.

    I'll send message soon.

    Always thanks Ole.

    • yjpark
Reply Children
No Data
Related