EEPROM emulation on stm32 using HAL drivers
<p>I am trying to emulate EEPROM on stm32f0. There is an <a href="http://www.st.com/content/ccc/resource/technical/document/application_note/2e/d4/65/6b/87/dd/40/25/DM00049914.pdf/files/DM00049914.pdf/jcr:content/translations/en.DM00049914.pdf" rel="noreferrer">application note</a> provided by STM.</p>

<p>In the sample <code>main.c</code>,</p>

<pre><code>int main(void)
{
  /*!&lt; At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f0xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f0xx.c file
     */  
   /* Unlock the Flash Program Erase controller */
  FLASH_Unlock();

  /* EEPROM Init */
  EE_Init();

/* --- Store successively many values of the three variables in the EEPROM ---*/
  /* Store 0x1000 values of Variable1 in EEPROM */
  for (VarValue = 1; VarValue &lt;= 0x64; VarValue++)
  {
    EE_WriteVariable(VirtAddVarTab[0], VarValue);
  }

  /* read the last stored variables data*/
  EE_ReadVariable(VirtAddVarTab[0], &amp;VarDataTab[0]);


  /* Store 0x2000 values of Variable2 in EEPROM */
  for (VarValue = 1; VarValue &lt;= 0xC8; VarValue++)
  {
    EE_WriteVariable(VirtAddVarTab[1], VarValue);
  }

  /* read the last stored variables data*/
  EE_ReadVariable(VirtAddVarTab[0], &amp;VarDataTab[0]);
  EE_ReadVariable(VirtAddVarTab[1], &amp;VarDataTab[1]);


  /* Store 0x3000 values of Variable3 in EEPROM */
  for (VarValue = 1; VarValue &lt;= 0x1C2; VarValue++)
  {
    EE_WriteVariable(VirtAddVarTab[2], VarValue);
  }

  /* read the last stored variables data*/
  EE_ReadVariable(VirtAddVarTab[0], &amp;VarDataTab[0]);
  EE_ReadVariable(VirtAddVarTab[1], &amp;VarDataTab[1]);
  EE_ReadVariable(VirtAddVarTab[2], &amp;VarDataTab[2]);

  while (1);
}
</code></pre>

<p><code>Flash_Unlock()</code> is a function used in STM standard peripheral library. However, I am using CubeMX that auto-generates code that uses HAL drivers. Is <code>Flash_Unlock()</code> necessary to be called before one can use the EEPROM_emulation APIs? If yes, what is the HAL equivalent for calling <code>Flash_Unlock()</code>? Any special configuration settings to make on CubeMX to use EEPROM emulation?</p>