/* Erases the flash memory. Note that this function also checks that no data is erased outside the flash memory region, so the bootloader can never be erased.  */
blt_bool FlashErase(blt_addr addr, blt_int32u len)
/* Erases the flash memory. Note that this function also checks that no data is erased outside the flash memory region, so the bootloader can never be erased.  */
blt_bool FlashErase(blt_addr addr, blt_int32u len)
{
  blt_int8u first_sector;
  blt_int8u last_sector;
  if ((len - 1) > (FLASH_END_ADDRESS - addr))
  {
    return BLT_FALSE;
  }
  first_sector = FlashGetSector(addr);
  last_sector  = FlashGetSector(addr+len-1);
  if ((first_sector == FLASH_INVALID_SECTOR) || (last_sector == FLASH_INVALID_SECTOR))
  {
    return BLT_FALSE;
  }
  return FlashEraseSectors(first_sector, last_sector);
}