添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Posted on June 01, 2012 at 16:59

I am trying to erase and program a 16KB sector (sector 2) in the STM32F405 (rev A)on the ST3240G eval board. The problem is that two error flags (PGSERR and PGPERR)are set and cannot be cleared.

Soon after a reset, still running at 16MHz on HSI, no PLL, and before any attempt to erase or write to flash I use this sequence to clear the error flags in the status register:

if(FLASH_GetStatus() != FLASH_COMPLETE) 
{ // clear flash error 
FLASH_Unlock(); // Unlock the Flash Program Erase controller 
FLASH_ClearFlag(FLASH_FLAG_PGSERR | FLASH_FLAG_PGPERR | 
FLASH_FLAG_PGAERR | FLASH_FLAG_WRPERR | 
FLASH_FLAG_OPERR | FLASH_FLAG_EOP); // clear error status 
test = FLASH->SR; // DEBUG 
FLASH_Lock(); // Lock the Flash Program Erase controller 
}
When I step through the code I see the FLASH->SR register set to 0x0000 00c0 before and after the call to reset the flags. Is there a reason these error flags are set immediately after a reset? The flash programming guide says the default on reset is 0x0000 0000. Jack Peacock #flash #stm32f4xx-flash Posted on June 19, 2014 at 16:57

I had the same problem with a STM32F405 board I made. Clearing the flash error flags before unlocking also resolved it. However, it isn't clear to me why the error flags are set in the first place. Any insight on this? Also, can just clearing the flags on startup cause any problems later on?

Posted on September 24, 2014 at 17:20

I am using EEPROM-Emulation on an STM32F207 as proposed by ST and came across the same problem. The software provided by ST (EEPROM-Emulation and SPL) is not clearing the error flags before accessing flash.

I am using Keil uVision 4.70 together with a ULink Pro. I found out that when I

- use ETM tracing

- have the program running

- set a breakpoint

PGSERR and PGPERR get set immediately when the breakpoint is set most of the time, leading to the flash routines returning errors.

Clearing the error flags before accessing flash helped in my case.