STM32duino + black pill, usb descriptor failed


#1

Hi there,

I’ve been trying to upload a simple blinking LED sketch, and to send something over the serial port (or rather USB port, emulating a COM port). The board is a “black pill”, containing an STM32f103C8T6. I measured the pull-up resistor located between D+ and VCC, and its value is 1.5 kOhm (this is often an issue with blue pill boards).

The LED blinks successfully. Both upload via STlink (clone) and DFU work (after flashing bootloader). However, after flashing the sketch, the USB device isn’t recognised anymore. An exclamation mark appears next to the device in device manager, stating “unknown usb device (device descriptor request failed)”.

I tested on two boards (from different vendors), and the issue is exactly the same. Can you guys provide me some help here?

The platform.ini file is as follows:
platform = https://github.com/platformio/platform-ststm32.git
board = bluepill_f103c8
; board = genericSTM32F103C8
framework = arduino
upload_protocol = stlink
; upload_protocol = dfu
; upload_port = anything

The main.c is very simple:
#include <Arduino.h>

#define LED_PIN PB12

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

void loop() {
digitalWrite(LED_PIN, 1);
delay(900);
digitalWrite(LED_PIN, 0);
delay(100);
Serial.println(“a”);
}


#2

Your real problem is the usb port is sketchy at best. It is terminated incorrectly and you are lucky anything worked up until now. I’m not bashing, but it is a frustrating design.

The solution is to get one of those little cheap st-link devices that connect to the pins at the opposite end of the usb port. It is seamless and you never have to change jumpers. It works in both PlatformIO or ArduinoIDE. No bootloader required.


#3

I am already using an STlink (see first post). I want to use the usb port for serial communication (data logging etc.). Given that the two boards give exactly the same error mode, AND that upload over DFU works ok (i.e. the USB port works), I suspect something is wrong in the software implementation. For completeness, a log from USBview:

[Port1] FailedEnumeration : Unknown USB Device (Device Descriptor Request Failed)

Is Port User Connectable: yes
Is Port Debug Capable: no
Companion Port Number: 5
Companion Hub Symbolic Link Name: USB#ROOT_HUB30#4&1a49b3c3&0&0#{f18a0e88-c30c-11d0-8815-00a0c906bed8}
Protocols Supported:
USB 1.1: yes
USB 2.0: yes
USB 3.0: no

   ---===>Device Information<===---

ConnectionStatus: FailedEnumeration
Current Config Value: 0x00 -> Device Bus Speed: Full (is not SuperSpeed or higher capable)
Device Address: 0x00
Open Pipes: 0
*!*ERROR: No open pipes!

      ===>Device Descriptor<===

*!*ERROR: bLength of 0 incorrect, should be 18
bLength: 0x00
bDescriptorType: 0x00
bcdUSB: 0x0000
bDeviceClass: 0x00
*!*ERROR: Device enumeration failure


#4

On a hunch, try a different port.


#5

Still the same. Also tried two different USB cables. Edit: also tried two different computers, no difference.


#6

How possible is it that there is no boot loader on the board? Your code may not include any usb initialization code. I believe the bluepill defaults the serial to pa9,10 (or what ever, I don’t remember anymore).


#7

Apparently that’s the case, thanks for the suggestion. If I upload via STlink, the serial data that I expected to be sent over USB appears on PA9.

However, according to https://wiki.stm32duino.com/index.php?title=API#Serial_.26_USB_Serial, Serial.print commands should print over USB CDC. This isn’t working in my case. Should I manually specify to use some bootloader somehwere in the pio options?

Edit: if I upload via DFU, the LED doesn’t even blink.