Page 1 of 1

USB CDC Serial API for blue pill

Posted: Tue Jul 04, 2023 8:03 am
by Vibhore
Hi all, I have flashed a blue-pill with maple boot loader and I am trying to use Serial capability of the bluepill board to read and write characters. My code is as follows:

Code: Select all

void setup() {
  Serial.begin(9600);  // Set the baud rate to match your serial monitor
  while(!Serial);
  Serial.println("Serial Working");
}

void loop() {
  
  if (Serial.available() > 0) {
    char receivedChar = Serial.read();  // Read the incoming character
    // Print the received character
    Serial.print("Received character: ");
    Serial.println(receivedChar);
  }
  delay(10);
  
}
While I do get "Serial Working" printed on the serial monitor, no matter what I do, I am unable to read the characters sent from my PC in the blue pill. On some debugging, I found that Serial.available() always returns 0 no matter what I send from my PC. Anyone faced similar issues with the Serial library. Enclosing a snippet for core and related information. Any leads are appreciated. Thanks!
UsbSerial.png
UsbSerial.png (43.35 KiB) Viewed 2653 times

Re: USB CDC Serial API for blue pill

Posted: Mon Aug 28, 2023 1:30 pm
by fpiSTM
Unfortunately, it works for me, if Serial.available() always return 0, this is because nothing is received.
https://github.com/stm32duino/Arduino_C ... C11-L95C11

On my side it works.

Re: USB CDC Serial API for blue pill

Posted: Mon Aug 28, 2023 4:54 pm
by ag123
Among the things, a 'blue pill' (stm32f103c8) (used to) have a 10k ohm pull up resistor at D+, some PCs/laptops have trouble with that, but most others work.
And that it seemed you are trying to use DFU (roger's) boot loader.
Do you have that boot loader installed? that needs an st-link dongle
https://www.adafruit.com/product/2548
https://www.st.com/en/development-tools/st-link-v2.html
or a usb-uart dongle to install it first hand.

oh and have you tried blinking the LED?
if the LED didn't even blink then the problem is probably elsewhere than USB CDC Serial.

oh and for DFU (roger's) libmaple boot loader, it first connects in DFU mode, and later jump to your sketch, it may take a single-ended-zero (usb reset) to get it to enumerate. i.e it first connects as vid 1eaf pid 0003 the bootloader and later jumps to your sketch which should show a different VID/PID.
if you have trouble with that you may need to 'disable/enable' the device to get it to reset. in linux there is a usbreset utilityhttps://github.com/jkulesza/usbreset

if you are still having trouble with that, an advice would be to get the st-link dongle as mention above to install your sketch.
That would 'most likely work' as you won't have to deal with another usb boot loader in the same device.