Skip to main content
Senior II
February 17, 2021
Question

Writing full flash page does not work

  • February 17, 2021
  • 3 replies
  • 4194 views

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

This topic has been closed for replies.

3 replies

Javier1
Principal
February 17, 2021

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

hit me up in https://www.linkedin.com/in/javiermuñoz/
sde c.1Author
Senior II
February 18, 2021

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 */

Javier1
Principal
February 18, 2021

Where did you found those defines?

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

hit me up in https://www.linkedin.com/in/javiermuñoz/
sde c.1Author
Senior II
February 18, 2021

stm32g4xx_hal_flash.h

Gumer RoMa
Visitor II
April 12, 2022

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.

Tesla DeLorean
Guru
April 12, 2022

Those two have specific sequencing expectations.

You have the STM32G4, or something else?

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Gumer RoMa
Visitor II
April 12, 2022

Yes, I have a STM32G491KE