alternative way to use STM DFU in Arduino 1.8.3 on Black F407VET6

Limited support for STM32F4 Discovery, Nucleo and custom F4 boards
poiuycat
Posts: 17
Joined: Tue Aug 22, 2017 4:53 pm

alternative way to use STM DFU in Arduino 1.8.3 on Black F407VET6

Post by poiuycat » Fri Oct 06, 2017 9:09 am

this is a demonstrate how to use STM DFU in Ardunio 1.8.3
for those who don't have STLINK do like to download vs USB STM DFU mode

first setup the Black F407VET6 set the jumper from PA0 to BOOT0
Image



Hold the K_UP button and plug the USB cable to PC.
(Due to the design, Hold the K_UP button and press the RESET will not enter to STM DFU mode)

Select Arduino tools to STM DFU and press upload button.
Image

When upload is completed MCU will auto reset and run the code.
and you will see the Upgrade successful !
Image


continue ...... how to setup the STM dfu in Arduino
Last edited by poiuycat on Sat Oct 07, 2017 8:44 am, edited 3 times in total.

poiuycat
Posts: 17
Joined: Tue Aug 22, 2017 4:53 pm

Re: alternative way to use STM DFU in Arduino 1.8.3 on Black F407VET6

Post by poiuycat » Fri Oct 06, 2017 9:35 am

Download the DfuSe Commandline Master.rar

https://hackaday.io/project/4139-stm32- ... -converter



create a directory in <user>\Documents\Arduino\hardware\Arduino_STM32-master\tools\win\stfdu
unzip to "stfdu" directory


modify the platform.txt in Arduino\hardware\Arduino_STM32-master\STM32F4


change the compiler from binary to ihex , because the upload tools required.

Code: Select all

compiler.elf2hex.flags=-O ihex
compiler.elf2hex.cmd=arm-none-eabi-objcopy

Code: Select all

## Create hex
recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"


## Save Compiled Binary
recipe.output.tmp_file={build.project_name}.hex
recipe.output.save_file={build.project_name}.{build.variant}.hex

add stmDFU upload

Code: Select all

# stmDFU upload
tools.stmDFU_upload.cmd=stmDFU_upload
tools.stmDFU_upload.cmd.windows=stmDFU_upload.bat
tools.stmDFU_upload.path.windows={runtime.hardware.path}/tools/win
tools.stmDFU_upload.path.macosx={runtime.hardware.path}/tools/macosx
tools.stmDFU_upload.path.linux={runtime.hardware.path}/tools/linux
tools.stmDFU_upload.path.linux64={runtime.hardware.path}/tools/linux64
tools.stmDFU_upload.upload.params.verbose=-d
tools.stmDFU_upload.upload.params.quiet=
tools.stmDFU_upload.upload.pattern="{path}/{cmd}" {serial.port.file} {upload.altID} {upload.usbID} "{build.path}/{build.project_name}.hex"

platform.txt
(8.92 KiB) Downloaded 11 times

modify the boards.txt

change tool to stmDFU_upload

Code: Select all

#generic_f407v.upload.tool=stlink_upload
#generic_f407v.upload.protocol=stlink
generic_f407v.upload.tool=stmDFU_upload
generic_f407v.upload.protocol=stlink
add tools menu

Code: Select all

generic_f407v.menu.usb_cfg.usb_dfu=STM DFU
generic_f407v.menu.usb_cfg.usb_dfu.build.cpu_flags=-DSERIAL_USB
boards.txt
(5.83 KiB) Downloaded 11 times

create the stmDFU_upload.bat in Arduino\hardware\Arduino_STM32-master\tools\win

Code: Select all

@echo off
rem: Note %~dp0 get path of this batch file
rem: Need to change drive if My Documents is on a drive other than C:
set driverLetter=%~dp0
set driverLetter=%driverLetter:~0,2%
%driverLetter%
cd %~dp0
rem: the two line below are needed to fix path issues with incorrect slashes before the bin file name
set str=%4
set str=%str:/=\%


rem: ------------- use STM DFU


"stfdu\DfuSe Commandline Master\BIN\DfuFileMgr.exe" %4 %4.dfu > nul
"stfdu\DfuSe Commandline Master\BIN\DfuSeCommand.exe" -c -d --fn %4.dfu -l

Done . 8-)


PS: I wonder how do I make USB serial work in DFU download.

edit:
thanks stevestrong USB serial work in stevestrong repo
STMdfu_batchfile for Stevestrong repo.rar
(5.82 KiB) Downloaded 7 times
Last edited by poiuycat on Fri Oct 06, 2017 4:52 pm, edited 4 times in total.

stevestrong
Posts: 1743
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: alternative way to use STM DFU in Arduino 1.8.3 on Black F407VET6

Post by stevestrong » Fri Oct 06, 2017 12:06 pm

poiuycat wrote:
Fri Oct 06, 2017 9:35 am
PS: I wonder how do I make USB serial work in DFU download.
You have to add -DSERIAL_USB to the cpu_flags in "boards.txt":

Code: Select all

generic_f407v.menu.usb_cfg.usb_dfu.build.cpu_flags=-DSERIAL_USB
This will compile the USB CDC part of the core so that you will be able to use USB serial after uploading.

poiuycat
Posts: 17
Joined: Tue Aug 22, 2017 4:53 pm

Re: alternative way to use STM DFU in Arduino 1.8.3 on Black F407VET6

Post by poiuycat » Fri Oct 06, 2017 12:27 pm

stevestrong wrote:
Fri Oct 06, 2017 12:06 pm
You have to add -DSERIAL_USB to the cpu_flags in "boards.txt":

Code: Select all

generic_f407v.menu.usb_cfg.usb_dfu.build.cpu_flags=-DSERIAL_USB
This will compile the USB CDC part of the core so that you will be able to use USB serial after uploading.
I did try before adding -DSERIAL_USB in cpu_flags but it wont compile at all !! usb not working and program not blinking.
that why I put -DUSB_NC

and I also tried add compiler.libs with usbF4/VCP , and still no working...... maybe I still miss something ?!?!

Code: Select all

compiler.libs.c.flags="-I{build.core.path}" "-I{build.system.path}/libmaple" "-I{build.core.path}/libmaple/usbF4" "-I{build.core.path}/libmaple/usbF4/STM32_USB_Device_Library/Core/inc" "-I{build.core.path}/libmaple/usbF4/STM32_USB_Device_Library/Class/cdc/inc" "-I{build.core.path}/libmaple/usbF4/STM32_USB_OTG_Driver/inc" "-I{build.core.path}/libmaple/usbF4/VCP" 


stevestrong
Posts: 1743
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: alternative way to use STM DFU in Arduino 1.8.3 on Black F407VET6

Post by stevestrong » Fri Oct 06, 2017 1:18 pm

poiuycat wrote:
Fri Oct 06, 2017 12:27 pm
I did try before adding -DSERIAL_USB in cpu_flags but it wont compile at all !!
Please post here the complete build output, including any error/warning message.

poiuycat
Posts: 17
Joined: Tue Aug 22, 2017 4:53 pm

Re: alternative way to use STM DFU in Arduino 1.8.3 on Black F407VET6

Post by poiuycat » Fri Oct 06, 2017 1:31 pm

stevestrong wrote:
Fri Oct 06, 2017 1:18 pm
poiuycat wrote:
Fri Oct 06, 2017 12:27 pm
I did try before adding -DSERIAL_USB in cpu_flags but it wont compile at all !!
Please post here the complete build output, including any error/warning message.
this is the complete build output with out any error.
DSERIAL_USB.txt
(81.77 KiB) Downloaded 11 times

stevestrong
Posts: 1743
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: alternative way to use STM DFU in Arduino 1.8.3 on Black F407VET6

Post by stevestrong » Fri Oct 06, 2017 1:44 pm

You wrote that
it won't compile at all!
And I expect that you show us why it does not compile at all, show us the error messages.

Or do you mean that USB serial will not work?

poiuycat
Posts: 17
Joined: Tue Aug 22, 2017 4:53 pm

Re: alternative way to use STM DFU in Arduino 1.8.3 on Black F407VET6

Post by poiuycat » Fri Oct 06, 2017 1:46 pm

poiuycat wrote:
Fri Oct 06, 2017 1:31 pm
stevestrong wrote:
Fri Oct 06, 2017 1:18 pm
poiuycat wrote:
Fri Oct 06, 2017 12:27 pm
I did try before adding -DSERIAL_USB in cpu_flags but it wont compile at all !!
Please post here the complete build output, including any error/warning message.
this is the complete build output with out any error.
DSERIAL_USB.txt
I found something strange !!
if I comment out
//Serial.begin(115200);
//Serial.println("OK!!!!!!!!!!");
complete build will fine and STM serial came out

if I use SerialUSB or Serial complete build OK but not working
SerialUSB.begin(115200);
SerialUSB.println("OK!!!!!!!!!!");
SerialUSB not working.txt
(81.77 KiB) Downloaded 9 times

Finally that I found I cannot use SerialUSB.begin(115200)
default SerialUSB 9600 without init will work .... not sure why

stevestrong
Posts: 1743
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: alternative way to use STM DFU in Arduino 1.8.3 on Black F407VET6

Post by stevestrong » Fri Oct 06, 2017 2:30 pm

I always use a delay of 1000 ms right at the beginning of setup, before calling Serial begin:

Code: Select all

void setup() {
  delay(1000); // seems to be needed
  Serial.begin(115200);
  Serial.println("bla-bla");
  ...
}
Do you use the latest version from Roger's repo or my repo? My repo is a bit further advanced with respect to F4 development. Although in this regard it should not make any difference, there was no development in the USB direction lately.

Can you show us your sketch?

poiuycat
Posts: 17
Joined: Tue Aug 22, 2017 4:53 pm

Re: alternative way to use STM DFU in Arduino 1.8.3 on Black F407VET6

Post by poiuycat » Fri Oct 06, 2017 3:37 pm

stevestrong,

after few round of test and yes it work on you repo but not work on Roger's repo

thanks again. :lol:

Post Reply