STM32F103C8 USBSerial hangs on object creation

04 Feb 2019

Hello everyone,

I'm struggling with writing a hello-world type application for STM32F103C8. It just blinks the LED and outputs messages on USBSerial. This is where I'm having issues. USBSerial object hangs on creation. Consider:

#include "mbed.h"
#include "USBSerial.h"

int main() {
    DigitalOut myled(PB_0, 1), myled2(PB_1, 1);
    USBSerial serial;

    while(1) {
        myled = 1;
        myled2 = 0;
        serial.puts("GREEN\n");
        wait(1);
        myled = 0;
        myled2 = 1;
        serial.puts("RED\n");
        wait(1);
    }
}

I'm using USBSerial library for STM32F103C8 from here.

A similar project based on Arduino framework works. So I think I have a simple mistake somewhere. Please help.

01 Feb 2019

Hello, Alexander

This example might help.

ADVISE: To have a more readable code after pasting it here (to mbed pages) try to mark it up as below (with <<code>> and <</code>> tags, each on separate line at the begin and end of your code)

<<code>>
text of your code
<</code>>
04 Feb 2019

Problem solved. I'm using custom board with STM32F103C8, and it has 12 MHz crystal instead of 8 MHz on Blue Pill board. After editing mbed startup code, the USB device was recognized. I'm only beginner in mbed, maybe I should create custom target for building my code, but that was quick and dirty fix.

Zoltan, I have another question about your fork of USBDevice for STM32F103C8. It considers serial terminal to be unconnected when any of RTS or DTR lines are set from USB host. Windows 10 standard serial port driver sets them right after opening the port, so my device thought it was never connected. I saw you used only DTR line state to detect serial port opening in the past (and it works correctly on my setup), why was that behaviour changed?

04 Feb 2019

Unfortunately, I'm neither the author of the USBDevice library nor a USB expert. I just published a fork of Norimasa's library with the aim to keep it updated for STM32F103 boards. Was the modification related to RTS state detection done in a file belonging to the library (which file? which revision?) or rather in the underlying mbed library?

20 Feb 2019

The modification was done in USBSerial/USBCDC.cpp file, in the library. Revision 65.

20 Feb 2019

I have reverted the library to the revision in which the serial terminal was considered connected when control line was set from USB host.

You need to log in to post a reply