2016-11-25 03:23 AM
Hello,
first i have to say, i´m a bloody Beginner with C and STM. Never the less, i have the following problem. I just want do make it possible to communicate with Terminal (Putty, Terra Term,...). Printf seems to work, there is a good example in Cubemx. But scanf is not working. Whatever i try, my program is not able to process the input. As well at the Terminal there is no input seen unless i activate ''local echo'' at the terminal. I have tried different example code, sometimes the programm stucks in my while loop and is waiting for an input. And without while loop, the input is skipped. I´m nearly sure this depends on Getchar_Prototype but for me, it is still not clear what i have to do. Maybe someone could help or knows some good online Tutorials/Books. Thanks Kai2016-11-25 03:40 PM
You'll probably find most embedded solutions don't use scanf() as the primary means of input. Think about managing the input/output more directly, and use sscanf() on the string to get from that.
2016-11-25 09:21 PM
Wait, I think I might know this one; I have seen that some of the compiler/libraries (newlib) use buffering on input.
Try holding down a key on your keyboard for about 210 seconds. I seem to remember that the buffer was about 2K and you get about 10 characters per second off of a keyboard.Just a shot in the dark.2016-11-25 09:34 PM
Kay, found it. The compiler was gcc from sw4stm32 (ac6). The buffer was 1024 characters, and the command to turn off buffering is:
.ExternalClassCE8F3B77326446E0B6CCD68E5AF37C27 p.p1 {margin:0.0px 0.0px 0.0px 0.0px;font:12.0px 'Courier New';} .ExternalClassCE8F3B77326446E0B6CCD68E5AF37C27 span.s1 {;} .ExternalClassCE8F3B77326446E0B6CCD68E5AF37C27 span.s2 {color:#793d93;} .ExternalClassCE8F3B77326446E0B6CCD68E5AF37C27 span.Apple-tab-span {white-space:pre;}setvbuf
(stdin, NULL, _IONBF, 0);
Put this in your program somewhere before your big loop.2016-11-28 01:07 AM
Many thanks, this is what i was searching for :)
It works now. That was not easy for a beginner like me. Kaily2016-11-28 11:49 AM
No, that definitely isn't your fault. I taught an intro to embedded systems class at the local maker space and this came up when I was teaching the UART section.
I'm doing a brain dump of my course notes on the Embedded.FM blog (embedded.fm/blog) and this week's topic is - UARTs.I will be giving you this tidbit in about two weeks. There's quite a bit to go over yet.I'm glad I could help.Andrei from The Great White North(as seen on the embedded.fm podcast and blog)