Skip to main content
FLast.11
Associate II
December 15, 2015
Question

printf problem in atollic truestudio stm32f103

  • December 15, 2015
  • 2 replies
  • 793 views
Posted on December 15, 2015 at 10:05

Hello, i am new to 32Bit world

i am using Atollic Lite the update version.

my IC was STM32F103C8 and

STM32F10x Standard Peripherals Library Drivers update History

V3.6.1.

I need to use printf to print thing to USART.

I saw some thread that need to attach sys_call.c and tiny_printf.c? Is that true?

i follow some thread that use the following code:

nt _write(int file, char *ptr, int len)

{

/* Implement your write code here, this is used by puts and printf for example */

int i=0;

for(i=0 ; i<len ; i++)

USARTSendChar((*ptr++)); //<–this is my usart code

return len;

}

however it doesnot work.

i use normal USART to dump ascii to hyperterminal was ok

can anyone help ?

many thanks

Jeff
    This topic has been closed for replies.

    2 replies

    TarekB-ST
    Associate
    December 15, 2015
    Posted on December 15, 2015 at 15:32

    Hello Jeff

    >> I saw some thread that need to attach sys_call.c and tiny_printf.c? Is that true?

    you need to add only syscalls.c that includes the_write and _read functions tiny_printf.c is a minimal implementation of printf features (like newlib-nano) : used to optimize the code size in your case you need the _write function

    int

    _write(

    int

    file,

    char

    *ptr,

    int

    len)
    {
    int

    DataIdx;
    for

    (DataIdx = 0; DataIdx < len; DataIdx++)
    {
    __io_putchar( *ptr++ );
    }
    return

    len;
    }

    then override the __io_putchar to write *ptr to USART or put the implementation within _write itself.

    >> however it doesnot work.

    In that case, please ensure that your USART is correctly initialized. For guidance, you can inspire from STM32CubeF1 V1.2.0\Projects\STM32VL-Discovery\Examples\UART\UART_Printf or fromSTM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Examples\USART\Printf Using Standard Peripherals Library:

    /**
    * @brief Retargets the C library printf function to the USART.
    * @param None
    * @retval None
    */
    int
    __io_putchar(
    int
    ch)
    {
    /* Place your implementation of fputc here */
    /* e.g. write a character to the USART */
    USART_SendData(EVAL_COM1, (uint8_t) ch);
    /* Loop until the end of transmission */
    while
    (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)
    {}
    return
    ch;
    }

    Where EVAL_COM1 could be USART1 (it depends on your implementation). Regards, TarekB
    FLast.11
    FLast.11Author
    Associate II
    December 29, 2015
    Posted on December 29, 2015 at 03:41

    thanks it solved