JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 07:51 17 Jun 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : CMM2 - Loading the firmware using Linux

Author Message

Joined: 18/11/2011
Location: United Kingdom
Posts: 3683
Posted: 10:24am 26 May 2020
Copy link to clipboard 
Print this post

Tested using a laptop PC but any RPi or other Linux host should also work.

The idea is to use the STM32's internal DFU (Device Firmware Update).  This is always available so you can't "brick" the chip.

You can use STM32Cube Programmer if you wish - see the CMM2 User Manual Appendix G - but let's use the command-line program dfu-util (also available for Windows & MacOS).

Your Linux distro (distribution) may well have dfu-util, if so install it (e.g. apt-get install dfu-util) but otherwise download its source.  It compiles as usual (./configure; make; sudo make install).  The latest version looks to be 0.9.

dfu-util has slightly odd syntax but works well.

1. Make sure your CMM2 / Waveshare board is not plugged in even via USB.

2. Use a Linux terminal (konsole or whatever you like) for command-line input.

3. If you're happy to use root a little then skip to step 4.  For this kind of very limited use, I'd skip to that step!

Otherwise, you need to tell the Linux USB subsystem enough to let you (as non-root) use the specific device VID & PID used by DFU mode.

You do that (as root) with a file in /etc/udev/rules.d, so create stm32.rules (you can use any name but it may need to end .rules) in there with content such as:
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="df11", MODE="0666"

That lets every user have read/write access.  (You can restrict it if you care.)

Then as root kick the device admin stuff:
udevadm control --reload

If you've done the above successfully, from this point on you don't need root and can omit the "sudo" in future commands.  (Include the sudo if things don't work, as something's not quite right.)

4. Set BOOT CONFIG switch to SYSTEM (this is what activates DFU mode).

5. With a Waveshare board you can either use its USB micro-B (set board power switch to USB) or via the CMM2 motherboard (set Waveshare board power switch to 5VIN) and the mobo's USB A.  I don't have the mobo that includes the STM32H7 but I think you'd use its USB A.

6. Plug the other end of your USB cable in to your PC (or RPi or other host, and yes it should work via a USB hub I reckon).

(If you're familiar with dmesg, you can if you wish check it found a DFU device.)

7. To check all is working, you can type either:
sudo dfu-util -l
su -c "dfu-util -l"

(you do need quotes)

Use the second one if your login is not a member of sudoers (you'll be prompted for the root password).

8. You should get output like:
Found DFU: [0483:df11] ver=0200, devnum=75, cfg=1, intf=0, path="1-1.1", alt=1, name="@Option Bytes   /0x5200201C/01*128 e", serial="200364500000"
Found DFU: [0483:df11] ver=0200, devnum=75, cfg=1, intf=0, path="1-1.1", alt=0, name="@Internal Flash   /0x08000000/16*128Kg", serial="200364500000"

It's cryptic, but shows you USB device VID 483 PID df11 has 2 chunks of flash available.  One (alt 1) is for the device options (which we leave alone).  The other (alt 0) is what we want.

9. To program the STM32 use a command like:
sudo dfu-util -d ,483:df11 --alt 0 -s 0x08000000:leave --download xxx.bin
su -c "dfu-util -d ,483:df11 --alt 0 -s 0x08000000:leave --download xxx.bin"

Note the comma (,) before the 483 and the word leave (I did mention the odd syntax).
(That comma is to restrict dfu-util's searching.)

Replace xxx.bin with the name of your firmware file.

You should see output from dfu-util as the file is sent to the STM32.

10. When complete, unplug the USB cable, remember to set the switch(es) back to FLASH and 5VIN, and you should have a working CMM2.


Joined: 05/03/2018
Location: Netherlands
Posts: 3691
Posted: 07:00am 27 May 2020
Copy link to clipboard 
Print this post

Hi John,

Thanks for this info.

I have succesfully installed dfu-util on a Pi4, and used it to upgrade my ARMmiteF4 to the latest software.

The ARMmiteF4 has 4 banks (alt 0 ... alt 3), where also 0 is the flash memory.


Edited 2020-05-27 17:02 by Volhout

Joined: 18/11/2011
Location: United Kingdom
Posts: 3683
Posted: 07:55am 27 May 2020
Copy link to clipboard 
Print this post

I'm glad to hear it works with a Pi, and on the F4 :)

Thanks for the report.

Print this page

To reply to this topic, you need to log in.

© JAQ Software 2024