Skip to main content
User.72
Associate II
December 12, 2019
Question

Write flash memory Error

  • December 12, 2019
  • 1 reply
  • 1528 views

Hi, sir.

Before I speak, I'm Korean so English may be wrong.

But please help me... (T^T)

I am using STM32H743VIT for project. And I want to save Flash memoty to some data.

Sometime, It is return HAL_OK. So i can save some data in flash memory.

but Most of them fail to save...​

The error code was return.

Error code is INCERR2: Bank 2 inconsistency error flag and PGSERR2: Bank 2 programming sequence error flag

what is woring?

I will attach my code and configuration.

1) my data size : 112000B

  • uint32_t save_data[28000]
  • It is in 0x24000000(AXI SRAM)

2) My compiler is IAR (8.34)

3) My Cubemx Setting

  • Flash Latency(Ws) : 7 WS(8 CPU cycle)

0690X00000BuX8TQAV.jpg

0690X00000BuX8dQAF.jpg

4) My code is

void test_agetn_lan1_setting_save_flash(void) // bank2 - sector 1번
{
 EnableWriteProtect(OPTIONBYTE_WRP,FLASH_BANK_2,FLASH_SECTOR_1,OB_WRPSTATE_DISABLE);
 EraseFlash(FLASH_TYPEERASE_SECTORS,FLASH_SECTOR_1,FLASH_BANK_2); 
 HAL_Delay(10);
 Flash_Wite_Func(LAN1_CSV_1_TO_100_SAVE_ADRSS,_32bit_lan1_csv_arr,_32BIT_LAN1_CSV_ARR_INDEX);
}

void Flash_Wite_Func(uint32_t sector,uint32_t* data, uint16_t len)
{
 HAL_FLASH_Unlock();
 if(FLASH_Program(FLASH_TYPEPROGRAM_FLASHWORD, sector,data, len) != HAL_OK)
 {
 while(1); 
 
 }
 HAL_FLASH_Lock();
}

HAL_StatusTypeDef FLASH_Program(uint32_t TypeProgram, uint32_t FlashAddress, uint32_t *DataAddress, uint16_t len)
{
 HAL_StatusTypeDef status;
 __IO uint32_t *dest_addr = (__IO uint32_t *)FlashAddress;
 __IO uint32_t *src_addr = (__IO uint32_t*)DataAddress;
 uint32_t bank;
 //uint8_t row_index = FLASH_NB_32BITWORD_IN_FLASHWORD;
 uint16_t row_index = len; 
 
 /* Check the parameters */
 assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram));
 assert_param(IS_FLASH_PROGRAM_ADDRESS(FlashAddress));
 
 /* Process Locked */
 __HAL_LOCK(&pFlash);
 
 if(IS_FLASH_PROGRAM_ADDRESS_BANK1(FlashAddress))
 {
 bank = FLASH_BANK_1;
 }
 else
 {
 bank = FLASH_BANK_2;
 }
 
 /* Reset error code */
 pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
 
 /* Wait for last operation to be completed */
 status = FLASH_WaitForLastOperation((uint32_t)50000U, bank);
 
 if(status == HAL_OK)
 {
 if(bank == FLASH_BANK_1)
 {
 /* Set PG bit */
 SET_BIT(FLASH->CR1, FLASH_CR_PG);
 }
 else
 {
 /* Set PG bit */
 SET_BIT(FLASH->CR2, FLASH_CR_PG);
 }
 
 __ISB();
 __DSB();
 
 /* Program the 256 bits flash word */
 do
 {
 *dest_addr = *src_addr;
 dest_addr++;
 src_addr++;
 row_index--;
 //HAL_Delay(1);
 } while (row_index != 0U);
 
 __ISB();
 __DSB();
 
 /* Wait for last operation to be completed */
 status = FLASH_WaitForLastOperation((uint32_t)50000U, bank);
 
 if(bank == FLASH_BANK_1)
 {
 /* If the program operation is completed, disable the PG */
 CLEAR_BIT(FLASH->CR1, FLASH_CR_PG);
 }
 else
 {
 /* If the program operation is completed, disable the PG */
 CLEAR_BIT(FLASH->CR2, FLASH_CR_PG);
 }
 }
 
 /* Process Unlocked */
 __HAL_UNLOCK(&pFlash);
 
 return status;
}

 5) Error Code

  • 0x8024000

0690X00000BuXAFQA3.jpg

plaese help me..

Thank you sir

This topic has been closed for replies.

1 reply

simosilva
Senior
October 20, 2021

Hi @부�? 강​  have you solved the problem?