AnsweredAssumed Answered

Problem writing to flash

Question asked by belchamber.ian on Jul 9, 2014
Latest reply on Jul 9, 2014 by Clive One
Hi, I'm running the example code to try to program the flash memory. This starts:

void WriteFlash(void)
{  
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */
  
  /* Unlock the Flash to enable the flash control register access *************/ 
  FLASH_Unlock();
 
/* Erase the user Flash area
    (area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR)

***********//* Clear pending flags (if any) */  
  FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | 
                  FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR); 

.............        etc................ 



Then it erases the flash:
if (FLASH_EraseSector(i, VoltageRange_3) != FLASH_COMPLETE) ..... 

But when I step into this, it jumps out to a hard fault on this line:

/* if the erase operation is completed, disable the SER Bit */
    FLASH->CR &= (~FLASH_CR_SER);


Does anyone know what the hard fault is and how to overcome it?

Thanks

Outcomes