When using the ble_app_uart example, "Failed receiving NUS message. Error 0x04. " appears

Hi:

My environment is: nRF5_SDK_17.1.0_ddde560,  keil, s113_nrf52_7.2.0_softdevice
When using the ble_app_uart example, "Failed receiving NUS message. Error 0x04. " appears

static void nus_data_handler(ble_nus_evt_t* p_evt)
{

    if (p_evt->type == BLE_NUS_EVT_RX_DATA) {
        uint32_t err_code;

        //        NRF_LOG_DEBUG("Received data from BLE NUS. Writing data on UART. %d", p_evt->params.rx_data.length);
        //        NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);

        for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++) {
            do {
                err_code = app_uart_put(p_evt->params.rx_data.p_data[i]);

                if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY)) {
                    NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ", err_code);
                    APP_ERROR_CHECK(err_code);
                }
            } while (err_code == NRF_ERROR_BUSY);
        }
    }
}

After investigation, it was found that `NRF_ERROR_NO_MEM` appeared when `app_uart_put`. I tried the following, but still couldn't solve it. Even when the data is far below 115200, this error will occasionally appear.

1. Uarte is turned on, and debugging shows that data is indeed sent and received through uarte.

2. Modify the data sending method in the interrupt.

 case NRF_DRV_UART_EVT_TX_DONE:
	
	//@modify by guojf start
    read_len = 127;
			
	if (app_fifo_read(&m_tx_fifo,tx_buffer,&read_len)== NRF_SUCCESS)
    {
        (void)nrf_drv_uart_tx(&app_uart_inst, tx_buffer, read_len);
    }
    else
    {
        // Last byte from FIFO transmitted, notify the application.
        app_uart_event.evt_type = APP_UART_TX_EMPTY;
        m_event_handler(&app_uart_event);
    }
	//@modify by guojf end
break;

3. Expand txFIFO to #define UART_TX_BUF_SIZE 4096

4. Try to increase the uart priority, but increasing the priority will cause the program to fail to run

I would like to ask the following people, has anyone encountered this problem, or how to solve it, is there something wrong with the method I use?

Thanks!

Related