Error: STM32 flash size failed, JTAG STICKY

Hi, I have an STM32F407IE on a custom board and I am programming/debugging with an Olimex ARM-USB-TINY-H using OpenOCD. I have come across this error with two separate microcontrollers now. It seems as though the microcontroller enter some type of error state while running (I have not had it attached to the debugger when this error happens). Once it occurs, I try running it through the debugger and it refuses to run. When running it through gdb, it gives me the following:

stm32f4x.cpu – clearing lockup after double fault

Program received signal SIGINT, Interrupt.

Using OpenOCD, I can issue a ‘reset halt’ command to halt the microcontroller, but when I do a ‘flash probe 0’, I get the following response:

device id = 0x10016413

JTAG-DP STICKY ERROR

MEM_AP_CSW 0x23000051, MEM_AP_TAR 0x1fff7a24

STM32 flash size failed, probe inaccurate - assuming 1024k flash

flash size = 1024kbytes

flash ‘stm32f2x’ found at 0x08000000

If I try to erase the flash and write a new image, I get the following error:

auto erase enabled

stm32x device protected

failed erasing sectors 0 to 7

in procedure ‘flash’

This sounds like a hardware error to me, but is there anything else I can do in OpenOCD to track down what’s happening? Does anyone have any suggestions? Any other logging information that I could provide to help?

One common cause of sticky errors is that the JTAG interface is running to fast in relation to the processor clock,

so the internal processor memory cannot deliver the requested information in time.

The other common reason is that OpenOCD tries to access nonexistent memory, the MEM_AP_TAR address

0x1fff7a24 belongs to a ‘reserved’ region according to the STM32F4 datasheet.

Are you sure that OpenOCD is configured for this processor ?

The stm32 flash driver tries to read the flash size register @ 0x1FFF7A22, but this should be a 16bit read.

It has been seen on other STM32 devices that ST have not programmed this register and the result is what you see, guess you have early silicon.

If the flash size is correct then you have nothing to worry about, but you can override this value if you wish by changing the size parameter to the flash bank cmd.

Also make sure you are using the latest version of OpenOCD as we have fixed a few issues with the stm32 flash driver.

Have you tried unlocking the target if it is reported as being locked.

stm32f2x unlock 0

Cheers

Spen