2024-12-25 05:10 PM - edited 2024-12-26 05:25 PM
So originally, I was using a custom bootloader and painfully sending 32 bytes over custom HID to my device. It works, but it's really slow. Not related, but I just want you to know how dumb I am...
Anyway,
I followed the tutorial to use DFU USB interface to patch application firmware.
https://www.youtube.com/watch?v=n_LDXOQHerU
I can't get the DFU programmer working on STM32 Cube Programmer because it can't erase properly.
=================== STM32 Cube Programmer Fail ===================
19:29:25 : UR connection mode is defined with the HWrst reset mode
19:29:27 : USB speed : Full Speed (12MBit/s)
19:29:27 : Manuf. ID : Demo LLC
19:29:27 : Product ID : STM32 DownLoad Firmware Update
19:29:27 : SN : 205C32824358
19:29:27 : DFU protocol: 1.1
19:29:27 : Board : --
19:29:27 : IAP
19:29:51 : Memory Programming ...
19:29:51 : Opening and parsing file: Demo_MainFirmware.bin
19:29:51 : File : Demo_MainFirmware.bin
19:29:51 : Size : 69.75 KB
19:29:51 : Address : 0x0800C100
19:29:51 : Erasing memory corresponding to segment 0:
19:29:51 : Error: failed to erase memory
==========================================================
So I used dfu-util tool instead. Which would work the first time as you can see. I would have it successfully jump to the application code, But if i try to do it again, It only erases first few bytes before stopping.
=================== dfu-util Tool Sucess ===================
F:\Demo\Demo_DesktopApp\src\tools\dfu-util\win64>dfu-util.exe -d 0x0483:0x580c -a 0 -s 0x0800C100:leave -D "Demo_MainFirmware.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/
Warning: Invalid DFU suffix signature
A valid DFU suffix will be required in a future dfu-util release
Opening DFU capable USB device...
Device ID 0483:580c
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 = 0x0800c100, size = 71428
Erase [=========================] 100% 71428 bytes
Erase done.
Download [=========================] 100% 71428 bytes
Download done.
File downloaded successfully
Submitting leave request...
Transitioning to dfuMANIFEST state
==========================================================
Now if I put my device in bootloader mode and send it again, it gets stuck every single time around 4096 bytes
=================== dfu-util Tool Fail ===================
Warning: Invalid DFU suffix signature
A valid DFU suffix will be required in a future dfu-util release
Opening DFU capable USB device...
Device ID 0483:580c
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 = 0x0800c100, size = 71428
Erase [=========================] 100% 71428 bytes
Erase done.
Download [= ] 4% 3072 bytesError during download get_status
==========================================================
I already set the priority for sys tick to be higher than usb for the interrupt priority. If I was to take a guess what I did wrong, the linker memory isn't aligned properly to erase pages, FLASH_DESC_STR is wrong, or im handling erasing wrong on my Cortex M0 microcontroller.
Also I tried to full send it and set FLASH_DESC_STR to "@Internal Flash /0x08000000/128*1Kg" to see if i can get erase working. Nope the programming tool does not like that lol.
Also #define USBD_DFU_APP_DEFAULT_ADD 0x0800C100
Any wisdom you have helps. I am using a custom STM32F070CBTX board I made, so there isnt any UART for debugging, The USB is being used for the DFU patching, and my SWD doesnt support serial wire viewer. So until I get another board made to see debugging better, im stumped.
Thanks and Happy Holidays!