cancel
Showing results for 
Search instead for 
Did you mean: 

stm32l476 how i can write 32bit data to internal flash

den2life
Associate II
Posted on November 17, 2017 at 16:08

Hi!!

I worked before them on this crystal stm32f0, stm32f1 series. Recording to the internal flash memory was not a difficult process, which made it fun to work. Why did you make it so complicated, why record 64-bit data?

The question and not only the question, but also it is desirable to show how I now write to flash memory as on that crystal

stm32f0

, that is 32-bit data and do not use the library HAL?
5 REPLIES 5
Uwe Bonnes
Principal II
Posted on November 17, 2017 at 16:30

Always write 64-bit entities. Either with single 32 bit data and 32 bit set e.g.to 0xffffffff or with 2 words concatenated as a double word.

Posted on November 17, 2017 at 16:59

Probably because it makes the hardware design simpler and more efficient for the 99.999% use case at the expense of making the writing 0.001% case a tad more complicated?

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on November 18, 2017 at 05:56

Please can you show me code sample write to internal flash not use library HAL?

Posted on November 18, 2017 at 10:18

Tell us what you do not understand from the pseudo code in the L4 reference manual!

Jack Peacock
Associate II
Posted on November 19, 2017 at 01:32

On the 'L47x flash uses ECC, computed across a 64 bit doubleword.  That's why you have to write in 64-bit sizes.  From what I understand the ECC is calculated at write time, over the entire 64-bit data word, so partial writes aren't supported.  Of course you can always read the contents, add in a partial modification and then write again, but that's not how internal flash is intended to be used.  You'd be better off with an external EEPROM or a different family with internal EEPROM.

In the code fragment  it shows how I first turn on PG to program, write 2 x 32-bit words, wait for the completion interrupt (FreeRTOS xSemaphoreTake in example) or poll for irq flag, and finally clear the PG bit to end the operation.  You have to make sure the flash is first erased.

FLASH->

CR

|= FLASH_CR_PG;

// start slow programming operation

*(

uint32_t

*) wrtptr = *bufptr;

// first word to program

wrtptr++;

// next page address

bufptr++;

// next data word

*(

uint32_t

*) wrtptr = *bufptr;

// second word to program, start operation

wrtptr++;

// next page address

bufptr++;

// next data word

oserr = xSemaphoreTake( ifmFlag, Iob->

Var

->

Timeout

);

// wait for operation to complete

if

(oserr == pdTRUE)

fstat = FLASH_GetStatus(Iob->

Var

->

Fstat

);

// results of write

else

fstat =

FLASH_TIMEOUT

;

// write timed out

FLASH->

CR

&= (~FLASH_CR_PG);

// clear program operation

Jack Peacock