cancel
Showing results for 
Search instead for 
Did you mean: 

Adding UART functionality to Touch GFX project; STM32F429I-Discovery; Keil;

IB.1
Associate III

Hello,

I would like to have printf functionality added to to Touch GFX generated project.

hardware: STM32F429I-Discovery

IDE: Keil 5.27

I have generated project using Touch GFX, then I can compile project using keil and run on my target board, work fine. Now I would like to add printf functionality to it.

enable HAL_UART_Driver in stm32f4xx_hal_conf.h

#define HAL_SPI_MODULE_ENABLED   
#define HAL_TIM_MODULE_ENABLED   
#define HAL_UART_MODULE_ENABLED //Uncomment this line
/* #define HAL_USART_MODULE_ENABLED */   
/* #define HAL_IRDA_MODULE_ENABLED */ 

in main.cpp I added function:

void UartInit(void){
 
  huart1.Instance = USART1;
  huart1.Init.BaudRate = 115200;
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
  huart1.Init.StopBits = UART_STOPBITS_1;
  huart1.Init.Parity = UART_PARITY_NONE;
  huart1.Init.Mode = UART_MODE_TX_RX;
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
 HAL_UART_Init(&huart1);
}

added re-direction to printf

#ifdef __GNUC__
  #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int std::fputc(int ch, FILE *f)
#endif /* __GNUC__ */
 
	
	PUTCHAR_PROTOTYPE{
  HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
  return ch;
}

in main function, after hw_init(), I am calling UartInit(..) function

code compiles and runs fine.

when I try to printf something it looks like code is crushing... I try to use Keil step debugger and it is not letting me step through the code...

Any suggestions , recommendations how to enable printf.

Please advise at your earliest convenience.

Regards,

IB

2 REPLIES 2
Jiri Klokocka
Associate II

Hello, try to end each your message with escape sequence \r\n. This actually starts the transmit. Otherwise your buffer owerflows easily, which could have caused that errors.

That was my case on F429+TouchGFX+VGA+Mouse projet an I'm using the same redirection system.

Be sure that your HAL_UART_Transmit() works.

Jiri Klokocka

IB.1
Associate III

Hi @Jiri Klokocka​  ,

thank you for your reply.

This is not any more an issue, I have to switch to large display and using STM32F746 kit, I think I might be wrong when was configuring clocks for USAR1

Regards

IB