Skip to main content
AVerm.4
Associate III
September 18, 2024
Solved

Retarget scanf on STM32G070RBxx Cortex M0+

  • September 18, 2024
  • 2 replies
  • 1858 views

(originally a reply to https://community.st.com/t5/stm32cubeide-mcus/retarget-printf-on-stm32g070rbxx-cortex-m0/td-p/720883)

 

Hi @Andrew Neil,

For the scanf do we need to make any other change?

My read function is-

 

 

int _read(int fd, char *ptr, int len){
 (void)fd;
 int i;
 for(i=0;i<len;i++){
 *ptr++ = uart_read();
 }
 return len;
}

 

 

In the terminal window it is not taking any keypress.

    Best answer by Pavel A.

     

    setbuf(stdin, NULL);

     

    2 replies

    Andrew Neil
    Super User
    September 18, 2024

    I've not tried it.

    I guess you would still need to do the extern "C" and anything else specific to C++ ...

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    AVerm.4
    AVerm.4Author
    Associate III
    September 18, 2024

    @Andrew Neil 

    This I'm trying on C. The cursor doesn't take input on keypress.

    Andrew Neil
    Super User
    September 18, 2024

    @AVerm.4 wrote:

    the cursor doesn't take input on keypress.


    What do you mean by that?

    Do you mean the keypress doesn't appear on your terminal?

    If you want that, it's called echo - it can be either local or remote:

    • Local - performed purely in the terminal itself
    • Remote - the echo is performed by your software.

    Again, beware of the line buffering.

     

    If you put a breakpoint in your _read function, is it hit ?

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    Pavel A.
    Pavel A.Best answer
    Super User
    September 19, 2024

     

    setbuf(stdin, NULL);