cancel
Showing results for 
Search instead for 
Did you mean: 

Putty not receiving Data from NUCLEO-F303ZE

Athandile
Visitor

Title edited to be clear that this is on a NUCLEO-F303ZE board.


Hello all.

I'm trying to write a simple message via UART to Putty using stm32f303ze microcontroller. I'm using USART2, via ST-link. All the configurations have been confirmed (baud rate, COM port, bits, etc.) And they are right. I even tried using the STM32 Cube IDE Terminal with no luck. Now I'm not sure if the problem is the UART I'm using, or I'm doing something wrong in the code.

Also I'm not sure about the UART that support VCP in STM32F303ZE microcontrollers. However I tried all the USART, and the were no response in the Terminals.

 

Below is the simple message I'm trying to send and the full code.

/* USER CODE BEGIN Header */

/**

  ******************************************************************************

  * @file : main.c

  * @brief : Main program body

  ******************************************************************************

  * @attention

  *

  * Copyright (c) 2025 STMicroelectronics.

  * All rights reserved.

  *

  * This software is licensed under terms that can be found in the LICENSE file

  * in the root directory of this software component.

  * If no LICENSE file comes with this software, it is provided AS-IS.

  *

  ******************************************************************************

  */

/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/

#include "main.h"



/* Private includes ----------------------------------------------------------*/

/* USER CODE BEGIN Includes */

#include <string.h>





/* USER CODE END Includes */



/* Private typedef -----------------------------------------------------------*/

/* USER CODE BEGIN PTD */



/* USER CODE END PTD */



/* Private define ------------------------------------------------------------*/

/* USER CODE BEGIN PD */



/* USER CODE END PD */



/* Private macro -------------------------------------------------------------*/

/* USER CODE BEGIN PM */



/* USER CODE END PM */



/* Private variables ---------------------------------------------------------*/

UART_HandleTypeDef huart2;



/* USER CODE BEGIN PV */



/* USER CODE END PV */



/* Private function prototypes -----------------------------------------------*/

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_USART2_UART_Init(void);

/* USER CODE BEGIN PFP */



/* USER CODE END PFP */



/* Private user code ---------------------------------------------------------*/

/* USER CODE BEGIN 0 */







/* USER CODE END 0 */



/**

  * @brief The application entry point.

  * @retval int

  */

int main(void)

{



  /* USER CODE BEGIN 1 */



  /* 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_USART2_UART_Init();

  /* USER CODE BEGIN 2 */





  /* USER CODE END 2 */



  /* Infinite loop */

  /* USER CODE BEGIN WHILE */

  while (1)

  {

    /* USER CODE END WHILE */



    /* USER CODE BEGIN 3 */

  char msg[] = "UART test OK\r\n";



  HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY);

  HAL_Delay(1000);



  }

  /* USER CODE END 3 */

}



/**

  * @brief System Clock Configuration

  * @retval None

  */

void SystemClock_Config(void)

{

  RCC_OscInitTypeDef RCC_OscInitStruct = {0};

  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};



  /** Initializes the RCC Oscillators according to the specified parameters

  * in the RCC_OscInitTypeDef structure.

  */

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;

  RCC_OscInitStruct.HSIState = RCC_HSI_ON;

  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;

  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;

  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

  {

    Error_Handler();

  }



  /** Initializes the CPU, AHB and APB buses clocks

  */

  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;

  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;



  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)

  {

    Error_Handler();

  }

  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2;

  PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;

  if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)

  {

    Error_Handler();

  }

}



/**

  * @brief USART2 Initialization Function

  *  None

  * @retval None

  */

static void MX_USART2_UART_Init(void)

{



  /* USER CODE BEGIN USART2_Init 0 */



  /* USER CODE END USART2_Init 0 */



  /* USER CODE BEGIN USART2_Init 1 */



  /* USER CODE END USART2_Init 1 */

  huart2.Instance = USART2;

  huart2.Init.BaudRate = 115200;

  huart2.Init.WordLength = UART_WORDLENGTH_8B;

  huart2.Init.StopBits = UART_STOPBITS_1;

  huart2.Init.Parity = UART_PARITY_NONE;

  huart2.Init.Mode = UART_MODE_TX_RX;

  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;

  huart2.Init.OverSampling = UART_OVERSAMPLING_16;

  huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;

  huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;

  if (HAL_UART_Init(&huart2) != HAL_OK)

  {

    Error_Handler();

  }

  /* USER CODE BEGIN USART2_Init 2 */



  /* USER CODE END USART2_Init 2 */



}



/**

  * @brief GPIO Initialization Function

  *  None

  * @retval None

  */

static void MX_GPIO_Init(void)

{

  /* USER CODE BEGIN MX_GPIO_Init_1 */



  /* USER CODE END MX_GPIO_Init_1 */



  /* GPIO Ports Clock Enable */

  __HAL_RCC_GPIOA_CLK_ENABLE();



  /* USER CODE BEGIN MX_GPIO_Init_2 */



  /* USER CODE END MX_GPIO_Init_2 */

}



/* USER CODE BEGIN 4 */



/* USER CODE END 4 */



/**

  * @brief This function is executed in case of error occurrence.

  * @retval None

  */

void Error_Handler(void)

{

  /* USER CODE BEGIN Error_Handler_Debug */

  /* User can add his own implementation to report the HAL error return state */

  __disable_irq();

  while (1)

  {

  }

  /* USER CODE END Error_Handler_Debug */

}

#ifdef USE_FULL_ASSERT

/**

  * @brief Reports the name of the source file and the source line number

  * where the assert_param error has occurred.

  *  file: pointer to the source file name

  *  line: assert_param error line source number

  * @retval None

  */

void assert_failed(uint8_t *file, uint32_t line)

{

  /* USER CODE BEGIN 6 */

  /* User can add his own implementation to report the file name and line number,

     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  /* USER CODE END 6 */

}

#endif /* USE_FULL_ASSERT */

Post edited by ST moderator to be inline with the community rules for the code sharing. In next time please use </> button to paste your code. Please read this post: How to insert source code.

 

9 REPLIES 9
TDK
Super User

Is the the NUCLEO-F303RE board? Are you trying to use the ST-Link's VCP? The VCP is connected to USART3 over PD8/PD9 by default.

If you feel a post has answered your question, please click "Accept as Solution".

I'm using NUCLEO-F303ZE board. Yes I'm tryjng to use the ST-Link's VCP, and I did try to use USART 3 but it didn't work. 

Try again, and if you can't get it, post the code you are using along with the IOC file. The code you posted won't work as it uses USART2.

There are also working examples you can follow.

STM32CubeF3/Projects/STM32F303ZE-Nucleo/Examples/UART/UART_Printf at master · STMicroelectronics/STM32CubeF3

If you feel a post has answered your question, please click "Accept as Solution".
Athandile
Visitor

Still I'm not getting anything. Below is the code with the IOC file as requested.

Hello @Athandile 

The pins associated with UART3 VCP are PD8 and PD9. However, in your IOC file, you have configured PB10 and PE15 instead.

Saket_Om_0-1761557394237.png

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om

As explained before, PD8/PD9 are the pins used for the VCP on this board. You have selected PB10/PE15 which cannot work.

In the IOC, find the PD8/PD9 pins, click on them, and select the USART3_TX/RX functions. Then regenerate the code.

If you feel a post has answered your question, please click "Accept as Solution".
Andrew Neil
Super User

@Athandile wrote:

I'm not sure about the UART that support VCP in STM32F303ZE microcontrollers.


The UART itself doesn't have anything to do with VCP - it's just a UART.

The VCP is part of the ST-Link on the Nucleo board.

The Nucleo board provides the physical connection from the STM32F303ZE microcontroller to the VCP in the ST-Link:

AndrewNeil_0-1761576479875.png

Details of which UART and which pins are used:

AndrewNeil_1-1761576559762.png

https://www.st.com/resource/en/user_manual/um1974-stm32-nucleo144-boards-mb1137-stmicroelectronics.pdf#page=27

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

 

You can also check this in the board schematics - see the 'CAD Resources' tab on the board's Product Page:

https://www.st.com/en/evaluation-tools/nucleo-f303ze.html#cad-resources

 

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.
johnwick954
Visitor

It sounds like your UART setup might not actually be routed through the ST-Link VCP on the STM32F303ZE. On this board, only certain UARTs are connected to the ST-Link’s virtual COM port—usually USART1 or USART3, not USART2.

Here’s what you can check:

  1. Make sure the TX and RX pins of the UART you’re using are physically connected to the ST-Link’s VCP pins.

  2. Try using USART1 (PA9, PA10) instead of USART2, as this is typically the one wired to the debugger.

  3. Ensure HAL_UART_Transmit() is being called correctly and not stuck waiting on flags.

  4. Test with a USB-to-TTL adapter directly on your chosen UART pins if ST-Link VCP still gives no output—this helps confirm if it’s a software or routing issue.


@johnwick954 wrote:

 VCP on the STM32F303ZE. .


As already noted, the VCP is not on the STM32F303ZE - it is on the ST-Link (which is an STM32F103CBT6).


@johnwick954 wrote:

2. Try using USART1 (PA9, PA10) instead of USART2, as this is typically the one wired to the debugger.


No, don't just randomly try stuff (or believe whatever AI tells you) - study the User Manual and/or the schematics to be sure !

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.