PDA

View Full Version : USB Bootloader with EEPROM - 18F4550



milosch
- 1st April 2011, 21:58
I looked at 2 yr old posting here regarding modification of the USB Vendor Class Bootloader from Microchip written in C18 and ran into a couple of issues that are now resolved. But, FYI:

1st, I was modifying this to use an EPROM value set from within PicBasic Pro to jump into the bootloader vs. a jumper setting etc. One problem I had was going over the size limit for the boot block. Once I removed the BlinkUSB() routines it was able to fit again. Adding the read and write to the EEPROM was pushing it.

2nd, I could not get the EEPROM read or write to work properly. I started with the more discrete routines accessing EECON2bits, etc. and finally switched to Read_B_eep() et al. None of this worked until I hit the following routine which actually reads and writes successfully. From main.c:



void enterbootload(void)
{
//Bootload Mode
mInitializeUSBDriver(); // See usbdrv.h
USBCheckBusStatus(); // Modified to always enable USB module
while(1)
{
USBDriverService(); // See usbdrv.c
BootService(); // See boot.c
}
}

void main(void)
{
unsigned char eeTemp;
unsigned int address;
address = 0x0009;

EEADR = address;
Read_b_eep(address);
eeTemp = EEDATA;

// Check EEProm-based Bootload Entry Condition
if(eeTemp == 0x01)
{
Write_b_eep(address, 0x00); // write into to EEPROM
Busy_eep();
enterbootload();
}

_asm goto 0x1000 _endasm
}


Simply doing something like "eeTemp = Read_b_eep(address);" did not return the correct value for me on read. Also, the only reason I broke out the bootload into a separate routine was that I was trying to also have the PORTB bits as a secondary option. I could easily put that into the if eeTemp portion.