Olimex Support Forum

ARM => ST => Topic started by: pkkkkkk on February 15, 2017, 06:36:28 am

Poll
Question: How can I use "printf" in STM32-H405.
Option 1: printf votes: 0
Option 2: H405 votes: 0
Title: How can I use "printf" in STM32-H405.
Post by: pkkkkkk 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.
Title: Re: How can I use "printf" in STM32-H405.
Post by: JohnS 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
Title: Re: How can I use "printf" in STM32-H405.
Post by: Lurch 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) ?