November 22, 2024, 02:15:26 PM

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

Started by pkkkkkk, February 15, 2017, 06:36:28 AM

Previous topic - Next topic

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

pkkkkkk

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

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

Did you initialize the GPIO pins (GPIO_InitStructure) ?
Where is the USART enable USART_Cmd (COMxx, ENABLE) ?