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

esb handler crash

I am trying to use ESB and BLE concurrently on NRF51822 SDK v11 SD130.. The BLE part is working fine but the ESB part keep causing error randomly. I put a break-point in app_error_handler and found that this is related to nrf_esb_event_handler.

I started my project from the example ble_app_uart.ESB_Timeslot. The operation is that the master device request data from slave device through ESB. The request is driven by app_timer every 1 second.

The code is as below:

void main_timeout_handler(void * p_context){
    uint32_t err_code;
    if (m_read_period){
	    m_read_period--;
	    if (m_MINIPM_read_period == 0){
		    m_read_period = C_DEFAULT_READ_PERIOD;
		    err_code = esb_timeslot_send_str(tx_buf, cmd1_LEN);
		    APP_ERROR_CHECK(err_code);
	    }
    }
}

Within 1-2minutes, I get an error that causes reset. Here is the call stack when error occur. image description

The error appear in the APP_ERROR_CHECK_BOOL after fifo_get_pkt():

void nrf_esb_event_handler(nrf_esb_evt_t const * p_event)
{
if (p_event->evt_id == NRF_ESB_EVENT_TX_FAILED)
{ 
    printf("f");            //Edited (2017/11/23)
    nrf_esb_flush_tx();

    m_tx_attempts += 1;
    m_state        = STATE_RX;
}

if (p_event->evt_id == NRF_ESB_EVENT_TX_SUCCESS)
{
    nrf_esb_payload_t payload;
    uint32_t          payload_len;

    printf("o");            //Edited (2017/11/23)

    /* Successful transmission. Can now remove packet from Tx FIFO. */
    payload_len = sizeof(payload);

    fifo_get_pkt(&m_transmit_fifo, (uint8_t *) &payload, &payload_len);
    APP_ERROR_CHECK_BOOL(payload_len == sizeof(payload));

    m_tx_attempts = 0;
}

if (p_event->evt_id & NRF_ESB_EVENT_RX_RECEIVED)
{
    printf("r");            //Edited (2017/11/23)
    /* Data reception is handled in a lower priority interrup. */
    /* Call UESB_RX_HANDLE_IRQHandler later. */
    NVIC_SetPendingIRQ(UESB_RX_HANDLE_IRQn);
}
}

--------Edit (2017/11/23)---------

I added debug message to see what is going on.

uint32_t esb_timeslot_send_str(uint8_t * p_str, uint32_t length)
{
    static nrf_esb_payload_t tx_payload;
    bool success;

    memset(&tx_payload, 0, sizeof(tx_payload));
    memcpy(tx_payload.data, p_str, length);
    tx_payload.length = length;
    tx_payload.pipe   = 0;
    
    printf("s");

    CRITICAL_REGION_ENTER();
    success = fifo_put_pkt(&m_transmit_fifo, (uint8_t *)&tx_payload, sizeof(tx_payload));
    CRITICAL_REGION_EXIT();
    
    return (success? NRF_SUCCESS: NRF_ERROR_NO_MEM);
}

//Short capture of this handler
void TIMESLOT_BEGIN_IRQHandler(void)
{
    ...
    if (m_tx_attempts < MAX_TX_ATTEMPTS)
    {  
        printf("t");
        fifo_peek_pkt(&m_transmit_fifo, (uint8_t *) &tx_payload, &tx_payload_len);
        APP_ERROR_CHECK_BOOL(tx_payload_len == sizeof(tx_payload));
    }
    ...
}

In uart, I can see "sttttto", "sttttttttttttto", "stttttstttt".

"sttttto": This is when it is normal.

"sttttttttttttto": This is pretty strange since it does not stop when it reach max attempt of 10 times.

"stttttstttt": If a new message is added before the previous is successfully sent, the error occur.

"f" never appear since it cannot go into NRF_ESB_EVENT_TX_FAILED in nrf_esb_event_handler.

It seems to be a problem that nrf_esb_event_handler is somehow not called such that it endlessly retry and cause other problems.

//----------Edit end (2017/11/23)--------

Basically I did not change much from the example. Can anyone help how I can solve this random reset issue? Any advise?

In addition to this random crash, there is another problem that unknown characters are being sent to UART. This only happen when ESB is enabled. I am not sure if this is also related to the random crash.

Uart Start!
ƒÖƒÖ
Uart Start!
ƒÖƒÖ
Parents Reply Children
No Data
Related