rogerclarkmelbourne / Arduino_STM32

Arduino STM32. Hardware files to support STM32 boards, on Arduino IDE 1.8.x including LeafLabs Maple and other generic STM32F103 boards
Other
2.5k stars 1.26k forks source link

USBSerial does not start #881

Closed ZavenArra closed 2 years ago

ZavenArra commented 2 years ago

I am attempting to use the USBSerial object provided in the USBComposite library. However, USBSerial never starts. I have ground, D+ and D- (PA12 and PA11 on the F103RB Nucleo) from the STM32F103RB pinout connected to a USB cable that is plugged into my computer. The gist below shows how I am using the code, which I believe is correct - I tried both ways recommended in the README. I also verified that USBCLK is running at 48MHz. The code simply sits in the while loop. I also dug into the library at little bit, and I can see that the USB_CONNECTED and USB_CONFIGURED booleans never change. What is missing here? Is this a problem with my code, or an issue with the library support?


  USBComposite.clear(); // clear any plugins previously registered
  USBSerial.registerComponent(); 
  USBComposite.begin();
  while(!USBComposite)
  {
    Serial2.println("waiting");
    delay(1000);
  }

  or 

  USBSerial.begin();
  while(!USBSerial)
  {
    Serial2.println("waiting");
    delay(1000);
  }

https://gist.github.com/ZavenArra/bd261c8eb6cbd8e77ec94c39e0f29eb7

JiriBilek commented 2 years ago

In all schematics around F103 there is a resistor from D+ to +5V. Do you have it there? I guess it is needed for USB Enumeration process.

ZavenArra commented 2 years ago

Thanks, that was it!

ZavenArra commented 2 years ago

@JiriBilek Where did you review schematics to come to this conclusion?

JiriBilek commented 2 years ago

You can find it easily, just google "bluepill schematics". One for all: https://microcontrollerslab.com/stm32f103c8t6-blue-pill-pinout-peripherals-programming-features/

Edit: I misunderstood your question. The schematics for Nucleo-F103RB is downloadable from STM's website: https://www.st.com/resource/en/schematic_pack/nucleo_64pins_sch.zip As you can see there is no resistor on PA12 and PA11.

ZavenArra commented 2 years ago

Oh I have the nucleo schematics, I meant how you knew to add the resistor. The blue pill schematic is actually what I did want, didn't think of that. Good reference for building a system off F103. Thanks!

JiriBilek commented 2 years ago

I checked the pullup resistor value - it should be 1k5 according to e.g. https://forum.arduino.cc/t/blue-pill-usb-and-1-8k-resistor/606316 I have several boards with 10k resistors and they generally work but sometimes, the enumeration fails. So please use 1k5.

JiriBilek commented 2 years ago

One more follow-up: the resistor should be to 3.3V - see https://community.st.com/s/question/0D50X00009XkY1uSAF/stm32f103-usb-circuit But for me 5V was always fine.