How to write to flash
"Michele Marcon" <M.Marcon-wB/b/[email protected]>
| Newsgroups | gmane.comp.hardware.microcontrollers.tini |
|---|---|
| Message-ID | <[email protected]> |
Here is my assembler code. I works fine for me and it will probably for you: it reads and writes the first 256 bytes of bank 4f.
You can easily modify it for other banks, other sizes etc.
The native functions:
public static native int readFlash(byte[] s);
public static native int writeFlash(byte[] s);
public static native int eraseFlash();
The assembler code:
$include(tini_400.inc)
$include(ds80c400.inc)
$include(tinimacro.inc)
$include(apiequ.inc)
$include(flashlib.inc)
FlashIO_Init:
ret
;LibraryID: ;
;db "DS" ;
;db 0,0,0,0,0,1 ;
Native_readFlash:
clr a
mov dps, #0 ; select dptr0
lcall NatLib_LoadJavaByteArray
; dptr0 contiene il target
mov dps, #1 ; select dptr1
mov dptr, #4f0000h;
; dptr1 contiene il source
mov dps, #31h ;
readloop:
movx a, @dptr;
movx @dptr, a;
mov a, dph1;
cjne a, #01h, readloop;
clr a;
; mov R0, #10h;
; mov R1, #0;
; mov R2, #0;
ret;
Native_eraseFlash:
;
; point to bank we wish to erase, and do the magic spell
;
clr a;
TINIOS_DISABLE_INTERRUPTS_AND_PUSH_INTERRUPT_STATE
mov dptr,#04f0000h;
ERASE_FLASH_SECTOR MACRO
WOS_ENABLE_INTERRUPTS MACRO
; mov a,#0AAh
; movx @dptr,a ; Some say spells should rhyme
; mov a,#055h
; movx @dptr,a ; I disagree completely
; mov a,#080h
; movx @dptr,a ; with that idea.
; mov a,#0AAh
; movx @dptr,a ; A good magic spell
; mov a,#055h
; movx @dptr,a ; Should be written in Haiku
; mov a,#030h
; movx @dptr,a ; or some variant
; clr a;
;waitloop:
; inc a;
; cjne a, #0BEBC200h, waitloop;
; clr a;
ret;
;Native_testEraseFinished:
; clr a
; mov dptr,#470000h
; movx a, @dptr
; ret;
Native_writeFlash:
clr a
mov dps, #0 ; select dptr0
lcall NatLib_LoadJavaByteArray
; dptr0 contiene il source
mov dpx1, dpx ;
mov dph1, dph ; sposto su dptr1
mov dpl1, dpl ;
mov dps, #0 ; select dptr1
mov dptr, #4f0000h;
; dptr0 contiene il target
writeloop:
mov dps, #11h ;
movx a, @dptr;
mov dps, #0h ;
lcall System_WriteFlashByte;
inc dptr ;
mov a, dph;
cjne a, #01h, writeloop;
clr a;
ret;
END
_______________________________________________
TINI mailing list
TINI-6tN4nzCoH/[email protected]
To UNSUBSCRIBE, edit your profile, or see list archives:
http://lists.dalsemi.com/mailman/listinfo/tini