modify the behaviour of scanf() stm32f3 discovery
I’m using Mac OSX and AC6 2.0.1.201705161428 on stm32f3 discovery. I’m trying to change the behaviour of scanf() function. To made this i modify the _read() function called by scanf(). I configure the USB as CDC class device and i want take data from a serial monitor, so i write some code into CDC_Receive_FS() to do this.The function CDC_receive_FS() receive 1 character and put it into an array. I implemented CDC_getChar(), a function to get the actual character of that array. The _read() function call CDC_getChar(), obtain the char and put it into ptr. At first execution the scanf() call the _read() function and i was able to obtain the string that i write into the serial monitor. The following calls of scanf() doesn’t call the _read(), so the _read() called once and never called again. if i pass %s as format specifier and i return a number that not is a power of 2 the _read() goes in loop, if i pass %d as format specifier does not go into loop. There is my _read() implementation
int j=0;
int _read (int file, char *ptr, int len)
{
j=0;
for(int k=0;k < CDC_getDim();k++){
ptrk=CDC_getChar();
j++;
}
return j;
}
the parameter len is always 1024. the value returned by the scanf() is always 1 regardless of the value returned by the _read(). I use also the linker option - -specs=nano.specs to use the newlib-nano. What can I do to make the scanf () call _read ()?