CMM2 - Loading the firmware using Linux

Author Message

Joined: 18/11/2011
Location: United Kingdom
Posts: 2777
Posted: 10:24am 26 May 2020      

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.