cancel
Showing results for 
Search instead for 
Did you mean: 

How to write a uint16_t array to flash memory for STM32L053 which only supports word write

AV.9
Associate II

Hi

I am able to erase two pages (my array is length 256 ), now I want to write my array to a particular memory location.

Here set is the address which is 0x080E0000

p_source is my uint16_t array which I want to write to flash. And length is 256.

How do I pass my array and also write it in this function?

I'm unlocking in the main function, calling erase function, then calling this function then locking the flash.

void FLASH_Write_HAL(uint16_t *p_source, uint16_t* seg, uint16_t length)

{

   uint32_t varToPass;

   uint16_t wordcount=0;

   int i;

   for (i=0; i<length; i++){

      varToPass = (uint32_t*) &p_source[i] ;

      HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD,seg+wordcount,varToPass);

      wordcount += 4;

//      if (wordcount>=256){

//         break;

//      }

   }

}

5 REPLIES 5
AV.9
Associate II

Can someone please help me?

LCE
Principal

Have you tried using FLASH_TYPEPROGRAM_BYTE instead of FLASH_TYPEPROGRAM_WORD with HAL_FLASH_Program() ?

I haven't used it yet, but it looks quite obvious...

Take a look at HAL_FLASH_Program() to understand how it works.

AV.9
Associate II

Unfortunately I can't use that for my controller, I also can't use FLASH_TYPEPROGRAM_HALFWORD as the last argument expects a 32 bit word to be passed as a variable

You get the level of service you pay for here..

S​o cast the array into a larger unit and write it as a block of data rather than individual array elements.

D​ata Representation..

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