2024-10-14 11:20 PM
Hey there,
I am using the CubeProgrammer API (2.17.0) to flash a STM32U545 MCU over USB DFU with a new firmware.
When doing so a write error occurs (downlaodFile(...) returns CUBEPROGRAMMER_ERROR_WRITE_MEM (-10)) when flashing a new hex file (when using the same hex file as already on the MCU no error occurs).
Flashing the hex file using the CubeProgrammer application (via J-LINK) works fine.
Also a full chip erase, so no write protection active.
My code:
CubeProgrammer::dfuDeviceInfo* dfu_list = nullptr;
int count = CubeProgrammer::getDfuDeviceList(&dfu_list, 0xdf11, 0x0483);
CubeProgrammer::connectDfuBootloader(dfu_list[0].usbIndex);
int FirmwareStartAddress = 0x08000000;
unsigned int verify = 1; // verify download
unsigned int skip_erase = 0; // do not skip erase
CubeProgrammer::cubeProgrammerError result = static_cast<CubeProgrammer::cubeProgrammerError>(
CubeProgrammer::downloadFile(file_path, FirmwareStartAddress, skip_erase, verify, L""));
When skipping the verify I don't get an error but the old firmware is still on the MCU after a reboot.
Does anyone might have a guess what could cause the write to fail?
Thank you and best Regards,
Howard Roak
PS: In case I missed somthing in the option bytes:
Solved! Go to Solution.
2024-10-24 03:55 AM
If the original content remains it strongly suggests the ERASE is the thing that isn't successful. Start there..
2024-10-24 03:05 AM
Hello @WhoIsJohnGalt ,
I apologize for the delayed response.
Could you please provide the full part number of the STM32U545 MCU and, if possible, share the hex file you're trying to flash? Thank you in advance !
Maryem.
2024-10-24 03:55 AM
If the original content remains it strongly suggests the ERASE is the thing that isn't successful. Start there..
2024-10-25 02:11 AM
Thanks, after adding a mass erase before the file download it was working.
It seems that the erase flag of the downloadFile() is ignored or not working...
CubeProgrammer::dfuDeviceInfo* dfu_list = nullptr;
int count = CubeProgrammer::getDfuDeviceList(&dfu_list, 0xdf11, 0x0483);
CubeProgrammer::connectDfuBootloader(dfu_list[0].usbIndex);
// Newly added mass erase
CubeProgrammer::cubeProgrammerError result =
static_cast<CubeProgrammer::cubeProgrammerError>(CubeProgrammer::massErase());
int FirmwareStartAddress = 0x08000000;
unsigned int verify = 1; // verify download
unsigned int skip_erase = 0; // do not skip erase <- not working anyways ...
CubeProgrammer::cubeProgrammerError result = static_cast<CubeProgrammer::cubeProgrammerError>(
CubeProgrammer::downloadFile(file_path, FirmwareStartAddress, skip_erase, verify, L""));