cancel
Showing results for 
Search instead for 
Did you mean: 

Writing full flash page does not work

sde c.1
Senior II

Hi !

I try to write 2048 Bytes at once to flash.

I do a page erase first of page 31.

EraseInitStruct.TypeErase   = FLASH_TYPEERASE_PAGES;
EraseInitStruct.Banks = FLASH_BANK_1 ;
EraseInitStruct.Page = 31;
EraseInitStruct.NbPages     = 1;

the description of the HAL library is not clear, what do they mean with "Fast program a 32 row double-word (64-bit) at a specified address.".

I understand a double word as 32 bit, but the HAL comment says 64 bit?

What do they mean with 32 row ? 32 x double word?

its confusing.

my device is a 65k device STM32G431C8T

PageData is a buffer of 2048 Bytes (uint8_t).

FLASH_EEPROM_BASEADDR = 0x0800F800.

When i execute flash_page_write(FLASH_EEPROM_BASEADDR,(uint64_t*)PageData);

i get HAL_ERROR wirh error code 1010100000

flash_status flash_page_write(uint32_t address, uint64_t *data) {
	HAL_FLASH_Unlock();
	if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_FAST_AND_LAST, address, *data)
			!= HAL_OK) {
		return FLASH_ERROR_WRITE;
	}
	HAL_FLASH_Lock();
	return FLASH_OK;
}

Thank you

12 REPLIES 12
Javier1
Principal

Hi, i am using a stm32f105 but maybe take a look inside your HAL_FLASH_Program() declaration, specifically the FLASH_Type_Program argument.

0693W000008GSnjQAG.pngI only get this options and i believe you should be using FLASH_TYPEPROGRAM_DOUBLEWORD

#define FLASH_TYPEPROGRAM_HALFWORD             0x01U  /*!<Program a half-word (16-bit) at a specified address.*/
#define FLASH_TYPEPROGRAM_WORD                 0x02U  /*!<Program a word (32-bit) at a specified address.*/
#define FLASH_TYPEPROGRAM_DOUBLEWORD           0x03U  /*!<Program a double word (64-bit) at a specified address*/

 best of lucks

we dont need to firmware by ourselves, lets talk
sde c.1
Senior II

i got the correct options, but am not able to execute them .

FLASH_TYPEPROGRAM_DOUBLEWORD works correctly but i would like to write a whole page at once.

#define FLASH_TYPEPROGRAM_DOUBLEWORD    0x00U              /*!< Program a double-word (64-bit) at a specified address.*/
#define FLASH_TYPEPROGRAM_FAST          0x01U              /*!< Fast program a 32 row double-word (64-bit) at a specified address.
                                                                And another 32 row double-word (64-bit) will be programmed */
#define FLASH_TYPEPROGRAM_FAST_AND_LAST 0x02U              /*!< Fast program a 32 row double-word (64-bit) at a specified address.
                                                                And this is the last 32 row double-word (64-bit) programmed */

Where did you found those defines?

I only have them in stm32_hal_legacy.h and they dont have any value in them

we dont need to firmware by ourselves, lets talk

stm32g4xx_hal_flash.h

Maybe is a family specific flash option, i have no idea why this is not working for you and i cannot replicate it sorry.

we dont need to firmware by ourselves, lets talk
Gumer RoMa
Associate II

Hi, did you find the solution? I have the same problem. FLASH_TYPEPROGRAM_DOUBLEWORD works fine, but I can not make it work with FLASH_TYPEPROGRAM_FAST_AND_LAST nor FLASH_TYPEPROGRAM_FAST.

Those two have specific sequencing expectations.

You have the STM32G4, or something else?

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

Yes, I have a STM32G491KE

This is my read on the docs, not having a G4 to hand

flash_status flash_page_write(uint32_t address, uint64_t *data)
{
  int i;
 
  i = 2048 / 256; // PAGE SIZE vs ROW SIZE
 
  if (address % 2048) return(FLASH_ERROR_ALIGN); // id10T check for page alignment
 
  HAL_FLASH_Unlock();
 
  // Clear OPTVERR bit set on virgin samples
  __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
 
  // Clear all FLASH errors flags before starting write operation
  __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
 
  while(i--) // Rows Remaining
  {
    if (i)
    {
      if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_FAST, address, data) != HAL_OK)
      {
        HAL_FLASH_Lock();
        return(FLASH_ERROR_WRITE);
      }
    }
    else // Last Row in Page
    {
      if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_FAST_AND_LAST, address, data) != HAL_OK)
      {
        HAL_FLASH_Lock();
        return(FLASH_ERROR_WRITE);
      }
    }
    Address += 256; // Advance by Row
    data += 256 / sizeof(uint64_t);
  }
 
  HAL_FLASH_Lock(); // sourcer32@gmail.com
 
  return(FLASH_OK);
}

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