Вы находитесь на странице: 1из 7

USB

 HID  PIC  bootloader  (de  Microchip)  


Traduction  de  la  documentation  en  fin  de  texte(  J’ai  fait  de  mon  mieux)  

1  PIC  principes  du  chargeur  de  démarrage    


 
Très  brièvement  ce  qu'il  fait.  La  mémoire  flash  code  de  PIC  est    découpée  en  deux  zones.  La  
première  est  utilisée  en  permanence  par  bootloader  lui-­‐même  .  C’est  un  code  qui  coopère  
avec  le  logiciel  de  programmation  pour  obtenir  votre  code  d'utilisateur  du  PIC.  La  deuxième  
partie  (reste  de  la  mémoire  FLASH  de  code)  est  disponible  pour  votre  code.  Cela  signifie  
que,  plus  le  bootloader  est  petit,  plus  votre  code  peut  être  gros.    
 
Chaque  bootloader  redirige  les  vecteurs  (RESET  et  interruption)  à  lui-­‐même.  si  bootloader  
n'est  pas  actif  ils  sont  redirigés  par  bootloader  de  votre  code.  Cette  spécialité  signifie  le  code  
d'utilisateur  de  votre:    
 
         n'a  pas  d’adresse    standart  de  début  de  vecteur    
         n'a  pas  d’adresse    interruption  standart  de  vecteur    

 
Et  c'est  la  raison,  pour  laquelle  vous  ne  pouvez  pas  utiliser  n'importe  quel  code  HEX  
disponible  sur  Internet  avec  bootloader  -­‐  car  il  ne  fonctionnera  pas.    
 
Si  vous  souhaitez  en  savoir  plus,  voir:    

What  is  a  boot  loader,  and  how  would  I  develop  one?  


         comment  un  tel  bootloader  fonctionne  est  en  principe    décrit  dans  l'article  de  Microchip  
AN851  AppNote  pour  un  FLASH  Bootloader  pour  PIC16  et  PIC18  appareils  et  AN1388  
AppNote  pour  PIC32  Bootloader.    
 

   
2  types  de  bootloader  PIC    
 
Il  existe  plusieurs  types  disponibles  sur  Internet,  et  pas  seulement  pour  l'USB  bootloader.  
Vous  pourrez  trouver:    
 
         Bootloader  USB  (utilise  l'interface  USB  de  PIC  pour  obtenir  le  programme  en  PIC)    

         COM  /  bootloader  série  (utilise  l'interface  USART  de  PIC)    


         certains  types  spéciaux  (comme  une  carte  SD  bootloader,  TCP  bootloader)    
   

3  PIC  USB  HID  bootloader    


 
Tous  les  critères  mentionnés  sont  remplies  par  USB  bootloader  de  Microchip  disponible  à  
Microchip  bibliothèques  pour  les  applications.  J'ai  utilisé  la  version  15.6.2013  Windows.  
Toutes  les  références  de  code  source  dans  cette  section  sont  des  sources  situées  dans  \  
microchip_solutions_v2013-­‐06-­‐15  \  USB  \  Device  -­‐  Bootloaders  \  HID  \  Firmware  -­‐  PIC18  
non-­‐J  \  de  ces  bibliothèques.    
Comme  décrit  dans  les  principes,  ce  sont  des  redirections  bootloader:    
 

(main.c)    
//  constantes    
#define  REMAPPED_APPLICATION_RESET_VECTOR  0x1000    
#define  REMAPPED_APPLICATION_HIGH_ISR_VECTOR  0x1008    

#define  REMAPPED_APPLICATION_LOW_ISR_VECTOR  0x1018    


 
Si  vous  le  souhaitez,  vous  pouvez  activer  bootloader  par  programmation  à  partir  de  votre  
application  utilisateur,  sauter  à  l'adresse:    
 
(main.c)    

#define  BOOTLOADER_ABSOLUTE_ENTRY_ADDRESS  0x001C    


 
Ici  vous  pouvez  voir  comment  la  mémoire  FLASH  de  code  est  organisée:    

http://rado.heliohost.org/cgi-­‐sys/suspendedpage.cgi  
USB  HID  bootloader  Code  FLASH  carte    
Figure  1:  USB  HID  bootloader  Code  FLASH  carte    
 

Le  fil  rouge  montre  comment  votre  programme  utilisateur  peut  remettre  le  contrôle  de  
bootloader.    

Le  fil  vert  montre  comment  votre  programme  utilisateur  prend  le  contrôle  depuis  PIC  est  
sous  tension  (quand  RB4  est  reliée  à  VCC  /  +5  V).    

 
Pour  activer  bootloader  par  le  matériel  vous  devez  vous  connecter  RB4  à  la  masse:    
 
(io_cfg.h)    

#elif  défini  (PIC18F4550_PICDEM_FS_USB)  //  Basé  sur  PIC18F4550,  pour  PIC18F45K50  


basé  bord,  voir  plus  loin  ci-­‐dessous    

           ...    
/  **  Mettez  **********************************************  *******  /    
mInitAllSwitches  #define  ()  {mInitSwitch2  ();}    
#define  mInitSwitch2  ()  {ADCON1  =  0x0F;}    

#define  sw2  PORTBbits.RB4    


#define  mDeInitSwitch2  ()  {ADCON1  =  0x07;}    
 

Dans  le  cas  où  vous  avez  PIC18F4550  ou  PIC18F4455,  qui  a  également  la  porte  D,  vous  
pouvez  voir  l'activité  de  bootloader  indiqué  par  LED  sur  la  broche  D0:    

 
(io_cfg.h)    
/  **  LED  **********************************************  *************  /    
mInitAllLEDs  #define  ()  LATD  &  =  0xFE;  TRISD  &  =  0xFE;    

#define  mLED_1  LATDbits.LATD0    


#define  mLED_1_On  ()  mLED_1  =  1;    
#define  mLED_1_Off  ()  mLED_1  =  0;    

#define  mLED_1_Toggle  ()  mLED_1  =  mLED_1!;    


 
Mais  rien  ne  se  passe  sur  PIC18F2550  ou  PIC18F2455,  car  ceux-­‐ci  n'ont  pas  la  porte  D.    

 
   
4  PIC  modèle  de  code  de  l'application  de  l'utilisateur    

 
Dans  votre  application  utilisateur,  vous  devez  tenir  compte  de  toutes  les  exigences  
apparues  par  USB  HID  bootloader.  En  cas  de  bootloader  de  Microchip,  vous  devez:    
 
         Utiliser  des  points  d'entrée  (RESET  et  interruption),    
         pas  utiliser  la  broche  RB4  (initialise  USB  HID  bootloader),    

         pas  utiliser  la  broche  D0  sur  PIC18F4550  ou  PIC18F4455  (USB  LED  signalant  l'activité  du  
bootloader  HID).    

 
J'ai  essayé  plusieurs  compilateurs  disponibles    pour  PIC,  mais  une  seule  fonctione  avec  le  
binaire  compatible  avec  bootloader.  Les  compilateurs  (comme  HI-­‐TECH  C  pour  PIC18,  
MPLAB  XC8)  n'ont  pas  de  problème  avec  les  points  d'entrée  rellocation  sauf  MPLAB  
compilateur  C  pour  PIC18  MCU.    
Avec  MPLAB®  X  environnement  de  développement  intégré  (IDE),  il  est  très  facile  à  utiliser.    
J'ai  réussi  avec  l'application  compatible  USB  du  chargeur  de  démarrage  généré  en  utilisant:    

 
         MPLAB  X  IDE  v1.95  pour  Windows  libéré  le  30/10/2013    
         MPLAB  C  pour  PIC18  v3.46  en  mode  LITE  publié  le  05/03/2013    
 

Il  s'agit  de  l'article  très  utile  avec  descripton  détaillée  quoi  et  comment  doit  être  modifié  
pour  obtenir  l'application  de  travailler  avec  Bootloader  USB  pour  PIC18F2550.  C’est  un  
modèle  d'application  complet    .Cette  tempate  utilise  0x1100  adresse  de  base,  nous  avons  
besoin  de  0x1000  adresse  de  base.    
 
Le  Modèle  modifié  avec  0x1000  adresse  de  base.    
Vous  avez  juste  à  importer  dans  votre  MPLAB  IDE  et  modifier  le  code  que  vous  avez  besoin.  
Ce  modèle  clignote  juste  LED  sur  RB6  de  port  et  RB7,  pour  plus  de  détails  voir  mon  article  
de  clignotant  à  LED.    

5  Téléchargements    
 
USB  HID  bootloader  et  Archives  modèle  d'application  package.zip  contient:    

 
         partie  \  microchip_solutions_v2013-­‐06-­‐15  \  USB  \  Device  -­‐  Bootloaders  \  HID  \  
Firmware  -­‐  PIC18  non-­‐J  \  de  Microchip  bibliothèques  pour  Applications  Version  
15/06/2013  Windows,    
         ici  est  USB  bootloader  fichier  HEX  périphérique  USB  HID  -­‐  HID  -­‐  Bootloader  HID  -­‐  C18  -­‐  
PIC18F4550.hex  vous  devez  télécharger  sur  PIC18F2550  avec  COM  /  programmeur  port  
série  ou  LPT  /  programmeur  de  port  parallèle    
   Les      applications  utilisateur  modèle  de  travail  /  compatible  avec  le  port  USB  de  Microchip  
HID  bootloader  y  compris  le  dossier  PIC18F2550_Application_template_RKA.hex  compilé  
généré  par  MPLAB  C  pour  PIC18  v3.46  en  mode  LITE,  que  vous  pouvez  télécharger  en  
utilisant  PIC  programmeur  USB    
 

PIC USB HID bootloader (from Microchip)


1 PIC bootloader principles
Just briefly what it does. PIC's code FLASH memory is organizationally splitted into 2 areas. First one is
permanently used by bootloader itself - it is code which cooperates with programming software to get your user code
into PIC. Second part (rest of code FLASH memory) is available for your code. That means, smaller the bootloader
is, bigger your code might be.
Every bootloader redirects vectors (RESET and interrupt) to itself. Than (if bootloader is not active) they are
redirected by bootloader to your code. This specialty means your's user code:
• has not standart starting vector address
• has not standart interrupt vector adress
And that is the reason, why you could not use any HEX code available on internet with bootloader - because it will
not work.
If you would like to know more, see:
• What is a boot loader, and how would I develop one? It is really brief and exhausting forum reply you have
to see.
• how such a bootloader works in principle detaily described in Microchip's article AN851 AppNote for a
FLASH Bootloader for PIC16 and PIC18 Devices and AN1388 AppNote for PIC32 Bootloader.

2 PIC bootloader types


There are several bootloader types available on internet and not just for USB. You could find:
• USB bootloader (uses PIC's USB interface to get program into PIC)
• COM/serial bootloader (uses PIC's USART interface)
• some special types (like SD card bootloader, TCP bootloader)
If you are interested more on these ones, you can continue reading on Microchip's forum topic Free Bootloader for
PIC.
From my point of view it is good for first experiments to start with something already tested, proven that works, and
ideally available from manufacturer.

3 PIC USB HID bootloader


All criterias mentioned in sentence above are met by USB bootloader from Microchip available at Microchip
Libraries for Applications. I have used version 2013-06-15 Windows. All source code references in this section are
to sources located in \microchip_solutions_v2013-06-15\USB\Device - Bootloaders\HID\Firmware - PIC18 Non-J\
of these libraries.
All necesarry you will find summarized in one archive at the bottom of page in Downloads section.
As described in principles, these are bootloader redirections:
(main.c)
//Constants
#define REMAPPED_APPLICATION_RESET_VECTOR 0x1000
#define REMAPPED_APPLICATION_HIGH_ISR_VECTOR 0x1008
#define REMAPPED_APPLICATION_LOW_ISR_VECTOR 0x1018
If you would like, you can activate bootloader programatically from your user application, jush jump to adress:
(main.c)
#define BOOTLOADER_ABSOLUTE_ENTRY_ADDRESS 0x001C
Here you can see how code FLASH memory is organized:

Figure 1: USB HID bootloader code FLASH map


Red wire shows how your user program can hand control over bootloader.
Green wire shows how your user program gets control since PIC is powered on (when RB4 is connected to
VCC/+5V).
To activate bootloader by hardware you have to connect RB4 to GND:
(io_cfg.h)
#elif defined(PIC18F4550_PICDEM_FS_USB) //Based on PIC18F4550, for PIC18F45K50 based board, see farther
below
...
/** S W I T C H *****************************************************/
#define mInitAllSwitches() {mInitSwitch2();}
#define mInitSwitch2() {ADCON1 = 0x0F;}
#define sw2 PORTBbits.RB4
#define mDeInitSwitch2() {ADCON1 = 0x07;}
In case you have PIC18F4550 or PIC18F4455, which has also gate D, you can see bootloader activity indicated by
LED on pin D0:
(io_cfg.h)
/** L E D ***********************************************************/
#define mInitAllLEDs() LATD &= 0xFE; TRISD &= 0xFE;
#define mLED_1 LATDbits.LATD0
#define mLED_1_On() mLED_1 = 1;
#define mLED_1_Off() mLED_1 = 0;
#define mLED_1_Toggle() mLED_1 = !mLED_1;
But nothing happens on PIC18F2550 or PIC18F2455, because these do not have gate D.

4 PIC user app code template


In your user application you have to reflect all requirements emerged by USB HID bootloader. In case of Microchip's
bootloader you have to:
• use relocated entry points (RESET and interrupt),
• not use RB4 pin (initializes USB HID bootloader),
• not use D0 pin on PIC18F4550 or PIC18F4455 (LED signalizing USB HID bootloader activity).
I have tried several available compilers available for PIC but only one created working binary compatible with
bootloader. Seems compilers (like HI-TECH C for PIC18, MPLAB XC8) do have problem with entry points
rellocation except MPLAB C Compiler for PIC18 MCUs.
With MPLAB® X Integrated Development Environment (IDE) it is very easy to use.
I have been successful with USB bootloader compatible application generated using:
• MPLAB X IDE v1.95 for Windows released on 30.10.2013
• MPLAB C for PIC18 v3.46 in LITE mode released on 3.5.2013
There is very useful article with detailed decripton what and how has to be modified to get application working with
USB Bootloader for PIC18F2550. There is complete application template attached, too, which I have used to get my
first working application uploadable by USB HID bootloader.
There has to be only changed parts that are relevat to Microchip's USB HID bootloader relocation addresses. This
tempate uses 0x1100 base address, we need 0x1000 base address.
Modified template with 0x1000 base address you can find for download below. You have just to import it to your
MPLAB IDE and modify code as you need. This template just blinks LED on port RB6 and RB7, for details see my
LED blinker article.
5 Downloads
Archive USB HID bootloader and application template package.zip contains:
• part \microchip_solutions_v2013-06-15\USB\Device - Bootloaders\HID\Firmware - PIC18 Non-J\ of
Microchip Libraries for Applications version 2013-06-15 Windows,
here is USB HID bootloader HEX file USB Device - HID - HID Bootloader - C18 - PIC18F4550.hex you
have to upload to PIC18F2550 using COM / serial port programmer or LPT / parallel port programmer
• user applications template working/compatible with Microchip's USB HID bootloader including compiled
PIC18F2550_Application_template_RKA.hex file generated by MPLAB C for PIC18 v3.46 in LITE
mode, that you can upload into PIC using USB programmer

If you found these information useful, please consider to:

in USD
in EUR
This will allow me to bring more information and projects for you.
This page was last modified on: 08/21/2014 02:04:08
© 2013, Radoslav Kastiel
 
 

Вам также может понравиться