cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F446RE-NUCLEO: Unable to get output from usb of on-board st-link using Standard Periph Library(via USART2)

HZhao.1
Associate
#define DEBUG_UART                USART2
#define DEBUG_UART_CLK            RCC_APB1Periph_USART2
#define DEBUG_UART_TX_GPIO_CLK    RCC_AHB1Periph_GPIOA
#define DEBUG_UART_TX_PIN         GPIO_Pin_2
#define DEBUG_UART_TX_GPIO_PORT   GPIOA
#define DEBUG_UART_RX_GPIO_CLK    RCC_AHB1Periph_GPIOA 
#define DEBUG_UART_RX_PIN         GPIO_Pin_3
#define DEBUG_UART_RX_GPIO_PORT   GPIOA
#define DEBUG_UART_BaudRate       115200
static void USARTConfig(){
  GPIO_InitTypeDef  GPIO_InitStructure;
  USART_InitTypeDef USART_InitStructure;
 
  RCC_AHB1PeriphClockCmd(DEBUG_UART_TX_GPIO_CLK | DEBUG_UART_RX_GPIO_CLK , ENABLE);
  RCC_APB1PeriphClockCmd(DEBUG_UART_CLK, ENABLE);
 
  GPIO_InitStructure.GPIO_Pin = DEBUG_UART_TX_PIN;           
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_Init(DEBUG_UART_TX_GPIO_PORT, &GPIO_InitStructure);
 
  GPIO_InitStructure.GPIO_Pin = DEBUG_UART_RX_PIN;              
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_Init(DEBUG_UART_RX_GPIO_PORT, &GPIO_InitStructure);
 
 
  USART_InitStructure.USART_BaudRate = DEBUG_UART_BaudRate;    
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;   
  USART_InitStructure.USART_StopBits = USART_StopBits_1;   
  USART_InitStructure.USART_Parity = USART_Parity_No ;      
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;  
  USART_Init(DEBUG_UART, &USART_InitStructure);
 
  USART_ClearFlag(DEBUG_UART, USART_FLAG_RXNE | USART_FLAG_TC);  
 
  USART_Cmd(DEBUG_UART, ENABLE);   
}
int fputc(int ch, FILE *f){
	while(USART_GetFlagStatus(USART2, USART_FLAG_TXE)==RESET);
	USART_SendData(USART2,(uint8_t) ch);
	while(USART_GetFlagStatus(USART2, USART_FLAG_TC)==RESET);
	return ch;
}

For some reasons, I have to learn to use std library and I have tried to fix the problem but failed. When debugging, the fputc function is called properly but no output is received by my PC while I can do that with another version with HAL Library.

The project is rewrited from ST official std library template for stm32f446xx.

0 REPLIES 0