Unable to View Output from STM32 Board via Serial Port
Greeting Everyone,
I am facing an issue with my STM32 board having STM32F103C8T6 as MCU, while trying to see a normal "Hello World" output. After debugging the board, I attempted to connect it to my PC via the serial port. To ensure proper communication, I installed the necessary Virtual COM Port drivers from the STM32 website.
However, my PC is not detecting the COM port to which the STM32 board is connected. Additionally, when I try to view the output on the Debugger Console within STM32CubeIDE, I encounter an error that prevents me from seeing the expected output.
I have written the code below that I'm using to print the Hello World which I have found online. Also I do not know if their is any problem on the code. With this I have also attached the Pin Configuration and Clock configuration details below as images.
#include "main.h"
#include "usart.h"
#include "gpio.h"
#include <stdio.h>
#include <stdint.h>
#include <stm32f1xx_hal_conf.h>
void SystemClock_Config(void);
int _write(int file, char *ptr, int len)
{
int i=0;
for(i=0;i<len;i++)
ITM_SendChar((*ptr++));
return len;
}
uint8_t count = 0;
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART2_UART_Init();
while (1)
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
count ++;
printf("Hello World count = %d \n",count);
HAL_Delay(250);
}
}
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
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_1) != HAL_OK)
{
Error_Handler();
}
}
void Error_Handler(void)
{
__disable_irq();
while (1)
{
}
}
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t *file, uint32_t line)
{
}
#endifCould you please assist me in resolving this issue? I would appreciate any guidance or troubleshooting steps you can provide to help me get the serial communication working and view the output correctly.
Thank you for your support!
Best regards,
Ratul Kar


