/* Erase SPI Flash sector. 
Erases SPI Flash Sector  */
unsigned char spi_flash_erase(uint32_t start_offset, uint32_t size)
/* Erase SPI Flash sector. 
Erases SPI Flash Sector  */
unsigned char spi_flash_erase(uint32_t start_offset, uint32_t size)
{
    unsigned long end_offset = start_offset + size;
    if (end_offset > FLASH_MEMORY_SIZE) {
        return 1;
    }
    start_offset = start_offset & FLASH_SECT_MASK;
    spi_flash_write_enable();
    while(start_offset < end_offset) {
			spi_flash_sector_erase(start_offset);
			while(spi_flash_read_status_reg() & 0x01) {
			}
			start_offset += FLASH_SECTOR_SIZE;
    }
	spi_flash_write_disable();
    return 0;
}