Bonjour,

Je suis actuellement en train de réaliser un projet qui consiste a créer une communication entre PC et port USB sur une carte d'évaluation "starter kit" pour microcontroleur PIC32mz2048ech144.

J'ai réussi à utiliser les switchs et les leds de ma carte afin de réaliser des tempos et m'amuser un peu à faire clignoter mes leds grâce au fonction BSP.
C'est la première fois que je suis sur ce genre de projet je ne suis donc pas un pro de la programmation en c mais je connais les bases.

Logiciel:

MplabX (v3.60)
framework harmony (V1.06)
compilateur XC32 (V1.40)

Je suis à la recherche d'un programme permettant de communiquer entre un port USB et le PC.

J'ai réalisé un petit programme en m'inspirant d'autre projet déjà réalisé mais je n'arrive ni à lire ni à écrire sur le port.
Avec les fonctions USB je ne peux pas utiliser les fonctions BSP (allumage de led) pour faire office de debugger et voir l'avancer du programme, j'ai donc voulu utiliser la fonction: SYS_PORTS_PinSet(PORTS_ID_0,PO RT_CHANNEL_H,PORTS_BIT_POS_2); ou encore SYS_PORTS_PinWrite (PORTS_ID_0,PORT_CHANNEL_H,POR TS_BIT_POS_1,true); pour allumer une led mais rien !!

Le programme se compile avec succès et ce charge dans le pic sans problème !

2 questions:

- Existe-t-il un paramètre dans mplab harmony pour voir l'avancer du programme voir si les fonctions sont réalisées ou non ? (un vrai debugger)

- Est ce qu'il faut créer une fonction pour les tampon d'émission et de réception ?
je transmet un tableaux d'une taille max de 10 bit mais je ne sais comment le remplir !!

Code:
APP_DATA appData;

// *****************************************************************************
// *****************************************************************************
// Section: Application Local Functions
// *****************************************************************************
// *****************************************************************************

/* TODO:  Add any necessary local functions.
*/

/* Receive data buffer */

uint8_t receivedDataBuffer[10] __attribute__((coherent, aligned(4)));;          // Tampo d'émission réception 

/* Transmit data buffer */

uint8_t transmitDataBuffer[10] __attribute__((coherent, aligned(4)));;          // Tampo d'émission réception

// *****************************************************************************
// *****************************************************************************
// Section: Application Initialization and State Machine Functions
// *****************************************************************************
// *****************************************************************************

/*******************************************************************************
  Function:
    void APP_Initialize ( void )

  Remarks:
    See prototype in app.h.
 */

void APP_Initialize ( void )
{
    /* Place the App state machine in its initial state. */
    appData.state = APP_STATE_INIT;
    
    appData.usbDeviceThisInstance = USB_DEVICE_HANDLE_INVALID;
    
    appData.isConfigured = false;
    
    appData.queueSizeEndpointRead = false;
    
    appData.queueSizeEndpointWrite = false;
    
    appData.bAlternateSetting = 0;
    
    appData.configurationValue = 01;
    
    appData.controlEndpointRx = 0x01;
    
    appData.controlEndpointTx = 0x81;
    
    /* TODO: Initialize your application's state machine and other
     * parameters.
     */
}


void APP_USBDeviceEventHandler(USB_DEVICE_EVENT event, void * eventData, uintptr_t context)
{
    uint8_t * configurationValue;                  // Data
    USB_SETUP_PACKET * setupPacket;                 
    
    switch(event)
    {
        case USB_DEVICE_EVENT_RESET:        // réinitialisation du bus USB
        case USB_DEVICE_EVENT_DECONFIGURED:  
            appData.isConfigured = false;  //appData.state = APP_STATE_WAIT_FOR_CONFIGURATION;
            break;
        case USB_DEVICE_EVENT_CONFIGURED:  // configure l'événement du périphérique
            appData.isConfigured = true;

            /* Save the other details for later use. */
            appData.configurationValue = ((USB_DEVICE_EVENT_DATA_CONFIGURED*)eventData)->configurationValue;    // 

            if (USB_DEVICE_EndpointIsEnabled(appData.usbDeviceThisInstance, appData.controlEndpointRx) == false )
            {
                /* Enable Read Endpoint */
                USB_DEVICE_EndpointEnable(appData.usbDeviceThisInstance, 0, appData.controlEndpointRx,USB_TRANSFER_TYPE_BULK, 64);
            }

             USB_DEVICE_RESULT USB_DEVICE_EndpointRead(USB_DEVICE_HANDLE usbDeviceThisInstance,USB_DEVICE_TRANSFER_HANDLE * transferHandle,USB_ENDPOINT_ADDRESS endpoint,void * buffer,size_t bufferSize);
            
            appData.queueSizeEndpointRead = true;
             
            break;
        case USB_DEVICE_EVENT_CONTROL_TRANSFER_SETUP_REQUEST:           // reception des données sous forme de packet
            /* This means we have received a setup packet */
            setupPacket = (USB_SETUP_PACKET *)eventData;
            if(setupPacket->bRequest == USB_REQUEST_SET_INTERFACE)
            {
                /* If we have got the SET_INTERFACE request, we just acknowledge
                 for now. This demo has only one alternate setting which is already
                 active. */
                USB_DEVICE_ControlStatus(appData.usbDeviceThisInstance,USB_DEVICE_CONTROL_STATUS_OK);
            }
            else if(setupPacket->bRequest == USB_REQUEST_GET_INTERFACE)
            {
                /* We have only one alternate setting and this setting 0. So
                 * we send this information to the host. */

                USB_DEVICE_ControlSend(appData.usbDeviceThisInstance, &appData.bAlternateSetting, 1);
            }
            else
            {
                /* We have received a request that we cannot handle. Stall it*/
                USB_DEVICE_ControlStatus(appData.usbDeviceThisInstance, USB_DEVICE_CONTROL_STATUS_ERROR);
            }
            break;
        case USB_DEVICE_EVENT_SUSPENDED:
            break;
        case USB_DEVICE_EVENT_POWER_DETECTED:           // alim détecter
            /* VBUS was detected. We can attach the device */
            USB_DEVICE_Attach (appData.usbDeviceThisInstance);
            break;
        case USB_DEVICE_EVENT_POWER_REMOVED:            // on enléve l'alim bus

            /* VBUS is not available */
            USB_DEVICE_Detach(appData.usbDeviceThisInstance);
            break;
        case USB_DEVICE_EVENT_ENDPOINT_READ_COMPLETE:
           /* Endpoint read is complete */
            appData.queueSizeEndpointRead = false;
            
            break;
        case USB_DEVICE_EVENT_ENDPOINT_WRITE_COMPLETE:
            /* Endpoint write is complete */
            appData.queueSizeEndpointWrite = false;
            break;
        /* These events are not used in this demo */
        case USB_DEVICE_EVENT_RESUMED:
        case USB_DEVICE_EVENT_ERROR:
        default:
            break;
    }
}

/******************************************************************************
  Function:
    void APP_Tasks ( void )

  Remarks:
    See prototype in app.h.
 */

void APP_Tasks ( void )
{
   /* char buffer[256];               //initialisation de la data*/
    SYS_PORTS_PinSet(PORTS_ID_0,PORT_CHANNEL_H,PORTS_BIT_POS_2);                      //allumer la led RH2
 
    SYS_PORTS_PinWrite (PORTS_ID_0,PORT_CHANNEL_H,PORTS_BIT_POS_1,true);           //allumer la led RH1 
    
    switch ( appData.state )
    {
        case APP_STATE_INIT:
        { 
 
            appData.usbDeviceThisInstance = USB_DEVICE_Open( USB_DEVICE_INDEX_0, DRV_IO_INTENT_READWRITE );

            USB_DEVICE_EventHandlerSet(appData.usbDeviceThisInstance, APP_USBDeviceEventHandler, 0);
            if(appData.usbDeviceThisInstance != USB_DEVICE_HANDLE_INVALID)
            {
                appData.state = APP_STATE_WAIT_FOR_CONFIGURATION;
            }
        }
        break;
        case APP_STATE_WAIT_FOR_CONFIGURATION:
            appData.state = APP_STATE_RUN;
        break;
        case APP_STATE_RUN:
        {

        }
        break;

        default:
        {
            break;
        }
    }
}
 
 

/*******************************************************************************
 End of File
 */
Code:
typedef struct
{
    /* The application's current state */
    APP_STATES state;
    APP_STATES isConfigured;
    APP_STATES usbDeviceThisInstance;
    APP_STATES queueSizeEndpointRead;
    APP_STATES queueSizeEndpointWrite;
    APP_STATES bAlternateSetting;
    APP_STATES controlEndpointRx;
    APP_STATES controlEndpointTx;
    APP_STATES configurationValue;
    /* TODO: Define any additional data used by the application. */


} APP_DATA;
Merci