Issues in Modifying an nRF52840-based Peripheral UART Program to Host_Only

I wanted to change the Peripheral UART program in the nrf samples to the host_only version, and I made some attempts. I added the following code to the prj.conf file:

CONFIG_BT_HCI=y
CONFIG_BT_CTLR=n
CONFIG_BT_H4=y

In the app.overlay file I added the following code:

/ {
	chosen {
		nordic,nus-uart = &uart0;
	};
};

&uart0 {
	current-speed = <115200>;
	// hw-flow-control;
};
&uart1 {
    compatible = "nordic,nrf-uarte";
    status = "okay";
    current-speed = <115200>;
    pinctrl-0 = <&uart1_default>;
    pinctrl-1 = <&uart1_sleep>;
    pinctrl-names = "default", "sleep";
};
/ {
    chosen {
        // zephyr,console = &uart0;
        // zephyr,shell-uart = &uart0;
        zephyr,bt-uart = &uart0;
        zephyr,bt-c2h-uart = &uart0;
    };
 };

After build and flash, the program doesn't seem to run correctly. After debug, I find that the program enters an endless loop in the uart_init() function, specifically "err = uart_callback_set(uart, uart_cb, NULL);" this line produced an error.

  • Hi, 

    Please let me know if you managed to make the beacon sample worked as the host when you connect to the controller  ?
    When you use the peripheral uart there can be a conflict as the sample uses UART to receive command (from human user) and the UART you are using for HCI communication. 
    In your case you are using uart0 for both normal nus-uart and HCI UART. You should choose for example nus-uart to use UART0 and HCI uart to use UART 1. 

  • I'm terribly sorry. I forgot to reply. With your help, I have successfully made the beacon sample worked as the host.
    I enabled uart1 in the overlay file with the intention of using UART 1 as HCI uart. When the overlay file is configured with the following code:

    &uart0 {
    	current-speed = <115200>;
    	// hw-flow-control;
    };
    &uart1 {
        compatible = "nordic,nrf-uarte";
        status = "okay";
        current-speed = <115200>;
        pinctrl-0 = <&uart1_default>;
        pinctrl-1 = <&uart1_sleep>;
        pinctrl-names = "default", "sleep";
    };
    / {
        chosen {
            nordic,nus-uart = &uart0;
            // zephyr,console = &uart0;
            // zephyr,shell-uart = &uart0;
            zephyr,bt-uart = &uart1;
            zephyr,bt-c2h-uart = &uart1;
        };
     };
    

    the program has the same problem. I don't know what the problem is with this project.

    Looking forward to your reply. 

  • Hi, 
    Have you checked if you configure the UART1 pins correctly ? 
    You would need to have RTS and CTS pin configured. 
    I did a quick test with peripheal_lbs and uart1 for HCI_UART seems to work with the following overlay: 

    &pinctrl {
    	uart1_default: uart1_default {
    		group1 {
    			psels = <NRF_PSEL(UART_TX, 0, 28)>,
    				<NRF_PSEL(UART_RTS, 0, 29)>;
    		};
    		group2 {
    			psels = <NRF_PSEL(UART_RX, 0, 30)>,
    				<NRF_PSEL(UART_CTS, 0, 31)>;
    			bias-pull-up;
    		};
    	};
    
    	uart1_sleep: uart1_sleep {
    		group1 {
    			psels = <NRF_PSEL(UART_TX, 0, 28)>,
    				<NRF_PSEL(UART_RX, 0, 30)>,
    				<NRF_PSEL(UART_RTS, 0, 29)>,
    				<NRF_PSEL(UART_CTS, 0, 31)>;
    			low-power-enable;
    		};
    	};
    };
    
    &uart1 {
        compatible = "nordic,nrf-uarte";
        status = "okay";
        current-speed = <1000000>;
        hw-flow-control;
        pinctrl-0 = <&uart1_default>;
        pinctrl-1 = <&uart1_sleep>;
        pinctrl-names = "default", "sleep";
    };
    / {
       chosen {
            zephyr,bt-uart = &uart1;
       };
    };

  • Hi,

    Using the overlay file you gave me, I can make the lbs program work as a host. But this doesn't seem to work for the peripheral_uart program, and the old problems remain.

  • Hi, 
    I assume you are familiar with the peripehral_uart sample. You can just disable the uart part (not the hci uart) and see if it works. Make sure the hci uart uses UART1 and the normal uart uses UART0. 

    Please check if you see any error log in UART/RTT. You may want to open a terminal on PC. I suspect that due to no terminal opened on PC to connect to UART0 , the sample doesn't run. 

Related