Full Version : Sim Vs Chip, M128
avr >>ASM PROGRAMMING (AVR) >>Sim Vs Chip, M128


dbvanhorn- 07-19-2007
I'm looking for what I hope is an obvious problem in my bootloader.
The top level works fine, xmodem protocol delivering 128 byte packets.
I have a mechanism to deal with making 256 byte pages with them, and dealing with an odd number of packets in a load, all that's fine.

The big problem is that although my routine to write the spm buffer into the codespace is working in sim, it does not work in the chip. The loader seems to be doing it's thing, but when I read the hexfile from the loaded chip, all of the application area is $FF.


;
;**
;
Loader_Page_Write:
rcall SPM_Ready ;Making sure the erase is done
rcall Loader_MakePage ;

ldi TEMP,$05 ;PGWRT and SPMEN
sts SPMCSR,TEMP ;
spm ; Flash page write
rcall Enable_RWW ;This checks ready state

ret
;
;
As far as I can see, this is correct.
Now it may be that somehow the spm buffer is $FF and I'm actually writing, but the thing is, that it's all good in the sim!


Here's how I load the buffer
;
Loader_Buffer_Load:
rcall SPM_Ready ;
rcall Loader_MakePage ;Point to the proper page using XmodemBlk
ldi XL,low(XmodemData) ;Point at the data, PAST the block number
ldi XH,high(XmodemData) ;and it's complement.
ldi TEMP,64 ;How many WORDS to run
mov LOOP,TEMP ;

FP_WriteLoop:
ld r0,X+ ;Load the word to write into R0,1
ld r1,X+ ;

ldi TEMP,$01 ;SPMEN
sts SPMCSR,TEMP ;
spm ;Temp storage write
rcall SPM_Ready ;Wait till it's finished

adiw ZH:ZL,2 ;Next word
dec LOOP ;
brne FP_WriteLoop ;
ret




Here's how I build the page address:


; Create the page pointer
;
Loader_MakePage:
;
; RAMPZ ZH ZL
;xxxxxxxx xxxxxxxx xxxxxxxx ;We don't depend on anything in here

;There are 1FF possible pages, so Hi_Page goes directly to
;RAMPZ and lo_page to ZH, ZL is set according to the half-page flag

mov ZH,Lo_Page ;Get the page counter
andi Hi_Page,$01 ;Only 0 or 1 is legal
out RAMPZ,Hi_Page ;
clr ZL ;
and HalfPage,HalfPage ;Do we need to do this?
breq MakePage_Noz
ldi ZL,$80

MakePage_Noz:
ret



So what am I doing wrong?



dbvanhorn- 07-19-2007
Ok, problem solved, sort of.

The code below works in the chip, AND in the sim.
If you move the call to "loader_Page_Erase" down into the second half, it still works in the sim, but writes all $FF when it's in the chip.



FlashPage:
and HalfPage,HalfPage ;We load the first packet, and wait for the
brne FlashPage_Go ;second one, then load that one, and then

;erase and burn the page
;First packet of a page
rcall Loader_Page_Erase ;This must come first for some reason
rcall Loader_Buffer_Erase ;Since this is a "first" packet, erase the buffer
rcall Loader_Buffer_Load ;Load an xmodem packet into the buffer
ldi HalfPage,$01 ;Show that we've done this
rjmp FlashPage_Done

FlashPage_Go:
;Second packet of a page
;DO NOT PUT THE PAGE ERASE HERE. DFW Error!
rcall Loader_Buffer_Load ;Load an xmodem packet into the buffer
rcall Loader_Page_Write ;Writes 128 WORDS


inc Lo_Page ;
brne FlashPage_Clr ;
inc Hi_Page ;High byte of page counter

FlashPage_Clr:
clr HalfPage ;The next one will be load-only


FlashPage_Done:
ret


Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.