Upload codes to Blue Pill using dfu method

Hi there, I have a customized usb bootloader for my blue pill. I’m using stm32cube framework for my code. I can successfully upload my code using dfu-util with a command like
dfu-util -a 0 -s 0x08002000 -D firmware.bin
I also recognize that PlatformIO support dfu-util but it seems it only works for arduino framework which requires maple core. So is it possible to upload my code thru dfu-util on PIO? Thanks all!

Per platform logic, setting upload_protocol = dfu will invoke dfu-util except for all microcontrollers starting with stm32f103, there it is remapped to maple_upload.

What’s the exact platformio.ini?

Thanks for your reply. So far I haven’t had much configuration. Pretty simple I believe.

[env:genericSTM32F103C8]
platform = ststm32
board = genericSTM32F103C8
framework = stm32cube
upload_protocol = 
    stlink 
;    dfu
; upload_flags = 
;    -c set CPUTAPID 0x2ba01477  ; override default CPU ID for the clone
lib_extra_dirs = ; add a local folder where one or more libraries can be found
    ${PROJECT_DIR}\3rd-party lib
board_build.ldscript =  ;   override default LD script
    STM32F103C8_FLASH.ld
board_upload.offset_address = 0x2000 ; change the base address of the code for DFU mode
; build_flags = 
;    -DDFU_MODE
;    -UVECT_TAB_OFFSET
;    -DUSER_VECT_TAB_ADDRESS
;    -DVECT_TAB_OFFSET=0x2000   ; override default vector tale to support ISR table for DFU mode

Open the file C:\Users\<user>\.platformio\platforms\ststm32\builder\main.py locally at line 228

and change it to

        elif board.get("build.mcu").startswith("stm32f103") and False:

to prevent PlatformIO from remapping it to maple_upload.

What does a “Advanced → Verbose Upload” show then as the final upload command?

Hi, it looks like this. I’m not with my device so will upload results when using Verbose Upload later on!
dfu