[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 » Mon Dec 31, 2018 2:04 pm

lsmod wrote:
Mon Dec 31, 2018 7:54 am
I will test this and give feedback.
Please let us know when you have a working setup using the instructions above.
lsmod wrote:
Mon Dec 31, 2018 7:54 am
I have posted the used linux-folders in my posts above.
Trying to install the core in ~/.arduino15 is the wrong place. That is why I created detailed instructions of where it should go.
lsmod wrote:
Mon Dec 31, 2018 7:54 am
1.) seems to be complete needless, because we have already installed the toolchain with the stm32duino board with the board manager.
Yes obviously, if you have already done this step.

However, I got the feeling that you thought you could use the Arduino Due board to create code for STM32 boards. This is never going to work. The Arduino DUE uses a Microchip SAM3X8E chip. The SAM3X8E also uses the cortex-m3 architecture however, all the peripherals on it are Microchip specific. The only thing compatible between an STM32F1 cortex-m3 and the SAM3X8E is the arm instruction set. Each vendor that utilizes the ARM cortex-m3 as the processor provides their own peripherals implementations (GPIO,USART,USB,I2C,SPI, etc..) that are completely incompatible with any other vendors peripherals.
lsmod wrote:
Mon Dec 31, 2018 7:54 am
You can find the folder .../sam/1.6.11/cores/arduino/USB which seems to contain the needed USB libraries.
Why it is not possible to use only this part?
The bigger question is why you think it might work? The peripherals and memory map locations for SAM3X8E are completely different from the STM32F1. Go read the reference manual for each chip and you can see this is never going to work.
-rick

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 » Mon Dec 31, 2018 2:19 pm

Once you have a working setup for Roger's core and have successfully uploaded Blink code that works using the Serial upload method, you can proceed to the next step.

Your problem is you want to use the builtin in ROM USART serial upload method but also use the native USB device. This is only possible if you modify the boards.txt file. Roger long ago made the assumption that if you wanted to use the USART Serial uploader, you probably didn't want to use the native USB. Native USB is enabled or disabled by defines passed to the compiler.

In the STM32F1/boards.txt line 380, we can look at the stlink upload method entry for the bluepill board that works with native USB:

Code: Select all

genericSTM32F103C.menu.upload_method.STLinkMethod.build.upload_flags=-DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1 -DSERIAL_USB -DGENERIC_BOOTLOADER
These flags: -DSERIAL_USB -DGENERIC_BOOTLOADER actually turn on native USB

If we now look at the serial upload method entry:

Code: Select all

genericSTM32F103C.menu.upload_method.serialMethod.build.upload_flags=-DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG
You can see it is missing those flags. You need to edit ~/Arduino/hardware/Arduino_STM32/STM32F1/boards.txt file and add those flags if you want to use both the USART serial upload and the native USB in your arduino code. You need to do this while the Arduino IDE isn't running.
-rick

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 » Tue Jan 01, 2019 8:51 am

Happy new year!

I am irritated, because i just followed the suggested instructions of http://stm32duinoforum.com/forum/index.php?title=Installation.
The second point is
Run Arduino IDE, and open the menu Tools -> Boards -> Boards Manager. Install the "Arduino SAM Boards" package (includes the Arduino Due) from the list of available boards. This installs compiler support for ARM Cortex-M3.
and i didn't understand this from the beginning. ;)
So this is complete nonsense when you have installed stm32duino before. :shock:

O.K. - then it makes of course no sense that the USB stuff of "SAM" is usable for the USB of an STM32F103!

Now i moved Roger's core to /srv/Arduino/hardware/Arduino_STM32/STM32F1/cores/maple that is my sketches folder.
In the folder maple i could find files like usb_serial.cpp that sounds to be what i want to have. ;)
The interesting part seems to be

Code: Select all

//Roger Clark. Two new begin functions has been added so that normal Arduino Sketches that use Serial.begin(xxx) will compile.
void USBSerial::begin(unsigned long ignoreBaud) 
{
volatile unsigned long removeCompilerWarningsIgnoreBaud=ignoreBaud;
	ignoreBaud=removeCompilerWarningsIgnoreBaud;
	begin();
}
void USBSerial::begin(unsigned long ignoreBaud, uint8_t ignore)
{
volatile unsigned long removeCompilerWarningsIgnoreBaud=ignoreBaud;
volatile uint8_t removeCompilerWarningsIgnore=ignore;
	ignoreBaud=removeCompilerWarningsIgnoreBaud;
	ignore=removeCompilerWarningsIgnore;
	begin();
}

Now back to the smoke test with the blink program.

Code: Select all

Using board 'genericSTM32F103C' from platform in folder: ~/.arduino15/packages/stm32duino/hardware/STM32F1/2018.12.3
Using core 'maple' from platform in folder: ~/.arduino15/packages/stm32duino/hardware/STM32F1/2018.12.3
Detecting libraries used...
Generating function prototypes...
Sketch wird kompiliert...
Compiling libraries...
Compiling core...
...
~/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++ -c -g -Os -w -DDEBUG_LEVEL=DEBUG_NONE -std=gnu++11 -MMD -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -DBOARD_generic_stm32f103c -DVECT_TAB_ADDR=0x8002000 -DERROR_LED_PORT=GPIOC -DERROR_LED_PIN=13 -mcpu=cortex-m3 -DF_CPU=72000000L -DARDUINO=10808 -DARDUINO_GENERIC_STM32F103C -DARDUINO_ARCH_STM32F1 -DSERIAL_USB -DGENERIC_BOOTLOADER -DMCU_STM32F103C8 -mthumb -march=armv7-m -D__STM32F1__ -DARDUINO_ARCH_STM32 -DMCU_STM32F103C8 -mthumb -march=armv7-m -D__STM32F1__ -DARDUINO_ARCH_STM32
-I ~/.arduino15/packages/stm32duino/hardware/STM32F1/2018.12.3/system/libmaple 
-I ~/.arduino15/packages/stm32duino/hardware/STM32F1/2018.12.3/system/libmaple/include 
-I ~/.arduino15/packages/stm32duino/hardware/STM32F1/2018.12.3/system/libmaple/stm32f1/include 
-I ~/.arduino15/packages/stm32duino/hardware/STM32F1/2018.12.3/system/libmaple/usb/stm32f1 
-I ~/.arduino15/packages/stm32duino/hardware/STM32F1/2018.12.3/system/libmaple/usb/usb_lib 
-I ~/.arduino15/packages/stm32duino/hardware/STM32F1/2018.12.3/cores/maple 
-I ~/.arduino15/packages/stm32duino/hardware/STM32F1/2018.12.3/variants/generic_stm32f103c 
~/.arduino15/packages/stm32duino/hardware/STM32F1/2018.12.3/cores/maple/usb_serial.cpp -o /tmp/arduino_build_27182/core/usb_serial.cpp.o
(Output is shortened and i replaced my home directory with ~)

You can see that usb_serial.cpp is included!
Before the blink-program needs 12632 Bytes FLASH and 2472 Bytes RAM.
Now the blink-program needs 14292 Bytes FLASH and 3096 Bytes RAM.

But when i connect the board to USB my kernel only says

Code: Select all

[ 3087.919500] usb 1-6.1: new full-speed USB device number 10 using ehci-pci
[ 3087.991484] usb 1-6.1: device descriptor read/64, error -32
[ 3088.167448] usb 1-6.1: device descriptor read/64, error -32
[ 3088.343412] usb 1-6.1: new full-speed USB device number 11 using ehci-pci
[ 3088.415393] usb 1-6.1: device descriptor read/64, error -32
[ 3088.591356] usb 1-6.1: device descriptor read/64, error -32
[ 3088.767320] usb 1-6.1: new full-speed USB device number 12 using ehci-pci
[ 3089.175234] usb 1-6.1: device not accepting address 12, error -32
[ 3089.247219] usb 1-6.1: new full-speed USB device number 13 using ehci-pci
[ 3089.655133] usb 1-6.1: device not accepting address 13, error -32
[ 3089.655821] usb 1-6-port1: unable to enumerate USB device
It's still not working. :(
The same result when i compile a sketch that is using the serial for output (RTC-example).

Can somebody explain how Arduino is putting together all the libraries?

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 » Tue Jan 01, 2019 12:15 pm

Did you flash a bootloader?
-------------------------------------
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 » Tue Jan 01, 2019 12:49 pm

No - up to now i did not try a bootloader, because i see no sense to occupy additional 20.6 KB of flash when a serial upload is working without it.

Is there a possibility to remove the additional bootloader when it was flashed?

The resistor for USB is soldered.

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 2:34 pm

lsmod wrote:
Tue Jan 01, 2019 8:51 am
Now i moved Roger's core to /srv/Arduino/hardware/Arduino_STM32/STM32F1/cores/maple that is my sketches folder.
So "/srv/Arduino" is your sketch directory. However the compiler output shows you are getting your platform and core from
~/.arduino15/packages/stm32duino/hardware/STM32F1/2018.12.3 ...

You have a seriously broken Arduino setup.
-rick

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 » Tue Jan 01, 2019 2:36 pm

It seems that i want to have the most complicated feature first! :lol:
I should simply use UART1 and the PL2303 USB-adapter. ;)

I searched a little bit around and found some interesting german texts for this problem.
Here is a complete article specially for USB on STM32: https://www.mikrocontroller.net/article ... _mit_STM32

Stefan has written that the serial usb should work out of the box, but this is half an year ago:
http://stefanfrings.de/stm32/#vcparduino

He also found out that there are some really small USB implementations:
http://stefanfrings.de/stm32/#vcpnohal
This leads to this source:
https://www.mikrocontroller.net/topic/382790#4365472
with this download
https://www.mikrocontroller.net/attachm ... XP_STM.zip
that should compile and give the functionality with only 6 kB Flash and 1,7 kB RAM.

Maybe some experts can adapt the code for STM32duino here?
Last edited by lsmod on Tue Jan 01, 2019 3:18 pm, edited 5 times in total.

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 » Tue Jan 01, 2019 2:39 pm

Rick Kimball wrote:
Tue Jan 01, 2019 2:34 pm
So "/srv/Arduino" is your sketch directory. However the compiler output shows you are getting your platform and core from
~/.arduino15/packages/stm32duino/hardware/STM32F1/2018.12.3 ...

You have a seriously broken Arduino setup.
Ah - i understand what you mean.
I expected that the installed stm32duino is used for compilation and should be correct.
But this library must be compiled from Roger's Arduino_STM32 folder.
Then .../hardware/Arduino_STM32 is still not the correct place for Roger's files !?
I don't understand why it should be placed in the sketches folder?

What should be the correct output?

As i have said - the compilation process of Arduino is mystic! :lol:

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 3:24 pm

lsmod wrote:
Tue Jan 01, 2019 2:36 pm
This leads to this source:
https://www.mikrocontroller.net/topic/382790#4365472
with this download
https://www.mikrocontroller.net/attachm ... XP_STM.zip
that should compile and give the functionality with only 6 kB Flash and 1,7 kB RAM.
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.

I gave you the simplest installation steps to get roger's/libmaple going on a linux box. Step by step. I then gave you instructions that show you how to modify your boards.txt so that it would allow you to use the native USB even though you are uploading via the usart rom serial bootloader. However, you seem to have already got your self in a state of brokeness. You are mixing and matching instructions to the point that your .arduino15 directory is broken.

My suggestion:

back up and save your ~/.arduino15
back up and save your ~/Arduino
delete ~/.arduino15
delete ~/Arduino

follow the instructions I specified
get a blink example working
ignore the fact that the /var/log/syslog is spewing messages about your bluepill USB device.

follow the instructions for modifying your boards.txt to add the defines
load the Asciitable example onto your bluepill
tail -f /var/log/syslog
make sure the boot0 pin on the bluepill is back to running mode.
unplug and replug your bluepill usb serial connection
... the whole problem with the native usb.. you aren't going to get a serial terminal running fast enough to catch the asciitable output
... you will come back when the modemmanager grabs the /dev/ttyACM0 and thinks it should be able to make calls
... you will come back when the permissions prevent you from opening /dev/ttyACM0
... you will come back and complain you see no output

It sounds to me that you should just be happy with the usart rom serial bootloader. Gain some experience using the bluepill with that setup and then tackle native USB in the future.

(here i go adding another monkey wrench to success) Maybe by the time you are getting comfortable with the STM32F1 the core being developed by ST will have native USB support for the bluepill and it will just be a simple install from the boards manager.
-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 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.

Flash the bootloader. https://github.com/rogerclarkmelbourne/ ... 0_pc13.bin
After flashing, unplug the board and move both boot jumpers to the 0 position. Plug in the USB cable and look at dmesg. Verify that both 0003 and 0004 idProduct codes appear.

Code: Select all

[Tue Jan  1 10:40:21 2019] usb 3-6: new full-speed USB device number 116 using xhci_hcd
[Tue Jan  1 10:40:21 2019] usb 3-6: New USB device found, idVendor=1eaf, idProduct=0003
[Tue Jan  1 10:40:21 2019] usb 3-6: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[Tue Jan  1 10:40:21 2019] usb 3-6: Product: Maple 003
[Tue Jan  1 10:40:21 2019] usb 3-6: Manufacturer: LeafLabs
[Tue Jan  1 10:40:21 2019] usb 3-6: SerialNumber: LLM 003
[Tue Jan  1 10:40:23 2019] usb 3-6: USB disconnect, device number 116
[Tue Jan  1 10:40:23 2019] usb 3-6: new full-speed USB device number 117 using xhci_hcd
[Tue Jan  1 10:40:23 2019] usb 3-6: New USB device found, idVendor=1eaf, idProduct=0004
[Tue Jan  1 10:40:23 2019] usb 3-6: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[Tue Jan  1 10:40:23 2019] usb 3-6: Product: Maple
[Tue Jan  1 10:40:23 2019] usb 3-6: Manufacturer: LeafLabs
[Tue Jan  1 10:40:23 2019] usb 3-6: ep 0x82 - rounding interval to 1024 microframes, ep desc says 2040 microframes
[Tue Jan  1 10:40:23 2019] cdc_acm 3-6:1.0: ttyACM0: USB ACM device
Open a serial terminal. I use miniterm.py but there are others that work just as well.

Code: Select all

miniterm.py /dev/ttyACM0
You should see the welcome message from the bootloader repeating every second or so.

Code: Select all

Congratulations, you have installed the STM32duino bootloader
See https://github.com/rogerclarkmelbourne/STM32duino-bootloader
For more information about Arduino on STM32
and http://stm32duinoforum.com/forum

Locked