pystlink icon indicating copy to clipboard operation
pystlink copied to clipboard

flash erase command can't suport STM32H7

Open JesseLliang opened this issue 2 years ago • 1 comments

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

JesseLliang avatar Jul 26 '21 02:07 JesseLliang

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;
}

Rotule666 avatar Jul 26 '21 10:07 Rotule666