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

nrf52832: ERRORSRC 0xC with UARTE0 when starting RX.

Hello everyone,

I am trying to implement UARTE on a custom board embedding an nRF52832, as part of an upgrade from SDK 12 to SDK 15. The nRF52832 is communicating via UART with a GSM chip, sending it messages and receiving some, with different lengths. I am using FreeRTOS.

In order to do that, I checked the example "experimental_libuarte" that is present in the SDK 15.2 file (nRF5_SDK_15.2.0_9412b96/examples/peripheral/experimental_libuarte).

But after implementing it in my project, I always have the same error: as soon as the STARTRX flag is raised, when calling "nrf_libuarte_async_enable(1)", the EVENTS_ERROR register pass to 1, and the ERRORSRC register shows 0xC, so framing and break errors. This happens before anything is send or retrieved. 

I then tried to run only the example program, so without SoftDevice and FreeRTOS, and I have the same error.

After configuration and initialization of UARTE0, everything seems to be fine with UARTE0 register.

r

But as soon as the enabling is done by calling "nrf_libuarte_async_enable(1)", the error appears.

The error is more precisely thrown as soon as the STARTRX flag is raised, inside the "nrf_libuarte_async_enable()" function.

At first I thought that it might be a hardware error, that could for example put the RX line to 0V, interpreted as sending an infinite amount of "0", but it is not : the program worked well when using UART FIFO before, and the RX line is driven high by the nRF52832.

I am adding the main file here, that I slightly modified to match my pins settings and to initialize external clock and gsm chip :

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "nrf_libuarte_async.h"
#include <bsp.h>
#include "nrf_delay.h"

#define GSM_TXD_PIN	30
#define GSM_RXD_PIN	29
#define GSM_DTR_PIN	28
#define GSM_RI_PIN	27
#define GSM_CTS_PIN	26
#define GSM_RTS_PIN	25
#define GSM_PWR_PIN	31
#define ENABLE_4V_PIN  6

static uint8_t text[] = "UART example started.\r\n Loopback:\r\n";
static uint8_t text_size = sizeof(text);

void uart_event_handler(nrf_libuarte_async_evt_t * p_evt)
{
    static uint8_t ch = 0;
    ret_code_t ret;
    switch (p_evt->type)
    {
        case NRF_LIBUARTE_ASYNC_EVT_ERROR:
            bsp_board_led_invert(0);
            break;
        case NRF_LIBUARTE_ASYNC_EVT_RX_DATA:
            ch = p_evt->data.rxtx.p_data[0];
            nrf_libuarte_async_rx_free(p_evt->data.rxtx.p_data, p_evt->data.rxtx.length);
            ret = nrf_libuarte_async_tx(&ch, 1);
            APP_ERROR_CHECK(ret);
            bsp_board_led_invert(1);
            break;
        case NRF_LIBUARTE_ASYNC_EVT_TX_DONE:
            bsp_board_led_invert(2);
            break;
        default:
            break;
    }
}

/**
 * @brief Function for main application entry.
 */
int main(void)
{
		//External clock init
		NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
		NRF_CLOCK->TASKS_HFCLKSTART = 1;
		while(NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) {  }
		NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
		NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
		NRF_CLOCK->TASKS_LFCLKSTART = 1;
		while(NRF_CLOCK->EVENTS_LFCLKSTARTED == 0) { }
		
    //Turning on GSM chip
		nrf_gpio_cfg_output(ENABLE_4V_PIN);
		nrf_gpio_pin_clear(ENABLE_4V_PIN);
		nrf_delay_ms(200);
		nrf_gpio_pin_set (ENABLE_4V_PIN);
		nrf_gpio_cfg_output(GSM_PWR_PIN);
		nrf_gpio_pin_set(GSM_PWR_PIN);
		nrf_delay_ms(4200);
	
		//UARTE0 configuration
    nrf_libuarte_async_config_t nrf_libuarte_async_config =
		{
				.rx_pin	 		= GSM_RXD_PIN,
				.tx_pin	 		= GSM_TXD_PIN,
				.cts_pin		=	GSM_CTS_PIN,
				.rts_pin		=	GSM_RTS_PIN,
				.timeout_us = 100,
				.baudrate		= NRF_UARTE_BAUDRATE_57600,
				.parity			= NRF_UARTE_PARITY_EXCLUDED,
				.hwfc				=	NRF_UARTE_HWFC_ENABLED
		};

		//UARTE0 initialization 
    ret_code_t err_code = nrf_libuarte_async_init(&nrf_libuarte_async_config, uart_event_handler);

    APP_ERROR_CHECK(err_code);

		//UARTE0 enabled (and rx start)
    nrf_libuarte_async_enable(1);

    err_code = nrf_libuarte_async_tx(text, text_size);
    APP_ERROR_CHECK(err_code);
    while (true)
    {
    }
}

Thank you for your help !

Parents Reply Children
  • I fully understand, and I'd also like to try on a nRF5 DK, but I don't have access to one... Though I did also try on a Thingy:52, and had the same problem.

  • I've tried to take source file you've attached. Ported it to 15.3 libuarte_async api, used on PCA10040 DK and picked gpio pins which are floating, not connected to anything. In fact, i got error on initialization. Then, I've modified nrf_libuarte_init line to use pullup for RX line:

    nrf_gpio_cfg_input(p_config->rx_pin, NRF_GPIO_PIN_PULLUP /*NRF_GPIO_PIN_NOPULL*/);

    Error was gone. Seems to me that this is the problem there that GSM device does not have pull up. In the example, we use libuarte to communicate with Segger chip on DK and segger chip keeps line high. Please let me know if that helps.

    Regarding using libuarte with RTC and Softdevice, there is a bug that driver tries to control clock without softdevice. In case of softdevice presence following line should be removed:

    nrfx_clock_lfclk_start();

  • Hi, thank you for your help. I tried enabling pullup on RX as you did and removed nrfx_clock_lfclk_start().

    But when calling nrf_libuarte_async_enable() I still have the same output errror:

    <debug> libUARTE: RX buf response (next). Provided buffer:0x20006B94
    <debug> libUARTE: (evt) RX dma_cnt:0, endrx_cnt:0, stop_cnt:0
    <debug> libUARTE: RX buf response (mp_next_rx not NULL:0x20006B94), Provided buffer:0x20006C9C
    <debug> libUARTE: (evt) RX dma_cnt:0, endrx_cnt:0, stop_cnt:0
    <error> libUARTE_async: (evt) Failed to allocate buffer for RX.
    ts\libraries\experimental_libuarte\nrf_libuarte_async.c:133
    PC at: 0x000444B5
    <error> app: End of error report

    Though this time I do not have any error shown in NRF_UARTE0 error register (EVENTS_ERROR), contrary to last time.

    Still it seems that it fails to allocate a RX buffer, which may come from the same issue...

  • So there was actually another issue which is related to the fact that buffer size in balloc is increased to be aligned to 4 bytes and requested rx buffer size (255) becomes 256 (and that on 8 bits become 0). To workaround it for now, please change rx buffer size parameter in macro which creates libuarte_async instance to something smaller than 253.

    Like:

    NRF_LIBUARTE_ASYNC_DEFINE(libuarte, 0, 0, 0, NRF_LIBUARTE_PERIPHERAL_NOT_USED, 252, 3);

  • Thanks a lot, by modifyng this value I indeed do not have this error anymore.

Related