Using 4 uarts of NRF5340 at the same time

Hi

I am using NRF5340 chip in my custom designed board and I want to use all the 4 UARTs available in this chip at the same time.

The interesting problem which I am confronting is that three of these UARTs work properly and answer to their interrupts. The forth

UART can send data but it doesn't response to its receiving data. It's call back routine doesn't work. Another interesting matter is 

that when I change the initializing sequence of these UARTs the non responding UART is also changes. For example when I 

initialize the UARTs in my main as: uart0,uart1,uart2,uart3 the non responding uart is the last one ie. uart3. When I change the 

initializing sequence for example as: uart0,uart1,uart3,uart2 the non responding uart is uart2 . Always the last initialized uart 

doesn't respond. It seems that only three receiving interrupts are active.

I would be very thankful if you could guide me to solve this problem, because I need all 4 UARTs in my project.

Best regards

 

    

  • Hi Sigurd

    This is my prl.conf

    I

    #
    # Copyright (c) 2018 Nordic Semiconductor
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    
    # CONFIG_PM_DEVICE=y
    
    CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y
    CONFIG_BT_SMP=y
    CONFIG_CLOCK_CONTROL_NRF_K32SRC_500PPM=y
    
    # Enable the UART driver
    CONFIG_SERIAL=y
    CONFIG_UART_ASYNC_API=y
    
    CONFIG_GPIO=y
    
    # Make sure printk is not printing to the UART console
    CONFIG_CONSOLE=n
    CONFIG_UART_CONSOLE=n
    
    CONFIG_HEAP_MEM_POOL_SIZE=2048
    CONFIG_BT=y
    CONFIG_BT_PERIPHERAL=y
    CONFIG_BT_DEVICE_NAME="KMS"
    CONFIG_BT_DEVICE_APPEARANCE=833
    CONFIG_BT_MAX_CONN=1
    CONFIG_BT_MAX_PAIRED=1
    CONFIG_BT_NUS_UART_BUFFER_SIZE=512
    # Enable the NUS service
    CONFIG_BT_NUS=y
    
    # Enable bonding
    # CONFIG_BT_SETTINGS=y
    # CONFIG_FLASH=y
    # CONFIG_FLASH_PAGE_LAYOUT=y
    # CONFIG_FLASH_MAP=y
    # CONFIG_NVS=y
    # CONFIG_SETTINGS=y
    
    # Enable DK LED and Buttons library
    CONFIG_DK_LIBRARY=y
    
    # This example requires more workqueue stack
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
    
    # Config logger
    CONFIG_LOG=n
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_LOG_BACKEND_RTT=y
    CONFIG_LOG_BACKEND_UART=y
    CONFIG_ASSERT=y
    
    CONFIG_ADC=y
    # CONFIG_CBPRINTF_FP_SUPPORT=y

  • 
    &uart0 {
    				compatible = "nordic,nrf-uarte";
    				reg = < 0x8000 0x1000 >;
    				interrupts = < 0x8 0x1 >;
    				status = "okay";
    				label = "UART_0";
    				current-speed = < 9600 >;
    				tx-pin = < 0x14 >;
    				rx-pin = < 0x16 >;
    				
    			};
    
    
    &uart1 {
    				compatible = "nordic,nrf-uarte";
    				reg = < 0x9000 0x1000 >;
    				interrupts = < 0x9 0x1 >;
    				status = "okay";
    				label = "UART_1";
    				current-speed = < 9600 >;
    				tx-pin = < 0x21 >;
    				rx-pin = < 0x20 >;
    				rx-pull-up;
    			};
    
    
    &uart2 {
    				compatible = "nordic,nrf-uarte";
    				reg = < 0xb000 0x1000 >;
    				interrupts = < 0xb 0x1 >;
    				status = "okay";
    				label = "UART_2";
    				current-speed = < 9600 >;
    				tx-pin = < 0x1F >;
    				rx-pin = < 0x0B >;
    				rx-pull-up;
    			};
    
    
    &uart3 {
    				compatible = "nordic,nrf-uarte";
    				reg = < 0xc000 0x1000 >;
    				interrupts = < 0xc 0x1 >;
    				status = "okay";
    				label = "UART_3";
    				current-speed = < 9600 >;
    				tx-pin = < 0x2E >;
    				rx-pin = < 0x2D >;
    				rx-pull-up;
    			};
    
    
    
    &led0  {
    			gpios = < &gpio0 0x1d 0x1 >;
    			label = "Green LED 0";
    		};
    &led1  {
    			gpios = < &gpio0 0x1e 0x1 >;
    			label = "Green LED 1";
    		};		
    &led2  {
    			gpios = < &gpio0 0x11 0x1 >;
    			label = "Green LED 2";
    		};         
    
    &led3  {
    			gpios = < &gpio0 0x12 0x1 >;
    			label = "Green LED 3";
    		};
    
    
    
    &adc {
    	compatible = "nordic,nrf-saadc";
    	reg = < 0xe000 0x1000 >;
    	interrupts = < 0xe 0x1 >;
    	status = "disabled";
    	label = "ADC_0";
    	#io-channel-cells = < 0x1 >;
    	phandle = < 0x6 >;
    };
    
    
    
    

    Hi again

    Its my overlay file too. I think it might be useful too.

    B.S. 

  • Hi Sigurd

    I want to inform you by changing the uart_init() functions as below the fourth uart also beccomes

    functional.

    static int uart3_init(void)
    {
    	uart_irq_rx_enable(uart3);
    	int err;
    	struct uart3_data_t *rx3;
    	uart3 = device_get_binding(DT_LABEL(DT_NODELABEL(uart3)));
    	
    	rx3 = k_malloc(256);       //k_malloc(sizeof(*rx3));
    	if (rx3)
    	{
    		rx3->len3 = 0;
    	}
    	else
    	{
    		return -ENOMEM;
    	}
    	
    	k_work_init_delayable(&uart3_work, uart3_work_handler);
    	
            err = uart_callback_set(uart3, uart3_cb, NULL);
    	if (err)
    	{
    		return err;
    	}
    	
    	return uart_rx_enable(uart3, rx3->data3, sizeof(rx3->data3), 10);
    	
    }

    Actually by allocating memory statically ( rx3 = k_malloc(256) ) the problem was solved.

    The maximum number of bytes in my application will never exceed 250 .

    Any how ,I am so thankful for your paying attention.

    B.S.

    Saeed Mahvis

  • Hi Saeed,

    Good job with fixing this!

    I were still working on a test for 4 uarts on my end, but met some bugs myself and was had not been able to complete it yet.

    I will mark your answer as the answer then.
    Good luck with your project

    Regards,
    Sigurd Hellesvik

Related