stm32duino / Arduino_Core_STM32

STM32 core support for Arduino
https://github.com/stm32duino/Arduino_Core_STM32/wiki
Other
2.7k stars 948 forks source link

"blue pill" w/STMF103C8 USB-CDC Serial not reading from host #2363

Closed bmo closed 1 month ago

bmo commented 1 month ago

Describe the bug With generic blue pill STM32F103C8 boards from multiple vendors, Serial.read and Serial.available do not report characters received from the host.

Setup Arduino IDE 2.3.2 STM32 support 2.7.1 ST-LINK v2 clone programmer

To Reproduce Use this sketch:

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  while (!Serial) {
    delay(100);
  }
  Serial.println("Connected!");

}

void loop() {
  // put your main code here, to run repeatedly:
  if (Serial.available() > 0) {  
    char read_ch = Serial.read();
    Serial.println("Got One");
    if (read_ch != -1) {
      Serial.print("Got a uart character ");
      Serial.println(read_ch, HEX);
    }
  }
}

Set the following under Tools: Board: "Generic STM32F1" Optimize: "Smallest (-Os default)" Board part number: "BluePill F103C8" C Runtime library: "Newlib nano (default)" Upload Method: "STM32CubeProgrammer (SWD)" USB Support (if available): "CDC (Generic 'Serial' superceds U(S)ART)" U(S)ART Support: "Disabled (no Serial support)"

Steps to reproduce the behavior:

  1. Program the target board
  2. Disconnect programmer
  3. Plug the target into a serial port (accept notifications for new hardware if provided)
  4. Select serial port installed in step 3 for Monitor
  5. Show monitor window
  6. Note "Connected!" message
  7. Type characters in send control, hit enter
  8. Note that no characters are displayed.

Expected behavior After connection, and after typing characters that are sent to the target board, the character codes should be echoed back to the host, like this (this was taken from success STM32F103ZE board):

10:49:45.499 -> Connected!
10:49:51.093 -> Got One
10:49:51.093 -> Got a uart character 6A
10:49:51.093 -> Got One
10:49:51.093 -> Got a uart character 6B
10:49:51.093 -> Got One
10:49:51.093 -> Got a uart character 6A
10:49:51.093 -> Got One
10:49:51.093 -> Got a uart character 6B

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Board (please complete the following information):

Additional context Also tested with the following other boards/processors:

fpistm commented 1 month ago

Hi @bmo I've tested your sketch with a BluePill F103C8 with Serial disabled and USB CDC enabled and it works. image