PlatformIO Community

使用Paltform IO 编程STM32 F103ZET6时,串口通信不能使用

我在使用VScode中的Paltform IO 对stm32 F103ZET6开发板进行编程时,串口无法使用.TT L芯片用的是PL2303.接到了STM32的PA9和PA10上,接线和TTL芯片问题,使用Keil V5编写的软件测试过(可以用).
我的Paltform IO 代码:

#include <Arduino.h>

void setup() {
 Serial.begin(115200);
 pinMode(PA2,OUTPUT);
}

void loop() {
 digitalWrite(PA2,LOW);
 delay(2000);
 Serial.print("Test!");
 digitalWrite(PA2,HIGH);
 delay(2000);
}

然后platformio.ini是这样的:

[env:genericSTM32F103ZE]
platform = ststm32
board = genericSTM32F103ZE
; change microcontroller
board_build.mcu = stm32f103zet6
; change MCU frequency
board_build.f_cpu = 72000000L
framework = arduino
upload_protocol = jlink
debug_tool = jlink

望各位大神,提示一下出错的地方!万分感激

Translation by DeepL

When I program the stm32 F103ZET6 development board using the Paltform IO in VScode, the serial port is not working. The TTL chip is PL2303. It is connected to PA9 and PA10 of STM32, wiring and TTL chip problem, tested with software written in Keil V5 (it works).
My PaltformIO code:

Then platformio.ini looks like this:

I hope you guys can give me a hint about what’s wrong! Thank you very much!

You should write

Serial.println("Test!");

here for a newline.

This will give you the Arduino variant

And thus this code from the STM32 Arduino core will be compiled

You can see that using PA9/PA10 is wrong. The board’s UART connection will be on RX = PA3, TX = PA2.

If you don’t want to change the connections, you can also add to the platformio.ini (docs)

build_flags = 
  -DSERIAL_UART_INSTANCE=1
  -DPIN_SERIAL_TX=PA9
  -DPIN_SERIAL_RX=PA10

Then the Serial output will be on the pins you expected them to be.

万分感谢,如您的回答一样,串口已通信成功!我想咨询一下您看到这个问题的思路是什么?我该如何像您这般,迅速定位到问题的所在之处?