cancel
Showing results for 
Search instead for 
Did you mean: 

How to use printf

syedhashmiraza
Associate II

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

1 ACCEPTED SOLUTION

Accepted Solutions

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

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.

View solution in original post

18 REPLIES 18
STTwo-32
ST Employee

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.

syedhashmiraza
Associate II

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

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. 


@syedhashmiraza wrote:

 in stm32f429i-disc1 board and my mcu is stm32f103cbt6


That doesn't make sense!

As its name suggests, the stm32f429i-disc1 board contains an stm32f429i microcontroller - not an stm32f103cbt6.

 

But, anyhow, the method to get printf working is the same irrespective of what microcontroller you use.

iam using stm32f429i-disc1 microcontroller for debug reason how to use printf

i treid this one but still printf is not working

Do you have USART output working? Via HAL_UART_Transmit()

Show code.

Plumb that into __io_putchar() or syscalls/_write()

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
syedhashmiraza
Associate II
#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 */

}

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 Venmo
Up vote any posts that you find helpful, it shows what's working..