Fail to flash firmware

I modified the CAN firmware (razoredge branch) so that error, axis state, current, and position is continuously streamed in the heartbeat message (since the position in our application we are using won’t be larger than the int16 max and min values).

I managed to flash the firmware successfully, and have confirmed that it works by looking at the CAN messages being sent.

However, when I tried to reflash it with our ST-link I got an error message “STm device protected”.
I then put our Odrive (v3.6) in DFU mode by flipping the DIP switch, and tried flash it over USB with the command “sudo dfu-util -a 0 -s 0x08000000 -D path/to/bin/file”, but it gave me the error message:

    dfu-util: Invalid DFU suffix signature
dfu-util: A valid DFU suffix will be required in a future dfu-util release!!!
Opening DFU capable USB device...
ID 0483:df11
Run-time device DFU version 011a
Claiming USB DFU Interface...
Setting Alternate Setting #0 ...
Determining device status: state = dfuERROR, status = 11
dfuERROR, clearing status
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 011a
Device returned transfer size 2048
DfuSe interface name: "Internal Flash  "
Downloading to address = 0x08000000, size = 174460
Download	[                         ]   0%            0 bytesdfu-util: ERASE_PAGE not correctly executed

I also tried using the command “odrivetool dfu path/to/firmware/file.hex” but that gave me the following error:

ODrive control utility v0.4.11
Waiting for ODrive...
Found ODrive 2075387E304E (v3.6-56V) with firmware v0.4.11-dev

Warning: you are about to flash firmware [unknown version] which is older than the firmware on the device (v0.4.11-dev).
Do you want to flash this firmware anyway? [y/N] y
Saving configuration to /tmp/odrive-config-2075387E304E.json...
Configuration saved.
Putting device 2075387E304E into DFU mode...
Traceback (most recent call last):
  File "/usr/local/bin/odrivetool", line 142, in <module>
    odrive.dfu.launch_dfu(args, logger, app_shutdown_token)
  File "/usr/local/lib/python3.5/dist-packages/odrive/", line 454, in launch_dfu
    update_device(device, firmware, logger, cancellation_token)
  File "/usr/local/lib/python3.5/dist-packages/odrive/", line 351, in update_device
    stm_device = find_device_in_dfu_mode(serial_number, cancellation_token)
  File "/usr/local/lib/python3.5/dist-packages/odrive/", line 241, in find_device_in_dfu_mode
    stm_device = usb.core.find(idVendor=0x0483, idProduct=0xdf11, **params)
  File "/usr/local/lib/python3.5/dist-packages/usb/", line 1269, in find
    return _interop._next(device_iter(**args))
  File "/usr/local/lib/python3.5/dist-packages/usb/", line 66, in _next
    return next(iter)
  File "/usr/local/lib/python3.5/dist-packages/usb/", line 1249, in device_iter
    if _interop._all(tests) and (custom_match is None or custom_match(d)):
  File "/usr/local/lib/python3.5/dist-packages/usb/", line 1248, in <genexpr>
    tests = (val == getattr(d, key) for key, val in kwargs.items())
  File "/usr/local/lib/python3.5/dist-packages/usb/", line 830, in serial_number
    self._serial_number = util.get_string(self, self.iSerialNumber)
  File "/usr/local/lib/python3.5/dist-packages/usb/", line 314, in get_string
    raise ValueError("The device has no langid")
ValueError: The device has no langid

Here is the error log when running “make flash”:
make flash

        openocd -f interface/stlink-v2.cfg  -f target/stm32f4x.cfg -c init \
        	-c 'reset halt' \
        	-c 'flash write_image erase build/ODriveFirmware.elf' \
        	-c 'reset run' \
        	-c exit
        Open On-Chip Debugger 0.9.0 (2018-01-24-01:05)
        Licensed under GNU GPL v2
        For bug reports, read
        Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
        Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
        adapter speed: 2000 kHz
        adapter_nsrst_delay: 100
        none separate
        Info : Unable to match requested speed 2000 kHz, using 1800 kHz
        Info : Unable to match requested speed 2000 kHz, using 1800 kHz
        Info : clock speed 1800 kHz
        Info : STLINK v2 JTAG v17 API v2 SWIM v4 VID 0x0483 PID 0x3748
        Info : using stlink api v2
        Info : Target voltage: 3.277108
        Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints
        target state: halted
        target halted due to debug-request, current mode: Thread 
        xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc
        auto erase enabled
        Info : device id = 0x10076413
        Warn : STM32 flash size failed, probe inaccurate - assuming 1024k flash
        Info : flash size = 1024kbytes
        Error: stm32x device protected
        Error: failed erasing sectors 0 to 5

    Makefile:17: recipe for target 'flash' failed
    make: *** [flash] Error 1

Is this a common issue, and does someone have info how to solve this?
I have repeated this on 3-4 odrive’s. First flash of firmware have always been successful (make flash), but then reflash it doesn’t seem to work?

It seems that it was a faulty-“ish” ST-LINK, I changed the 3.3V pin on the ST link (there are two), and the ground pin, and tried reflash, and it did work for 3 of 4 odrives. The last one still got the error “Error: stm32x device protected”

In case you run into this again, or someone else does. I fixed this by entering the following command to unlock the odrive.

openocd -f interface/stlink-v2.cfg -f target/stm32f4x.cfg -c init -c "reset halt" -c "stm32f4x unlock 0" -c "reset run" -c exit

You can also use the command make unlock in the Firmware folder. It just runs the command Riewert put