2022-06-23 06:43 AM
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
2022-06-23 06:47 AM
Check and clear any pending error/status held in the status register.
Perhaps read and print values so you can observe behaviour without a debugger attached.
2022-06-23 07:09 AM
Ok I'll try it. Than you.
2022-06-27 07:42 AM
Hi tried and everytime it fails flash status register is all 0s. Any other suggestion? Thank you.