2017-02-02 12:31 AM
I found several posts like
, using syscalls.c, but I don't have this file in my project... I generate the code with CubeMX v4.18.0.#qt-creator #cubemx #stm32 #arm-none-eabi2017-02-02 12:47 AM
Hello David,
To get printf working, you have to do the following.
In the main.c, add this code in the relevant sections:
/* USER CODE BEGIN Includes */
#include
'stdio.h'
/* USER CODE END Includes */
/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/
#ifdef
__GNUC__
/* With GCC/RAISONANCE, small
printf
(option LD Linker->Libraries->Smallprintf
set to 'Yes') calls __io_putchar() */
#define
PUTCHAR_PROTOTYPE
int__io_putchar(
intch)
#else
#define
PUTCHAR_PROTOTYPE
intfputc(
intch, FILE *f)
#endif
/* __GNUC__ */
/* USER CODE END PFP */
/* USER CODE BEGIN 4 */
/**
* @brief
Retargets
the C libraryprintf
function to the USART.* @
param
None* @
retval
None*/
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(&UartHandle, (uint8_t *)
&ch
, 1, 0xFFFF);HAL_UART_Transmit(&huart2, (
uint8_t
*)&ch, 1, 0xFFFF);
 
return
ch;
}
/* USER CODE END 4 */
In combination with the syscall.c, you should get your printf getting out on the UART.
Kind regards
Sirma
2017-02-02 01:50 AM
Addapt the code to the uart handler you are using :)
With cube, I generate mine with UART2. So in the code huart2 has been used.
You can refer to some projects examples in the firmware library directory.
Under the family you are using, you will find them.
Kind regards
Sirma