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

log printk uart0 to external pin on nrf9160 - Tutorial

ubuntu host PC rs232 to usb:
Target board nrf9160:

get log from /dev/ttyACM0 change to /dev/ttyUSB0
PC Tx ---- target rx p0.00
PC Rx ---- target tx p0.01

#########################################################
ubuntu PC host:
the /dev/ttyUSB0 will receive from nrf9160

#########################################################
SEGGER Embedded Studio for ARM
Release 5.34a  Build 2021011401.44914
Nordic Edition
Linux x64

#########################################################
1.
Hardware support for boardname:
nrf9160dk_nrf9160ns -> Sw10 -> NRF91

2.
nrf9160dk_nrf9160ns:
~/ncs/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160ns_defconfig
#add in last line
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_DEBUG=y

the CONFIG_DEBUG=y help you trace into ~/ncs/zephyr/drivers/serial/uart_nrfx_uarte.c

3.
create file nrf9160dk_nrf9160ns.overlay in ~/ncs/zephyr/samples/hello_world
add follows setting

&uart0 {
        current-speed = <115200>;
        status = "okay";
        tx-pin = <1>;
        rx-pin = <0>;
        rts-pin = <0xFFFFFFFF>;
        cts-pin = <0xFFFFFFFF>;
};

&uart1 {
        current-speed = <115200>;
        status = "okay";
        tx-pin = <27>;
        rx-pin = <26>;
        rts-pin = <0xFFFFFFFF>;
        cts-pin = <0xFFFFFFFF>;
};

4.
add ${BOARD}.overlay in ~/ncs/zephyr/samples/hello_world/CMakeLists.txt

cmake_minimum_required(VERSION 3.13.1)

#add this line
set(DTC_OVERLAY_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${BOARD}.overlay")

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(hello_world)

target_sources(app PRIVATE src/main.c)


(you do not need to change ~/ncs/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160ns.dts)
(overlay file will do it)

5.
SEGGER Embedded Studio open hello_world project
BoardName: nrf9160dk_nrf9160ns

6.
/root/ncs/zephyr/samples/hello_world/build_nrf9160dk_nrf9160ns/zephyr/zephyr.dts
there are uart0 and uart1 setting same as overlay file

uart0: uart@8000 {
                compatible = "nordic,nrf-uarte";
                reg = < 0x8000 0x1000 >;
                interrupts = < 0x8 0x1 >;
                status = "okay";
                label = "UART_0";
                current-speed = < 0x1c200 >;
                tx-pin = < 0x1 >;
                rx-pin = < 0x0 >;
                rts-pin = < 0xffffffff >;
                cts-pin = < 0xffffffff >;
            };
            uart1: uart@9000 {
                compatible = "nordic,nrf-uarte";
                reg = < 0x9000 0x1000 >;
                interrupts = < 0x9 0x1 >;
                status = "okay";
                label = "UART_1";
                current-speed = < 0x1c200 >;
                tx-pin = < 0x1b >;
                rx-pin = < 0x1a >;
                rts-pin = < 0xffffffff >;
                cts-pin = < 0xffffffff >;
            };
            
7. set breakpoint
~/ncs/zephyr/drivers/serial/uart_nrfx_uarte.c

switch (cfg->flow_ctrl) {  //------------------>set breakpoint at this can see it use CTS RTC or not
    case UART_CFG_FLOW_CTRL_NONE:
        uarte_cfg.hwfc = NRF_UARTE_HWFC_DISABLED;
        break;
    case UART_CFG_FLOW_CTRL_RTS_CTS:
                if (get_dev_config(dev)->rts_cts_pins_set) {
            uarte_cfg.hwfc = NRF_UARTE_HWFC_ENABLED;
        } else {
            return -ENOTSUP;
        }
        break;
    default:
        return -ENOTSUP;
    }


All done and successfully

Related