Console Echo

I'm doing a project for adding a Bluetooth capability to an embedded Linux device. The Linux master talks to the nRF52840-based Bluetooth module via a dedicated serial (UART) link. I've got a console feature on the BT module such that the Linux master can send commands and receive responses in plain old ASCII.

Since there's not actually a human watching a screen, the commands should go out and the responses should come back, period. For testing, I want to set the terminal for local echo and see what I'm typing with no remote echo. If I do a basic UART driver, I can get this. However, with the console subsystem, outgoing characters are echoed back. I've looked through uart_console.c to see how incoming characters are sent back, and I don't see it, much less how to turn it off.

  • Hello,

    Do you have an example project I can try to recreate this? Looking at the code (as you do) I can't seem to find any either, it seems it's for instance through console_putchar(), so can't imagine what else may be doing this.

    Kenneth

  • I took the hello_world sample and modified it to use console_getline():

    prj.conf:

    CONFIG_CONSOLE=y
    CONFIG_UART_CONSOLE=y
    CONFIG_CONSOLE_SUBSYS=y
    CONFIG_CONSOLE_GETLINE=y

    (I don't know that the first two lines are necessary; the program works identically without them).

    main.c:

    #include <stdio.h>
    #include <string.h>
    #include <zephyr/kernel.h>
    #include <zephyr/sys/printk.h>
    #include <zephyr/console/console.h>
    
    int main(void)
    {
            char *p;
            console_getline_init();
            printf("Hello World! %s\n", CONFIG_BOARD);
            while(1) {
                    p = console_getline();
                    printf("orig: >%s<\n", p);
            }
            return 0;
    }
    

    When I flash the program and attach a terminal, I get output and can enter text and get it back.

    But if I set the terminal for "local echo", I get:

    So it's clear that Console, or at least console_getline(), is doing remote echo.

  • Hello,

    I can confirm I see the same as you, I must admit I have not used the console. I did try to dig around a bit, but I could not really find how this actually "works" either, I did at the end ask chatgpt if it could provide any insight, and it kind of confirmed what we already see: "When using `console_getline()` in Zephyr, characters are displayed as you type because this function is designed to provide real-time input feedback. It's particularly useful for interactive command-line interfaces where users need immediate feedback as they type their input. This behavior allows users to see what they are typing and correct any mistakes before submitting the input."

    Kenneth

Related