BluePill stm32f103c8t6 USBSerial issues

I have an issue connecting the Bluepill stm32 board via USB to my linux box. I would like to use it as a USB_CDC device.

The device gets recognized:

Apr 07 08:29:27 ferrero kernel: usb 8-1: new full-speed USB device number 26 using uhci_hcd
Apr 07 08:29:27 ferrero kernel: usb 8-1: New USB device found, idVendor=1eaf, idProduct=0004, bcdDevice= 0.00
Apr 07 08:29:27 ferrero kernel: usb 8-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Apr 07 08:29:27 ferrero kernel: usb 8-1: Product: BLUEPILL_F103C8_128K CDC in FS Mode
Apr 07 08:29:27 ferrero kernel: usb 8-1: Manufacturer: Unknown
Apr 07 08:29:27 ferrero kernel: usb 8-1: SerialNumber: 6D9144804953
Apr 07 08:29:27 ferrero kernel: cdc_acm 8-1:1.0: ttyACM0: USB ACM device
Apr 07 08:29:27 ferrero mtp-probe[13925]: checking bus 8, device 26: "/sys/devices/pci0000:00/0000:00:1d.2/usb8/8-1"
Apr 07 08:29:27 ferrero mtp-probe[13925]: bus: 8, device: 26 was not an MTP device
Apr 07 08:29:28 ferrero mtp-probe[13956]: checking bus 8, device 26: "/sys/devices/pci0000:00/0000:00:1d.2/usb8/8-1"

The device /dev/ttyACM0 is created but I cannot use it. It says I/O error:

[j0b314:/dev]$ minicom -b 9600 -D /dev/ttyACM0 
minicom: Fehler beim Öffnen der Datei »/dev/ttyACM0«: Eingabe-/Ausgabefehler

The platformio.ini is configured this way:

[env:bluepill_f103c8_128k]
platform = ststm32
board = bluepill_f103c8_128k
framework = arduino

debug_tool = jlink
upload_protocol = jlink

build_flags = -D USBCON 
          -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
          -D HAL_PCD_MODULE_ENABLED
          -D USBD_VID=0x1EAF
          -D USBD_PID=0x0004
          -D USB_PRODUCT=\"bluepill\"

The main.c looks like this:

#include <Arduino.h>

void setup() {
  // initialize LED digital pin as an output.
  pinMode(LED_BUILTIN, OUTPUT);

  // Enable USB Serial
  SerialUSB.begin();
}

void loop() {
  // turn the LED on (HIGH is the voltage level)
  digitalWrite(LED_BUILTIN, HIGH);

  // wait for a second
  delay(1500);

  SerialUSB.write("Hello from USB\r\n");

  // turn the LED off by making the voltage LOW
  digitalWrite(LED_BUILTIN, LOW);

  // wait for a second
  delay(1500);
}

Nothing changes if I exchange “SerialUSB” with “Serial”. The led flashing works as expected.

I don’t understand why the kernel says “bus: 8, device 26 was not an MTP device”

Does someone had this issue already?

Thanks

Might be interesting?

I found out that this is related to a recent change in the default Udev rules to set a catch-all rule for devices to be handled by MTP if they don’t match any other udev rules for USB devices.

Have you got the PlatformIO udev rules installed?

Also, as noted in [CDC] Serial USB without DTR · Issue #1193 · stm32duino/Arduino_Core_STM32 · GitHub, opening the serial port must be done with the DTR line equal to logic 1, otherwise the firmware won’t send output.

I have tried it with
monitor_dtr = 1

but that does not help. I wonder if /dev/ttyACM0 is really the right device. Thought it should be /dev/ttyUSB0 or something.

Yes, the platformio udev rules are installed.

Looks strange.

If I use your exact code and platformio.ini (but with upload_protocol changed to stlink), upload the firwmare and plug it into my Windows PC, I get the device

grafik

further if I look at it with a serial monitor and DTR is enabled

So the firmware is not the problem, likely your PC configuration is. I will test in a Linux VM.

Result of forwarding the USB device to a Ubuntu 20.04 VM:

[  122.701699] usb 1-2: new full-speed USB device number 3 using xhci_hcd
[  122.965026] usb 1-2: New USB device found, idVendor=1eaf, idProduct=0004, bcdDevice= 0.00
[  122.965029] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  122.965030] usb 1-2: Product: BLUEPILL_F103C8_128K CDC in FS Mode
[  122.965031] usb 1-2: Manufacturer: Unknown
[  122.965032] usb 1-2: SerialNumber: 6D8D41985356
[  122.978796] cdc_acm 1-2:1.0: ttyACM0: USB ACM device
[  122.979239] usbcore: registered new interface driver cdc_acm
[  122.979240] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
max@max-VirtualBox:~$ miniterm.py --eol CRLF --dtr 1 /dev/ttyACM0 115200
--- forcing DTR active
--- Miniterm on /dev/ttyACM0  115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
Hello from USB
Hello from USB
Hello from USB

all working nicely.

The machine has the PlatformIO udev installed.

HarHar…that is so weird. I have it also plugged into a windows 10 computer and it works so cool out of the box ;).

Maybe my udev rule is to old. I will update it. Ok good to know that I do not have a firmware issue.

The platform is MANJARO (arch linux).
The udev rules are updated, so no issue here.

I’ve had a Manjaro VM handy and in there…

[max@max-virtualbox ~]$ cat /etc/lsb-release 
DISTRIB_ID=ManjaroLinux
DISTRIB_RELEASE=20.0.3
DISTRIB_CODENAME=Lysia
DISTRIB_DESCRIPTION="Manjaro Linux"
[max@max-virtualbox ~]$ uname -a
Linux max-virtualbox 5.6.16-1-MANJARO #1 SMP PREEMPT Wed Jun 3 14:26:28 UTC 2020 x86_64 GNU/Linux
[max@max-virtualbox ~]$ sudo dmesg -w 
[  125.649675] usb 1-2: new full-speed USB device number 3 using xhci_hcd
[  125.904977] usb 1-2: New USB device found, idVendor=1eaf, idProduct=0004, bcdDevice= 0.00
[  125.904979] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  125.904981] usb 1-2: Product: BLUEPILL_F103C8_128K CDC in FS Mode
[  125.904982] usb 1-2: Manufacturer: Unknown
[  125.904982] usb 1-2: SerialNumber: 6D8D41985356
[  126.455841] cdc_acm 1-2:1.0: ttyACM0: USB ACM device
[  126.456274] usbcore: registered new interface driver cdc_acm
[  126.456275] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
[max@max-virtualbox ~]$ miniterm.py --eol crlf --dtr 1 /dev/ttyACM0 115200
--- forcing DTR active
--- Miniterm on /dev/ttyACM0  115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
Hello from USB
Hello from USB
Hello from USB
Hello from USB

and that is again with the PlatformIO udev rules installed and usergroups configured per documentation.

Maybe your kernel is somehow wrongly configured.

Very odd, very odd…

I have a

Linux ferrero 5.10.23-1-MANJARO #1 SMP PREEMPT Thu Mar 11 18:47:18 UTC 2021 x86_64 GNU/Linux

DISTRIB_ID=ManjaroLinux
DISTRIB_RELEASE=21.0
DISTRIB_CODENAME=Ornara
DISTRIB_DESCRIPTION=“Manjaro Linux”

Maybe it is really a kernel issue. I will try to down/upgrade…

Nah, not working. Tried with:

Linux ferrero 5.4.105-1-MANJARO #1 SMP PREEMPT Thu Mar 11 18:27:58 UTC 2021 x86_64 GNU/Linux

It looks like the usbcore is not registering cdc_acm. Your 2 lines:

[  126.456274] usbcore: registered new interface driver cdc_acm
[  126.456275] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters

are missing on my machine.

When you look into the loaded kernel modules, cdc_acm is loaded, yes?

[max@max-virtualbox ~]$ sudo lsmod | grep cdc
cdc_acm                45056  0

if it is loaded then maybe there is still something of higher preference (that MTP thing) so that it doesn’t get there.

I’ve updated my installation now and I’m at

[max@max-virtualbox ~]$ uname -a
Linux max-virtualbox 5.6.16-1-MANJARO #1 SMP PREEMPT Wed Jun 3 14:26:28 UTC 2020 x86_64 GNU/Linux
[max@max-virtualbox ~]$ cat /etc/lsb-release 
DISTRIB_ID=ManjaroLinux
DISTRIB_RELEASE=21.0
DISTRIB_CODENAME=Ornara
DISTRIB_DESCRIPTION="Manjaro Linux"

now and it still works

[  204.111160] usb 1-2: new full-speed USB device number 4 using xhci_hcd
[  204.366618] usb 1-2: New USB device found, idVendor=1eaf, idProduct=0004, bcdDevice= 0.00
[  204.366621] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  204.366623] usb 1-2: Product: BLUEPILL_F103C8_128K CDC in FS Mode
[  204.366624] usb 1-2: Manufacturer: Unknown
[  204.366625] usb 1-2: SerialNumber: 6D8D41985356
[  204.372036] cdc_acm 1-2:1.0: ttyACM0: USB ACM device

Still working.

[max@max-virtualbox ~]$ miniterm.py --eol crlf --dtr 1 /dev/ttyACM0 115200
--- forcing DTR active
--- Miniterm on /dev/ttyACM0  115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
Hello from USB

Yes, cdc_acm is loaded. But it is used by no one (Used by = 0). But the bluepill is physically connected.

[j0b314:~]$ lsmod
Module                  Size  Used by
cdc_acm                45056  0
mousedev               24576  0
...

I have modified the udev rules so that mtp does not fiddle around with the device (no more mtp messages appears) but that doesn’t help.

This also only goes to 2 for me if I access it using miniterm.py, otherwise it stays at 0.

I just found the manjaro settings manager and I’m updating to the same kernel version as you.

At

[max@max-virtualbox ~]$ uname -a
Linux max-virtualbox 5.10.23-1-MANJARO #1 SMP PREEMPT Thu Mar 11 18:47:18 UTC 2021 x86_64 GNU/Linux

now and still getting

[  111.254295] usb 1-2: new full-speed USB device number 4 using xhci_hcd
[  111.538420] usb 1-2: New USB device found, idVendor=1eaf, idProduct=0004, bcdDevice= 0.00
[  111.538423] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  111.538425] usb 1-2: Product: BLUEPILL_F103C8_128K CDC in FS Mode
[  111.538426] usb 1-2: Manufacturer: Unknown
[  111.538427] usb 1-2: SerialNumber: 6D8D41985356
[  111.541217] cdc_acm 1-2:1.0: ttyACM0: USB ACM device
[max@max-virtualbox ~]$ miniterm.py --eol crlf --dtr 1 /dev/ttyACM0 115200
--- forcing DTR active
--- Miniterm on /dev/ttyACM0  115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
Hello from USB

Whatever I do, I can’t seem to be able to reproduce your error :smiley:

Very weird! When I try to connect to /dev/ttyACM0 with minicom the device gets resetted and reconnected. Maybe a kernel or hostcontroller issue. Nothing with the firmware or platformio. Thanks for your support!

I have reopened a thread in the Manjaro forum because this is not a platformio issue: