Skip to main content
Explorer
September 11, 2025
Solved

UART doesn't work on STM32F407G-DISC1

  • September 11, 2025
  • 1 reply
  • 535 views

I am a beginner, and this is my first time trying to use UART to send data from MCU to PC.I try to follow the deep blue embedded tutorial (STM32 Serial Print & Monitor (UART Data Debug), however the console does not receive anything when I connect to it.

This is my main function code

int main(void)
{

 /* USER CODE BEGIN 1 */
	//USART vs UART
	//synchronous generates data on clock and sends it to
	//the receiver which works accordingly in synchronized manner
	//asynchronous generates data clock internally

 /* USER CODE END 1 */

 /* MCU Configuration--------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 HAL_Init();

 /* USER CODE BEGIN Init */

 /* USER CODE END Init */

 /* Configure the system clock */
 SystemClock_Config();

 /* USER CODE BEGIN SysInit */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */
 MX_GPIO_Init();
 MX_DMA_Init();
 MX_I2C1_Init();
 MX_I2S3_Init();
 MX_SPI1_Init();
 MX_USB_HOST_Init();
 MX_USART2_UART_Init();
 /* USER CODE BEGIN 2 */

 //uint8_t UART2rxBuffer[12] = {0};
 //HAL_UART_Transmit(&huart2, UART2rxBuffer, sizeof(UART2rxBuffer), 5000);
 //HAL_UART_Transmit(&huart2, UART2rxBuffer, sizeof(UART2rxBuffer), 100);
 uint8_t MSG[35] = {'\0'};
 uint8_t X = 0;

 /* USER CODE END 2 */

 /* Infinite loop */
 /* USER CODE BEGIN WHILE */
 uint8_t hello_world[13] = "Hello World\n";
 HAL_UART_Transmit(&huart2, hello_world, sizeof(hello_world), 500);

 while (1)
 {
 /* USER CODE END WHILE */
 MX_USB_HOST_Process();

 /* USER CODE BEGIN 3 */
 //sprintf(MSG, "Hello Dudes! Tracing X = %d\r\n", X);
 //HAL_UART_Transmit(&huart2, MSG, sizeof(MSG), 500); //timeout time
 HAL_UART_Transmit(&huart2, hello_world, sizeof(hello_world), 500);
 HAL_Delay(500); //wait half a second
 X++;
 }
 /* USER CODE END 3 */
}

These are my UART2 settings.

cockatoo_0-1757561247991.png

 

These are my pins.

cockatoo_1-1757561267511.png

This is my clock configuration.

cockatoo_2-1757561322230.png

 

What should I change so that UART sends the data correctly?

 

    This topic has been closed for replies.
    Best answer by Ozone

    If I remember correctly, the ST-Link embedded in the F407 discovery is not wired to a target MCU UART, and thus has no VCOM capability.

    You could connect a USB-to-Serial adapter to you target USART pins (PA2, PA3), provided the adapter works with 3.3V, not 5V.

    Following the link to the tutorial, it does not mention the F407 discovery, for that very reason.

    1 reply

    OzoneAnswer
    Explorer
    September 11, 2025

    If I remember correctly, the ST-Link embedded in the F407 discovery is not wired to a target MCU UART, and thus has no VCOM capability.

    You could connect a USB-to-Serial adapter to you target USART pins (PA2, PA3), provided the adapter works with 3.3V, not 5V.

    Following the link to the tutorial, it does not mention the F407 discovery, for that very reason.

    cockatooAuthor
    Explorer
    September 11, 2025

    Thank you, I didn't know. What should I use if I need data transfer between PC and F407 discovery if there is no UART?

    Super User
    September 11, 2025

    @cockatoo wrote:

     I didn't know. 


    See above - it is documented in the User Manual

     


    @cockatoo wrote:

    What should I use if I need data transfer between PC and F407 discovery if there is no UART?


    There is a UART (in fact, the STM32F407VG has four UARTs) - what's missing is just the physical connection from the UART to the PC.

    As described, you need to provide that physical connection.

    You have two options:

    1. Add physical link wires to the Discovery board;
    2. Connect to a separate USB-to-UART adaptor.

    (I guess a third option would be to choose a board which does have this connection built-in - most do nowadays)