[Solved] Serial USB for Blue Pill board

Generic boards that are not Maple or Maple mini clones, and don't contain the additional USB reset hardware
User avatar
Rick Kimball
Posts: 1400
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Serial USB for Blue Pill board

Post by Rick Kimball » Tue Jan 01, 2019 5:08 pm

fredbox wrote:
Tue Jan 01, 2019 4:58 pm
Flash the bootloader. https://github.com/rogerclarkmelbourne/ ... 0_pc13.bin
The whole point of his post is that he doesn't want to use the user loaded DFU bootloader, he wants to use the builtin rom serial usart bootloader. However he still wants to use native USB in his Arduino code, which isn't supported unless he modifies the boards.txt file.
fredbox wrote:
Tue Jan 01, 2019 4:58 pm
An additional suggestion is to verify that your hardware actually works. The soldering on the blue pill boards i received last week was poor and the USB port was non-functional on one of them due to a solder bridge at the connector.
In this post, he describes how he used non-arduino code that let him create a native usb dongle that created 3 serial ttyACM devices using the satoshinm code: viewtopic.php?f=28&t=4474#p51935
-rick

fredbox
Posts: 211
Joined: Tue Jul 07, 2015 4:44 pm

Re: Serial USB for Blue Pill board

Post by fredbox » Tue Jan 01, 2019 6:56 pm

The USBComposite libraries that were updated recently and included in Roger's core let you create a USB serial device without too much trouble. I didn't need to modify any of the board definitions.

Code: Select all

#include 
USBCompositeSerial CompositeSerial;
uint32_t counter = 0;
void setup() 
{
  CompositeSerial.registerComponent();
  USBComposite.begin();
  delay(2000);
}
void loop() 
{
  CompositeSerial.print("Counter: ");
  CompositeSerial.print(counter);
  CompositeSerial.println(" - Hello World!");
  counter++;
  delay(500);
}
I compiled and uploaded using a serial dongle with Boot0=1 and Boot1=0.

Code: Select all

Sketch uses 17580 bytes (13%) of program storage space.
After moving both jumpers back to 0 and plugging in the USB cable, dmesg shows a new USB serial device with a different idProduct (0024).

Code: Select all

[Tue Jan  1 12:37:30 2019] usb 3-6: new full-speed USB device number 3 using xhci_hcd
[Tue Jan  1 12:37:30 2019] usb 3-6: New USB device found, idVendor=1eaf, idProduct=0024
[Tue Jan  1 12:37:30 2019] usb 3-6: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[Tue Jan  1 12:37:30 2019] usb 3-6: Product: Maple
[Tue Jan  1 12:37:30 2019] usb 3-6: Manufacturer: LeafLabs
[Tue Jan  1 12:37:30 2019] usb 3-6: ep 0x82 - rounding interval to 1024 microframes, ep desc says 2040 microframes
[Tue Jan  1 12:37:30 2019] cdc_acm 3-6:1.0: ttyACM0: USB ACM device
Opening miniterm.py shows

Code: Select all

Counter: 161 - Hello World!
Counter: 162 - Hello World!
Counter: 163 - Hello World!
Counter: 164 - Hello World!
Counter: 165 - Hello World!
Last edited by fredbox on Tue Jan 01, 2019 7:06 pm, edited 1 time in total.

User avatar
Rick Kimball
Posts: 1400
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Serial USB for Blue Pill board

Post by Rick Kimball » Tue Jan 01, 2019 7:06 pm

Nice @fredbox! Do you have the link for the USBComposite library?
-rick

fredbox
Posts: 211
Joined: Tue Jul 07, 2015 4:44 pm

Re: Serial USB for Blue Pill board

Post by fredbox » Tue Jan 01, 2019 7:09 pm

I edited my post to show that you don't need to download anything special - it is already included in Roger's core.

User avatar
lsmod
Posts: 65
Joined: Mon Dec 24, 2018 4:36 pm
Location: Germany

Re: Serial USB for Blue Pill board

Post by lsmod » Wed Jan 02, 2019 8:34 am

Thank you Rick!
I have overseen this remark:
Rick Kimball wrote:
Tue Jan 01, 2019 3:24 pm
modify your boards.txt

My suggestion:
And i must read exactly what fredfox has done - but later when i have the time ...

When this will not work i will follow your suggestion.

I will give feedback ...

User avatar
lsmod
Posts: 65
Joined: Mon Dec 24, 2018 4:36 pm
Location: Germany

Re: Serial USB for Blue Pill board

Post by lsmod » Wed Jan 02, 2019 4:34 pm

Rick Kimball wrote:
Tue Jan 01, 2019 3:24 pm
You seem to think you can just grab anything with the words STM32 and it will work for the STM32F103C8 with roger's core? Can you just grab stuff that mentions atmel and usb and expect it to compile and run atmega32u4 usb code that you intend to run on an attiny using the arduino core?

Those articles you point to have nothing to do with the libmaple core here. They are specifically talking about an STM32F4 which is completely different than the STM32F103 we are using.

I think the problem here is a language barrier. I don't speak German so I'm probably not explaining this stuff well.
Hmm - I have understand the sense of Arduino to have one easy developement system that is able to compile cross platform the same code for different µC's and boards.
Of course only hardware can be supported that is existent - so an ATMega328 has no built in USB interface.
The STM32 are 32 Bit and not 8 Bit and so there must be incompatible differences!
Besides - i am asking me how i can access a nibble or byte on the ports for reading and writing?

So it is a good question if STM32duino is working as i expected. 8-)
My first steps did fullfill my expectations - the complicate USB handling not.
That's the reason i have written that i want to have the most complicated feature first!

The problem is more my understanding and expectations then a language barrier. :lol:

But now back to the Arduino USB adventure ...

User avatar
lsmod
Posts: 65
Joined: Mon Dec 24, 2018 4:36 pm
Location: Germany

[Solved] Re: Serial USB for Blue Pill board

Post by lsmod » Wed Jan 02, 2019 4:52 pm

fredbox wrote:
Tue Jan 01, 2019 4:58 pm
An additional suggestion is to verify that your hardware actually works. The soldering on the blue pill boards i received last week was poor and the USB port was non-functional on one of them due to a solder bridge at the connector.
fredbox has convinced me to try the bootloader first. ;)

Rick Kimball wrote:
Tue Jan 01, 2019 5:08 pm
The whole point of his post is that he doesn't want to use the user loaded DFU bootloader, he wants to use the builtin rom serial usart bootloader. However he still wants to use native USB in his Arduino code, which isn't supported unless he modifies the boards.txt file.
Now it is not the whole point any more. :lol:
But you have not told me that it is a complete different situation when the bootloader is flashed. ;)

O.K. Flashing of bootloader generic_boot20_pc13.bin works without problems.
Connecting the board with USB gives an satisfied feedback of my kernel:

Code: Select all

[ 1719.972698] usb 1-6.1: new full-speed USB device number 5 using ehci-pci
[ 1720.065769] usb 1-6.1: New USB device found, idVendor=1eaf, idProduct=0003
[ 1720.065780] usb 1-6.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1720.065786] usb 1-6.1: Product: Maple 003
[ 1720.065792] usb 1-6.1: Manufacturer: LeafLabs
[ 1720.065796] usb 1-6.1: SerialNumber: LLM 003
[ 1721.510966] usb 1-6.1: USB disconnect, device number 5
[ 1721.712357] usb 1-6.1: new full-speed USB device number 6 using ehci-pci
[ 1721.806339] usb 1-6.1: New USB device found, idVendor=1eaf, idProduct=0004
[ 1721.806349] usb 1-6.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 1721.806356] usb 1-6.1: Product: Maple
[ 1721.806361] usb 1-6.1: Manufacturer: LeafLabs
[ 1721.838126] cdc_acm 1-6.1:1.0: ttyACM0: USB ACM device
[ 1721.838438] usbcore: registered new interface driver cdc_acm
[ 1721.838440] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
Is it correct that the first part is the waiting for an flash upload and then it goes to work as an serial USB?
Last edited by lsmod on Wed Jan 02, 2019 4:56 pm, edited 2 times in total.

User avatar
Rick Kimball
Posts: 1400
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Serial USB for Blue Pill board

Post by Rick Kimball » Wed Jan 02, 2019 4:53 pm

I'm going to mark this solved!
-rick

User avatar
BennehBoy
Posts: 886
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: [Solved] Serial USB for Blue Pill board

Post by BennehBoy » Wed Jan 02, 2019 4:56 pm

Hooray :lol:
-------------------------------------
https://github.com/BennehBoy

User avatar
lsmod
Posts: 65
Joined: Mon Dec 24, 2018 4:36 pm
Location: Germany

Re: Serial USB for Blue Pill board

Post by lsmod » Wed Jan 02, 2019 5:10 pm

Rick Kimball wrote:
Wed Jan 02, 2019 4:53 pm
I'm going to mark this solved!
Not so quick my friend. :mrgreen:
First i must test if i can output serial data over USB. ;)

But thank you all!
I should edit the Wiki to leave the missing tips there if it is possible for me.

Locked