STM32F439ZI first embedded flash program issue
Hi,
I'm working with STM32F439ZI MCU. I setted system clock 180 MHz and as Reference Manual (RM0090) says I did:
-- VOS[1:0] = 0x11
-- over drive mode enabling
-- 5 WS latency (6 CPU cycles)
When I try to program something the first time after power up, it failes. Only the sector erase is good. The strange is that from the second time on, all operations are goods. I can correctly erase, program and read. I post my code:
void my_func(void)
{
HAL_FLASH_Unlock();
FLASH_EraseInitTypeDef EraseInitStruct;
EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;
EraseInitStruct.Sector = COM_CONFIG_SECTOR;
EraseInitStruct.NbSectors = 1;
uint32_t SECTORError = 0;
HAL_StatusTypeDef ret = HAL_FLASHEx_Erase(&EraseInitStruct, &SECTORError);
{
ret += HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, COM_CONFIG_BASE_ADDR + i), _comConfig.ucDhcpEnable);
HAL_FLASH_Lock();
}
How is it possible? Why does the first time it fail? Please could you help me? Thank you.
Best regards,
Antonio
