2024-12-28 01:39 AM
Hello ST Community,
I am working on a custom bootloader for the STM32G473CCU6 microcontroller to enable firmware updates via the USB DFU interface. I am using the STM32CubeProgrammer API v2.17.0 | Windows-64Bits.
The microcontroller has 256 KB of flash memory in dual banks, which is 128 sectors of 2 KB.
Flags: BFB2 = 0, DBANK = 1.
I need to erase sectors 1...125 and not erase sectors 0, 126, 127.
I am trying to do this with the following function:
int sectorErase(unsigned int sectors[],unsigned int sectorNbr, char* sFlashMemName = nullptr);
But only 64 sectors (0...63) from bank 1 can be erased. Sectors from bank 2 are not erased.
I tried using indexes (64...127) and (65280...65343)
DisplayCallbacks output when erasing sectors 1, 2:
Info: [INFO]: "\nFlash sector erase ... \n"
Info: [UNKNOWN]: "DFU status = 0 : OK"
Info: [UNKNOWN]: "DFU state = 5 : dfuDNLOAD-IDLE"
Info: [UNKNOWN]: "Status: 0, State: 5"
Info: [UNKNOWN]: "sending a page erase request @: 0x08000800"
Info: [UNKNOWN]: "data: 4100080008"
Info: [UNKNOWN]: "DFU status = 0 : OK"
Info: [UNKNOWN]: "DFU state = 4 : dfuDNBUSY"
Info: [UNKNOWN]: "DFU status = 0 : OK"
Info: [UNKNOWN]: "DFU state = 5 : dfuDNLOAD-IDLE"
Info: [UNKNOWN]: "erasing sector 0001 @: 0x08000800 done"
Info: [UNKNOWN]: "DFU status = 0 : OK"
Info: [UNKNOWN]: "DFU state = 5 : dfuDNLOAD-IDLE"
Info: [UNKNOWN]: "Status: 0, State: 5"
Info: [UNKNOWN]: "sending a page erase request @: 0x08001000"
Info: [UNKNOWN]: "data: 4100100008"
Info: [UNKNOWN]: "DFU status = 0 : OK"
Info: [UNKNOWN]: "DFU state = 4 : dfuDNBUSY"
Info: [UNKNOWN]: "DFU status = 0 : OK"
Info: [UNKNOWN]: "DFU state = 5 : dfuDNLOAD-IDLE"
Info: [UNKNOWN]: "erasing sector 0002 @: 0x08001000 done"
Info: [ERROR]: "Flash page/sector erase command correctly executed.\nNote: if flash sector is protected, it will not be erased."
DisplayCallbacks output when erasing sectors 64, 65:
Info: [INFO]: "\nFlash sector erase ... \n"
Info: [UNKNOWN]: "Error: Sector 0064 does not exist"
Info: [UNKNOWN]: "Error: Sector 0065 does not exist"
Info: [UNKNOWN]: "Error: No sectors selected to be erased"
DisplayCallbacks output when erasing sectors 65280, 65281
Info: [INFO]: "\nFlash sector erase ... \n"
Info: [INFO]: "sector 65280 does not exist"
Info: [INFO]: "sector 65281 does not exist"
Info: [ERROR]: "Flash page/sector erase command correctly executed.\nNote: if flash sector is protected, it will not be erased."
The output says that "erase command correctly executed", but in fact no sectors are erased.
Does anyone know how to erase sectors from bank 2 using STM32CubeProgrammer API function sectorErase()?
Thank you!