cancel
Showing results for 
Search instead for 
Did you mean: 

UART doesn't work on STM32F407G-DISC1

cockatoo
Associate

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?

 

8 REPLIES 8
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.

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?


@Ozone wrote:

If I remember correctly, the ST-Link embedded in the F407 discovery is not wired to a target MCU UART...


This is true.

 


@Ozone wrote:

... and thus has no VCOM capability.


This is not true.

The Virtual COM Port (VCP) capability is there - it's just the physical connection that's missing.

@cockatoo  This is described in the User Manual:

AndrewNeil_0-1757592128294.png

https://www.st.com/resource/en/user_manual/um1472-discovery-kit-with-stm32f407vg-mcu-stmicroelectronics.pdf#page=18

via: https://www.st.com/en/evaluation-tools/stm32f4discovery.html#documentation

 

 

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

@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)

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

All of my F407 Disco boards are the older version with ST-Link V2, which has no VCOM capability at all :

Ozone_0-1757593752700.png

Just fore reference.

Later boards, like all of the Nucleos, have one target MCU wired to the onboard ST-Link (V2.1 or later), install the VCP driver automatically, and work "out of the box".

This boards not.
This is probably why the tutorial site did not mention them.

Maybe that's the difference between the OP's DISC1 and the original DISCOVERY?

AndrewNeil_0-1757596810087.png

 

PS:

Indeed, it seems so:

AndrewNeil_1-1757597052827.png

 

So they updated the ST-Link to add VCP Capability, but didn't update the board to take advantage of it!

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

@Andrew Neil 

Just like @Ozone, my Discovery board is the older version.

 

This Mikroe shield board has been great to use and has a built in USB connector to USART2 and a connector to CAN1

 

 

KarlYamashita_3-1757605953944.png

https://www.mikroe.com/stm32f4-discovery-click-shield

 

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.
CAN Jammer an open source CAN bus hacking tool

I have two or three "base-boards" for the F4 Disco from Embest, which had been distributed by Farnell :
https://www.elinux.org/DM-STF4BB_Base_Board

Not sure if they are still available.
But in combination with the LCD extension, this gave a nice combination I used for several projects.