cancel
Showing results for 
Search instead for 
Did you mean: 

UART doesn't work on STM32F407G-DISC1

cockatoo
Visitor

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?

 

1 REPLY 1
Ozone
Principal II

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.