2019-11-06 05:35 AM
In windows7, my project (iar) can send string to serial ports with printf, but in ubuntu 18.04 (stm32cubeide), HAL_UART_Transmit can send char, but it seems that printf do nothing.
Thanks for your help.
2019-11-06 05:45 AM
With GNU/GCC you will need to make sure the pluming is present and connected.
ST typically has a _write() function in syscalls or newlib that calls __io_putchar(), and that has to output characters to your chosen UART, via HAL_UART_Transmit() or whatever.
2019-11-06 04:48 PM
thank you for your answer.
I read the example at STM32Cube_FW_F4_V1.24.1/Projects/STM32F410xx-Nucleo/Examples/UART/UART_Printf, and i use the code in my main file before i ask the question. By the way , i use c++, not c:
#ifdef __GNUC__
/* With GCC, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
in ubuntu 18.04, if i test HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF), so i can see a test char with cutecom
but if i test printf("test"), not happened with cutecom, no output, no error
What should I do...
2019-11-06 05:37 PM
I move __io_putchar from main file to syscalls.c, so now __io_putchar can be called after _write() was called.
I see the "test" with cutecom now...
But I don't know if I should do it(move __io_putchar to syscalls.c file ). It seems that something is not so good
2019-11-07 03:30 PM
Put a breakpoint in your PUTCHAR_PROTOTYPE and see if it is hit.
-- pa
2019-11-07 03:36 PM
__io_putchar in syscalls.c usually is declared as weak, so no need to modify syscalls.c.
It can stay in main.c. Use a breakpoint to verify it is called.
-- pa