[Solved] Serial USB for Blue Pill board

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:
// 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


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:

...
[ 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


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.


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 https://wiki.stm32duino.com/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
Wed Dec 26, 2018 11:42 am
[lsmod – 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.


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.


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.


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.


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 – 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 – 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.


BennehBoy
Thu Dec 27, 2018 1:40 pm
[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

^^

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


lsmod
Thu Dec 27, 2018 1:54 pm
[BennehBoy – Thu Dec 27, 2018 1:40 pm] –
Everything you need is in there, you just have to make the effort to read it.

O.K. thanks.

The problem was that i didn’t expect to find the answer to my question there.
There is no description what the difference between this cores are?
Or why they exist?

mrburnette screwed informations together on a really high abstraction layer without explaining them. ;)

[BennehBoy – Thu Dec 27, 2018 1:40 pm] –
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

Ah – i think now i have the answer for the main question of this thread. :mrgreen:
I will try to figure it out …


paulvdh
Thu Dec 27, 2018 11:03 pm
If you go to the main page of this forum index and scroll down you find a whole forum section dedicated to “cores”
viewforum.php?f=42

A “core” is a set of libraries, which form the base to build your application on.
Roger maintains a list of them in the first thread in that forum section:
viewtopic.php?f=42&t=97

It seems that what is called a “core” on this forum is somewhat comparable on what is called a “platform” on platformio:
https://platformio.org/frameworks


lsmod
Fri Dec 28, 2018 9:26 am
[paulvdh – Thu Dec 27, 2018 11:03 pm] –
A “core” is a set of libraries, which form the base to build your application on.
Roger maintains a list of them in the first thread in that forum section:
viewtopic.php?f=42&t=97

It seems that what is called a “core” on this forum is somewhat comparable on what is called a “platform” on platformio:
https://platformio.org/frameworks

Hmm – i can’t understand the advantage of this “core” concept.

Before i worked direct with avr-gcc in a very simple way.
I made smaller projects with an ATMega8 and directly included in the main.c or makefile what i need.
So i did have the total control and really small binaries with much functionality.
With the compiler option “-ffunction-sections” only needed functions where compiled and linked.
With avr-objdump i am able to create a really nice output showing the C- and generated Assembler-Code.

I tried Arduino for AVR too, but i found it disturbing to have not really control over the generated output.
There is so much overhead compiled, that you could not use smaller ВµC’s like an ATMega8.
But when you use the bigger ВµC’s, the advantage is that you have plenty of libraries that can easily be used!

When i must decide about cores for STM32duino, i see the advantage of the simple use of libraries lost !?

The blue pill board seems to have 128KB Flash in most of the cases and so there should be enough space for really big projects.
But what i can’t understand is that an simple blink-program needs 12632 Bytes FLASH and 2472 Bytes RAM.
And additional the compiled code is not able to handle the USB interface. What’s going on here? :shock:

Is there something like an similar objdump for the arm-none-eabi-gcc to see what is happening?
What is part of the core that is compiled?


lsmod
Fri Dec 28, 2018 9:50 am
There is a similar objdump named arm-none-eabi-objdump.
(I additional have installed the debian package binutils-arm-none-eabi)

So i could process the compiled blink program with

cd /tmp/arduino_build_914460
arm-none-eabi-objdump -h -S Blink.ino.elf > blink.lst


lsmod
Sat Dec 29, 2018 1:30 pm
[BennehBoy – Thu Dec 27, 2018 1:40 pm] –
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

Please – i don’t understand the meaning of
Copy the Arduino_STM32 folder to the hardware folder in your Arduino sketches folder. If the hardware folder does not exist, please create one.

What is the hardware folder in the sketches folder?

I can find the STM32duino in ~/.arduino15/packages/stm32duino
But when i add roger’s files as ~/.arduino15/packages/Arduino_STM32 nothing happens …

I have defined an folder for the sketches.
But when i copy the files to …/libraries/Arduino_STM32 it is the same.

What must be done to use this “core” ?


stevestrong
Sat Dec 29, 2018 8:38 pm
http://wiki.stm32duino.com/index.php?title=Installation

lsmod
Sun Dec 30, 2018 8:55 am
Yes – i did follow this installation and installed the “Arduino SAM Boards” additionally.

It is placed in ~/.arduino15/packages/arduino/hardware/sam/1.6.11
Then i placed the download in ~/.arduino15/packages/arduino/hardware/Arduino_STM32

Then i can find a new board “Arduino Due” with
* Programming Port
* Native USB Port

Trying to compile the Blink program for it results in compilation errors like:

Sketch wird kompiliert...
/home/me/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++ -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -Dprintf=iprintf -MMD -mcpu=cortex-m3 -mthumb -DF_CPU=84000000L -DARDUINO=10808 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino Due\""
... /srv/Arduino/Blink/Blink.ino: In function 'void setup()':
Blink:22:13: error: 'PC13' was not declared in this scope
pinMode(PC13, OUTPUT);


BennehBoy
Sun Dec 30, 2018 4:26 pm
I’m not a linux user but I think you must place the Arduino_STM32 folder in your sketches area, which will be somewhere in /home/<your user>/Arduino/hardware. eg ~/Arduino/hardware/

See here -> http://wiki.stm32duino.com/index.php?ti … n_on_Linux


Rick Kimball
Sun Dec 30, 2018 4:35 pm
How to install “Roger’s core” from github on linux and use it with a Bluepill.
AKA “libmaple core”, “original stm32duino core”, “not compatible with HAL core”. “not the one ST is working on core”

1.) In the Arduino IDE, from Tools/ menu, select Board manager and install one of the Arduino SAM cortex-m3/ or cortex-m0 cores. We will never select any of these boards, it is installed only to obtain the arm-none-eabi-g++/gcc toolchain (*)

2.) Close all Arduino windows to exit Arduino.

3.) Install latest version of Roger’s core from github into Sketch Directory/hardware/Arduino_STM32.
Note: assumes your Sketch directory is $HOME/Arduino (the default for Arduino IDE)

In a linux terminal window:
$ mkdir -p ~/Arduino/hardware
$ cd ~/Arduino/hardware
$ git clone https://github.com/rogerclarkmelbourne/Arduino_STM32.git Arduino_STM32


lsmod
Mon Dec 31, 2018 7:54 am
Thank you for the detailed description Rick!
I will test this and give feedback.

I have posted the used linux-folders in my posts above.

Some thoughts before:

1.) seems to be complete needless, because we have already installed the toolchain with the stm32duino board with the board manager.
Even if you choose “Arduino Due” you can see that ~/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++ is been called for compilation.

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?


Rick Kimball
Mon Dec 31, 2018 2:04 pm
[lsmod – 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 – 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 – 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 – 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 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:

genericSTM32F103C.menu.upload_method.STLinkMethod.build.upload_flags=-DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1 -DSERIAL_USB -DGENERIC_BOOTLOADER


lsmod
Tue Jan 01, 2019 8:51 am
Happy new year!

I am irritated, because i just followed the suggested instructions of http://wiki.stm32duino.com/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

//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();
}


BennehBoy
Tue Jan 01, 2019 12:15 pm
Did you flash a bootloader?

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.


Rick Kimball
Tue Jan 01, 2019 2:34 pm
[lsmod – 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.


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?


lsmod
Tue Jan 01, 2019 2:39 pm
[Rick Kimball – 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:


Rick Kimball
Tue Jan 01, 2019 3:24 pm
[lsmod – 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.


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.[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


Rick Kimball
Tue Jan 01, 2019 5:08 pm
[fredbox – 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 – 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


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.#include <USBComposite.h>
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);
}


Rick Kimball
Tue Jan 01, 2019 7:06 pm
Nice @fredbox! Do you have the link for the USBComposite library?

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.

lsmod
Wed Jan 02, 2019 8:34 am
Thank you Rick!
I have overseen this remark:

[Rick Kimball – 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 …


lsmod
Wed Jan 02, 2019 4:34 pm
[Rick Kimball – 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 …


lsmod
Wed Jan 02, 2019 4:52 pm
[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.

fredbox has convinced me to try the bootloader first. ;)

[Rick Kimball – 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:

[ 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

Rick Kimball
Wed Jan 02, 2019 4:53 pm
I’m going to mark this solved!

BennehBoy
Wed Jan 02, 2019 4:56 pm
Hooray :lol:

lsmod
Wed Jan 02, 2019 5:10 pm
[Rick Kimball – 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.


lsmod
Wed Jan 02, 2019 5:22 pm
It really worked only without the bootloader functionality.
I set the Arduino interface to Upload method: “STM32duino Bootloader” and tried to compile and upload my RTC program.

No reaction. :cry:

After reset the green LED flashes some times – that’s all.
Connecting with putty as serial console shows in an endless loop:
Congratulations, you have installed the STM32duino bootloader
See https://github.com/rogerclarkmelbourne/ … bootloader

For more information about Arduino on STM32
and http://www.stm32duino.com


lsmod
Wed Jan 02, 2019 5:37 pm
Now i know how to get rid of the bootloader: Just flash again over the serial interface UART1.

So it will be interesting to go the other way, because the bootloader does not really solve my problem. :P

[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.

In which folder did you drop the Roger’s core that the libraries can be included?

Now something surprising:

I just compiled your example viewtopic.php?f=28&t=4474&start=30#p52042
with the magic #include <USBComposite.h>

and it works for me too compiling with 17584 Bytes Flash and 3880 Bytes RAM.
After setting the jumper back my kernel can see
[ 6959.078076] usb 1-6.1: new full-speed USB device number 27 using ehci-pci
[ 6959.174182] usb 1-6.1: New USB device found, idVendor=1eaf, idProduct=0024
[ 6959.174194] usb 1-6.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 6959.174200] usb 1-6.1: Product: Maple
[ 6959.174206] usb 1-6.1: Manufacturer: LeafLabs
[ 6959.174811] cdc_acm 1-6.1:1.0: ttyACM0: USB ACM device


Rick Kimball
Wed Jan 02, 2019 6:19 pm
Here is a little sample I used with the composite serial that provides a reasonable approach to allow native USB serial output without a bootloader and using the builtin ROM serial uploader:

/*
composite_serial - bluepill composite serial device with reset support

tested using "Serial" upload method which doesn't configure builtin usb serial
This code allows you to leave the BOOT0 pin tied high and toggle the reset button to
upload via the USART0 (PA9/PA10) on /dev/ttyUSB0, then connect to /dev/ttyACM0
with putty without having to mess with the BOOT0 pin during development.
The USBCompositeSerial object normally doesn't toggle the PA12 pin.
This behaviour is bluepill specific. (proper bluepills only have a 1k5 pull up on PA12)
*/

#include <USBComposite.h>
#include <Streaming.h>

USBCompositeSerial SerialUSB;
uint32_t counter = 0;

void setup()
{
// toggle USBD+ (PA12 pin) to signal host to
// reenumerate our USB device on reset press
pinMode(PA12, OUTPUT_OPEN_DRAIN); // use external 1k5 resistor
digitalWrite(PA12, LOW); // force low to signal reset
delay(50);
digitalWrite(PA12, HIGH); // actually floats high, not driven

SerialUSB.registerComponent();
USBComposite.begin();
delay(100);
}

void loop()
{
// only output data if someone is listening
if ( SerialUSB.isConnected() ) {
SerialUSB << "Counter: " << counter << " - Hello World!\n";
}
counter++;
delay(500);
}


lsmod
Wed Jan 02, 2019 6:31 pm
What have i done wrong with the bootloader?
(Maybe there will be some cases where it will be useful ;) )

What is the really advantage of Roger’s core and how it can be used?
(For USB it is not needed)


Rick Kimball
Wed Jan 02, 2019 6:33 pm
[lsmod – Wed Jan 02, 2019 5:37 pm] –
Everything has been taken from the path ~/.arduino15/packages/stm32duino/hardware/STM32F1/2018.12.3/system/libmaple !

So why all this stuff about Roger’s core ? :shock:

It seems to me that at some point you used “Dan Drown’s” json file to install Roger’s core. That installs “Dan Drown’s version of Roger’s core” in the .arduino15 directory and you must be selecting the boards from that one instead of the boards from “Roger’s”.

The easiest fix is exit Arduino IDE, delete your ~/.arduino15 directory. That will destroy any configured boards and preferences and get you back to the default Arduino configuration. Then just follow the instructions for installing Roger’s core from github. Don’t modify the boards.txt file.


Rick Kimball
Wed Jan 02, 2019 6:35 pm
[lsmod – Wed Jan 02, 2019 6:31 pm] –
What have i done wrong with the bootloader?
(Maybe there will be some cases where it will be useful ;) )

What is the really advantage of Roger’s core and how it can be used?
(For USB it is not needed)

Dan Drown’s version of Roger’s core is a snapshot and changes the some of the config files.

If you install from github, you get the latest version of “Roger’s core” and to update it you just exit the Arduino IDE change directories to ~/Arduino/hardware/Arduino_STM32 and do “git pull” to grab the latest changes.


lsmod
Wed Jan 02, 2019 6:40 pm
[Rick Kimball – Wed Jan 02, 2019 6:33 pm] –
It seems to me that at some point you used “Dan Drown’s” json file to install Roger’s core. That installs “Dan Drown’s version of Roger’s core” in the .arduino15 directory and you must be selecting the boards from that one instead of the boards from “Roger’s”.

The easiest fix is exit Arduino IDE, delete your ~/.arduino15 directory. That will destroy any configured boards and preferences and get you back to the default Arduino configuration. Then just follow the instructions for installing Roger’s core from github. Don’t modify the boards.txt file.

No – i don’t believe this.
As i remember there is the same URL in the installation description for Roger’s core http://dan.drown.org/stm32duino/package … index.json
as for STM32duino with STM32F1.

Yes – of course everything is at the start point when i delete the .arduino15 directory.
But as you can see that was not the way to solve the USB problems. ;)

USB flashing with the bootloader has no priority – i will look for it another time …


Rick Kimball
Wed Jan 02, 2019 6:44 pm
[lsmod – Wed Jan 02, 2019 6:40 pm] –
No – i don’t believe this.
As i remember there is the same URL in the installation description for Roger’s core http://dan.drown.org/stm32duino/package … index.json
as for STM32duino with STM32F1.

Roger’s core doesn’t have a boards manager .json file. The only way to install it is manually. It will never end up in .arduino15. It is meant to be installed in $HOME/Arduino/hardware/Arduino_STM32


Rick Kimball
Wed Jan 02, 2019 7:18 pm
I just added Dan Drown’s .json file to my arduino preferences (http://dan.drown.org/stm32duino/package … index.json) Using the Arduino board manager it installs Dan’s version of Roger’s core in $HOME/.arduino15/packages/stm32duino/hardware/STM32F1/2018.12.3.

When I look at the Tools menu after the install, I see two sets of identical “STM32F1 Boards (STM32duino.com)”. One uses Dan’s core from .arduno15 and the other uses $HOME/Arduino/hardware/Arduino_STM32.


lsmod
Thu Jan 03, 2019 10:42 am
[Rick Kimball – Wed Jan 02, 2019 7:18 pm] –
it installs Dan’s version of Roger’s core in $HOME/.arduino15/packages/stm32duino/hardware/STM32F1/2018.12.3.

When the installation of STM32duino is indirect a version of Roger’s core then we have the explanation why Roger’s core don’t have to be installed. ;)

At least USB functionality can be added as usual as a library via “#include <USBComposite.h>”.
But this cannot be found in the documentation so far.


stevestrong
Thu Jan 03, 2019 4:33 pm
[stevestrong – Sat Dec 29, 2018 8:38 pm] –
http://wiki.stm32duino.com/index.php?title=Installation

Under the link you have been warned that the boards manager package installation method of Roger’s core is deprecated and not supported by this forum.


fredbox
Thu Jan 03, 2019 5:11 pm
But this cannot be found in the documentation so far.If you need something that has good documentation, I suggest that you pick up a copy of the book “Beginning STM32” by Warren Gay. This book is written for the Blue Pill, but doesn’t use the Arduino or any of the cores or libraries found on this forum. If you have a Safari Books account, you can read it there. Google books has some of it: https://books.google.com/books?id=UYteD … &q&f=false

mrburnette
Fri Jan 04, 2019 3:39 am
No need to buy a book if you are not looking for Arduino-ish info:
Discovering the STM32 Microcontroller
https://www.google.com/url?sa=t&source= … n/book.pdf

lsmod
Fri Jan 04, 2019 12:32 pm
Thank you for the book recommendations!

Here are the files for the book from Warren Gay:
https://github.com/Apress/Beg-STM32-Dev … pencm3-GCC

[stevestrong – Thu Jan 03, 2019 4:33 pm] –
Under the link you have been warned that the boards manager package installation method of Roger’s core is deprecated and not supported by this forum.

No need for warnings.
The problem has been solved within my expectations – everything is fine now! :D


fredbox
Fri Jan 04, 2019 10:46 pm
Here is another guide: https://www.hitex.com/fileadmin/documen … 8d-scr.pdf

lsmod
Sun Jan 06, 2019 10:40 am
I like the book from Warren Gay to understand some basic things.
Mostly he writes what i am really interested for and points out the basic facts.

But it is a problem that he is using examples that base on FreeRTOS and libopencm3,
but STM32duino is basing on the Leaflabs based core viewtopic.php?f=2&t=3111.

That’s really annoying and very unpractical.
You read about an good example, understand it, but you cannot use it in STM32duino. :(
Then you have to search an working example for STM32duino and must understand again.
Regulary you will find not an similar example and you are standing there frustrated without an solution …

How can this problem be solved?
Is the only solution to drop STM32duino and go his way without Arduino?
(Same idea in the middle of 2016 https://www.stm32duino.com/viewtopic.php?t=1218)

As i have written i see the main advantage of Arduino to use existant libraries for external components like sensors and displays etc.
But in the wiki i can’t found any positive feedback about this https://wiki.stm32duino.com/index.php?t … :Libraries ?

(Maybe this should be moved to the General discussion?)


stevestrong
Sun Jan 06, 2019 2:00 pm
[lsmod – Fri Jan 04, 2019 12:32 pm] –
The problem has been solved within my expectations – everything is fine now! :D

If solved, then leave it that way.
Open a new topic for any other question.


Rick Kimball
Sun Jan 06, 2019 2:01 pm
For a long while this thread was staying on topic. If you want to talk about books and documentation start another topic. I’ve locked this topic.

[lsmod – Thu Jan 03, 2019 10:42 am] –
At least USB functionality can be added as usual as a library via “#include <USBComposite.h>”.
But this cannot be found in the documentation so far.

To answer your original question, the reason the USBComposite library isn’t documented in the core is because it is a newly included user library. User libraries typically aren’t packaged with cores, however Arduino_STM32 isn’t usual is it :) User libraries usually are born from a blog entry or forum post. User libraries typically provide most of their documentation with examples.

This library follows that path:

See: viewtopic.php?f=13&t=2926&hilit=USBComposite
See: https://github.com/rogerclarkmelbourne/ … e/examples


Leave a Reply

Your email address will not be published. Required fields are marked *