Two problems using stm32f103rct6 with pio

1.After I download the program to the flash,it supposed to display something through serial port,but it didnt.The same code was fine worked in the stm32CUBEide. The project was configured as stm32cube framework.Here is the main.c file.

2.I can’t debug.When I press F5 ,the Building process triggered,and then nothing happend,the left panel of Vscode didn’t show debug contents like variables or break point.

  1. I need all project files (code + platfomio.ini) to judge why it isn’t working
  2. Even though it seemed like nothing had happened, the “Debug Console” tab still should have some output, please post it.

And here is the ini:

platform = ststm32
board = genericSTM32F103RC
framework = stm32cube
upload_protocol = jlink-jtag
debug_tool = jlink
monitor_speed = 115200

here is the main.c:

#include <stm32f1xx_hal.h>
unsigned char buf[] = "spggogogo!!!";
UART_HandleTypeDef huart1;

int main()
return 0;

void SystemClock_Config(void)
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {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.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

/** Initializes the CPU, AHB and APB buses clocks
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)

static void MX_USART1_UART_Init(void)
huart1.Instance = USART1;
huart1.Init.BaudRate = 115200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart1) != HAL_OK)


* @brief This function is executed in case of error occurrence.
* @retval None
void Error_Handler(void)
/* User can add his own implementation to report the HAL error return state */
while (1)

Actually just nothing even in the Debug Console,and I have re-install the PIO in Vscode ,it still doesn’t work.

Open a CLI and execute

pio debug -v --interface=gdb -- -x .pioinit

what’s the output?

SEGGER J-Link GDB Server V7.70a Command Line Version

JLinkARM.dll V7.70a (DLL compiled Aug 10 2022 16:32:56)

Command line: -singlerun -if SWD -select USB -device STM32F103RC -port 2331
-----GDB Server start settings-----
GDBInit file: none
GDB Server Listening port: 2331
SWO raw output listening port: 2332
Terminal I/O port: 2333
Accept remote connection: localhost only
Generate logfile: off
Verify download: off
Init regs on start: off
Silent mode: off
Single run mode: on
Target connection timeout: 0 ms
------J-Link related settings------
J-Link Host interface: USB
J-Link script: none
J-Link settings file: none
------Target related settings------
Target device: STM32F103RC
Target device parameters: none
Target interface: SWD
Select auto target interface speed (4000 kHz)
Resetting target
Loading section .isr_vector, size 0x1e4 lma 0x8000000
Loading section .text, size 0xf0 lma 0x80001e4
Loading section .init_array, size 0x4 lma 0x80002d4
Loading section .fini_array, size 0x4 lma 0x80002d8
Start address 0x8000270, load size 732
Transfer rate: 79 KB/sec, 183 bytes/write.
Temporary breakpoint 1 at 0x8000228
PlatformIO: Initialization completed
(gdb) PlatformIO: Resume the execution to debug_init_break = tbreak main
PlatformIO: More configuration options → Redirecting...

Okay so it indeed loads up in JLink SWD mode (which is differnt to the jlink-jtag upload protocol you specified, you may want to correct that).

But it doesn’t hit main. Maybe it’s hanging up before that. When you press Ctrl+C, the program should halt in-place. Execute backtrace then. What’s the output?

Things turn out wierd like ,I used command line to debug the program through jlink gdb server and gdb,and i set no break point else but only on the “main”,but the program still halted earlier or just run haywire,I can not even knows what’s wrong.Backtrace didn’t work either.
I suppose there are still some problems to use the PIO to develop stm32f103,I will get back to STM32cubeIDE Temporarily,which work just fine.Thanks a lot for answering.

I routinely program my STM32 chips with STLink in the PlatformIO and never had problems. I’m pretty sure it’s just a configuration of code issue. Importing STM32Cube projects in PlatformIO has some pitfalls that can lead to problems, such as different STM32HAL versions used in PlatformIO and STM32CubeIDE, or configuration files being missing / unused in the PlatformIO project, clock configuration issues, etc.

Since debugging seems to at least start up in the CLI and PlatformIO, is there no debug control panel like


in which you can press pause?

yes,no panel like that,but this problem seems like has no business with stm32,because I used another RISCV chip before with the same problem.I have reinstalled the PIO but it did not help.:joy::joy:


Try only having the C/C++ extension by Microsoft and PlatformIO installed, or all other deactivated for the workspace.

okay,I will try it tomorrow,thanks a lot!

I disabled those extensions and it worked!
Now I can debug in Vscode and everything seems work fine.,just the serial still not work.I will check it.
Thanks a lot

now I have tested the GPIO output both in PIO and stm32cubeIDE ,and all worked fine.
but when I test the serial port,the program worked which built in cubeIDE ,but didn’t work which built in PIO,while they ran exactly the same code.
did I missed something? I tried to add this config into the .ini file according to another answer from you in another topic:

build_flags = 

also tried

build_flags = 

neither worked.Can u give me some advices?

You’d need to upload both PlatformIO + STM32Cube projects for me to be able to say anything about it.

well,I figured it out.

__weak void HAL_UART_MspInit(UART_HandleTypeDef *huart)
  /* Prevent unused argument(s) compilation warning */
  /* NOTE: This function should not be modified, when the callback is needed,
           the HAL_UART_MspInit could be implemented in the user file

this function was called in ‘HAL_UART_Init’, but it is just a weak definition without any content.It should be like this:

void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  /* USER CODE BEGIN USART2_MspInit 0 */

  /* USER CODE END USART2_MspInit 0 */
    /* Peripheral clock enable */

    /**USART2 GPIO Configuration
    PA2     ------> USART2_TX
    PA3     ------> USART2_RX
    GPIO_InitStruct.Pin = GPIO_PIN_2;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_3;
    GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /* USER CODE BEGIN USART2_MspInit 1 */

  /* USER CODE END USART2_MspInit 1 */


the code above was copied from cubeIDE,and that is why cubeIDE build a available program.By the way,‘SysTick_Handler’ should be implemented too like this to make sure the ‘timeout’ in ‘HAL_UART_Transmit’ take effect:

void SysTick_Handler(void)
  /* USER CODE BEGIN SysTick_IRQn 0 */

  /* USER CODE END SysTick_IRQn 0 */
  /* USER CODE BEGIN SysTick_IRQn 1 */

  /* USER CODE END SysTick_IRQn 1 */

lucky me and thank you!