Welcome, Guest

Poll

How can I use "printf" in STM32-H405.

printf
0 (0%)
H405
0 (0%)

Total Members Voted: 0

Voting closed: May 26, 2017, 07:36:28 AM

Author Topic: How can I use "printf" in STM32-H405.  (Read 1320 times)

pkkkkkk

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
How can I use "printf" in STM32-H405.
« on: February 15, 2017, 06:36:28 AM »
Hi all.

I want to display with printf function from UART4 of H405 board.
I mate the following below.

*****************************************************************
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
PUTCHAR_PROTOTYPE
{
   USART_SendData(UART_PORT[0], ch);

   return ch;
}

void uart_debug()
{
   RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
   
   UART_InitStructure.USART_BaudRate = 9600;
   UART_InitStructure.USART_WordLength = USART_WordLength_8b;
   UART_InitStructure.USART_StopBits = USART_StopBits_1;
   UART_InitStructure.USART_Parity = USART_Parity_Odd;
   UART_InitStructure.USART_Mode = USART_Mode_Rx|USART_Mode_Tx;
   UART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

   USART_Init(UART_PORT[0], &UART_InitStructure);

   printf("Debug Serial Test");
}
*****************************************************************

I wonder how the UART port is connected to the printf function.
If only PUTCHAR_PROTOTYPE is defined, can I use the "printf function" ?

Please let me know if you know anyone.

JohnS

  • Hero Member
  • *****
  • Posts: 1666
  • Karma: +33/-45
Re: How can I use "printf" in STM32-H405.
« Reply #1 on: February 15, 2017, 10:45:03 AM »
With so little info about tools etc it may be no-one can answer but instead of printf you could use sprintf then a loop to output each char to any uart.

John

Lurch

  • Sr. Member
  • ****
  • Posts: 272
  • Karma: +11/-0
Re: How can I use "printf" in STM32-H405.
« Reply #2 on: March 15, 2017, 01:11:00 PM »
Did you initialize the GPIO pins (GPIO_InitStructure) ?
Where is the USART enable USART_Cmd (COMxx, ENABLE) ?