cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F439ZI first embedded flash program issue

AFara.2
Associate II

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

3 REPLIES 3

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Ok I'll try it. Than you.

Hi tried and everytime it fails flash status register is all 0s. Any other suggestion? Thank you.