2017-02-09 05:47 AM
I'm using examples of project 'UART_Printf'.
But I can't use printf.
I set uart1. and I checked that uart1 tx/rx works.
I added below code to my source.
&sharpinclude 'stdio.h'
&sharpifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf set to 'Yes') calls __io_putchar() */&sharpdefine PUTCHAR_PROTOTYPE int __io_putchar(int ch)&sharpelse&sharpdefine PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)&sharpendif /* __GNUC__ */PUTCHAR_PROTOTYPE
{ /* Place your implementation of fputc here */ /* e.g. write a character to the USART1 and Loop until the end of transmission */ HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);return ch;
}#uart #printf #stm32f42017-02-09 06:17 AM
You are using what chip, or what board, with what compiler?
Where do you expect to see this data, and how have you connected up and configured the USART?
2017-02-09 07:10 AM
Hello Kim,
Assuming that you are using Eclipse IDE, your code should be enough, but you have to add Syscalls.c file into your project.
Then considering that cube has been well configured to generate the correct code to initialise the board, you have to connect the demo board to your pc, and open the virtual com port... set it with the correct parameters... and your printf should show up.
As you can see, I made few assuptions....
Could you please detail a bit more your code generation chain, your IDE, the HW on which you want to do this test ?
Kind regards
Sirma
2017-02-09 02:07 PM
I'm using STM32CubeMX + SWSTM32 to program a stm32f446RE board.
I've found the code
of software development tools.2017-02-09 02:09 PM
I already checked the USART is working. I can receive and transmit the data through USART1 to PC.
But I can't use only 'printf' function.
when I use 'printf', it doesn't have any reaction.
I'm using STM32CubeMX + SWSTM32 to program a stm32f446RE board.
2017-02-09 03:03 PM
The next place to look would be the write functionality implemented in syscalls/newlib code. This would need to call the __io_putchar() functionality provided.
Your options here would be to review the code compiled into the project, and to debug/breakpoint various points, and single-stepping code. Going in via puts() might be simpler than printf()
The Nucleo 446RE would likely be using USART2 for VCP connectivity.
2017-02-09 06:35 PM
I can't find syscalls.c file. should I copy from the project of Nucleo 446RE Examples?
Do you mean that I prefer to use puts() instead of printf()?
2017-02-09 07:31 PM
I use GNU/GCC directly, I do not use SWSTM32. I have posted numerous GNU/GCC + MAKE examples which provide printf() via SWV and USART.
I mean puts() is easier to debug/trace. There isn't a lot of faffing about with formatting strings to confuse the process, you should be a few function calls away from code that touches the USART with puts(), or putchar().
2017-02-09 07:33 PM
yes copy it from the other example.
2017-02-10 01:51 AM
Yes, copy syscalls.c from example into your project.
Kind regards
Sirma