CVS: jtag/funclets eraseFlashSegment.S,NONE,1.1
Chris Liechti <[email protected]>
| Newsgroups | gmane.comp.hardware.texas-instruments.msp430.gcc.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/mspgcc/jtag/funclets
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8620/jtag/funclets
Added Files:
eraseFlashSegment.S
Log Message:
- separate mass/main and segment erase, so that each program fits in 128 bytes RAM (important for the smallest MSP430 derrivates)
--- NEW FILE: eraseFlashSegment.S ---
/* Flash erase funclet to be used with MSP430mspgcc.dll/so.
Three arguments must be supplied in RAM:
srinit: initial value for SR, used to switch of DCO+
type: value for FCTL1, which selects MASS, MAIN or single segment erase
addr: an address within the segment to be erased
Notes:
- SegmentA in F2xx devices is unlocked and erased if target address is within
that segment. It is locked again at the end.
- SegmentA lock code is also executed on F1xx/F4xx devices. Should be no
problem with the currently availabe devices.
*/
#include <io.h>
.text
start: .word start
.word main
.word stop
srinit: .word 0
type: .word 0
addr: .word 0
main: mov #WDTPW|WDTHOLD, &WDTCTL ;Disable Watchdog.
dint ;Disable interrupts.
mov srinit, r2 ;Initialize status register (Possibly disable FLL+).
; mov #0xa544, &FCTL2 ;Source = MCLK, DIV = 5.
mov #FWKEY|0x41, &FCTL2 ;Source = MCLK, DIV = 2.
mov #FWKEY, &FCTL3 ;Clear bits.
mov #1, r9 ;just one loop suffices for segment erase
cmp #0x1040, addr ;check for SegmentA in F2xx devices
jhs .LAgain ;not segA -> start erase
; Unlock SegmentA (F2xx)
bit #LOCKA, &FCTL3 ;Test LOCKA
jz .Lunlocked ;Already unlocked?
mov #FWKEY|LOCKA, &FCTL3 ;No, unlock SegmentA
.Lunlocked:
; SegmentA is unlocked
.LAgain:mov type, &FCTL1 ;Load FCTL1 value. MUST CONTAIN PASSWORD.
mov addr, r10 ;Load (page) address to erase.
mov #0xffff, 0(r10) ;Write data into the address (to erase the FLASH).
mov #4820/3+1, r10 ;Delay for FLASH to erase (BUSY does not work on older devices).
.LWait: dec r10 ;Loop requires 3 clock cycles.
jnz .LWait ;
mov #FWKEY, &FCTL1 ;Clear ERASE + MERAS bits.
mov #FWKEY, &FCTL3 ;Clear BUSY + LOCK bits.
dec r9 ;Loop on erase cycles.
jnz .LAgain ;
; Lock SegmentA again (F2xx)
bit #LOCKA, &FCTL3 ;Test LOCKA
jnz .Llocked ;Already locked?
mov #FWKEY|LOCKA, &FCTL3 ;No, lock SegmentA
.Llocked:
; SegmentA is locked
stop: jmp stop ;Wait here until detected by driver.
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click