Implement UART to example

Hi,

I have example nrf/samples/esb/prx. Now I want to add UART0 (in ASYNC mode - DMA) for TX and RX communication with another device.

I just tried to proceed according to this: https://docs.zephyrproject.org/3.1.0/hardware/peripherals/uart.html#

What I did:

1) Commented all LOG_ERR and LOG_INF lines, commented  #include <logging/log.h> and LOG_MODULE_REGISTER(esb_prx, CONFIG_ESB_PRX_APP_LOG_LEVEL); Because uart0 is probably used for logging?!?

2) In main.c I add these "for brinking" uart0:

#define UART0   DT_NODELABEL(uart0)
const struct device *uart0_dev;
 and add init for uart0 like that:
static bool initUART(void)
{
    uart0_dev = DEVICE_DT_GET(UART0);  
    if (uart0_dev == NULL) {
        //printk("Device not found\n");
        return false;
    }

    uart_callback_set(uart0_dev,CallbackUART0,NULL);

    return true;
}
3) My prj.conf now looks like that:
#
# Copyright (c) 2019 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
#CONFIG_NCS_SAMPLES_DEFAULTS=y
CONFIG_ESB=y
CONFIG_SERIAL=y
CONFIG_UART_0_ASYNC=y
CONFIG_UART_ASYNC_API=y
#CONFIG_DEBUG_OPTIMIZATIONS=y
#CONFIG_DEBUG_THREAD_INFO=y
When I build it - this error occurs:
error: '__device_dts_ord_DT_CHOSEN_zephyr_console_ORD' undeclared (first use in this function)
96 | #define DEVICE_NAME_GET(name) _CONCAT(__device_, name)
Could you please help me?. I still have no idea how it works, still can not understand all these .dts and prj.conf etc...
Thank you very much. Jan.

  • Hi,

    thank you for pointing me. I could not find this sample in VS code (when browsing examples): 

    OK, never mind - I found it on the github.

    In the example I can not see major difference in using of uart.

    I found out that the error (see above in my previous post) occurs already if I try to remove using uart0 for functions like LOG_ERR,... So Is there any "smart" way how to get LOG_ERR,... to stop using the uart0? Let say that now LOG_ERR uses uart0, but we could let LOG_ERR use only e.g. RTT, and uart0 could be then free for another purpose.

    How I tried to to get LOG_ERR,... to stop using the uart0:

    1) Commented line: LOG_MODULE_REGISTER(esb_prx, CONFIG_ESB_PRX_APP_LOG_LEVEL);

    but some errors appeared: 

    2) commented  #include <logging/log.h> in main.c and set CONFIG_NCS_SAMPLES_DEFAULTS=n in prj.conf

    unfortunatelly it also did not help. 

    Hope my question is clear, Do you please know how to use uart0 for my purpose and how to disable uart0 from using LOG_xxx functions?

    Thank you very much.

  • Hi,

    You can have logging use several backends at once. So if you want to make logging use RTT and disable UART logging, do:

    CONFIG_LOG_BACKEND_RTT=y
    CONFIG_LOG_BACKEND_UART=n

    The VS Code Kconfig extension is nice to figure out which alternatives you have with Kconfig.
    Also see our Kconfig search and Logging in nRF Connect SDK.

    Another alternative is to send logging to another uart. This is done using the devicetree:

    / {
        zephyr,console = &uart1;
    };
    

    PS: I remembered that we also have this tutorial on UART.

    Regards,
    Sigurd Hellesvik

  • Thank you!

    When implementing LOG_xx module I tried to understand how to set up it for uart and RTT output.

    I found  CONFIG_LOG_BACKEND_RTT and  CONFIG_USE_SEGGER_RTT - what is a difference?

    Also I found  CONFIG_LOG and  CONFIG_CONSOLE I found out that I need to set booth of them to =y - what is the differnce?

    For LOG output on uart I need to set also  CONFIG_SERIAL,  CONFIG_UART_CONSOLE - why booth of them?

    Thank you, Jan.

  • Hi,

    witc said:
    I found  CONFIG_LOG_BACKEND_RTT and  CONFIG_USE_SEGGER_RTT - what is a difference?

    CONFIG_USE_SEGGER_RTT enables the functionality for Segger RTT.

    CONFIG_LOG_BACKEND_RTT makes it so that the logger module use RTT as a backend.

    witc said:
    Also I found  CONFIG_LOG and  CONFIG_CONSOLE I found out that I need to set booth of them to =y - what is the differnce?

    CONFIG_CONSOLE is for general output from the chip. CONFIG_LOG is to enable the Logger module.

    witc said:
    For LOG output on uart I need to set also  CONFIG_SERIAL,  CONFIG_UART_CONSOLE - why booth of them?

    Here is an example to log on uart with only CONFIG_LOG set manually:

    hello_world_with_log.zip

    Regards,
    Sigurd Hellesvik

Related