PDA

View Full Version : USBDemo with Bootloader



vacpress
- 23rd January 2007, 11:32
Hello again!

I am currently trying to get the USBDemo program Mister E made to work with the Microchip.com bootloader.
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2124&param=en022627

The progress is as follows:

1. Install all applications fresh
* MPLAB 7.31
* Microchip Student Edition C18
* Pic Basic Pro(Oh be worth it please)
* Microcode Studio (not plus)
* Microchip Bootloader Files Install
* EasyHID Program (well, it is also included in microcode, i think?)

2. Setup all compilers and IDEs
3. Compile bootloader files, modified to 4mhz by setting the configuration flags in MPLAB - I don't quite get where to put the flags in the C18 code. Is there an include like in pbasic?
4. Compile .hex -easy.
5. Program 18f4550 via ICD2 and MPLAB
6. Put chip in tested board(runs USBDemo off another programmed chip)
7. do switch combo thing to go into booloader mode.. cool, it works.
8. select USBDemo.hex (Stock one)
9. Uh oh - an error. it says the config flags are not the same.. funny, i thought i got them! try anyway? doesn't work... scrambled bootloader somehow... tried all options each time with freshly programmed chip.

any direction here? is there another bootloader that is better? do i need to add some sort of code to the USBDemo to see bootloader interrupts?

I tried this with a simple LED example i found somewhere... It didnt really work quite right.. it didn't blink unless I was in the USB recognized state - the one in which the microchip bootloader utility sees the chip..

Please ask me to clarify if this is muddled!

I appreciate it.

Robert

Bruce
- 23rd January 2007, 19:20
The Microchip loader expects your config settings to match the settings in
the C18 loader template. If they're different, it throws up this error.

I've recompiled the C18 USB framework files myself, for use with the 18F2550
or 18F4550. Here's what I did in Main.c;

Note this assumes a 20MHz external xtal.


#if defined(__18F4550)
#pragma config PLLDIV=5,CPUDIV=OSC1_PLL2,USBDIV=2,FOSC=HSPLL_HS,F CMEN=OFF,IESO=OFF
#pragma config VREGEN=ON,CCP2MX=ON,WDT=OFF,WDTPS=32768,PBADEN=OFF ,PWRT=OFF,MCLRE=ON
#pragma config LPT1OSC=OFF,BOR=ON,BORV=2,STVREN=ON,LVP=OFF,ICPRT= OFF,XINST=OFF,DEBUG=OFF
#pragma config WRTB=ON
#else
// For 18F2550 (NOTE: Be sure to swap linker files for the USB PIC being used)
#pragma config PLLDIV=5,CPUDIV=OSC1_PLL2,USBDIV=2,FOSC=HSPLL_HS,F CMEN=OFF,IESO=OFF
#pragma config VREGEN=ON,CCP2MX=ON,WDT=OFF,WDTPS=32768,PBADEN=OFF ,PWRT=OFF,MCLRE=ON
#pragma config LPT1OSC=OFF,BOR=ON,BORV=2,STVREN=ON,LVP=OFF,XINST= OFF,DEBUG=OFF
#pragma config WRTB=ON
#endif

Just be sure to swap linker files before recompiling.

Then in my PBP 18F4550.INC file I placed the same config settings in it.


INCLUDE "P18F4550.INC" ; MPASM Header
CONFIG PLLDIV=5,CPUDIV=OSC1_PLL2,USBDIV=2,FOSC=HSPLL_HS,F CMEN=OFF,IESO=OFF
CONFIG VREGEN=ON,CCP2MX=ON,WDT=OFF,WDTPS=32768,PBADEN=OFF ,PWRT=OFF,MCLRE=ON
CONFIG LPT1OSC=OFF,BOR=ON,BORV=2,STVREN=ON,LVP=OFF,ICPRT= OFF,XINST=OFF,DEBUG=OFF
CONFIG WRTB=ON

I made a few other modifications to the C18 loader firmware. Mainly just to
change the USB loader status LED's to a different port when using the
18F2550.

In io_cfg.h;


/** L E D ************************************************** *********/
#if defined(__18F4550)
#define mInitAllLEDs() LATD &= 0xF0; TRISD &= 0xF0;
#define mLED_1 LATDbits.LATD0
#define mLED_2 LATDbits.LATD1
#define mLED_3 LATDbits.LATD2
#define mLED_4 LATDbits.LATD3
#else
#define mInitAllLEDs() LATB &= 0xF0; TRISB &= 0xF0;
#define mLED_1 LATBbits.LATB0
#define mLED_2 LATBbits.LATB1
#define mLED_3 LATBbits.LATB2
#define mLED_4 LATBbits.LATB3
#endif

PJALM
- 25th January 2007, 05:38
For me I had to add the following lines in PicBasic...

DEFINE LOADER_USED 1
DEFINE RESET_ORG 800h ' For Microchip USB Bootloader
DEFINE INTERRUPT_ORG 808h ' For Microchip USB Bootloader

Bruce
- 25th January 2007, 18:13
If you're using the Microchip USB boot-loader, you can drop some of your
defines.

DEFINE LOADER_USED 1 is only required if user code will start at 0. With the
Microchip USB loader, it starts at 800h. You don't need this define.

DEFINE RESET_ORG 800h ' This is required so user code is inserted at 800h (if
using the Microchip USB Bootloader).

DEFINE INTERRUPT_ORG 808h ' This one doesn't really do anything. If you're
using assembler interrupts, then use the PBP DEFINE INTHAND or INTLHAND
options for high/low interrupt vectors.

The Microchip USB loader already has interrupt jump vectors setup in the
loader firmware that will vector to 808h for high pri, and 818h for low pri
interrupts.


#pragma code high_vector=0x000808
void interrupt_at_high_vector(void)
{
_asm goto high_isr _endasm
}
#pragma code

#pragma code low_vector=0x000818
void interrupt_at_low_vector(void)
{
_asm goto low_isr _endasm
}
#pragma code
In the USB loader firmware, at the hardware interrupt vectors, it has GOTO
808h (for high pri) and GOTO 818h (for low pri). You just need to force PBP
to stick your .asm int handlers (or a GOTO each one) in these locations.

To do this, you tell PBP where your high & low interrupt service handlers will
be using the INTHAND & INTLHAND defines below.

DEFINE RESET_ORG 800h ' User code starts at 800h for USB Boot-Loader
DEFINE INTHAND my_high_isr ' High priority int handler
DEFINE INTLHAND my_low_isr ' Low priority int handler

Now add your assembler interrupt handlers like this;



ASM
my_high_isr
; do stuff here
RETFIE FAST
ENDASM

ASM
my_low_isr
; do stuff here
RETFIE
ENDASM
PBP will place a GOTO my_high_isr at location 808h, and a GOTO my_low_isr
at 818h.

The rest of your code will start just after location 818h.

You have re-mapped the reset vector to 800h with DEFINE RESET_ORG 800h
so PBP knows where to stick these. It simply adds 08h or 18h to the reset
address for the high/low priority interrupt locations.

The USB firmware vectors to 808h for high pri, and 818h for low pri, and PBP
has placed GOTO's in these locations vectoring to your re-mapped .asm
interrupt handlers.

If you're 100% sure you have all interrupts disabled, and you're never planning
to use them, then you can drop the interrupt defines altogether.

If you're not sure, or you do plan to use interrupts, and you're using the USB
loader from Microchip, then it's a really good idea to setup these vectors.

If you don't, then PBP will place 'user' code in locations the loader will vector
to when an interrupt happens. Then you have no idea what's going to happen.

vacpress
- 25th January 2007, 23:29
allrite.. well. i am reading these suggestions, and they are not entirely clear without the code in front of me. i wont have a chance to work on this tonite, but i should get time over the weekend...

in the meantime, let me complain about microcode studio's lack of a config fuse editor! it really is a PIA, and it is causing lots of headaches.

then also let me complain about the weird interaction between 18x series config flags, mpasm, and picbasic pro! why is it so abnormal feeling?

also, let me repeat my initial question - has anyone gotten the USBDemo application from mister e to work with a usb bootloader?

thanks!