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