IMPORTANT: Cypress Developer Community is transitioning on October 20th. To learn more and be prepared for this change, check out our latest announcement.
Showing results for 
Search instead for 
Did you mean: 

FM0+, FM3 & FM4 MCU

Esteemed Contributor



I've been writing some demo programs 
for FM0-64L-S6E1C3 with PDL 2.1.0 and PSoC Creator 4.0.


So far, I could manage SPI(CSIO) and I2C to work.
Using utilities/printf_scanf by setting following in pdl_user.h
// Printf/Scanf via UART function


Although printf seems reasonably working,
scanf does not come back.


So I spent a few days and found that 
int _read(int file, char *ptr, int len) in uart_io.c 
does not return until it reads "len" number of letters.
In my debugger, the len was 1024, when I was trying to read a few letters.


So I replaced following lines


    int i;
    file = file;
    for(i = 0; i < len; i++)
        while (TRUE != Mfs_Uart_GetStatus(UartCh, UartRxFull))
            /* Wait until there is a character in the Rx FIFO */
        *ptr++ = (char)Mfs_Uart_ReceiveData(UartCh);
    return len;


with following lines


    int i = 0  ;
    char c ;
    file = file ;


    while(i < len) {
        while (TRUE != Mfs_Uart_GetStatus(UartCh, UartRxFull)) {
            /* Wait until there is a characer in the Rx FIFO */
        c = (char)Mfs_Uart_ReceiveData(UartCh);
        Mfs_Uart_ClrStatus(UartCh, UartRxFull) ;
        ptr[i++] = c ;
        if (!isprint(c)) { 
            break ;


    ptr = 0 ;
    return i ;


now scanf can read "%d", "%x", "%s".
But I wonder if my correction is correct,
or if there is/(will be) a better fix of PDL.



1 Solution
Not applicable

Yes, this seems to be a problem with scanf implementation. The work-around you added seems to be fine. We will check this with our software team.

View solution in original post

2 Replies
Top labels