Skip to main content
Associate III
October 15, 2024
Solved

CubeProgrammer API downlaodFile error

  • October 15, 2024
  • 2 replies
  • 1238 views

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:

WhoIsJohnGalt_0-1728972907764.png

Best answer by Tesla DeLorean

If the original content remains it strongly suggests the ERASE is the thing that isn't successful. Start there..

2 replies

Maryem
Technical Moderator
October 24, 2024

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.

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
October 24, 2024

If the original content remains it strongly suggests the ERASE is the thing that isn't successful. Start there..

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Associate III
October 25, 2024

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""));