cancel
Showing results for 
Search instead for 
Did you mean: 

Retarget scanf stm32 atollic

kostalexis
Associate II
Posted on October 17, 2011 at 18:59

Hi guys,

I am trying to retarget scanf for USART1 of STM32 using Atollic. I think the utilized toolchain makes use of _read_r for the scanf (please verify if possible). So I need a new definition of _read_r. Any ideas?

I have looked at IAR's _read for keyboard I/O and tried to modify for Atollic (_read_r redirected to USART1) but no luck until now. 

Thanks!
2 REPLIES 2
Posted on October 17, 2011 at 20:59

http://mcu.cz/print.php?news.2265

  1. int

    _read_r

    (

    void

    *reent, uint16_t fd,

    char

    *ptr, uint32_t len

    )

  2. {

  3.         uint32_t counter = len;

  4.         USART_TypeDef *Usart;

  5.        

    if

    (

    fd == STDIN_FILENO

    )

    {

                           

    // stdin from UARTx

  6.                 Usart = USART1;

  7.        

    }

    else

    {

  8.                

    return

    len;
  9.        

    }

  10.        

    while

    (

    counter-- >

    0

    )

    {

                             

    // Read the character to the buffer from UART

  11.                

    while

    (

    USART_GetFlagStatus

    (

    Usart, USART_FLAG_RXNE

    )

    == RESET

    )

    ;
  12.                 *ptr = USART_ReceiveData

    (

    Usart

    )

    ;
  13.                 ptr++;

  14.        

    }

  15.        

    return

    len;
  16. }

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
kostalexis
Associate II
Posted on October 18, 2011 at 09:59

Thanks man!