candle-usb/candleLight_fw

CANable-MKS problem

Closed this issue · 1 comments

I'm having trouble flashing a CANable-MKS V2.0 Pro.

The firmware built and shipped by MKS (in the candlelight.zip here) works fine:

# Add Boot jumper on board, connect to USB
$ lsusb
...
Bus 001 Device 120: ID 0483:df11 STMicroelectronics STM Device in DFU Mode
...

$ sudo dfu-util -d 0483:df11 -D ./canable2_fw-ba6b1dd.dfu
dfu-util 0.11

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2021 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Multiple alternate interfaces for DfuSe file
Opening DFU capable USB device...
Device ID 0483:df11
Device DFU version 011a
Claiming USB DFU Interface...
Setting Alternate Interface #2 ...
Determining device status...
DFU state(2) = dfuIDLE, status(0) = No error condition is present
DFU mode device DFU version 011a
Device returned transfer size 1024
DfuSe interface name: "OTP Memory   "
DfuSe interface name: "Option Bytes   "
DfuSe interface name: "Internal Flash   "
File contains 1 DFU images
Parsing DFU image 1
Target name: ST...
Image for alternate setting 0, (1 elements, total size = 16760)
Setting Alternate Interface #0 ...
Parsing element 1, address = 0x08000000, size = 16752
Erase           [=========================] 100%        16752 bytes
Erase    done.
Download        [=========================] 100%        16752 bytes
Download done.
Done parsing DfuSe file

# Unplug from USB, remove Boot jumper, reconnect to USB 
$ lsusb
...
Bus 001 Device 121: ID 1d50:606f OpenMoko, Inc. Geschwister Schneider CAN adapter
...

At this point the device works fine and i can read CAN packets.

Then i build candleLight_fw commit b1e557b per the README:

$ mkdir build

$ cd build

$ cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/gcc-arm-none-eabi-8-2019-q3-update.cmake
-- The C compiler identification is GNU 10.2.1
-- The ASM compiler identification is GNU
-- Found assembler: /opt/gcc-arm-none-eabi-10-2020-q4-major/bin/arm-none-eabi-gcc
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Detecting C compile features
-- Detecting C compile features - done
-- The CXX compiler identification is GNU 10.2.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Detecting CXX compile features
-- Detecting CXX compile features - done
*******************
You may now:
        -compile all targets ('make')
        -compile a single target (e.g. 'make cantact_fw'
        -flash a device (e.g. 'make flash-cantact_fw'
-- Configuring done (0.4s)
-- Generating done (0.0s)
-- Build files have been written to: /home/seb/candleLight_fw/build

$ make -j20 CANable_MKS_fw
[  0%] Building C object libs/STM32_HAL/CMakeFiles/STM32_HAL_STM32F072xB.dir/src/stm32f0xx/stm32f0xx_hal_can.c.obj
[  7%] Building C object libs/STM32_HAL/CMakeFiles/STM32_HAL_STM32F072xB.dir/src/stm32f0xx/stm32f0xx_hal.c.obj
... lots more build output, it all ran successfully

But when i try to flash it i get nothing good (at this point the CANable-MKS is running the candleLight firmware built by Makerbase):

$ lsusb
...
Bus 001 Device 013: ID 1d50:606f OpenMoko, Inc. Geschwister Schneider CAN adapter
...

$ sudo make flash-CANable_MKS_fw
0 16:34:50 seb@seb-laptop /home/seb/candleLight_fw/build> sudo make flash-CANable_MKS_fw
dfu-util 0.11

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2021 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Match vendor ID from file: 1d50
Match product ID from file: 606f
dfu-util: Failed to retrieve string descriptor 224
dfu-util: More than one DFU capable USB device found! Try `--list' and specify the serial number or disconnect all but one device

make[3]: *** [CMakeFiles/flash-CANable_MKS_fw.dir/build.make:70: CMakeFiles/flash-CANable_MKS_fw] Error 74
make[2]: *** [CMakeFiles/Makefile2:540: CMakeFiles/flash-CANable_MKS_fw.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:547: CMakeFiles/flash-CANable_MKS_fw.dir/rule] Error 2
make: *** [Makefile:306: flash-CANable_MKS_fw] Error 2

$ sudo dfu-util --list
dfu-util 0.11

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2021 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

dfu-util: Failed to retrieve string descriptor 224
Found Runtime: [1d50:606f] ver=0000, devnum=16, cfg=1, intf=1, path="1-3", alt=0, name="UNKNOWN", serial="003800394D4D501220383834"
Found DFU: [04f2:5800] ver=0001, devnum=3, cfg=1, intf=0, path="1-6", alt=0, name="Camera DFU Device", serial="200901010001"

I then tried the "failsafe" flash method from the README:

# Unplug  USB, add Boot jumper, reconnect USB
$ lsusb
...
Bus 001 Device 014: ID 0483:df11 STMicroelectronics STM Device in DFU Mode
...

$ sudo dfu-util --dfuse-address -d 0483:df11 -c 1 -i 0 -a 0 -s 0x08000000 -D ./CANable_MKS_fw.bin 
Error: Unexpected argument: 0483:df11

Usage: dfu-util [options] ...
...

# I read the dfu-util manpage and came up with this command line instead (serial number from `dfu-util --list`):
$ sudo dfu-util -S 2070386D4D4D -d 0483:df11 -c 1 -i 0 -a 0 -s 0x08000000 -D ./CANable_MKS_fw.bin 
dfu-util 0.11

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2021 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

dfu-util: Warning: Invalid DFU suffix signature
dfu-util: A valid DFU suffix will be required in a future dfu-util release
Opening DFU capable USB device...
Device ID 0483:df11
Device DFU version 011a
Claiming USB DFU Interface...
Setting Alternate Interface #0 ...
Determining device status...
DFU state(2) = dfuIDLE, status(0) = No error condition is present
DFU mode device DFU version 011a
Device returned transfer size 1024
DfuSe interface name: "Internal Flash   "
Downloading element to address = 0x08000000, size = 16812
Erase           [=========================] 100%        16812 bytes
Erase    done.
Download        [=========================] 100%        16812 bytes
Download done.
File downloaded successfully

At this point i unplugged USB, removed the Boot jumper, and replugged USB. The red power LED on the CANable-MKS comes on, but nothing else happens, and the device does not enumerate on the USB bus.

I noticed a couple of things that seem off:

The build talks about a different microcontroller than what's on the board i have:

[  0%] Building C object libs/STM32_HAL/CMakeFiles/STM32_HAL_STM32F072xB.dir/src/stm32f0xx/stm32f0xx_hal_can.c.obj

Here's a picture of the CANable-MKS v2.0 PRO board which has an STM32G431:
CANable_MKS_V2 0_Pro

The .dfu file built by this repo is not accepted as valid by dfuse-pack --dump (though i bypassed the dfu and flashed the bin above, and it still didn't work):

$ dfuse-pack --dump CANable_MKS_fw.dfu 
File: "CANable_MKS_fw.dfu"
b'\x00@\x00 \xb5' v46, image size: 86837248, targets: 0
usb: 0008:0005, device: 0x3108, dfu: 0x0000, b'\x00\x00\x00', 0, 0x00000000
CRC ERROR: computed crc32 is 0xa9c10c0f
PARSE ERROR

That's in contrast to the dfu shipped by Makerbase:

dfuse-pack --dump canable2_fw-ba6b1dd.dfu
File: "canable2_fw-ba6b1dd.dfu"
b'DfuSe' v1, image size: 17045, targets: 1
b'Target' 0, alt setting: 0, name: "b'ST...'", size: 16760, elements: 1
  0, address: 0x08000000, size: 16752
    DUMPED IMAGE TO "canable2_fw-ba6b1dd.dfu.target0.image0.bin"
usb: 0483:df11, device: 0x0200, dfu: 0x011a, b'UFD', 16, 0xa87300fe

At this point i'm stumped, but motivated to help resolve the issue. I'm happy to do any experiments you suggest.

Ok, typing all the out make me realize i built the firmware for the CANable-MKS 1.0 and tried to run it on the CANable-MKS 2.0. Sorry for the noise...