Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

Bootloader Frustration

Bootloader Frustration

2007-07-12 by Dave VanHorn

Hmm.. Having much fun trying to implement this..

The basics of the Xmodem transfer protocol are working, and I get 128 
byte packets from the host.

But putting them into program memory isn't working out right.

I have a register that counts packets from the host, of course it 
rolls at 255, so I grab another register that counts rollovers.  1024 
packets of 128 bytes fills a M128.  Here's how I translate the packet 
count to the write address:

;
;***********************************************************
;
; Create the page pointer in three DIFFERENT registers.
; from the Xmodem packet count, and ITEMP, which is used
; as the high byte, since we have no INTS at this point.
;
Loader_MakePage:
	lds	TEMP,XmodemBlk		;
	call	Pong			;

	clr	ZL			;
	out	RAMPZ,ZL		;
	;   RAMPZ       ZH       ZL
	;00000000 xxxxxxxx 00000000

	lds	ZH,XmodemBlk		;The packet number
	;00000000 pppppppp 00000000

	dec	ZH						;
	;packet 1 goes to block zero
	;00000000 bbbbbbbb 00000000

	lsr	ZH					
	;shifts a 0 into MSB of ZH
	ror	ZL					
	;shifts carry into MSB of ZL
	;   RAMPZ       ZH       ZL
	;00000000 0bbbbbbb b0000000
	;       |          ||    ||
	;       |          ||    |\----- Which byte within word
	;       |          |\----\------ Words within page
	;	\----------\------------ Pages

	mov	TEMP,ITEMP	;UGLY fix for how they bastardized the
	andi	TEMP,$03	;000000xx
	breq	MakePage_NOZ	;If neither bit is set, then done.

	sbrc	TEMP,0		;If lsb is set, then set MSB of ZH
	ori	ZH,$80		;dosen't touch TEMP
	;00000000 Bbbbbbbb b000000

	sbrs	TEMP,1		;if b1 is set, then set B0 of RAMPZ
	rjmp	MakePage_Noz	;
	ldi	TEMP,$01	;
	out	RAMPZ,TEMP	;

	;00000001 Bbbbbbbb b0000000
	;       |          ||    ||
	;       |          ||    |\----- Which byte within word
	;       |          |\----\------ Words within page
	;       \----------\------------ Pages

MakePage_Noz:
	in	TEMP,RAMPZ	;So I can see the adrs on the LA
	call	PONG
	mov	TEMP,ZH
	call	Pong
	mov	TEMP,ZL
	call	Pong
	ret
;
;***********************************************************
;

What's happening, is that it seems to be erasing EVERY page, but 
writing every OTHER page, although I can't tell if it's wrapping, or 
exactly what is going on..  The "pong" statements are my byte in PWM 
output on a single pin, and that shows me what I expect as the 
packets come in.

Re: Bootloader Frustration

2007-07-14 by poitsplace

I've never attempted to use any of the AVR's with the store program
memory instruction...but I can't help but notice there's an interrupt
vector (and therefore a corresponding flag somewhere) called "SPM
READY" (Store Program Memory Ready).  Is your program using this
interrupt (or checking the flag manually) to make sure it's ready?



--- In AVR-Chat@yahoogroups.com, "Dave VanHorn" <microbrix@...> wrote:
Show quoted textHide quoted text
>
> 
> Hmm.. Having much fun trying to implement this..
> 
> The basics of the Xmodem transfer protocol are working, and I get 128 
> byte packets from the host.
> 
> But putting them into program memory isn't working out right.
> 
> I have a register that counts packets from the host, of course it 
> rolls at 255, so I grab another register that counts rollovers.  1024 
> packets of 128 bytes fills a M128.  Here's how I translate the packet 
> count to the write address:
> 
> ;
> ;***********************************************************
> ;
> ; Create the page pointer in three DIFFERENT registers.
> ; from the Xmodem packet count, and ITEMP, which is used
> ; as the high byte, since we have no INTS at this point.
> ;
> Loader_MakePage:
> 	lds	TEMP,XmodemBlk		;
> 	call	Pong			;
> 
> 	clr	ZL			;
> 	out	RAMPZ,ZL		;
> 	;   RAMPZ       ZH       ZL
> 	;00000000 xxxxxxxx 00000000
> 
> 	lds	ZH,XmodemBlk		;The packet number
> 	;00000000 pppppppp 00000000
> 
> 	dec	ZH						;
> 	;packet 1 goes to block zero
> 	;00000000 bbbbbbbb 00000000
> 
> 	lsr	ZH					
> 	;shifts a 0 into MSB of ZH
> 	ror	ZL					
> 	;shifts carry into MSB of ZL
> 	;   RAMPZ       ZH       ZL
> 	;00000000 0bbbbbbb b0000000
> 	;       |          ||    ||
> 	;       |          ||    |\----- Which byte within word
> 	;       |          |\----\------ Words within page
> 	;	\----------\------------ Pages
> 
> 	mov	TEMP,ITEMP	;UGLY fix for how they bastardized the
> 	andi	TEMP,$03	;000000xx
> 	breq	MakePage_NOZ	;If neither bit is set, then done.
> 
> 	sbrc	TEMP,0		;If lsb is set, then set MSB of ZH
> 	ori	ZH,$80		;dosen't touch TEMP
> 	;00000000 Bbbbbbbb b000000
> 
> 	sbrs	TEMP,1		;if b1 is set, then set B0 of RAMPZ
> 	rjmp	MakePage_Noz	;
> 	ldi	TEMP,$01	;
> 	out	RAMPZ,TEMP	;
> 
> 	;00000001 Bbbbbbbb b0000000
> 	;       |          ||    ||
> 	;       |          ||    |\----- Which byte within word
> 	;       |          |\----\------ Words within page
> 	;       \----------\------------ Pages
> 
> MakePage_Noz:
> 	in	TEMP,RAMPZ	;So I can see the adrs on the LA
> 	call	PONG
> 	mov	TEMP,ZH
> 	call	Pong
> 	mov	TEMP,ZL
> 	call	Pong
> 	ret
> ;
> ;***********************************************************
> ;
> 
> What's happening, is that it seems to be erasing EVERY page, but 
> writing every OTHER page, although I can't tell if it's wrapping, or 
> exactly what is going on..  The "pong" statements are my byte in PWM 
> output on a single pin, and that shows me what I expect as the 
> packets come in.
>

Re: [AVR-Chat] Re: Bootloader Frustration

2007-07-14 by David VanHorn

On 7/14/07, poitsplace <lmburt@email.uncc.edu> wrote:
> I've never attempted to use any of the AVR's with the store program
> memory instruction...but I can't help but notice there's an interrupt
> vector (and therefore a corresponding flag somewhere) called "SPM
> READY" (Store Program Memory Ready).  Is your program using this
> interrupt (or checking the flag manually) to make sure it's ready?

Yes, I am doing that, no need to use the ints, I'm not doing anything
else while loading so this is one time I'm ok with "sit and spin", and
polling.

I found one problem already.. The page size is 128 words, not 64 like it says.
I found this out by running it in sim, and watching it erase a page.
The docs mention different chips having different page sizes, and I
didn't see anywhere that it calls out a table to give those sizes.  I
only saw examples at 64 words/128 bytes, so I made the assumption that
in the M128 that was the actual size, since this IS a M128 data
sheet...  :-P

So, I think I may have it now, all that's remaining is to handle the
case of an odd number of 128 byte packets.

Re: Bootloader Frustration

2007-07-14 by stevech11

This project, and others, has source code configurable for many AVRs
for bootloading. And the PC side too. As an example. This one is in
asm language to keep the bootloader small - since the bootloader area
size increased in steps of two-fold.

http://www.avrfreaks.net/index.php?module=Freaks%20Academy&func=viewItem&item_type=project&item_id=625


> I found one problem already.. The page size is 128 words, not 64
like it says.
Show quoted textHide quoted text
> I found this out by running it in sim, and watching it erase a page.
> The docs mention different chips having different page sizes, and I
> didn't see anywhere that it calls out a table to give those sizes.  I
> only saw examples at 64 words/128 bytes, so I made the assumption that
> in the M128 that was the actual size, since this IS a M128 data
> sheet...  :-P
> 
> So, I think I may have it now, all that's remaining is to handle the
> case of an odd number of 128 byte packets.
>

Re: Bootloader Frustration

2007-07-15 by Mike Perks

David,

> I found one problem already.. The page size is 128 words, not 64
like it says.
> I found this out by running it in sim, and watching it erase a page.
> The docs mention different chips having different page sizes, and I
> didn't see anywhere that it calls out a table to give those sizes.  I
> only saw examples at 64 words/128 bytes, so I made the assumption that
> in the M128 that was the actual size, since this IS a M128 data
> sheet...  :-P

I really hope you are using one of the standard ASM include files such
as mdef128.inc. It is going to save hardcoding everything. It includes
definitions for PAGESIZE (128), and FIRSTBOOTSTART (0xfe00).

The flash page size is also listed in the table on page 294 of the
mega128 datasheet and referred to from pages 201 and 306 as well. See
http://atmel.com/dyn/resources/prod_documents/doc2467.pdf.

Re: [AVR-Chat] Re: Bootloader Frustration

2007-07-15 by David VanHorn

> I really hope you are using one of the standard ASM include files such
> as mdef128.inc. It is going to save hardcoding everything. It includes
> definitions for PAGESIZE (128), and FIRSTBOOTSTART (0xfe00).

I am, but of course you have to know it's there, or go looking for it.
My loader fits in nicely at FE00, and it would go at FF00 if that was an option.

> The flash page size is also listed in the table on page 294 of the
> mega128 datasheet and referred to from pages 201 and 306 as well. See
> http://atmel.com/dyn/resources/prod_documents/doc2467.pdf.

Silly me, I expected that to happen in the section about the SPM
instruction, or at least a reference out to there.  Ah well.

Re: Bootloader Frustration

2007-07-15 by Mike Perks

David,
 
> > The flash page size is also listed in the table on page 294 of the
> > mega128 datasheet and referred to from pages 201 and 306 as well. See
> > http://atmel.com/dyn/resources/prod_documents/doc2467.pdf.
> 
> Silly me, I expected that to happen in the section about the SPM
> instruction, or at least a reference out to there.  Ah well.

Sorry that should be page 281 (not 201) which is in the SPM section.
The reference is to the table 123 on page 294. It's there but it
doesn't exactly jump out at you. I have found that you need to
carefully read the datasheets at least twice.

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.