Example #1
0
int erase_sector_flash(unsigned int start_sector, unsigned int end_sector)
{
  //reset_flash();
  int i, z;

  print_string("Erasing ... ");

  write_flash_unlock_sequence();
  write_flash_command((unsigned char) FLASH_CMD_ERASE_SETUP);
  write_flash_unlock_sequence();
  
  /* Sector erase */
  for (i = start_sector; i <= end_sector; i++)
  {
    //print_string("Erasing sector at address: ");
    //print_hex_unsigned(FLASH_BASE + SECTOR_ADDRESS(i));
    //print_string("\r\n");
    *((volatile unsigned short *) (FLASH_BASE + SECTOR_ADDRESS(i))) = FLASH_CMD_SECTOR_ERASE;
  }
  DELAY(500);
  if (poll_status(FLASH_OP_ERASE, SECTOR_ADDRESS(i), 0) != 0)
  {
    write_flash_command((unsigned char) FLASH_CMD_RESET);
    return -1;
  }
  print_string("ok\r\n");
  return 0;
}
Example #2
0
int erase_chip_flash()
{
  int z;
  reset_flash();
  write_flash_unlock_sequence();
  write_flash_command((unsigned char) FLASH_CMD_ERASE_SETUP);
  write_flash_unlock_sequence();
  write_flash_command((unsigned char) FLASH_CMD_CHIP_ERASE);
  DELAY(200);
  /*if (poll_status(FLASH_OP_ERASE, SECTOR_ADDRESS(0x00), 0) != 0)
  {
    write_flash_command((unsigned char) FLASH_CMD_RESET);
    return -1;
  }*/
  print_string("OK\r\n");
  return 0;
}
Example #3
0
static int write_flash_byte(unsigned int address, uint8_t data)
{
	write_flash_command(0x0555, 0xAA);
	write_flash_command(0x02AA, 0x55);
	write_flash_command(0x0555, 0xA0);
	write_flash_command(address, data);

	int timeout = 0;
	while (read_prg_byte(address | 0x8000) != data && timeout < 10)
	{
		ROMSEL_HI;
		PHI2_LOW;
		_delay_us(100);
		timeout++;
	}
	ROMSEL_HI;
	return timeout < 10;
}
Example #4
0
int single_word_program_flash(unsigned long address, unsigned short data)
{
  write_flash_unlock_sequence();
  write_flash_command((unsigned char) FLASH_CMD_PROGRAM_SETUP);
  *( (volatile unsigned short *) (FLASH_BASE + ALIGN(address))) = data;
  
  /*if (poll_status(FLASH_OP_PROGRAMMING, ALIGN(address), data) != 0)
  {
    write_flash_command((unsigned char) FLASH_CMD_RESET);
    return -1;
  }*/
  int z;
  DELAY(5);
  if (*( (volatile unsigned short *) (FLASH_BASE + ALIGN(address))) != data)
    return -1;
  
  return 0;
}
Example #5
0
// Do not run this method from within the Flash memory 
void print_flash_info()
{
  reset_flash();
  write_flash_unlock_sequence();
  write_flash_command((unsigned char) FLASH_CMD_AUTOSELECT);
  
  unsigned short manuf_id = FLASH_EXTRACT(0x00);
  print_string("Flash Device Information (AUTOSELECT)\r\n");
  print_string("Manufacturer ID: ");
  print_hex_unsigned(manuf_id);
  
  if ((manuf_id) == 0x01)
	  print_string(" (Spansion)\r\n");
  else
	  print_string(" (Unknown)\r\n");
  
  print_string("Device ID: ");
  
  //unsigned short dev_id_1 = FLASH_EXTRACT(0x01);
  unsigned short dev_id_2 = FLASH_EXTRACT(0x0E);
  //unsigned short dev_id_3 = FLASH_EXTRACT(0x0F);
  
  switch (dev_id_2)
  {
    case 0x28:
    	print_string(" S29GL01GP - 1 Gb\r\n");
    	break;
    case 0x23:
    	print_string(" S29GL512P - 512 Mb\r\n");
    	break;
    case 0x22:
    	print_string(" S29GL256P - 256 Mb\r\n");
    	break;
    case 0x21:
    	print_string(" S29GL128P - 128 Mb\r\n");
    	break;
    default:
    	print_string(" Unknown\r\n");
    	break;
  }

  // Reset flash 
  reset_flash();
}
Example #6
0
static int erase_flash()
{
	LED_RED_ON;
	write_flash_command(0x0555, 0xAA);
	write_flash_command(0x02AA, 0x55);
	write_flash_command(0x0555, 0x80);
	write_flash_command(0x0555, 0xAA);
	write_flash_command(0x02AA, 0x55);
	write_flash_command(0x0555, 0x10);
	
	int timeout = 0;
	while ((read_prg_byte(0x8000) != 0xFF) && (timeout < 10000))
	{
		ROMSEL_HI;
		_delay_ms(1);
		timeout++;
	}
	ROMSEL_HI;
	LED_RED_OFF;
	return timeout < 10000;
}
Example #7
0
/*
 * Unlock bypass mode.
 * Enter this mode before doing a sequence of similar program
 * operations. After this call, programming only takes two write 
 * cycles.
 * Once you enter Unlock Bypass Mode, do a series of like
 * operations (programming or sector erase) and then exit
 * Unlock Bypass Mode before beginning a different type of
 * operations.
 */
void unlock_bypass_flash()
{
  write_flash_unlock_sequence();
  write_flash_command((unsigned char) FLASH_CMD_UNLOCK_BYPASS);
  unlock_bypass = 1;
}
Example #8
0
/* Soft reset */
void reset_flash()
{
  write_flash_command((unsigned char) FLASH_CMD_RESET);
}