cancel
Showing results for 
Search instead for 
Did you mean: 

How to use printf() function with NUCLEO-F072RB??

Bhautik
Associate II

I have used NUCLEO-F072RB EVK and just print "Hello World" using printf function but didn't print anything on console.

IDE : STM32CubeIDE

May I know How to use printf function with proper steps?

Please find below code :

##########################################################

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

#include "main.h"

#include <stdio.h>

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

/* USER CODE BEGIN Includes */

/* 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 ---------------------------------------------------------*/

/* USER CODE BEGIN PV */

/* USER CODE END PV */

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

void SystemClock_Config(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 */

 /* USER CODE BEGIN 2 */

 /* USER CODE END 2 */

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

  /* USER CODE END WHILE */

 printf("Hello, World!\n");

 HAL_Delay(1000);

  /* USER CODE BEGIN 3 */

 }

 /* USER CODE END 3 */

}

##########################################################

1 REPLY 1
KnarfB
Principal III

The implementation of printf will eventually call the _write syscall. There is a default (weak) implementation of _write in syscalls.c. You are expected to override this by your own implementation redirecting the output to an UART of your choice etc.. An example is given in the STM AN4989 Application note "STM32 microcontroller debug toolbox" which is a good read anyway.

hth

KnarfB