Printf issues on nucleoF401RE
Hello,
I’m currently using a nucleoF401RE with HAL cube drivers to control an arduino 9 axes motion shield.
I would like to send message to my pc terminal through the printf function but i have some trouble.
Since the Uart pin are not configured i have to do it myself, so, as recommended i implemented the HAL_UART_MspInit function:
GPIO_InitTypeDef GPIO_InitStruct;
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_USART2_CLK_ENABLE();
/*Reglages des ports*/
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_3;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
And i set the huart handler as recommended :
huart.Instance = USART2;
huart.Init.BaudRate = 9600;
huart.Init.WordLength = UART_WORDLENGTH_8B;
huart.Init.StopBits = UART_STOPBITS_1;
huart.Init.Parity = UART_PARITY_NONE;
huart.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart.Init.Mode = UART_MODE_TX_RX;
huart.Init.OverSampling = UART_OVERSAMPLING_16;
if(HAL_UART_Init(&huart) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
But when i’m using printf() function nothing happened... BUT if i used the function HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout) which is already implemented, i’m able to send data though the serial port.
Could you help me to “fix” the printf() function ? As i dont know how to send full words or data values with the HAL_UART_Transmit function.
Thank you very much
PMA