Bienvenue aux nouveaux arrivants sur FantasPic !

- Pensez à lire les règles durant votre visite, il n'y en a pas beaucoup, mais encore faut-il les respecter .
- N’hésitez pas à faire des remarques et/ou suggestions sur le Forum, dans le but de l'améliorer et de rendre vos prochaines visites plus agréables.
- Vous pouvez regarder votre "panneau de l'utilisateur" afin de configurer vos préférences.
- Un passage par "l'utilisation du forum" est recommandé pour connaître les fonctionnalités du forum.

--- L’équipe FantasPic ---
On parle des Pics, sans rapport avec le langage ou la programmation

Modérateur : Jérémy

bootloader USB
cyril13110
Confirmé
Confirmé
Messages : 724
Âge : 41
Enregistré en : avril 2016
Localisation : 13

#1 Message par cyril13110 » lun. 1 août 2016 13:18

bonjour à tous,
Je ne sais pas trop ou mettre ce post du coup je l'ai mis ici.
est ce que quelqu'un as deja utiliser un bootloader sur USB de chez mikroelektronika?
est ce que ca fonctionne bien?

d’après la doc il ny a pas de modif de code particulière à faire, et ca me permettrai de m'occuper au bureau car en ce moment c'est plutôt long......

bootloader USB
paulfjujo
Avatar de l’utilisateur
Expert
Expert
Messages : 2589
Âge : 73
Enregistré en : juillet 2015
Localisation : 01800
Contact :

#2 Message par paulfjujo » lun. 1 août 2016 17:06

bonjour,


J'utilise regulierement le bootloader USB sur
les pics Cliker2 18F87J50 et click 18F46J53 .. ça marche nikel .. et tres rapide.! car via USB
Les cartes MikroE sont livrées avec le bootloader installé .. pas besoin de Pickit2 ou 3
meme si l'ICSP reste accessible .
On dispose aussi dans le foulée du TERMINAL USB ! pour l'application.
(Testé 2 UARTS + 3em UART TX soft + HID terminal )

sur les cartes 18F2550 ready for PIC .. aussi ..mais biens moins rapide..
le USB servant à fare une com en UART via un circuit FTDI !
de meme pour la carte Ready for PIC 18F45K22
USB <-> FTDI <--> UART
par rapport à un bootloader serie UART ,
le seul avantage est de disposer du Terminal USB serial
Aide toi, le ciel ou FantasPic t'aidera

bootloader USB
cyril13110
Confirmé
Confirmé
Messages : 724
Âge : 41
Enregistré en : avril 2016
Localisation : 13

#3 Message par cyril13110 » lun. 1 août 2016 17:59

Ok ok alors moi je compte en fabriquer une car jai tous ce quil me faut et pas forcement le moyen aujourd'hui dzn acheter une toute faite, je prendrais sur le net le schéma par contre jai besoin dune confirmation pour lutilisation.
Apparement si jai bien compris il faut inclure dans le projet sous mikrobasic le fichier de bootloader pour chaque compile.
Mais il ny a pas de conf spécifique a faire pour le code ? Du style pointer a une zone memoire spécifique comme il se fait sur certainz puces voir vieux bootloader ?

bootloader USB
paulfjujo
Avatar de l’utilisateur
Expert
Expert
Messages : 2589
Âge : 73
Enregistré en : juillet 2015
Localisation : 01800
Contact :

#4 Message par paulfjujo » lun. 1 août 2016 20:15

il faut inclure dans le projet sous mikrobasic le fichier de bootloader pour chaque compile.


NON, le bootloader est installé une bonne fois pour toute, en general en fond de memoire,
et le vecteur de demarrage est modifié .
Le programme d'application doit etre chargé par un programme specifique "bootloader xxx.exe"
et il se charge de loger l'application sans bousiller le bootloader.

nota: il peut arriver qu'une aplli deborde et ecrabouille le bootloader
lorsque l'appli est mal controlée .. index depassant un bornage de table ou autre..
Cela m'est déja arrivé ...
Une compilation et transfert reussi n'est pas gage de programme correct !

un bootoader est construit pour une certaine frequence FOSC.. because UART en bauds definit.
le bootloader reduit la capacité utile ROM du PIC , pour l'application (Zone Bootloader reservée)

Sur quel PIC veut tu installer un bootloader ?

quelques bootloaders
Aide toi, le ciel ou FantasPic t'aidera

bootloader USB
cyril13110
Confirmé
Confirmé
Messages : 724
Âge : 41
Enregistré en : avril 2016
Localisation : 13

#5 Message par cyril13110 » lun. 1 août 2016 20:40

Ok je vois dans tous les cas je comptais utiliser le bootloader hid usb de mikroe (pour ne pas le citer).

Pour un debut je pensais utiliser un 18f2550, la premiere appli que jai en tete est de comprendre comment fonctionne le hid usb avec la conf dun joystique avec le pic.
Je pense faire une toute petite carte avec le pic et 6 bp simple voir 1 ou 2 potar tous simple et jai en tete de largement utiliser le bootloader dans les applis.....

bootloader USB
paulfjujo
Avatar de l’utilisateur
Expert
Expert
Messages : 2589
Âge : 73
Enregistré en : juillet 2015
Localisation : 01800
Contact :

#6 Message par paulfjujo » mar. 2 août 2016 13:53

bonjour,

comment fonctionne le hid usb avec la conf d'un joystique avec le pic.


Si tu veux connecter un joystick USB sur un 18F2550, c'est pas gagné..
les 18F , à ma connaissance (limitée) ne gerent pas le USB HOST ( sous entendu Joystick esclave ou client)
voir PIC24 ou PIC32..

neamoin un joystick peut tres bien etre géré via 2 entrees ANA et les BPs par ailleurs ...
j'ai utilisé un micro-joystick pour gerer un menu LCD appli gene BF DDS.. deplacement lateral dans le menu et deplacement vertical pour le sous menu
et aussi pour gerer une consigne de frequence.

Le HID bootloader de MikroE que je connais pour le 18F2550 est du simli UART ! non natif USB comme je l'ai precisé plus haut.
C'est comme si on utilisait un cordon TTL/Prolifix 2303 .. en gros.

A moins qu'il existe une version HID 100% USB ?
Aide toi, le ciel ou FantasPic t'aidera

bootloader USB
cyril13110
Confirmé
Confirmé
Messages : 724
Âge : 41
Enregistré en : avril 2016
Localisation : 13

#7 Message par cyril13110 » mar. 2 août 2016 16:57

Ha ok bizare car jai trouvé un exemple avec mikroc et un 18f de montage complet hid joystique. Demain je le poste.
Ce que jen ai retenu cest que tous viens du fichier de conf du hid usb, qui est absolument abominable a créer.....

bootloader USB
cyril13110
Confirmé
Confirmé
Messages : 724
Âge : 41
Enregistré en : avril 2016
Localisation : 13

#8 Message par cyril13110 » mer. 3 août 2016 08:48

bonjour,
comme promis je post l'exemple que j'ai trouvé avec un 18f4550 tous en mikroc sur lequel je vais m'appuyer pour faire mon montage.
il va falloir que je face des tests , pour le moment je ne comprend pas trop comment est composé le fichier de description et la relation avec le code du micro.

code µC:

Code : Tout sélectionner

/*
 * Project name:
                USB HID JOYSTICK PROJECT

 * Copyright (c) 2012 Emil Enchev

 * Description:
  USB HID JOYSTICK PROJECT

 * Test configuration:
     MCU:             PIC18F4550

     dev.board:       easypic5

     Oscillator:      HS+PLL, 32.000 MHz (8MHz Crystal)

     SW:              mikroC PRO for PIC

 * NOTES:
 1. USB COMM.Enabled J12
 2. PORTB PULL-UP
 3. PORTA - ANALOG INPUTS(10k potentiometers):
    3.1. PORTA,0 -> x_axys
    3.2  PORTA,1 -> y_axys
    3.3. PORTA,2 -> ANALOG Point Of View Hat(POV), PORTB 4,5,6,7 - DIGITAL POV CONTROL
                    SET PORTB,4=0 for digital POV
    3.4. PORTA,3 -> Throttle
    
    Note: For testing, You can move the jumpers to change AN0-AN3 on the internal
    ADC input on easyPic Board, but it's better to use mikroElektronika's
    Additional Potentiometer board: http://www.mikroe.com/add-on-boards/measurement/potentiometer/

 4. DIGITAL Inputs:
       PORTB,0 =>  Button1
       PORTB,1 =>  Button2
       PORTB,2 =>  Button3
       PORTB,3 =>  Button4


  5.  Open Control Panel-> Game Controllers -> HID Manipulator to test functions
  6.  You can use Analog or Digital POV control. If PORTB,4,5,6 or 7 pressed - POV control is digital

 */

#define button1 PORTB.F0
#define button2 PORTB.F1
#define button3 PORTB.F2
#define button4 PORTB.F3


unsigned char readbuff[64] absolute 0x500;
unsigned char writebuff[64] absolute 0x540;
unsigned char buttons;
unsigned char pov, pov_hat, dig_pov;
char x_axis, y_axis, throttle=0;   // signed char

void interrupt()
{
     USB_Interrupt_Proc();        // USB servicing is done inside the interrupt
}

void main()
{
        PORTB=0;           //Initialize PORTB
        TRISB=255;         //PORTB - INPUTS

        HID_Enable(readbuff,writebuff);

        while(1)
        {
                //   Joystick buttons
                buttons=button1 + (button2*2) + (button3*4) + (button4*8); //Compact buttons
                buttons=~buttons;       //Convert to LOW LEVEL Detection
                buttons<<=4;            //Send bits to left
                dig_pov=~PORTB & 0b11110000;  //Read upper 4 bits only
                dig_pov>>=4;                 //move bits right

                //Point Of View Hat
                if(dig_pov==0){               //Alternate Analog POV
                    pov=Adc_Read(2)>>2;
                if (pov>=&& pov<=60)        //Up
                    pov_hat=buttons;
                if (pov>=61 && pov<=142)      //Right
                    pov_hat=buttons|1;
                if (pov>=143 && pov<=175)     //Down
                    pov_hat=buttons|2;
                if (pov>=176 && pov<=193)     //Left
                    pov_hat=buttons|3;
                    }else{                    //Alternate digital POV
                    if (dig_pov==1) pov_hat=buttons;
                    if (dig_pov==3) pov_hat=buttons|1;
                    if (dig_pov==5) pov_hat=buttons|2;
                    if (dig_pov==9) pov_hat=buttons|3;
                         }

                //Joystick Axes
                x_axis=(Adc_Read(0)>>2)-128;      //Read only the upper 8 bits of the ADC
                y_axis=(Adc_Read(1)>>2)-128;
                throttle=(Adc_Read(3)>>2)-128;

                //USB
                writebuff[0]=throttle;
                writebuff[1]=x_axis;
                writebuff[2]=y_axis;
                writebuff[3]=pov_hat;

                while(!HID_Write(writebuff,4));
        }
}



fichier d'identification HID USB:

Code : Tout sélectionner

const unsigned int USB_VENDOR_ID = 0x1234;
const unsigned int USB_PRODUCT_ID = 0x0001;
const char USB_SELF_POWER = 0x80;            // Self powered 0xC0,  0x80 bus powered
const char USB_MAX_POWER = 50;               // Bus power required in units of 2 mA
const char HID_INPUT_REPORT_BYTES = 64;
const char HID_OUTPUT_REPORT_BYTES = 64;
const char USB_TRANSFER_TYPE = 0x03;         //0x03 Interrupt
const char EP_IN_INTERVAL = 1;
const char EP_OUT_INTERVAL = 1;

const char USB_INTERRUPT = 1;
const char USB_HID_EP = 1;
const char USB_HID_RPT_SIZE = 77;

/* Device Descriptor */
const struct {
    char bLength;               // bLength         - Descriptor size in bytes (12h)
    char bDescriptorType;       // bDescriptorType - The constant DEVICE (01h)
    unsigned int bcdUSB;        // bcdUSB          - USB specification release number (BCD)
    char bDeviceClass;          // bDeviceClass    - Class Code
    char bDeviceSubClass;       // bDeviceSubClass - Subclass code
    char bDeviceProtocol;       // bDeviceProtocol - Protocol code
    char bMaxPacketSize0;       // bMaxPacketSize0 - Maximum packet size for endpoint 0
    unsigned int idVendor;      // idVendor        - Vendor ID
    unsigned int idProduct;     // idProduct       - Product ID
    unsigned int bcdDevice;     // bcdDevice       - Device release number (BCD)
    char iManufacturer;         // iManufacturer   - Index of string descriptor for the manufacturer
    char iProduct;              // iProduct        - Index of string descriptor for the product.
    char iSerialNumber;         // iSerialNumber   - Index of string descriptor for the serial number.
    char bNumConfigurations;    // bNumConfigurations - Number of possible configurations
} device_dsc = {
      0x12,                   // bLength
      0x01,                   // bDescriptorType
      0x0200,                 // bcdUSB
      0x00,                   // bDeviceClass
      0x00,                   // bDeviceSubClass
      0x00,                   // bDeviceProtocol
      8,                      // bMaxPacketSize0
      USB_VENDOR_ID,          // idVendor
      USB_PRODUCT_ID,         // idProduct
      0x0001,                 // bcdDevice
      0x01,                   // iManufacturer
      0x02,                   // iProduct
      0x00,                   // iSerialNumber
      0x01                    // bNumConfigurations
  };

/* Configuration 1 Descriptor */
const char configDescriptor1[]= {
    // Configuration Descriptor
    0x09,                   // bLength             - Descriptor size in bytes
    0x02,                   // bDescriptorType     - The constant CONFIGURATION (02h)
    0x29,0x00,              // wTotalLength        - The number of bytes in the configuration descriptor and all of its subordinate descriptors
    1,                      // bNumInterfaces      - Number of interfaces in the configuration
    1,                      // bConfigurationValue - Identifier for Set Configuration and Get Configuration requests
    0,                      // iConfiguration      - Index of string descriptor for the configuration
    USB_SELF_POWER,         // bmAttributes        - Self/bus power and remote wakeup settings
    USB_MAX_POWER,          // bMaxPower           - Bus power required in units of 2 mA

    // Interface Descriptor
    0x09,                   // bLength - Descriptor size in bytes (09h)
    0x04,                   // bDescriptorType - The constant Interface (04h)
    0,                      // bInterfaceNumber - Number identifying this interface
    0,                      // bAlternateSetting - A number that identifies a descriptor with alternate settings for this bInterfaceNumber.
    2,                      // bNumEndpoint - Number of endpoints supported not counting endpoint zero
    0x03,                   // bInterfaceClass - Class code
    0,                      // bInterfaceSubclass - Subclass code
    0,                      // bInterfaceProtocol - Protocol code
    0,                      // iInterface - Interface string index

    // HID Class-Specific Descriptor
    0x09,                   // bLength - Descriptor size in bytes.
    0x21,                   // bDescriptorType - This descriptor's type: 21h to indicate the HID class.
    0x01,0x01,              // bcdHID - HID specification release number (BCD).
    0x00,                   // bCountryCode - Numeric expression identifying the country for localized hardware (BCD) or 00h.
    1,                      // bNumDescriptors - Number of subordinate report and physical descriptors.
    0x22,                   // bDescriptorType - The type of a class-specific descriptor that follows
    USB_HID_RPT_SIZE,0x00,  // wDescriptorLength - Total length of the descriptor identified above.

    // Endpoint Descriptor
    0x07,                   // bLength - Descriptor size in bytes (07h)
    0x05,                   // bDescriptorType - The constant Endpoint (05h)
    USB_HID_EP | 0x80,      // bEndpointAddress - Endpoint number and direction
    USB_TRANSFER_TYPE,      // bmAttributes - Transfer type and supplementary information    
    0x40,0x00,              // wMaxPacketSize - Maximum packet size supported
    EP_IN_INTERVAL,         // bInterval - Service interval or NAK rate

    // Endpoint Descriptor
    0x07,                   // bLength - Descriptor size in bytes (07h)
    0x05,                   // bDescriptorType - The constant Endpoint (05h)
    USB_HID_EP,             // bEndpointAddress - Endpoint number and direction
    USB_TRANSFER_TYPE,      // bmAttributes - Transfer type and supplementary information
    0x40,0x00,              // wMaxPacketSize - Maximum packet size supported    
    EP_OUT_INTERVAL         // bInterval - Service interval or NAK rate
};

const struct {
  char report[];
}
hid_rpt_desc =
  {
    0x05, 0x01,             // USAGE_PAGE (Generic Desktop)
    0x15, 0x00,             // LOGICAL_MINIMUM (0)
    0x09, 0x04,             // USAGE (Joystick)
    0xa1, 0x01,             // COLLECTION (Application)
    0x05, 0x02,             // USAGE_PAGE (Simulation Controls)
    0x09, 0xbb,             // USAGE (Throttle)
    0x15, 0x81,             // LOGICAL_MINIMUM (-127)
    0x25, 0x7f,             // LOGICAL_MAXIMUM (127)
    0x75, 0x08,             // REPORT_SIZE (8)
    0x95, 0x01,             // REPORT_COUNT (1)
    0x81, 0x02,             // INPUT (Data,Var,Abs)
    0x05, 0x01,             // USAGE_PAGE (Generic Desktop)
    0x09, 0x01,             // USAGE (Pointer)
    0xa1, 0x00,             // COLLECTION (Physical)
    0x09, 0x30,             // USAGE (X)
    0x09, 0x31,             // USAGE (Y)
    0x95, 0x02,             // REPORT_COUNT (2)
    0x81, 0x02,             // INPUT (Data,Var,Abs)
    0xc0,                   // END_COLLECTION
    0x09, 0x39,             // USAGE (Hat switch)
    0x15, 0x00,             // LOGICAL_MINIMUM (0)
    0x25, 0x03,             // LOGICAL_MAXIMUM (3)
    0x35, 0x00,             // PHYSICAL_MINIMUM (0)
    0x46, 0x0e,             // PHYSICAL_MAXIMUM (270)
    0x01, 0x65,
    0x14,                   // UNIT (Eng Rot:Angular Pos)
    0x75, 0x04,             // REPORT_SIZE (4)
    0x95, 0x01,             // REPORT_COUNT (1)
    0x81, 0x02,             // INPUT (Data,Var,Abs)
    0x05, 0x09,             // USAGE_PAGE (Button)
    0x19, 0x01,             // USAGE_MINIMUM (Button 1)
    0x29, 0x04,             // USAGE_MAXIMUM (Button 4)
    0x15, 0x00,             // LOGICAL_MINIMUM (0)
    0x25, 0x01,             // LOGICAL_MAXIMUM (1)
    0x75, 0x01,             // REPORT_SIZE (1)
    0x95, 0x04,             // REPORT_COUNT (4)
    0x55, 0x00,             // UNIT_EXPONENT (0)
    0x65, 0x00,             // UNIT (None)
    0x81, 0x02,             // INPUT (Data,Var,Abs)
    0xc0                    // END_COLLECTION
  };

//Language code string descriptor
const struct {
  char bLength;
  char bDscType;
  unsigned int string[1];
  } strd1 = {
      4,
      0x03,
      {0x0409}
    };


//Manufacturer string descriptor
const struct{
  char bLength;
  char bDscType;
  unsigned int string[11];
  }strd2={
    22,           //sizeof this descriptor string
    0x03,
    {'E','m','i','l',' ','E','n','c','h','e','v'}
  };

//Product string descriptor
const struct{
  char bLength;
  char bDscType;
  unsigned int string[15];
}
strd3={
    32,          //sizeof this descriptor string
    0x03,
    {'U','S','B',' ','M','a','n','i','p','u','l','a','t','o','r'}
 };

//Array of configuration descriptors
const char* USB_config_dsc_ptr[1];

//Array of string descriptors
const char* USB_string_dsc_ptr[3];

void USB_Init_Desc(){
  USB_config_dsc_ptr[0] = &configDescriptor1;
  USB_string_dsc_ptr[0] = (const char*)&strd1;
  USB_string_dsc_ptr[1] = (const char*)&strd2;
  USB_string_dsc_ptr[2] = (const char*)&strd3;
}

bootloader USB
paulfjujo
Avatar de l’utilisateur
Expert
Expert
Messages : 2589
Âge : 73
Enregistré en : juillet 2015
Localisation : 01800
Contact :

#9 Message par paulfjujo » mer. 3 août 2016 10:02

Vu OK,

J'avais mal compris, Ce n'est pas un joystick USB que l'on veut connecter sur le port USB du 18F !
le PIC sert alors que de passerelle pour recevoir les infos du Joystick 2 valeurs ANA (X,Y) et Boutons poussoirs
pour les mettre dans le package USB liaison avec le PC qui est lui, le HOST USB.

C'est un detournement/modification du USB descriptor pour le HID terminal.
+1 .. qui vaut effectivement le detour,pour etre étudié.

et au niveau de l'integration d'un bootloader ?
- 100% USB .?
- ou USB<>-FTDTI<-> UART PIC ? mon avis, dans ce cas autant garder l'ICSP + Pickit3
Aide toi, le ciel ou FantasPic t'aidera

bootloader USB
cyril13110
Confirmé
Confirmé
Messages : 724
Âge : 41
Enregistré en : avril 2016
Localisation : 13

#10 Message par cyril13110 » mer. 3 août 2016 11:34

alors pour bricoler au bureau il me faudra du 100% usb pour le bootloader afin que ca soit le plus discret possible........

en gros c'est pour développer au bureau vue que ne ce moment je n'ai rien à faire et c'est partie pour durer.

Je voudrai fabriquer une passerelle pour ma manette SNES avec le moins de modif possible de la manette.
ca fait deja un moment que je regarde le USB descriptor mais c'est tous de meme bien hard, il faut que je face des tests et que j'aille a taton.
dans un premier temps je vais simuler les boutons en les faisans clignoter et plus tard je ferai la com avec la manette.


Retourner vers « Généralités sur les PICs »

Qui est en ligne

Utilisateurs parcourant ce forum : Aucun utilisateur enregistré et 27 invités