cancel
Showing results for 
Search instead for 
Did you mean: 

Programming sequence error occur randomly on STM32H750

fema
Associate III

Hi guys,

I am using the STM32H750 and try to reprogram the internal 128KB flash.

Please check my code as below :

During the programming i got the "PGSERR" randomly , and error code is "0x00040000 "

Any comment , thanks

HAL_FLASH_Unlock();  

__HAL_FLASH_CLEAR_FLAG_BANK1 (FLASH_FLAG_PGSERR_BANK1 | FLASH_FLAG_INCERR_BANK1); // clear error flag before do it 

EraseInternalFlash(0x08000000); // Erase IAP area begin address and size

Write_Addr=0x08000000;

do

{

  Read_Size = fs_fread(Temp_512Bytes,1,512,fp);

  ProgramImage(Write_Addr,Temp_512Bytes);

  Write_Addr=Write_Addr+512;

}while (Read_Size != 0);

void EraseInternalFlash (uint32_t BeginAddr)

{

 uint32_t PAGEError = 0; uint8_t Retry=0;

 FLASH_EraseInitTypeDef EraseInitStruct; u32 SECTORError;

 /* Unlock the Flash to enable the flash control register access *************/  

  

 /* Fill EraseInit structure*/

 EraseInitStruct.TypeErase   = FLASH_TYPEERASE_SECTORS; // erase use sector type 

 EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;

 EraseInitStruct.Banks     = FLASH_BANK_1;

 EraseInitStruct.Sector    = FLASH_SECTOR_0; // sector 0

 EraseInitStruct.NbSectors   = 1; // NbOfSectors; 1 sector for H750 is 128KB

  

 if (HAL_FLASHEx_Erase(&EraseInitStruct, &SECTORError) != HAL_OK)

 {

  /*

   Error occurred while sector erase.

   User can add here some code to deal with this error.

   SECTORError will contain the faulty sector and then to know the code error on this sector,

   user can call function 'HAL_FLASH_GetError()'

  */

  /* Infinite loop */

  printf(" Erase flash error \r\n ");

  while (1);

 }

}

static bool ProgramImage(uint32_t Address, u8* Buffer)

{

 u32 j=0; uint32_t Data; 

 Data = (uint32_t) Buffer;

 for (j = 0; j < 512 ; j += 32)

 {   

  if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_FLASHWORD, Address, Data) == HAL_OK)

  {

   Address = Address + 32;

   Data = Data + 32;

  }

  else

  {

   /* Error occurred while writing data in Flash memory.

     User can add here some code to deal with this error */

   printf(" ***** Program Error(%x)(%x) ***** \r\n ",Address,HAL_FLASH_GetError());

   return false;

  }

 } 

 return true;

}

4 REPLIES 4

What memory is this code running in?

Code looks to write numbers into FLASH not data from the Buffer.

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

Thanks for your response.

The code run on the winbond w25q128J dual flash through the QSPI interface (memory mapping) .

If there is no any programming error occur then the flash contain exactly what i program . I read flash content out to a file and compare.

Any suggestion .

fema
Associate III

After i changed the "Optimization from Medium to None" in the IAR options for all the "stm32h7xx_hal_XXXX.c " files then i can't reproduce this problem.

Any suggestion .. thanks

simosilva
Senior

Hi @fema​  did you solve the problem?