AnsweredAssumed Answered

hello, Im using stm32f103 microcontroller. Im trying flash programming. while unlocking flash program erase controller by writing key values to register, controller not comming out of that loop. Is their any changes required in code????

Question asked by manjunath r on Mar 24, 2018
Latest reply on Mar 25, 2018 by manjunath r

#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
}

Outcomes