Can't get erase plane to work on dual plane device (SAM4C32)

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Folks,

 

Got a SAM4C32C bootloader essentially working, but the one I thing I can't get going is the erase plane command.

 

I have the following:

 

uint32_t ErasePlane(uint8_t Plane)
{
	
	volatile uint32_t FlashCMD;
	volatile uint32_t RetVal;
	volatile uint32_t PageNumber;
	
	if (Plane == 0)
		PageNumber = 0;
	else
		PageNumber = IFLASH0_NB_OF_PAGES;
	
	FlashCMD = EFC_UNLOCK_KEY | EFC_FCMD_EPL | ((PageNumber << 8) & 0xFFFF00);
	
	RetVal = ExecuteSelfProgrammingCommand(FlashCMD,Plane); 

	return RetVal;
	
	
}

RAMFUNC uint16_t ExecuteSelfProgrammingCommand(uint32_t Command, enum PlaneType Plane)
{

    volatile uint32_t Status;  
	volatile irqflags_t flags;
	
	Efc *p_efc;

	if (Plane == PLANE_ONE)          
		p_efc = EFC0;
	else
		p_efc = EFC1;
		
		  
    while ((p_efc->EEFC_FSR & 0x01) == 0);
    Status = p_efc->EEFC_FSR;
	flags = cpu_irq_save(); // This should be global interrupt disable
    p_efc->EEFC_FCR = Command;
    do 
		{
		Status = p_efc->EEFC_FSR;
		} while ((Status & EEFC_FSR_FRDY) != EEFC_FSR_FRDY);
 
    cpu_irq_restore(flags); // This should be global interrupt enable
    return Status;

}

If I call ErasePlane(PLANE_ONE);

 

The command I end up writing to the command register is:

 

0x5A080006

 

But I get back the FCMDE bit set (as well as the FRDY). I can erase pages just fine.

 

I can't see anything wrong with that command.

 

Is there a gotcha I'm not aware of, or is that command wrong and I'm blind to it?

 

Many thanks! :-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm using erase pages only. Either erase plane was simply not working (at the moment I can't even find EFC_FCMD_EPL) or took much longer than needed b/c the required space is much less than the whole bank. I can't remember .. ;)