Skip to content

An altogether better idea

February 26, 2017

It occurred to me that the whole xmodem thing was a waste of time.  It’s trivial to have the 1806 fake a load mode like the 1802.  All I need is a little program that runs at startup and accepts binary data whenever IN is pressed.  Then I can use the existing avrdude on windows and more-or-less the same program in the avr bridge processor. Instead of talking to the 1802 load mode the AVR talks to my fake loader program in the 1802/1806.  A piece of cake.

//fakeloader simulates 1802 load mode in run for 1806
void main(){
	asm(" 	b4 run\n"		//bypass bootloader if IN pressed
	" 	ldAD 14,0x2000\n"	//starting address
	" 	sex 14\n"		//in X register
	"noEF4:	bn4 noEF4\n"		//loop til IN pressed
	"yEF4:	b4 yEF4\n"		//wait til switch released
	"	inp 6\n"		//load memory
	"   	nop\n"
	"	out 7\n"		//and echo
	"	br noEF4\n"		//back for more
	"run:	lbr 0x2000\n");	//finally - off we go

The 1802/6 loader code really is simple. On startup, it tests EF4 to see if the bootloader should run. Then it loads bytes starting at location 0x2000 every time it sees EF4 go low and then high. To invoke it the AVR resets the 1802/1806 then puts it in run with /EF4 high. It feeds it the code from avrdude then, when that’s done it restarts the 1802/1806 with /EF4 held low to bypass the loader and execute the application at 0x2000.

The changes to the avr loader were simple compared to what was done for xmodem. It looks at the first address avrdude sends for program loading. If it’s 0 it assumes this is an 1802 and it puts it in load mode. If it’s not 0 it puts the assumed 1806 in pseudo-load mode then programs it the same way.

Of course, getting this working involved four programs running on three platforms (avrdude on windows, my loader application on the avr, the fake loader and the loaded application on the 1802/1806). Much head-scratching and logic-analyzer poking was required. But, now that it works it’s all much simpler and once the fake loader is in eprom it should be pretty reliable.



UPDATE: There was a major flaw in my execution of this brilliant idea.  By the time the loader starts running we’ve already gone through initialization and we’re running with R3 as program counter.  When we branch to the loaded program we run the initialization again and, more specifically, we load R3 again.  This does not work well.  For some reason it works a lot of the time but future me will spend a couple of days debugging it.

From → Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: