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

Device hang in libuarte function when no debugger run

Hi,
Our platform is NRF-52833

Our project use RS485 bus (nordic's uart + a 485 chip) to communicate with other device.
And we choose the libuarte to be the uart handler to tranxfer data.
It works fine when device is in debugging run(segger, SWD).

But if running without debugging, device will hang after uart start to tranxfer data.
(I create a timer to print log(RTT) periodically to check if device alive or not)
Device can be recovered back by attaching on debugger.

It's hard to debug since this issue only happen in no debugger attached.
I tried the different baudrates but issue still happen.
I also tried to change the LF_CLK source from XTAL to RC and this issue still happen.
(Our device default use an external 32.768Khz XTAL)


Could anyone give me some suggestion?

The below is the main framework of my program:

Init:
	nrf_drv_clock_lfclk_request(NULL);
	
    nrf_libuarte_async_config_t nrf_libuarte_async_config = {
            .tx_pin     = UART_ERV_TX,
            .rx_pin     = UART_ERV_RX,
            .baudrate   = buadrate,
            .parity     = NRF_UARTE_PARITY_EXCLUDED,
            .hwfc       = NRF_UARTE_HWFC_DISABLED,
            .timeout_us = 100,
            .int_prio   = APP_IRQ_PRIORITY_LOW
    };
    err_code = nrf_libuarte_async_init(&libuarte, &nrf_libuarte_async_config, uart_event_handler, (void *)&libuarte);
    APP_ERROR_CHECK(err_code);
    
    nrf_libuarte_async_enable(&libuarte);


Handler:
void rs485_byte_send(uint8_t tx_byte)
{
    uint32_t err_code;
    uint8_t  data;

    data = tx_byte;
    is_byte_sent = false;
    err_code = nrf_libuarte_async_tx(&libuarte, &data, 1);
}

bool rs485_byte_available(uint8_t *data_register)
{
    bool data_available = false; /* return value */

    if (!FIFO_Empty(&Receive_Buffer)) {
        if (data_register) {
            *data_register = FIFO_Get(&Receive_Buffer);
        }
        data_available = true;
        //NRF_LOG_INFO("byte_available: %d, data=0x%x\n", Receive_Buffer.head-Receive_Buffer.tail, *data_register);
    }

    return data_available;
}

void uart_event_handler(void * context, nrf_libuarte_async_evt_t * p_evt)
{
    nrf_libuarte_async_t * p_libuarte = (nrf_libuarte_async_t *)context;
    ret_code_t ret;
    switch (p_evt->type)
    {
        case NRF_LIBUARTE_ASYNC_EVT_ERROR:
            break;
        case NRF_LIBUARTE_ASYNC_EVT_RX_DATA:
            FIFO_Add(&Receive_Buffer, p_evt->data.rxtx.p_data,  p_evt->data.rxtx.length);
            NRF_LOG_INFO("byte push:%x %d!!\n", *(p_evt->data.rxtx.p_data), p_evt->data.rxtx.length);
            nrf_libuarte_async_rx_free(p_libuarte, p_evt->data.rxtx.p_data, p_evt->data.rxtx.length);
            break;
        case NRF_LIBUARTE_ASYNC_EVT_TX_DONE:
            is_byte_sent = true;
            //NRF_LOG_INFO("byte tx done!!\n");
            break;
        default:
            break;
    }
}





thanks,

Jacob

Related