CubeProgrammer fails to erase multiple external sectors
- August 23, 2024
- 2 replies
- 1725 views
We are currently trying to build a external loader for our application.
Our System consists of a STM32H743 and a STM32F427ZIT.
For the initial upload of the firmware the DFU interface of the H7 should be used and via a external loader application loaded to the F4 via SPI1 (of the F4) bootloader.
We successfully built a external loader with Init, Read, Write, SectorErase and MassErase.
All these functions work when used via the STM32CubeProgrammer application.
However the SectorErase completes successfully only for one section, if multiple external sections are to be erased cubeprogrammer fails "Error: Sector erase operation has failed at least for one of the existing specified sectors.Please verify flash memory protection."
We have debug output of our own external loader:
eg.:
Debug Start for SPI external Loader
Init with SPI bootloader status: 1
SectorErase with StartAdr: 0x8040000 and EndAd: 0x8040000
SectorErase success StartAdr: 0x8060000 and EndAd: 0x8040000
This output is generated when trying to erase sector 2 (True sectors of F4 are combined to only homogenous sectors of size 0x20000). (Note 0x8060000 is only generated because of += sectorsize, see code bellow)
The same Output is generated if we try to erase sector 2 and 3, therefore our loader never receives the second SectorErase.
The erase of the first sector succeeds.
Sector 3 is erasable when its the only one selected, but not when multiple are selected. This holds true for all combinations of sectors.
I have 3 log files attached, two success when sector 2/3 is selected as the only one. And one fail with sector 2&3 selected.
Here is my implementation of SectorErase in Loader_Src.c:
int SectorErase(uint32_t EraseStartAddress, uint32_t EraseEndAddress) {
EraseStartAddress &= ~(0xF0000000);
EraseStartAddress |= 0x08000000;
EraseEndAddress &= ~(0xF0000000);
EraseEndAddress |= 0x08000000;
__set_PRIMASK(0); //enable interrupts
snprintf((char *)debugTemp,128, "SectorErase with StartAdr: 0x%X and EndAd: 0x%X\n\r" ,EraseStartAddress, EraseEndAddress);
HAL_UART_Transmit(&huart7, debugTemp, strlen((char*)debugTemp), 100);
uint32_t sector;
uint32_t sectorSize;
uint8_t realNbSectors = 0;
while(EraseStartAddress <= EraseEndAddress){
sector = flashGetSector(EraseStartAddress, §orSize, &realNbSectors);
if(BL_EraseMemory_Command(realNbSectors - 1, sector) != HAL_OK){
snprintf((char *)debugTemp,128, "SectorErase failed StartAdr: 0x%X and EndAd: 0x%X\n\r" ,EraseStartAddress, EraseEndAddress);
HAL_UART_Transmit(&huart7, debugTemp, strlen((char*)debugTemp), 100);
__set_PRIMASK(1); //disable interrupts
return LOADER_FAIL;
}
EraseStartAddress += sectorSize;
}
snprintf((char *)debugTemp,128, "SectorErase success StartAdr: 0x%X and EndAd: 0x%X\n\r" ,EraseStartAddress, EraseEndAddress);
HAL_UART_Transmit(&huart7, debugTemp, strlen((char*)debugTemp), 100);
__set_PRIMASK(1); //disable interrupts
return LOADER_OK;
}
However I think the problem is somehow at the cubeprogrammer side, as the output of UART suggests.
