Questions about uart fifo and rtt debug

Hi,

I'm devoloping a code that neeed send parameters using ble_uart. I used the ble_nus service as reference and works, but using rtt and not serial pin that I configured.

I tried initialize the code with uart_init and log_init, but inside the log_init function, the error 8 is returned during NRF_LOG_DEFAULT_BACKENDS_INIT() function.

my code is:

int main(void)
{
    bool erase_bonds;
    uint32_t deviceID[2]; //ID unico de cada processador

    ret_code_t err_code;
    //external_clock_init(); // Inicialização do clock externo
    // Initialize.
    #ifdef BLE_UART_CAL
    uart_init();                //todo ble_uart
    #endif
    log_init();                 //Inicializa Log serial utilizado pela pilha nrf - ok
    gpiote_init();
    //continue
    }

and the uart_init function:

/**@snippet [UART Initialization] */
static void uart_init(void)
{
    uint32_t                     err_code;
    app_uart_comm_params_t const comm_params =
    {
        .rx_pin_no    = NRF_UART_PSEL_DISCONNECTED,
        .tx_pin_no    = NRF_LOG_BACKEND_UART_TX_PIN,
        .rts_pin_no   = NRF_UART_PSEL_DISCONNECTED,
        .cts_pin_no   = NRF_UART_PSEL_DISCONNECTED,
        .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
        .use_parity   = false,
#if defined (UART_PRESENT)
        .baud_rate    = NRF_UART_BAUDRATE_115200
#else
        .baud_rate    = NRF_UARTE_BAUDRATE_115200
#endif
    };

    APP_UART_FIFO_INIT(&comm_params,
                       UART_RX_BUF_SIZE,
                       UART_TX_BUF_SIZE,
                       uart_event_handle,
                       APP_IRQ_PRIORITY_LOWEST,
                       err_code);
    APP_ERROR_CHECK(err_code);
}

and the log_init function, the log backends init enabled:

void nrf_log_default_backends_init(void)
{
    int32_t backend_id = -1;
    (void)backend_id;
#if defined(NRF_LOG_BACKEND_RTT_ENABLED) && NRF_LOG_BACKEND_RTT_ENABLED
    nrf_log_backend_rtt_init();
    backend_id = nrf_log_backend_add(&rtt_log_backend, NRF_LOG_SEVERITY_DEBUG);
    ASSERT(backend_id >= 0);
    nrf_log_backend_enable(&rtt_log_backend);
#endif

Using this code, my debug is visualized in debug terminal inside the segger ide:

and according to ble_uart example, the values that I sent my ble application to my device, appears in serial terminal connected on pin that I configured.

When I tried using just pin to serial, the error 8 is returned. The init uart_serial using fifo mode and rtt is not. What is the best solution to transfer my debug terminal to serial pin.

Can you help me?

Regards

Laerte

Parents
  • I change my sdk_config file as follow:

    #define NRF_LOG_BACKEND_RTT_ENABLED 0

    and

    #define NRF_LOG_BACKEND_UART_ENABLED 1

    inside the nrf_log_backend_uart_init function in the nrf_log_backend_uart.c, the uart_init is tried inicicialized again and the error_code is returned as 8.

    static void uart_init(bool async_mode)
    {
        nrf_drv_uart_config_t config = NRF_DRV_UART_DEFAULT_CONFIG;
        config.pseltxd  = NRF_LOG_BACKEND_UART_TX_PIN;
        config.pselrxd  = NRF_UART_PSEL_DISCONNECTED;
        config.pselcts  = NRF_UART_PSEL_DISCONNECTED;
        config.pselrts  = NRF_UART_PSEL_DISCONNECTED;
        config.baudrate = (nrf_uart_baudrate_t)NRF_LOG_BACKEND_UART_BAUDRATE;
        ret_code_t err_code = nrf_drv_uart_init(&m_uart, &config, async_mode ? uart_evt_handler : NULL);
        APP_ERROR_CHECK(err_code);
    
        m_async_mode = async_mode;
    }

  • Problem solved I modified my nus_data_handler funcion and comment the uart_init

    here my nus_data_handler funcion modified:

    /**@snippet [Handling the data received over BLE] */
    static void nus_data_handler(ble_nus_evt_t * p_evt)
    {
        uint8_t parametros_recebidos[MAX_LENGTH];
        if (p_evt->type == BLE_NUS_EVT_RX_DATA)
        {
            uint32_t err_code;
    
            /*NRF_LOG_DEBUG*/NRF_LOG_INFO("Received data from BLE NUS. Writing data on UART.");
            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++)
            {
                parametros_recebidos[i] = p_evt->params.rx_data.p_data[i];
                NRF_LOG_INFO("Valor recebido na ble_uart: %x ", p_evt->params.rx_data.p_data[i]);   
                //do
                //{
                //    err_code = app_uart_put(p_evt->params.rx_data.p_data[i]); //p_data recebe o valor na uart
                //    //NRF_LOG_INFO("Valor recebido na ble_uart: %x ", 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);
            }
            //if (p_evt->params.rx_data.p_data[p_evt->params.rx_data.length - 1] == '\r')
            //{
            //    while (app_uart_put('\n') == NRF_ERROR_BUSY);
            //}
        }
    }

Reply
  • Problem solved I modified my nus_data_handler funcion and comment the uart_init

    here my nus_data_handler funcion modified:

    /**@snippet [Handling the data received over BLE] */
    static void nus_data_handler(ble_nus_evt_t * p_evt)
    {
        uint8_t parametros_recebidos[MAX_LENGTH];
        if (p_evt->type == BLE_NUS_EVT_RX_DATA)
        {
            uint32_t err_code;
    
            /*NRF_LOG_DEBUG*/NRF_LOG_INFO("Received data from BLE NUS. Writing data on UART.");
            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++)
            {
                parametros_recebidos[i] = p_evt->params.rx_data.p_data[i];
                NRF_LOG_INFO("Valor recebido na ble_uart: %x ", p_evt->params.rx_data.p_data[i]);   
                //do
                //{
                //    err_code = app_uart_put(p_evt->params.rx_data.p_data[i]); //p_data recebe o valor na uart
                //    //NRF_LOG_INFO("Valor recebido na ble_uart: %x ", 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);
            }
            //if (p_evt->params.rx_data.p_data[p_evt->params.rx_data.length - 1] == '\r')
            //{
            //    while (app_uart_put('\n') == NRF_ERROR_BUSY);
            //}
        }
    }

Children
No Data
Related