cancel
Showing results for 
Search instead for 
Did you mean: 

Retarget scanf on STM32G070RBxx Cortex M0+

AVerm.4
Associate III

(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.

1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III

 

setbuf(stdin, NULL);

 

View solution in original post

9 REPLIES 9

I've not tried it.

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

@Andrew Neil 

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


@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 ?

Both the local and remote echo is working fine. now, i have to handle CR so that on pressing Enter key the code should return to main function.

 

Also it is hitting my read function correctly.!

Pavel A.
Evangelist III

 

setbuf(stdin, NULL);

 


@AVerm.4 wrote:

Both the local and remote echo is working fine.


So what did you mean by, "The cursor doesn't take input on keypress", then ?

It was not visible on my terminal. So enabled it in settings.

Right - so it was an echo setting, then?

Exactly !