cancel
Showing results for 
Search instead for 
Did you mean: 

Error Writing 64 bit in FLASH

varani luciano
Associate III

Tranferring data from serial input,(in my case idDA), or from an SD, may be you try to write a double word a time (64bit) in flash area and you may use the:

HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, flash_ptr,codeData64). This function calls the

static void FLASH_Program_DoubleWord(uint32_t Address, uint64_t Data);

(file stm32F4xx_hal_flash.c);

but the system signals TWO errors :

PGSERR: Programming sequence error

Set by hardware when a write access to the Flash memory is performed by the code while the control register has not been correctly configured.

PGAERR: Programming alignment error

Set by hardware when the data to program cannot be contained in the same 128-bit Flash memory row.

mmm....

There is a little bug , as you can see.....

static void FLASH_Program_DoubleWord(uint32_t Address, uint64_t Data)

{

 /* Check the parameters */

 assert_param(IS_FLASH_ADDRESS(Address));

 /* If the previous operation is completed, proceed to program the new data */

   CLEAR_BIT(FLASH->CR, FLASH_CR_PSIZE);     

 //FLASH->CR |= FLASH_PSIZE_DOUBLE_WORD;    <<<<<<<<<<<------------------- HEY!!!

 FLASH->CR |= FLASH_PSIZE_WORD;              <<<<<<------- NEW VERSION

 FLASH->CR |= FLASH_CR_PG;

 /* Program the double-word */

 *(__IO uint32_t*)Address = (uint32_t)Data;

 *(__IO uint32_t*)(Address+4) = (uint32_t)(Data >> 32);

}

You are NOT writing a DuobleWord but TWO TIMES a word.....

Have a happy new year.

7 REPLIES 7

And what's the Address when this actually fails?

A 64-bit write is achieved with an STRD which are two back-to-back 32-bit writes.

if ((Address & 7) != 0) puts("Not Aligned");

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

The base address is 0x8008000 (or other sector beginning address); the devicesin use are stm32F401 or stm32F429VI, the compiler-linker is Atollic V9.2. I was writing a bootloader from some different peripheral device (this was one of the last problems).

Many thanks, but it is logic: the row *(__IO uint32_t*)Address = (uint32_t)Data;

do prepare to write in a 32 bit word and the FLASH->CR |= FLASH_PSIZE_DOUBLE_WORD prepare a 64 bit space

(as FLASH_CR and FLASH_SR in the Reference manual specify).

LV

Pavel A.
Evangelist III

Do you mean this place in the F4 library?

https://github.com/pavel-a/stm32f4_libs/blob/c4560650ddaea6ee33de171027d801a31109565a/STM32Cube_FW_F4/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c#L635

STM32 has a 32-bit processor so it cannot possibly move 64-bit value in one hit. But there are limitations when 32 and 64 bit flash writes can be used, it depends on the voltage. Usually 16-bit writes work with any voltage, for 32 and 64 bit higher voltage is required, See RM for details. Maybe on your board there's not enough power for 64-bit writes. Thus it reports some errors. Don't forget to erase before writing. And the erase API has similar parameter that depends on the voltage.

-- pa

You need a supply on VPP to use 64-bit mode on the F4 parts. The architecture effects a 64-bit write using two back-to-back 32-bit writes

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

Many thanks; but I can't change a VPP voltage on the board ( a solid 3.3V /1A ).

In earesing phase of the sector , I use a

...

EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3; //operating range: 2.7V to 3.6

...

And there is no problems.

The solution (indicated) have good results : no waste of time , respect of hardware manuals and of programming logic : I write 32 bit? I do prepare the system to accept 32 bit.

LV

ELeyl.1
Associate II

Wow, This is the answer to my program. Your code fix makes sense because there is not one 64 bit write but two 32 bit writes. Takes away the program error PGS and PGA and now I can write to the FLASH.

I agree to what you said,

The solution (indicated) have good results : no waste of time , respect of hardware manuals and of programming logic : I write 32 bit? I do prepare the system to accept 32 bit.

JJhin.1
Senior II

Thanks @varani luciano  for shairing this artical... i also getting same problem with and i made same changes in hal_Flash.c file and its working =).

but after jumping to application code controller is gettin stucked in some where..