pavelrevak / pystlink

Python tool for flashing and debugging STM32 devices using ST-LINK/V2
MIT License
216 stars 58 forks source link

flash erase command can't suport STM32H7 #26

Open JesseLliang opened 2 years ago

JesseLliang commented 2 years ago

As title,when I use flash erase command on STM32H745, it deosn't work as all

Rotule666 commented 2 years ago

For STM32H7 I have changed the erase flash with the following , notive that I keep one full sector in bank 1 for the bootloader

/* Erase flash ---------------------------------------------------------------*/
uint8_t btld_EraseFlash(void) {
    uint32_t SectorError = 0;
    FLASH_EraseInitTypeDef pEraseInit;
    HAL_StatusTypeDef status = HAL_OK;

    HAL_FLASH_Unlock();

    if (status == HAL_OK) {

        // Bank 0
        pEraseInit.Banks = FLASH_BANK_1;
        pEraseInit.Sector = 1;
        pEraseInit.NbSectors = 7;
        pEraseInit.TypeErase = FLASH_TYPEERASE_SECTORS;
        pEraseInit.VoltageRange = FLASH_VOLTAGE_RANGE_3;

        status = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);

        // Bank1
        pEraseInit.Banks = FLASH_BANK_2;
        pEraseInit.Sector = 0;
        pEraseInit.NbSectors = 8;
        pEraseInit.TypeErase = FLASH_TYPEERASE_SECTORS;
        pEraseInit.VoltageRange = FLASH_VOLTAGE_RANGE_3;

        status = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
    }

    HAL_FLASH_Lock();

    return (status == HAL_OK) ? BL_OK : BL_ERASE_ERROR;
}