May be I post the section of my code which is doing the entire thing..
// Save the 1k sector that is to be erased
memcpy(Buffer,(unsigned long*)(0x400),1024);
// Change the byte for FOPT
Buffer[13]=0xFB;
//Erase the sector to be written back
FLASH_EraseSector((unsigned long)(0x400));
// Write the modified buffer back to the original address
// *Note: The size here is in long words. 32 bits. 4 bytes. So 256 words = 1024 bytes
FLASH_ProgramSectionByLongs((unsigned long)(0x400),(unsigned long*)Buffer,256);
// Select ALT1(GPIO) function for PTA4
PORTA_PCR4 |= PORT_PCR_MUX(1);
// Setting PTA4 pin as Output
GPIOA_PDDR |= (0x01<<4);
// Disable PU and PFE
PORTA_PCR4 &= (~((0x1<<1)|(0x1<<4)));
// Start The toggle loop
for( ;; )
{
COMSendStringLine("Toggle");
// toggle the PTA4 pin
GPIOA_PCOR |= (0x01<<4); // Clear the pin.
vTaskDelay(1000/portTICK_RATE_MS);
GPIOA_PSOR |= (0x01<<4); // Set the pin
vTaskDelay(1000/portTICK_RATE_MS);
}
For the very first time this block of code is executed, it will not have any effect because the value of the FOPT is loaded from the flash config field during reset. So If I cycle the power to my board one time, it should start working and toggling the pin.
Unless there is some mistake in my code 