Problem with Erase Flash Sector on Kinetis KL25 Freedom board

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem with Erase Flash Sector on Kinetis KL25 Freedom board

Jump to solution
1,739 Views
mikethomas
Contributor II

Hello All,

I am in the process of evaluating the Freedom board with the Kinetis KL25 MCU.

Basically, writing a small program that interacts with the serial port to test peripherals, and become familiar with CodeWarrior and the Kinetis MCU.

Up to now, everything has worked as expected.

I am now getting hung up on the flash programming and erasing.

To test the ability to erase a flash sector, and reprogram a long word, I have used code snippets from application note AN2295, specifically the Flash Driver code comprised of three modules; flash_kinetis.c, flash_kinetis.h and flash_kinetisRamFunc.c

My test program calls functions in these modules to; initialize the ram code, erase a sector, and program a long word (not using the other flash functions)

After initializing the ram code, and assuming the 1st long word in the sector is already erased (0xffffffff), I can perform a long word program using FLASH_ProgramLongWord(LWord destination, LWord data32b) which works correctly. A query of the long word flash location shows it was programmed as expected. However, if I call the sector erase function; FLASH_EraseSector(LWord destination), the sector is erased, but its as though the stack gets screwed up, because the program resets and starts from the begining. The Hard Fault exception is being handled, so I know a Hard Fault is not occurring.

If I load the PE Micro SDA debugger into the Freedom board, invoke the Eclipse debugger and step through the code, the reset does not occur after erasing the sector, however, if I run the program in the debugger without stepping through it (at full speed) , it again resets.

Any help would be greatly appreciated,

Mike

1 Solution
556 Views
mikethomas
Contributor II

Problem solved - needed to disable interrupts during the relatively lengthy erase function.

Surprised that the flash driver in the AN2295 source code does not do this.

View solution in original post

2 Replies
556 Views
mikethomas
Contributor II

After further investigation , is has become clear that the reset is caused by a "Core Lockup" condition.

(Bit 1 in the RCM_SRS1 register is set.)

This problem sounds very much like the post entitled "K20 Reset bit Lockup set after sector erase", but I am not sure I understand the response.

0 Kudos
557 Views
mikethomas
Contributor II

Problem solved - needed to disable interrupts during the relatively lengthy erase function.

Surprised that the flash driver in the AN2295 source code does not do this.