From 179d0a77f47e6b4c1e5f72d19352d121511812ab Mon Sep 17 00:00:00 2001 From: Bernhard Urban Date: Mon, 14 Dec 2009 07:19:13 +0100 Subject: [PATCH] use chip erase command instead of deleting each cell. however, this won't work atm. although the code is executed from IRAM there seems to be further access on the flash... i'll check this out... --- pkernel/flash.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ pkernel/kernel.py | 14 ++++++++++++++ pkernel/main.c | 9 +++++++++ 3 files changed, 70 insertions(+) diff --git a/pkernel/flash.c b/pkernel/flash.c index c72b463..fb160dd 100644 --- a/pkernel/flash.c +++ b/pkernel/flash.c @@ -63,6 +63,53 @@ void FLASH_PrepareReadMode() FMWT_WTC = 4; } +unsigned char FLASH_ChipErase(void) +{ + unsigned char flag = 0; + + /*Disable Interrupts if necessary*/ + IFlag = FLASH_SaveDisableInterruptFlag(); + + /*Set FLASH access mode to 16Bit Write Mode*/ + FLASH_PrepareWriteHalfWordMode(); + + /*Start FLASH Sector Erase Sequence*/ + *hseq_1 = 0x00AA; + *hseq_2 = 0x0055; + *hseq_1 = 0x0080; + *hseq_1 = 0x00AA; + *hseq_2 = 0x0055; + *hseq_1 = 0x0010; + + /*Wait for the Auto Algorithm to finish*/ + while( flag == 0 ) { + /* Feed Hardware Watchdog */ + HWWD_CL = 0; + + if(*hseq_1 & DPOLL) { + flag = 1; + } + if(*hseq_1 & TLOVER) { + if(*hseq_1 & DPOLL) { + flag = 1; + } + else { + /*Reset FLASH (keep in mind 16Bit access to FLASH)*/ + *hseq_1 = 0x00F0; // Keep in Mind (16Bit access) + + flag = 2; + } + } + } + + /*Set FLASH access mode to 32Bit Read Mode*/ + FLASH_PrepareReadMode(); + + /*Restore the original Interrupt Flag*/ + FLASH_RestoreInterruptFlag(IFlag); + + return flag; +} unsigned char FLASH_SectorErase(unsigned int secadr) { diff --git a/pkernel/kernel.py b/pkernel/kernel.py index 54a9fd3..3ebda56 100755 --- a/pkernel/kernel.py +++ b/pkernel/kernel.py @@ -29,6 +29,15 @@ def sendDWord(dword): sendByte((dword >> 16) & 0xFF) sendByte((dword >> 24) & 0xFF) +def pkernCHIPERASE(): + sendByte(0x15) + if (recvByte() != 0x45): + raise Exception + print "wait..." + if (recvByte() != 0x23): + raise Exception + print "Chip erasing done." + def pkernERASE(address, size): sendByte(0x12) if (recvByte() != 0x11): @@ -125,9 +134,14 @@ for seq in flashseqs: # let the fun begin! +""" for seq in flashseqs: print "Erasing", len(seq.data), "bytes at address", hex(seq.address) pkernERASE(seq.address, len(seq.data)) +""" +print "ChipErase..." +pkernCHIPERASE() + for seq in flashseqs: print "Flashing", len(seq.data), "bytes at address", hex(seq.address) diff --git a/pkernel/main.c b/pkernel/main.c index 452c388..78ca2dc 100644 --- a/pkernel/main.c +++ b/pkernel/main.c @@ -71,6 +71,15 @@ void main(void) cleardata(); increaseled(); switch(recvbyte()) { + case 0x15: //chip erase + Putch4(0x45); + increaseled(); + if(FLASH_ChipErase() != 1) { + panic(); + } + Putch4(0x23); + break; + case 0x12: //erase Putch4(0x11); address = recvdword(); -- 2.25.1