/* This function writes a data buffer in flash (data are 32-bit aligned).  */
uint32_t FLASH_If_Write(uint32_t FlashAddress, uint32_t *Data, uint32_t DataLength)
/* This function writes a data buffer in flash (data are 32-bit aligned).  */
uint32_t FLASH_If_Write(uint32_t FlashAddress, uint32_t *Data, uint32_t DataLength)
{
  uint32_t i = 0;
  for (i = 0; (i < DataLength) && (FlashAddress <= (USER_FLASH_END_ADDRESS-4)); i++)
  { 
    if (HAL_FLASH_Program(TYPEPROGRAM_WORD, FlashAddress, *(uint32_t*)(Data+i)) == HAL_OK)      
    {
      if (*(uint32_t*)FlashAddress != *(uint32_t*)(Data+i))
      {
        return(FLASHIF_WRITINGCTRL_ERROR);
      }
      FlashAddress += 4;
    }
    else
    {
      return (FLASHIF_WRITING_ERROR);
    }
  }
  return (FLASHIF_OK);
}