USBDemo with Bootloader


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2007
    Posts
    70

    Default USBDemo with Bootloader

    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/id...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
    Last edited by vacpress; - 23rd January 2007 at 10:34.

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405

    Default

    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.
    Code:
    #if   defined(__18F4550)
    #pragma config PLLDIV=5,CPUDIV=OSC1_PLL2,USBDIV=2,FOSC=HSPLL_HS,FCMEN=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,FCMEN=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.
    Code:
      INCLUDE "P18F4550.INC"	; MPASM  Header
            CONFIG PLLDIV=5,CPUDIV=OSC1_PLL2,USBDIV=2,FOSC=HSPLL_HS,FCMEN=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;
    Code:
    /** 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
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Jan 2006
    Location
    Toronto
    Posts
    109

    Default

    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

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405

    Default

    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.
    Code:
    #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;

    Code:
    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.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Jan 2007
    Posts
    70

    Default hmmmgrumble

    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!

Similar Threads

  1. PIC18F4680 bootloader
    By vinyl_theif in forum General
    Replies: 1
    Last Post: - 29th January 2009, 17:45
  2. 18F4550 Bootloader enter via eeprom setting
    By bradb in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 22nd November 2008, 23:51
  3. 18F2550 MCRL/RE3 problem with USB bootloader Microchip
    By Ronald123 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 24th September 2007, 10:48
  4. Using the Mecanique Bootloader without the DTR reset signal
    By picnaut in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th September 2005, 03:39
  5. Bootloader Problems
    By rossfree in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 11th February 2005, 17:51

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts