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

UART integration with BLE Thread RTOS example

I am attempting to add a UART to interface to an external MCU. I have the uart example running (without any RTT info) yet when I port the uart code to the ble-thread example I am not getting any data out the TX pin, I am getting data from the RX pin. What am I missing? Is the RTT messing with the transmitting of UART data?

Parents
  • Is the RTT messing with the transmitting of UART data?

     If you are using the same UART pins for RTT and your UART interface, they most likely are interfereing.

    Please check the URAT pins used by the RTT in the sdk_config.h file (

    NRF_LOG_BACKEND_UART_TX_PIN)
  • I do not have that defined in the sdk_config file. I am use the nrf52840 dev kit and SES. RTT and NRF_LOG_ENABLE are set.

  • Which SDK version are you using. 

    You cannot compile latest SDK having RTT backend as UART and not defining NRF_LOG_BACKEND_UART_TX_PIN. Please search for this in your project escpecially in nrf_log_backend_uart.c and look into uar_init() to see if the TX pin used there is conflictiing with the RX pin you are using to communicate with the external MCU.

  • I am using the "nRF5 SDK for Thread and Zigbee v4.0.0". I am using the RTT in SES not a uart, I thought this may be a conflict as the "peripheral/uart" example does not use a debug terminal. I am not using any IO pins in the project. If I run the "peripherial/uart" example every thing works through the pins into the FTDI cable connected to the PCA10056 dev board. I ran the example with the hardware and everything works.

    I then ported the uart example code into the "examples\multiprotocol\ble_thread\ble_thread_dyn_hrs_coap_srv_freertos" example. I intend to use the UART for my border router interface.

    I am using the same functions the uart example is using having a RTOS thread process the "app_uart_get" and "app_uart_put" data.

    here is the code

    #define UART_HWFC APP_UART_FLOW_CONTROL_DISABLED
    
    #define MAX_TEST_DATA_BYTES (15U) /**< max number of test bytes to be used for tx and rx. */
    #define UART_TX_BUF_SIZE (256) /**< UART TX buffer size. */
    #define UART_RX_BUF_SIZE (256) /**< UART RX buffer size. */
    
    #define UART_COMMAND_BUFFER 32
    
    
    // *********************************************************************************************************************************
    // *********************************************************************************************************************************
    // *********************************************************************************************************************************
    //
    // Variables
    //
    static TaskHandle_t go_UARTStackTask = NULL; /**< Thread stack task handle */
    static uint8_t gau8_CommandBuffer[UART_COMMAND_BUFFER] = {0};
    
    
    // *********************************************************************************************************************************
    // *********************************************************************************************************************************
    // *********************************************************************************************************************************
    //
    // Function Prototypes
    //
    static void uart_error_handle(app_uart_evt_t* p_event);
    static void UART_task(void * arg);
    
    
    // *********************************************************************************************************************************
    // *********************************************************************************************************************************
    // *********************************************************************************************************************************
    //
    // External methods
    //
    void SENTINEL_UART_Init(void)
    {
    	NRF_LOG_INFO("Uart Init");
    
    
    	// Start thread stack execution.
    	if (pdPASS != xTaskCreate(UART_task, "UART", UART_STACK_TASK_STACK_SIZE, NULL, UART_STACK_TASK_PRIORITY, &go_UARTStackTask))
    	{
    		APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
    	}
    }
    
    // *********************************************************************************************************************************
    // *********************************************************************************************************************************
    // *********************************************************************************************************************************
    //
    // Internal methods
    //
    static void UART_task(void * arg)
    {
    	UNUSED_PARAMETER(arg);
    
    	NRF_LOG_INFO("UART Task Started");
    
    	uint32_t err_code;
    	nrf_gpio_cfg_output(TX_PIN_NUMBER);
    
    	const app_uart_comm_params_t comm_params =
    	{
    		RX_PIN_NUMBER,
    		TX_PIN_NUMBER,
    		RTS_PIN_NUMBER,
    		CTS_PIN_NUMBER,
    		UART_HWFC,
    		false,
    #if defined (UART_PRESENT)
    		NRF_UART_BAUDRATE_115200
    #else
    		NRF_UARTE_BAUDRATE_115200
    #endif
    	};
    
    	APP_UART_FIFO_INIT(&comm_params,
    	UART_RX_BUF_SIZE,
    	UART_TX_BUF_SIZE,
    	uart_error_handle,
    	APP_IRQ_PRIORITY_LOWEST,
    	err_code);
    
    	APP_ERROR_CHECK(err_code);
    
    	uint32_t u32_CommandIndex = 0;
    
    	printf("Uart task completed");
    	while (1)
    	{
    		// Process an received data for a new command
    
    		uint8_t u8_Data = 0;
    		if (app_uart_get(&gau8_CommandBuffer[u32_CommandIndex]) == NRF_SUCCESS)
    		{
    
    			if (gau8_CommandBuffer[u32_CommandIndex] == 0x0D)
    			{
    				// command is complete
    
    				NRF_LOG_INFO("Uart byte, %i",u32_CommandIndex);
    
    				for(uint32_t u32_Index = 0; ((u32_Index < u32_CommandIndex) && (u32_Index < UART_COMMAND_BUFFER)); u32_Index++)
    				{
    					if (app_uart_put(gau8_CommandBuffer[u32_Index]) != NRF_SUCCESS)
    					{
    						// problem sending data
    						NRF_LOG_INFO("Uart put error");
    						break;
    					}
    				}
    
    				u32_CommandIndex = 0;
    				memset(&gau8_CommandBuffer[0],0,UART_COMMAND_BUFFER);
    			}
    			else
    			{
    				// we recieved some data, append to 
    				u32_CommandIndex++;
    
    				if (u32_CommandIndex >= UART_COMMAND_BUFFER)
    				{
    					// command overrun
    					u32_CommandIndex = 0;
    					memset(&gau8_CommandBuffer[0],0,UART_COMMAND_BUFFER);
    				}
    			}
    		}
    
    		vTaskDelay(20);
    	}
    }
    
    static void uart_error_handle(app_uart_evt_t * p_event)
    {
    	if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR)
    	{
    		APP_ERROR_HANDLER(p_event->data.error_communication);
    	}
    	else if (p_event->evt_type == APP_UART_FIFO_ERROR)
    	{
    		APP_ERROR_HANDLER(p_event->data.error_code);
    	}
    }

Reply
  • I am using the "nRF5 SDK for Thread and Zigbee v4.0.0". I am using the RTT in SES not a uart, I thought this may be a conflict as the "peripheral/uart" example does not use a debug terminal. I am not using any IO pins in the project. If I run the "peripherial/uart" example every thing works through the pins into the FTDI cable connected to the PCA10056 dev board. I ran the example with the hardware and everything works.

    I then ported the uart example code into the "examples\multiprotocol\ble_thread\ble_thread_dyn_hrs_coap_srv_freertos" example. I intend to use the UART for my border router interface.

    I am using the same functions the uart example is using having a RTOS thread process the "app_uart_get" and "app_uart_put" data.

    here is the code

    #define UART_HWFC APP_UART_FLOW_CONTROL_DISABLED
    
    #define MAX_TEST_DATA_BYTES (15U) /**< max number of test bytes to be used for tx and rx. */
    #define UART_TX_BUF_SIZE (256) /**< UART TX buffer size. */
    #define UART_RX_BUF_SIZE (256) /**< UART RX buffer size. */
    
    #define UART_COMMAND_BUFFER 32
    
    
    // *********************************************************************************************************************************
    // *********************************************************************************************************************************
    // *********************************************************************************************************************************
    //
    // Variables
    //
    static TaskHandle_t go_UARTStackTask = NULL; /**< Thread stack task handle */
    static uint8_t gau8_CommandBuffer[UART_COMMAND_BUFFER] = {0};
    
    
    // *********************************************************************************************************************************
    // *********************************************************************************************************************************
    // *********************************************************************************************************************************
    //
    // Function Prototypes
    //
    static void uart_error_handle(app_uart_evt_t* p_event);
    static void UART_task(void * arg);
    
    
    // *********************************************************************************************************************************
    // *********************************************************************************************************************************
    // *********************************************************************************************************************************
    //
    // External methods
    //
    void SENTINEL_UART_Init(void)
    {
    	NRF_LOG_INFO("Uart Init");
    
    
    	// Start thread stack execution.
    	if (pdPASS != xTaskCreate(UART_task, "UART", UART_STACK_TASK_STACK_SIZE, NULL, UART_STACK_TASK_PRIORITY, &go_UARTStackTask))
    	{
    		APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
    	}
    }
    
    // *********************************************************************************************************************************
    // *********************************************************************************************************************************
    // *********************************************************************************************************************************
    //
    // Internal methods
    //
    static void UART_task(void * arg)
    {
    	UNUSED_PARAMETER(arg);
    
    	NRF_LOG_INFO("UART Task Started");
    
    	uint32_t err_code;
    	nrf_gpio_cfg_output(TX_PIN_NUMBER);
    
    	const app_uart_comm_params_t comm_params =
    	{
    		RX_PIN_NUMBER,
    		TX_PIN_NUMBER,
    		RTS_PIN_NUMBER,
    		CTS_PIN_NUMBER,
    		UART_HWFC,
    		false,
    #if defined (UART_PRESENT)
    		NRF_UART_BAUDRATE_115200
    #else
    		NRF_UARTE_BAUDRATE_115200
    #endif
    	};
    
    	APP_UART_FIFO_INIT(&comm_params,
    	UART_RX_BUF_SIZE,
    	UART_TX_BUF_SIZE,
    	uart_error_handle,
    	APP_IRQ_PRIORITY_LOWEST,
    	err_code);
    
    	APP_ERROR_CHECK(err_code);
    
    	uint32_t u32_CommandIndex = 0;
    
    	printf("Uart task completed");
    	while (1)
    	{
    		// Process an received data for a new command
    
    		uint8_t u8_Data = 0;
    		if (app_uart_get(&gau8_CommandBuffer[u32_CommandIndex]) == NRF_SUCCESS)
    		{
    
    			if (gau8_CommandBuffer[u32_CommandIndex] == 0x0D)
    			{
    				// command is complete
    
    				NRF_LOG_INFO("Uart byte, %i",u32_CommandIndex);
    
    				for(uint32_t u32_Index = 0; ((u32_Index < u32_CommandIndex) && (u32_Index < UART_COMMAND_BUFFER)); u32_Index++)
    				{
    					if (app_uart_put(gau8_CommandBuffer[u32_Index]) != NRF_SUCCESS)
    					{
    						// problem sending data
    						NRF_LOG_INFO("Uart put error");
    						break;
    					}
    				}
    
    				u32_CommandIndex = 0;
    				memset(&gau8_CommandBuffer[0],0,UART_COMMAND_BUFFER);
    			}
    			else
    			{
    				// we recieved some data, append to 
    				u32_CommandIndex++;
    
    				if (u32_CommandIndex >= UART_COMMAND_BUFFER)
    				{
    					// command overrun
    					u32_CommandIndex = 0;
    					memset(&gau8_CommandBuffer[0],0,UART_COMMAND_BUFFER);
    				}
    			}
    		}
    
    		vTaskDelay(20);
    	}
    }
    
    static void uart_error_handle(app_uart_evt_t * p_event)
    {
    	if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR)
    	{
    		APP_ERROR_HANDLER(p_event->data.error_communication);
    	}
    	else if (p_event->evt_type == APP_UART_FIFO_ERROR)
    	{
    		APP_ERROR_HANDLER(p_event->data.error_code);
    	}
    }

Children
Related