[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
lsmod
Posts: 65
Joined: Mon Dec 24, 2018 4:36 pm
Location: Germany

[Solved] Serial USB for Blue Pill board

Post by lsmod » Wed Dec 26, 2018 8:52 am

Hello,

i am making my first experiments with STM32duino.
Up to know i could find not an thread that answer the following questions:

I want to try to use the USB interface of the STM32 blue pill as serial device.
Programming is working with an PL2303 over the UART1 and i can receive data there.
But i want to use the built in USB for input and output.

I thought part of the flashed image is the software to use the USB interface?
Or must the bootloader of 20 KB be flashed to use the USB interface as serial device?

Of course i found out that there is the mismatching resistor R10 - i fixed it with an 1K8 resistor parallel - but without any result.

I found this page http://amitesh-singh.github.io/stm32/20 ... -pill.html
but i could not compile the software solution:

Code: Select all

// This is required if proper pullup is not present at D+ line.
// This is must for chinese stm32f103c8t6 aka "blue pill"
rcc_periph_clock_enable(RCC_GPIOA);
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
              GPIO_CNF_OUTPUT_PUSHPULL, GPIO12);
gpio_clear(GPIOA, GPIO12);
msleep(5); //delay
This results in a mass of errors with missing libraries like

Code: Select all

RTClock:115:36: error: 'rcc_periph_clock_enable' was not declared in this scope
   rcc_periph_clock_enable(RCC_GPIOA);
                                    ^
RTClock:116:24: error: 'GPIO_MODE_OUTPUT_2_MHZ' was not declared in this scope
   gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
                        ^
RTClock:117:3: error: 'GPIO_CNF_OUTPUT_PUSHPULL' was not declared in this scope
   GPIO_CNF_OUTPUT_PUSHPULL, GPIO12);
What must be done to add this to the setup?

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 Dec 26, 2018 8:59 am

The problems are a little bit similar to viewtopic.php?f=28&t=4468

I want to add that i am working with Linux.
So i can see that the USB device cannot be enumerated:

Code: Select all

...
[ 1573.486459] usb 1-6.1: new full-speed USB device number 21 using ehci-pci
[ 1573.894384] usb 1-6.1: device not accepting address 21, error -32
[ 1573.895265] usb 1-6-port1: unable to enumerate USB device

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

Re: Serial USB for Blue Pill board

Post by BennehBoy » Wed Dec 26, 2018 11:06 am

Have a read of this introductory information that MrBurnette put together -> viewtopic.php?f=2&t=3111

As it stands there's just not enough information provided for people to be able to answer effectively.

The software hack that you mention works with libopencm3 which is not relevant to any of the available Arduino cores which facilitate stm32 devices.
-------------------------------------
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 Dec 26, 2018 11:21 am

Yes - but this stuff is not organized so that it can be found easily. ;)

The Wiki says http://stm32duinoforum.com/forum/index.php?t ... USB_Serial
Serial USB is enabled for all F103 boards when uploading using the bootloader, it is also available when uploading by ST-Link (SWD) In these cases:
Serial.print("Hello world"); will print via Serial USB (CDC).
So the bootloader of 20KB must be installed (aditionally) so that serial USB is available?
Or is the meaning of the use of the standard bootloader that can be used with UART1?

There is nothing written HowTo get serial USB working when you don't want to use the additional bootloader !?

Some basics are not clear and most of the threads belongs to specific other detail problems ...

stevestrong
Posts: 3053
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: Serial USB for Blue Pill board

Post by stevestrong » Wed Dec 26, 2018 11:42 am

lsmod wrote:
Wed Dec 26, 2018 11:21 am
There is nothing written HowTo get serial USB working when you don't want to use the additional bootloader !?
Yes, the bootloader will ocupy the lowest 4k memory of the cpu, and is used to upload new code over USB DFU.
USB serial is available as default "Serial" instance, and has nothing to do with the bootloader, they are two different things.

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

Re: Serial USB for Blue Pill board

Post by BennehBoy » Wed Dec 26, 2018 1:23 pm

The main point I was making is you have not said which core you are using. CDC (Serial via USB) is not available in STM's core yet (it's available as a PR on their dev branch, but not via boards manager), but IS available in Roger's core....

There's a template for asking questions on the post I linked, it's well thought out.
-------------------------------------
https://github.com/BennehBoy

paulvdh
Posts: 17
Joined: Fri Apr 06, 2018 2:04 am

Re: Serial USB for Blue Pill board

Post by paulvdh » Thu Dec 27, 2018 12:07 am

I am also quite a beginner with STM32 and I am quite overwhelmed with al the options for STM32.
As a sort of random test project I compiled, flashed and experimented a bit with:
https://github.com/satoshinm/pill_serial

This project worked without modifications to the source code for me. It added 3 extra serial ports to my Linux box.
I tested all three very briefly by typing some characters into Minicom and a loopback wire on the Blue Pill.
All 3 Serial ports work, and they all three go through the same USB cable to my Blue Pill.
Data echoing stopped immediately when a loopback wire was disconnected, so I am sure that the data ended up at the right UsART.

According to the notes I made I had to put an 1k8 resistor between PA12 and 3V3 to get my PC (with Sitecom hub) to recognise the Blue Pill Device.

Edit:
You asked about some bootloader.
The first thing I do when starting with a new Blue Pill is to unlock the flash and probably also erase / overwrite the bootloader accordint to the hands-on primer from Pandafruits (Real nice introduction into linker scripts and such).
I simply use a Chinese ST-Link V2 clone for programming.
Last edited by paulvdh on Thu Dec 27, 2018 12:11 am, edited 1 time in total.

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

Re: Serial USB for Blue Pill board

Post by BennehBoy » Thu Dec 27, 2018 12:10 am

And again, that's another project which IS NOT an stm32duino one, it is libopencm based.

I fear you misunderstand the purpose of this forum.
-------------------------------------
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 » Thu Dec 27, 2018 1:23 pm

Thank you all for the Tips!
Now i have to experience it. :D

But it s not clear for me what Bennyboy is writing?
BennehBoy wrote:
Wed Dec 26, 2018 1:23 pm
The main point I was making is you have not said which core you are using. CDC (Serial via USB) is not available in STM's core yet (it's available as a PR on their dev branch, but not via boards manager), but IS available in Roger's core....

There's a template for asking questions on the post I linked, it's well thought out.
I thought with Blue Pill Board and STM32Duino is clear what i am using?
What is Roger's core?

Hmm - it seems there is no easy approach for the serial USB problem.
I assumed this is the most wanted function for the use of the internal USB ... :?
BennehBoy wrote:
Thu Dec 27, 2018 12:10 am
And again, that's another project which IS NOT an stm32duino one, it is libopencm based.

I fear you misunderstand the purpose of this forum.
Yes - this is an complete own project - but an interesting one!
O.K. This is not what i asked for - but gives some ideas ...

I see the purpose of this forum to learn and communicate everything to work with STM32 µC's.
STM32duino is a very good approach to get a start working with this controllers.

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

Re: Serial USB for Blue Pill board

Post by BennehBoy » Thu Dec 27, 2018 1:40 pm

BennehBoy wrote:
Wed Dec 26, 2018 11:06 am
Have a read of this introductory information that MrBurnette put together -> viewtopic.php?f=2&t=3111
^^

Everything you need is in there, you just have to make the effort to read it.

EDIT. I suspect the problem is that you are using the official STM core via the Arduino boards manager, it does not include serial over USB yet. You will need to use Roger's leaflabs based core for USB Serial -> https://github.com/rogerclarkmelbourne/Arduino_STM32 Installation instructions here -> https://github.com/rogerclarkmelbourne/ ... stallation
-------------------------------------
https://github.com/BennehBoy

Locked