Skip to main content
AFara.2
Associate III
June 23, 2022
Question

STM32F439ZI first embedded flash program issue

  • June 23, 2022
  • 3 replies
  • 1687 views

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

This topic has been closed for replies.

3 replies

Tesla DeLorean
Guru
June 23, 2022

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
AFara.2
AFara.2Author
Associate III
June 23, 2022

Ok I'll try it. Than you.