2018-03-23 09:43 PM
#define FLASH_KEY1 ((u32)0x45670123)
#define FLASH_KEY2 ((u32)0xCDEF89AB)
void main (void){ //FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR); /*unlock the flash to enable the flash control register*/ //while((FLASH->SR & FLASH_FLAG_BSY) != 0) { }FLASH_Unlock();
/*Clear pending flag*/ //FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR); /*Define number of pages to be erassed*/ Nbrofpage = (Flash_user_end_addr - Flash_user_strt_addr)/ Flash_page_size; for(Erasecounter = 0; (Erasecounter < Nbrofpage ); Erasecounter++) { if(FLASH_ErasePage(Flash_user_strt_addr + (Flash_page_size * Erasecounter)) != FLASH_COMPLETE) { //while(1){} } } address = Flash_user_strt_addr; while(address < Flash_user_end_addr) { if(FLASH_ProgramWord(address,data_32) == FLASH_COMPLETE) { address = address+4; } }address1 = Flash_user_strt_addr;
while(address < Flash_user_end_addr) { data = *address1; } }void FLASH_Unlock(void)
{ /* Authorize the FPEC Access */ FLASH->KEYR = FLASH_KEY1; FLASH->KEYR = FLASH_KEY2}2018-03-24 05:57 AM
Please don't post entire question into summary.
Suggest you use subroutines for your code and don't dump it entirely in main()
Instrument the code so it doesn't need a debugger and so you can observe behaviour externally. Use a USART or other available interface.
It is important to clear errors/status from the controller.
The main() function should never exit, use a while(1) loop to make it stop at the end. Nothing good will happen when it exits, only bad things.
2018-03-24 08:01 PM
hi
Turvey.Clive.002
But the problem is after writingkey2 value to the register, the controller is not coming out of that FLASH_Unlock function and it goes to hard fault exception. Is their any problem with starting address or I need to configure something before main ????