Skip to main content
Best answer by mƎALLEm

@syedhashmiraza wrote:

hello

can you provide me  a disign setting for printf


Hello,

Attached a project that prints "Hollo World" using printf over USART1.

Need first to check which COM was allocated by windows to your STLINK VCP in Device manager: 

SofLit_0-1730218459392.png

Then in the HyperTerminal to configure these parameters:

Baudrate: 115200

Datasize: 7

Parity: None

Handshake: Off

Hope it helps.

5 replies

STTwo-32
Technical Moderator
October 19, 2024

Hello @syedhashmiraza and welcome to the ST Community :smiling_face_with_smiling_eyes:.

I suggest you to take a look at this article. It should be helpful.

Best Regards.

STTwo-32 

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.
carlosdelfino
Senior
January 18, 2025

Hello, I'm finding the article very interesting and it seems to be the answer to my question about how to direct the printf output to the virtual connection port on the USB, but I couldn't help but ask if the process is exactly the same for the Nucleo-F411RE board.

Is the UART used the same? And how many pins are also the same? I think the rest is the same.

Buy me a coffeeMy Portal about Analog ElectronicsMy Youtube Channel where I share my learning about Analog Electronic
carlosdelfino
Senior
January 18, 2025

In response to my anxious question, it worked perfectly on the Nucleo-F411RE.

Now the STM32 world opens up to great challenges.

Buy me a coffeeMy Portal about Analog ElectronicsMy Youtube Channel where I share my learning about Analog Electronic
Associate III
October 19, 2024

hey how to use printf in stm32f429i-disc1 board and my mcu is stm32f103cbt6

Andrew Neil
Super User
October 19, 2024

as @STTwo-32 already said, see this article:

https://community.st.com/t5/stm32-mcus/how-to-redirect-the-printf-function-to-a-uart-for-debug-messages/ta-p/49865

 

And here's a 3rd-party article on the same:

https://shawnhymel.com/1873/ 

 

Tip:

Get the basic direct UART output working before adding the printf stuff. 

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.
Associate III
October 19, 2024

i treid this one but still printf is not working

Associate III
October 19, 2024
#include "main.h"

#include "cmsis_os.h"

#include "usb_host.h"

#include <stdio.h>

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_CRC_Init(void);

static void MX_DMA2D_Init(void);

static void MX_FMC_Init(void);

static void MX_I2C3_Init(void);

static void MX_LTDC_Init(void);

static void MX_SPI5_Init(void);

static void MX_TIM1_Init(void);

static void MX_USART1_UART_Init(void);

void StartDefaultTask(void const * argument);



#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)







PUTCHAR_PROTOTYPE

{

HAL_UART_Transmit(&huart, (uint8_t *)&ch, 1, 0xFFFF);

return ch;

}



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_CRC_Init();

MX_DMA2D_Init();

MX_FMC_Init();

MX_I2C3_Init();

MX_LTDC_Init();

MX_SPI5_Init();

MX_TIM1_Init();

MX_USART1_UART_Init();

/* USER CODE BEGIN 2 */



/* USER CODE END 2 */



/* USER CODE BEGIN RTOS_MUTEX */

/* add mutexes, ... */

/* USER CODE END RTOS_MUTEX */



/* USER CODE BEGIN RTOS_SEMAPHORES */

/* add semaphores, ... */

/* USER CODE END RTOS_SEMAPHORES */



/* USER CODE BEGIN RTOS_TIMERS */

/* start timers, add new ones, ... */

/* USER CODE END RTOS_TIMERS */



/* USER CODE BEGIN RTOS_QUEUES */

/* add queues, ... */

/* USER CODE END RTOS_QUEUES */



/* Create the thread(s) */

/* definition and creation of defaultTask */

osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);

defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);



/* USER CODE BEGIN RTOS_THREADS */

/* add threads, ... */

/* USER CODE END RTOS_THREADS */

while (1)

{

printf("Hello World\n\r");

HAL_Delay(1000);

}

/* Start scheduler */

osKernelStart();



/* We should never get here as control is now taken by the scheduler */



/* Infinite loop */

/* USER CODE BEGIN WHILE */

while (1)

{

/* USER CODE END WHILE */



/* USER CODE BEGIN 3 */

}

/* USER CODE END 3 */

}
Tesla DeLorean
Guru
October 19, 2024

Do you have USART output working? Via HAL_UART_Transmit()

This a Yes / No question, it needs to work for printf() to succeed

How about

void OutString(char *s)
{
 while(*s) __io_putchar(*s++);
}

OutString("Hello World!\n");

Look at the code initializing the UART, clocks and pins related to it, perhaps the MSP file.

USART1  PA9:TX, PA10:RX

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Associate III
October 21, 2024

this one also not working

Andrew Neil
Super User
October 21, 2024

New Knowledge Base article today, "Implementing UART receive and transmit functions on an STM32":

https://community.st.com/t5/stm32-mcus/implementing-uart-receive-and-transmit-functions-on-an-stm32/ta-p/694926

This shows you how to do the basic HAL_UART_Transmit() - START HERE !

 

See also the linked Wiki article, "Getting started with UART":

https://wiki.st.com/stm32mcu/wiki/Getting_started_with_UART 

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
Super User
November 25, 2024
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.
Associate III
November 26, 2024

this is not working

Andrew Neil
Super User
November 26, 2024

That tells us nothing!

You've been directed to the Posting Tips before:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

You need to give full details before anyone is going to be able to help you!

So, again:

  1. What, exactly, have you tried?
    Show code (following the instructions above) & give full hardware details, tools used, etc.
  2. What were you expecting to happen?
  3. What actually happened - give full details; not just, "it didn't work"
  4. What investigation/testing/debugging have you done to find out what's going wrong?

Some general debugging tips here:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/tac-p/706966/highlight/true#M49 

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.