[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

Re: Serial USB for Blue Pill board

Post by lsmod » Thu Dec 27, 2018 1:54 pm

BennehBoy wrote:
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 wrote:
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
Posts: 17
Joined: Fri Apr 06, 2018 2:04 am

Re: Serial USB for Blue Pill board

Post by 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

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 » Fri Dec 28, 2018 9:26 am

paulvdh wrote:
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?
Last edited by lsmod on Fri Dec 28, 2018 9:57 am, edited 2 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 » 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

Code: Select all

cd /tmp/arduino_build_914460
arm-none-eabi-objdump -h -S Blink.ino.elf > blink.lst
and get an output of 319.1 KB.
There is much stuff about initialization of IRQ, clock and timer for everything in it.

And stuff like

Code: Select all

/* Use USB_ISR_MSK to only include code for bits we care about. */
    /* TODO decide if read/modify/write is really what we want
     * (e.g. usb_resume_init() reconfigures CNTR). */
    /* Cache RX/TX statuses in SaveRState/SaveTState, respectively.
     * The various handle_foo0() may clobber these values
     * before we reset them at the end of this routine. */
    /* Set actual RX/TX statuses to NAK while we're thinking */
    set_rx_tx_status0(USB_EP_STAT_RX_NAK, USB_EP_STAT_TX_NAK);
static void usbInit(void) {
    pInformation->Current_Configuration = 0;
 80014ac:	4b0c      	ldr	r3, [pc, #48]	; (80014e0 )
 80014ae:	2200      	movs	r2, #0
 80014b0:	681b      	ldr	r3, [r3, #0]
    // Reset and power up the peripheral.
    USB_BASE->CNTR = USB_CNTR_FRES; 
 80014b2:	2101      	movs	r1, #1
    }
    return (uint8*)&line_coding;
}
static void usbInit(void) {
    pInformation->Current_Configuration = 0;
 80014b4:	729a      	strb	r2, [r3, #10]
    // Reset and power up the peripheral.
    USB_BASE->CNTR = USB_CNTR_FRES; 
 80014b6:	4b0b      	ldr	r3, [pc, #44]	; (80014e4 )
    USBLIB->irq_mask = 0;
    USB_BASE->CNTR = USBLIB->irq_mask;
    USB_BASE->ISTR = 0;
    USBLIB->irq_mask = USB_CNTR_RESETM | USB_CNTR_SUSPM | USB_CNTR_WKUPM;
    USB_BASE->CNTR = USBLIB->irq_mask;
 80014b8:	f44f 50e0 	mov.w	r0, #7168	; 0x1c00
static void usbInit(void) {
    pInformation->Current_Configuration = 0;
    // Reset and power up the peripheral.
    USB_BASE->CNTR = USB_CNTR_FRES; 
 80014bc:	6419      	str	r1, [r3, #64]	; 0x40
    USBLIB->irq_mask = 0;
 80014be:	490a      	ldr	r1, [pc, #40]	; (80014e8 )
 80014c0:	6809      	ldr	r1, [r1, #0]
    USB_BASE->CNTR = USBLIB->irq_mask;
 80014c2:	641a      	str	r2, [r3, #64]	; 0x40
    USB_BASE->ISTR = 0;
 80014c4:	645a      	str	r2, [r3, #68]	; 0x44
    USBLIB->irq_mask = USB_CNTR_RESETM | USB_CNTR_SUSPM | USB_CNTR_WKUPM;
    USB_BASE->CNTR = USBLIB->irq_mask;
 80014c6:	6418      	str	r0, [r3, #64]	; 0x40
    USB_BASE->ISTR = 0;
    USBLIB->irq_mask = USB_ISR_MSK;
 80014c8:	f44f 403f 	mov.w	r0, #48896	; 0xbf00
    USB_BASE->CNTR = USBLIB->irq_mask;
    USB_BASE->ISTR = 0;
    USBLIB->irq_mask = USB_CNTR_RESETM | USB_CNTR_SUSPM | USB_CNTR_WKUPM;
    USB_BASE->CNTR = USBLIB->irq_mask;
    USB_BASE->ISTR = 0;
 80014cc:	645a      	str	r2, [r3, #68]	; 0x44
    USBLIB->irq_mask = USB_ISR_MSK;
 80014ce:	6008      	str	r0, [r1, #0]
    USB_BASE->CNTR = USBLIB->irq_mask;
 80014d0:	6418      	str	r0, [r3, #64]	; 0x40
Well - it's a kind of magic ... :D

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 » Sat Dec 29, 2018 1:30 pm

BennehBoy wrote:
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
Posts: 3053
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: Serial USB for Blue Pill board

Post by stevestrong » Sat Dec 29, 2018 8:38 pm


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

Code: Select all

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);
And now?

The question of this Thread remains: "How to get an working serial USB with an blue pill board" ?

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 » 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//Arduino/hardware. eg ~/Arduino/hardware/

See here -> http://stm32duinoforum.com/forum/index.php?ti ... n_on_Linux
Last edited by BennehBoy on Sun Dec 30, 2018 4:38 pm, edited 1 time in total.
-------------------------------------
https://github.com/BennehBoy

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

Code: Select all

$ mkdir -p ~/Arduino/hardware
$ cd ~/Arduino/hardware
$ git clone https://github.com/rogerclarkmelbourne/Arduino_STM32.git Arduino_STM32
4.) Start Arduino IDE

5.) From the Tools menu, find the section titled "STM32F1 Boards (stm32duinoforum.com/forum)", select the "Generic STM32F103C series" board.

6.) From the Tools menu, now you can select the upload method.

o If you installed a bootloader, you can use the "STM32duino booloader" upload method. (1)
o If you have a usb serial dongle connected to PA9/PA10, you can use the "Serial" upload method. (2)
o If you have an STLink V2 connected to DCLK/DIO, you can use the "STLink" upload method. (3)
o If you have an BlackMagic probe connected to DCLK/DIO, you can use the "BMP (Black Magic Probe)" upload method. (4)

(1) You probably have to fix the pull up R10 resistor as described in the wiki (10k needs to be 1k5). Once this is fixed the bluepill should enumerate as a /dev/ttyACM0 ( assuming you don't have other ACM devices). This ACM device is used by the uploader to program the board. The Serial object in Arduino code will be the native USB device. You lose some flash to the user DFU bootloader with this method. It also introduces a delay when the chip is powered on. None of the other upload methods result in a delay at chip power on.

(2) Selecting this upload method uses the chip's ROM builtin serial uploader, It also has the side effect of turning off the define that enables the native USB. To start the ROM serial bootloader you have to move the BOOT0 pin to 1 and press the reset. You have to set it back to 0 and press reset to run the code. Code compiled using this upload method results in the Serial object in Arduino code using PA9/PA10. All flash memory available. The serial bootloader is burned at the factory to the chip's ROM. Always available and can't be deleted. See Application note AN3155

(3) Selecting this upload method uses SWD as the upload method. It doesn't matter what serial port you have selected it isn't used for upload. You will still be able to use the USB native it will be Serial (assuming you have fixed the R10 resistor probem). Serial1 is PA9/PA10. Either way, it doesn't matter which port you have selected in the Arduino IDE, it will not be used for upload, only for Serial console. All flash memory available no bootloader used.

(4) Selecting this upload method uses SWD via GDB Remote Serial Protocol to the BMP device. You must select the first BMP /dev/ttyACM device (there are 2, /dev/ttyACM0, /dev/ttyACM1) ttyACM0 is the BMP gdb debug port. This is used for programming using GDB RSP. ttyACM1 is the BMP virtual port (it acts just like an USB serial dongle). If you want to use the Arduino Serial console you must flip the port back and forth between upload and serial console mode. It is much easier to use an external program like putty on /dev/ttyACM1. All flash memory available no bootloader used.

(*) For fear of confusing the whole issue of the arm gcc toolchain, I'll not describe how to do it, however it is possible to use the arm-none-eabi-gcc toolchain from other boards packages.
-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 » 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?

Locked