BluePill using Roger USB download process

Please ignore this as I only want to post something but was not allowed for new users …

Uh, ok? So what did you want to post about? o_O

I am sorry I just keep getting the message that I cannot , because I am new and I have 2 links ?..

I changed your trust level so it should work now.

Basically I can program a bluepill with roger 20k program and linux detect a virtual port and dfu. I the use maple as source. I can then download a test program and both UART and LED works, however if I try to use SPI1 I get many errors, change to stm and it complies file , but cannot download. I then change the download to dfu, and it programs, but the virual port disappears and only a dfu is sense in Linux
I want to send all info but cannot

After programming via stlink Roger < /bluepilRoger/STM32duino-bootloader/binaries/generic_boot20_pc13.binaries

Mar  4 16:56:20 AmdRyzen7 kernel: [ 4571.517366] usb 1-2: new full-speed USB device number 19 using xhci_hcd
Mar  4 16:56:20 AmdRyzen7 kernel: [ 4571.763683] usb 1-2: New USB device found, idVendor=1eaf, idProduct=0003
Mar  4 16:56:20 AmdRyzen7 kernel: [ 4571.763687] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Mar  4 16:56:20 AmdRyzen7 kernel: [ 4571.763689] usb 1-2: Product: Maple 003
Mar  4 16:56:20 AmdRyzen7 kernel: [ 4571.763691] usb 1-2: Manufacturer: LeafLabs
Mar  4 16:56:20 AmdRyzen7 kernel: [ 4571.763693] usb 1-2: SerialNumber: LLM 003
Mar  4 16:56:21 AmdRyzen7 kernel: [ 4572.539858] usb 1-2: USB disconnect, device number 19
Mar  4 16:56:21 AmdRyzen7 kernel: [ 4572.809014] usb 1-2: new full-speed USB device number 20 using xhci_hcd
Mar  4 16:56:21 AmdRyzen7 kernel: [ 4573.139370] usb 1-2: New USB device found, idVendor=1eaf, idProduct=0004
Mar  4 16:56:21 AmdRyzen7 kernel: [ 4573.139373] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
Mar  4 16:56:21 AmdRyzen7 kernel: [ 4573.139376] usb 1-2: Product: Maple
Mar  4 16:56:21 AmdRyzen7 kernel: [ 4573.139377] usb 1-2: Manufacturer: LeafLabs
Mar  4 16:56:21 AmdRyzen7 kernel: [ 4573.158315] cdc_acm 1-2:1.0: ttyACM0: USB ACM device
Mar  4 16:56:21 AmdRyzen7 kernel: [ 4573.160213] usbcore: registered new interface driver cdc_acm
Mar  4 16:56:21 AmdRyzen7 kernel: [ 4573.160214] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters

if I use this in the ini file

[env:maple]
platform = ststm32
board = maple
framework = arduino
monitor_speed = 115200
upload_port = /dev/ttyACM0

I can creats a blink led and download it successful …

#define LED PC13


void setup()
{
  // initialize LED digital pin as an output.
  pinMode(LED, OUTPUT);
  Serial.begin(115200);
}

void loop()
{
  // turn the LED on (HIGH is the voltage level)
  digitalWrite(LED, HIGH);
  // wait for a second
  delay(1000);
  // turn the LED off by making the voltage LOW
  digitalWrite(LED, LOW);
   // wait for a second
  delay(1000);
  Serial.println("Hello");
}
Mar  4 17:03:31 AmdRyzen7 kernel: [ 5003.089975] usb 1-2: USB disconnect, device number 22
Mar  4 17:03:40 AmdRyzen7 kernel: [ 5012.275919] usb 1-2: new full-speed USB device number 23 using xhci_hcd
Mar  4 17:03:41 AmdRyzen7 kernel: [ 5012.526520] usb 1-2: New USB device found, idVendor=1eaf, idProduct=0003
Mar  4 17:03:41 AmdRyzen7 kernel: [ 5012.526524] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Mar  4 17:03:41 AmdRyzen7 kernel: [ 5012.526526] usb 1-2: Product: Maple 003
Mar  4 17:03:41 AmdRyzen7 kernel: [ 5012.526528] usb 1-2: Manufacturer: LeafLabs
Mar  4 17:03:41 AmdRyzen7 kernel: [ 5012.526530] usb 1-2: SerialNumber: LLM 003
Mar  4 17:03:41 AmdRyzen7 kernel: [ 5013.257194] usb 1-2: USB disconnect, device number 23
Mar  4 17:03:42 AmdRyzen7 kernel: [ 5013.527922] usb 1-2: new full-speed USB device number 24 using xhci_hcd
Mar  4 17:03:42 AmdRyzen7 kernel: [ 5013.855643] usb 1-2: New USB device found, idVendor=1eaf, idProduct=0004
Mar  4 17:03:42 AmdRyzen7 kernel: [ 5013.855647] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
Mar  4 17:03:42 AmdRyzen7 kernel: [ 5013.855649] usb 1-2: Product: Maple
Mar  4 17:03:42 AmdRyzen7 kernel: [ 5013.855651] usb 1-2: Manufacturer: LeafLabs
Mar  4 17:03:42 AmdRyzen7 kernel: [ 5013.859612] cdc_acm 1-2:1.0: ttyACM0: USB ACM device
Filter on vendor = 0x1eaf product = 0x0003
Opening DFU capable USB device... ID 1eaf:0003
Run-time device DFU version 0110
Found DFU: [1eaf:0003] devnum=0, cfg=1, intf=0, alt=1, name="STM32duino bootloader v1.0  Upload to Flash 0x8005000"
Claiming USB DFU Interface...
Setting Alternate Setting #1 ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 0110
Device returned transfer size 1024
bytes_per_hash=399
Copying data from PC to DFU device
Starting download: [##################################################] finished!
state(8) = dfuMANIFEST-WAIT-RESET, status(0) = No error condition is present
Done!
Resetting USB to switch back to runtime mode
Waiting for /dev/ttyACM0 serial...Done
=============================================================== [SUCCESS] Took 4.41 seconds ===============================================================

Terminal will be reused by tasks, press any key to close it.
Looking for advanced Serial Monitor with UI? Check http://bit.ly/pio-advanced-monitor
--- Miniterm on /dev/ttyACM0  115200,8,N,1 ---
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
Hello
Hello
Hello
Hello

--- exit ---

All seem fine… but … if I tried to compile a program that uses SPI2 I get lots of error messages
like

> Executing task in folder addPSU: platformio run --target upload <

Processing maple (platform: ststm32; board: maple; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/maple.html
PLATFORM: ST STM32 6.0.0 > Maple
HARDWARE: STM32F103RBT6 72MHz, 17KB RAM, 108KB Flash
DEBUG: Current (blackmagic) External (blackmagic, jlink, stlink)
PACKAGES: 
 - framework-arduinoststm32-maple 1.10000.190819 (1.0.0) 
 - tool-dfuutil 1.9.190708 
 - tool-openocd 2.1000.190707 (10.0) 
 - tool-stm32duino 1.0.1 
 - toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
Converting modbusPSU.ino
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 31 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <gprintf>
|-- <SPI> 1.0
Building in release mode
Compiling .pio/build/maple/src/modbusPSU.ino.cpp.o
Compiling .pio/build/maple/libd3a/SPI/SPI.cpp.o
/home/gerrie/Documents/PlatformIO/Projects/addPSU/src/modbusPSU.ino:72:43: error: no matching function for call to 'SPIClass::SPIClass(<unnamed enum>, <unnamed enum>, <unnamed enum>, <unnamed enum>)'
 SPIClass SPI_POT(MOSI2, MISO2, SCLK2, NSS2);
                                           ^
In file included from /home/gerrie/Documents/PlatformIO/Projects/addPSU/src/modbusPSU.ino:2:0:
/home/gerrie/.platformio/packages/framework-arduinoststm32-maple/STM32F1/libraries/SPI/src/SPI.h:186:5: note: candidate: SPIClass::SPIClass(uint32)
     SPIClass(uint32 spiPortNumber);
     ^~~~~~~~
/home/gerrie/.platformio/packages/framework-arduinoststm32-maple/STM32F1/libraries/SPI/src/SPI.h:186:5: note:   candidate expects 1 argument, 4 provided
/home/gerrie/.platformio/packages/framework-arduinoststm32-maple/STM32F1/libraries/SPI/src/SPI.h:180:7: note: candidate: constexpr SPIClass::SPIClass(const SPIClass&)
 class SPIClass {
       ^~~~~~~~
/home/gerrie/.platformio/packages/framework-arduinoststm32-maple/STM32F1/libraries/SPI/src/SPI.h:180:7: note:   candidate expects 1 argument, 4 provided
/home/gerrie/.platformio/packages/framework-arduinoststm32-maple/STM32F1/libraries/SPI/src/SPI.h:180:7: note: candidate: constexpr SPIClass::SPIClass(SPIClass&&)
/home/gerrie/.platformio/packages/framework-arduinoststm32-maple/STM32F1/libraries/SPI/src/SPI.h:180:7: note:   candidate expects 1 argument, 4 provided
/home/gerrie/.platformio/packages/framework-arduinoststm32-maple/STM32F1/libraries/SPI/src/SPI.h:168:15: warning: '_spi2_this' defined but not used [-Wunused-variable]
 static void (*_spi2_this);
               ^~~~~~~~~~
/home/gerrie/.platformio/packages/framework-arduinoststm32-maple/STM32F1/libraries/SPI/src/SPI.h:165:15: warning: '_spi1_this' defined but not used [-Wunused-variable]
 static void (*_spi1_this);
               ^~~~~~~~~~
/home/gerrie/.platformio/packages/framework-arduinoststm32-maple/STM32F1/libraries/SPI/src/SPI.h:163:16: warning: 'ff' defined but not used [-Wunused-variable]
 static uint8_t ff = 0XFF;
                ^~
*** [.pio/build/maple/src/modbusPSU.ino.cpp.o] Error 1
/home/gerrie/.platformio/packages/framework-arduinoststm32-maple/STM32F1/libraries/SPI/src/SPI.cpp: In member function 'uint16_t SPIClass::transfer16(uint16_t) const':
/home/gerrie/.platformio/packages/framework-arduinoststm32-maple/STM32F1/libraries/SPI/src/SPI.cpp:383:5: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
     while (spi_is_busy(spi_d) != 0);     // wait until BSY=0
     ^~~~~
/home/gerrie/.platformio/packages/framework-arduinoststm32-maple/STM32F1/libraries/SPI/src/SPI.cpp:384:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
  uint16_t ret = spi_rx_reg(spi_d)<<8; // read and shift high byte
  ^~~~~~~~
/home/gerrie/.platformio/packages/framework-arduinoststm32-maple/STM32F1/libraries/SPI/src/SPI.cpp:387:5: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
     while (spi_is_busy(spi_d) != 0);     // wait until BSY=0
     ^~~~~
/home/gerrie/.platformio/packages/framework-arduinoststm32-maple/STM32F1/libraries/SPI/src/SPI.cpp:388:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
  ret += spi_rx_reg(spi_d);            // read low byte
  ^~~
/home/gerrie/.platformio/packages/framework-arduinoststm32-maple/STM32F1/libraries/SPI/src/SPI.cpp: In function 'spi_baud_rate determine_baud_rate(spi_dev*, uint32_t)':
/home/gerrie/.platformio/packages/framework-arduinoststm32-maple/STM32F1/libraries/SPI/src/SPI.cpp:778:12: warning: enumeration value 'RCC_AHB' not handled in switch [-Wswitch]
     switch (rcc_dev_clk(dev->clk_id))

This is using this

[env:maple]
platform = ststm32
board = maple
framework = arduino
monitor_speed = 115200
upload_port = /dev/ttyACM0
lib_extra_dirs = ~/Documents/Arduino/libraries

Changing the line baord to bluepill_f103c8 and get this

Compiling .pio/build/maple/src/modbusPSU.ino.cpp.o
Compiling .pio/build/maple/libce5/gprintf/gprintf.cpp.o
Compiling .pio/build/maple/libf8b/SPI/SPI.cpp.o
Archiving .pio/build/maple/libf8b/libSPI.a
Indexing .pio/build/maple/libf8b/libSPI.a
Archiving .pio/build/maple/libce5/libgprintf.a
Indexing .pio/build/maple/libce5/libgprintf.a
Linking .pio/build/maple/firmware.elf
Building .pio/build/maple/firmware.bin
Checking size .pio/build/maple/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   9.0% (used 1848 bytes from 20480 bytes)
Flash: [====      ]  38.5% (used 25248 bytes from 65536 bytes)
=============================================================== [SUCCESS] Took 4.92 seconds ================================

But it does not download the program ... 
I then add this line to the config 
upload_protocol = dfu

Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   9.0% (used 1848 bytes from 20480 bytes)
Flash: [====      ]  38.5% (used 25248 bytes from 65536 bytes)
Configuring upload protocol...
AVAILABLE: blackmagic, dfu, jlink, mbed, stlink
CURRENT: upload_protocol = dfu
Looking for upload port...
Use manually specified: /dev/ttyACM0
Uploading .pio/build/maple/firmware.bin
dfu-util 0.7
No DFU capable USB device found

Copyright 2005-2008 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2012 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to dfu-util@lists.gnumonks.org

Filter on vendor = 0x1eaf product = 0x0003
Waiting for /dev/ttyACM0 serial...Done
=============================================================== [SUCCESS] Took 10.81 seconds ========================

But the virual port is now gonners

Mar  4 17:05:32 AmdRyzen7 kernel: [ 5123.563182] usb 1-2: Manufacturer: LeafLabs
Mar  4 17:05:32 AmdRyzen7 kernel: [ 5123.566972] cdc_acm 1-2:1.0: ttyACM0: USB ACM device
Mar  4 17:14:47 AmdRyzen7 kernel: [ 5679.351749] cdc_acm 1-2:1.0: failed to set dtr/rts
Mar  4 17:15:33 AmdRyzen7 kernel: [ 5725.380214] usb 1-2: USB disconnect, device number 28
Mar  4 17:15:37 AmdRyzen7 kernel: [ 5728.471320] usb 1-2: new full-speed USB device number 29 using xhci_hcd
Mar  4 17:15:37 AmdRyzen7 kernel: [ 5728.717160] usb 1-2: New USB device found, idVendor=1eaf, idProduct=0003
Mar  4 17:15:37 AmdRyzen7 kernel: [ 5728.717163] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Mar  4 17:15:37 AmdRyzen7 kernel: [ 5728.717166] usb 1-2: Product: Maple 003
Mar  4 17:15:37 AmdRyzen7 kernel: [ 5728.717167] usb 1-2: Manufacturer: LeafLabs
Mar  4 17:15:37 AmdRyzen7 kernel: [ 5728.717169] usb 1-2: SerialNumber: LLM 003

What must I change in

[env:maple]
platform = ststm32
;board = maple
board = bluepill_f103c8
framework = arduino
monitor_speed = 115200
upload_port = /dev/ttyACM0
lib_extra_dirs = ~/Documents/Arduino/libraries
upload_protocol = dfu

I get simular results with

[env:bluepill_f103c8]

It should be SPI2, not SPI1 , just made a typo error.

Seems like a usage error. Your sketch may be written for the STM32Duino core (called “stm32” in PIO) and not the maple core by Roger Clark. The maple board uses core: "maple" while bluepill_f103c8 defaults to stm32:

The SPI class in the Maple core is instantiated by using only the SPI number from 1 to 3. The slave select / NSS pin is then given in the beginTransaction() call.

The STM32Duino core fits the code you have shown with the 4 pins in the consturctor.

So it’s very clear that your sketch was written against STM32Duino/STM32 core and not maple, so using board = bluepill_f103c8 is correct for that. Now to the question

The STM32Duino doesn’t activate the USB CDC interface by default. See Difficulty with getting USB serial [USB CDC] working - #6 by maxgerhardt for the needed flags.

I don’t however know if it’s possible to have the USB DFU bootloader from the Maple core AND the USB CDC from the STM32Duino core running… You might still try to pre-flash the Maple bootlader, add upload_protocol = dfu to the platformio.ini and then upload a STM32Duino firmware.

Thanks a lot, I used the reference to the CDC and it is now working. It is appreciated.

1 Like

Thanks it works now…

1 Like