printk becomes slow when CONFIG_LOG=y and trying to recieve serial communication over uart

I'm using a nRF52840 with the nRF Connect SDK version 2.4.1. I've been using Zephyr's logging module however now I want to also receive data over UART. I followed the Serial Communication (UART) example in nRF Connect SDK Fundamentals course however I've noticed it's very unresponsive (takes ~3 seconds to indicate that data was recieved). I found that this was due to enabling logging (removing CONFIG_LOG makes it responsive).

As an example, take the Lesson 5 Exercise 1 Solution repo from the course NRF Connect Fundamentals and add

case UART_RX_RDY:
        printk("Recieved!");

Then upload normally, when you type into the terminal it instantly prints backed Recieved!

However, if in prj.conf you add

CONFIG_LOG=y

You can see that it takes ~2 seconds before Received! is printed to the console

I thought this may be an issue with both the trying to receive logs and communication over uart0 so I tried switching the logging backend to RTT

CONFIG_LOG_BACKEND_UART=n
CONFIG_LOG_BACKEND_RTT=y

However, it still takes ~2 seconds for Received! to be printed

Parents
  • Hello,

    Yes, I can see a very slight delay in printing while enabling the log module. For me, it is very slight; I probably can't say it is 2 seconds because I haven't checked how much difference in time it creates with CONFIG_LOG enabled. But have you tested this and found that it is taking 2 seconds?

    Kind Regards,

    Abhijith

  • Im running the following piece of code:

    #include <zephyr/kernel.h>

    int main(void)
    {
    while(1)
    {
    printk("Hello World\n");
    k_sleep(K_MSEC(100));
    }
    return 0;
    }

    with the following configs:

    CONFIG_LOG=y
    CONFIG_PRINTK=y
    CONFIG_SERIAL=y

    and what i see is that is takes about a second before it actually sends anything over uart:

    if i include this (or disable logs entirely):

    CONFIG_LOG_PRINTK=n

    it runs consistently:

Reply
  • Im running the following piece of code:

    #include <zephyr/kernel.h>

    int main(void)
    {
    while(1)
    {
    printk("Hello World\n");
    k_sleep(K_MSEC(100));
    }
    return 0;
    }

    with the following configs:

    CONFIG_LOG=y
    CONFIG_PRINTK=y
    CONFIG_SERIAL=y

    and what i see is that is takes about a second before it actually sends anything over uart:

    if i include this (or disable logs entirely):

    CONFIG_LOG_PRINTK=n

    it runs consistently:

Children
No Data
Related