2025-09-10 8:29 PM
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.
These are my pins.
This is my clock configuration.
What should I change so that UART sends the data correctly?
2025-09-10 10:34 PM
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.
2025-09-11 4:57 AM
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?
2025-09-11 5:03 AM - edited 2025-09-11 5:03 AM
@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:
via: https://www.st.com/en/evaluation-tools/stm32f4discovery.html#documentation
2025-09-11 5:07 AM - edited 2025-09-11 5:09 AM
@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:
(I guess a third option would be to choose a board which does have this connection built-in - most do nowadays)
2025-09-11 5:32 AM
All of my F407 Disco boards are the older version with ST-Link V2, which has no VCOM capability at all :
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.
2025-09-11 6:23 AM - edited 2025-09-11 6:25 AM
Maybe that's the difference between the OP's DISC1 and the original DISCOVERY?
PS:
Indeed, it seems so:
So they updated the ST-Link to add VCP Capability, but didn't update the board to take advantage of it!
2025-09-11 8:55 AM
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
https://www.mikroe.com/stm32f4-discovery-click-shield
2025-09-11 10:07 PM
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.