cancel
Showing results for 
Search instead for 
Did you mean: 

Write to OTP with stm32f4 HAL Flash Driver

Simon Sch�pbach
Associate II
Posted on June 02, 2017 at 10:27

Until now we used a really old STm32f4xx_DFP version 1.0.7. Now we change to the latest version 2.11.0.

In the older version it was possible to use the HASH driver functionality to write to/read from OTP. But in the latest version this doesn't work anymore. There will be just a small changed be necessary in HAL Flash driver to get it work.

// unlock flash access -> OK

HAL_FLASH_Unlock();

// clear write protection flag -> OK

 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_WRPERR);

// write data to OTP -> FAILS

HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, addr, data);

 // lock flash access -> OK

  HAL_FLASH_Lock();

The reason is the following check inside FLASH_Program_Word()

/* Check the parameters */

assert_param(IS_FLASH_ADDRESS(Address));

Because the OTP address (0x1FFF7800U - 0x1FFF7A0FU) doesn't match flash range (0x08000000U - 0x081FFFFFU).

Just expand IS_FLASH_ADDRESS() with the address range from OTP and it would run!!!

Or is there an other possibility to write to OTP? ( I'm not really interested to set the FLASH flags on my own....)

#hal #otp #stm32f4 #otp-flash-keil
0 REPLIES 0