• AVR Freaks

AnsweredHow Set up USB in Harmony 2.02b

Page: 12 > Showing page 1 of 2
Author
sulivan.ganter
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2017/01/19 06:13:52
  • Location: 0
  • Status: offline
2017/01/31 12:55:57 (permalink)
0

How Set up USB in Harmony 2.02b

Hi,
 
I am trying to set up the USB module (Host MSD) on the PIC32MZ for save data in pendrive device, but the function "USB_HOST_BusIsEnabled(0);" always return : USB_HOST_RESULT_FALSE == (0x00000000).
 
I'm using Harmony 2.02b, MPLAB 3.50 and the development board: Olimex  PIC32-HMZ144 with PIC32MZ2048ECG144.
 
 
 
The code was generated using the code configurator for harmony framework. I just add the funtion for set pin to power up usb port, RB5 in this board. I got 4.88V in the port.
 
I already tried the example for host msd 
 
system_config.h
/*******************************************************************************
  MPLAB Harmony System Configuration Header

  File Name:
    system_config.h

  Summary:
    Build-time configuration header for the system defined by this MPLAB Harmony
    project.

  Description:
    An MPLAB Project may have multiple configurations. This file defines the
    build-time options for a single configuration.

  Remarks:
    This configuration header must not define any prototypes or data
    definitions (or include any files that do). It only provides macro
    definitions for build-time configuration options that are not instantiated
    until used by another MPLAB Harmony module or application.

    Created with MPLAB Harmony Version 2.02
*******************************************************************************/

// DOM-IGNORE-BEGIN
/*******************************************************************************
Copyright (c) 2013-2015 released Microchip Technology Inc. All rights reserved.

Microchip licenses to you the right to use, modify, copy and distribute
Software only when embedded on a Microchip microcontroller or digital signal
controller that is integrated into your product or third party product
(pursuant to the sublicense terms in the accompanying license agreement).

You should refer to the license agreement accompanying this Software for
additional information regarding your rights and obligations.

SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER
CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR
OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR
CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF
SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
*******************************************************************************/
// DOM-IGNORE-END

#ifndef _SYSTEM_CONFIG_H
#define _SYSTEM_CONFIG_H

// *****************************************************************************
// *****************************************************************************
// Section: Included Files
// *****************************************************************************
// *****************************************************************************
/* This section Includes other configuration headers necessary to completely
    define this configuration.
*/


// DOM-IGNORE-BEGIN
#ifdef __cplusplus // Provide C++ Compatibility

extern "C" {

#endif
// DOM-IGNORE-END

// *****************************************************************************
// *****************************************************************************
// Section: System Service Configuration
// *****************************************************************************
// *****************************************************************************
// *****************************************************************************
/* Common System Service Configuration Options
*/
#define SYS_VERSION_STR "2.02"
#define SYS_VERSION 20200

// *****************************************************************************
/* Clock System Service Configuration Options
*/
#define SYS_CLK_FREQ 200000000ul
#define SYS_CLK_BUS_PERIPHERAL_1 100000000ul
#define SYS_CLK_BUS_PERIPHERAL_2 100000000ul
#define SYS_CLK_BUS_PERIPHERAL_3 100000000ul
#define SYS_CLK_BUS_PERIPHERAL_4 100000000ul
#define SYS_CLK_BUS_PERIPHERAL_5 100000000ul
#define SYS_CLK_BUS_PERIPHERAL_7 200000000ul
#define SYS_CLK_BUS_PERIPHERAL_8 100000000ul
#define SYS_CLK_CONFIG_PRIMARY_XTAL 12000000ul
#define SYS_CLK_CONFIG_SECONDARY_XTAL 32768ul
#define SYS_CLK_CONFIG_FREQ_ERROR_LIMIT 10
#define SYS_CLK_WAIT_FOR_SWITCH true
#define SYS_CLK_ON_WAIT OSC_ON_WAIT_IDLE 
 
/*** Ports System Service Configuration ***/
#define SYS_PORT_A_ANSEL 0x3B23
#define SYS_PORT_A_TRIS 0xFFEF
#define SYS_PORT_A_LAT 0x0000
#define SYS_PORT_A_ODC 0x0000
#define SYS_PORT_A_CNPU 0x0400
#define SYS_PORT_A_CNPD 0x0000
#define SYS_PORT_A_CNEN 0x0000

#define SYS_PORT_B_ANSEL 0x8FDB
#define SYS_PORT_B_TRIS 0xFFDF
#define SYS_PORT_B_LAT 0x0000
#define SYS_PORT_B_ODC 0x0000
#define SYS_PORT_B_CNPU 0x7020
#define SYS_PORT_B_CNPD 0x0000
#define SYS_PORT_B_CNEN 0x0000

#define SYS_PORT_C_ANSEL 0xFFFD
#define SYS_PORT_C_TRIS 0xFFFD
#define SYS_PORT_C_LAT 0x0000
#define SYS_PORT_C_ODC 0x0000
#define SYS_PORT_C_CNPU 0x0000
#define SYS_PORT_C_CNPD 0x0000
#define SYS_PORT_C_CNEN 0x0000

#define SYS_PORT_D_ANSEL 0xC100
#define SYS_PORT_D_TRIS 0xEFD3
#define SYS_PORT_D_LAT 0x0000
#define SYS_PORT_D_ODC 0x0000
#define SYS_PORT_D_CNPU 0x0000
#define SYS_PORT_D_CNPD 0x0000
#define SYS_PORT_D_CNEN 0x0000

#define SYS_PORT_E_ANSEL 0xFFF0
#define SYS_PORT_E_TRIS 0xFFFF
#define SYS_PORT_E_LAT 0x0000
#define SYS_PORT_E_ODC 0x0000
#define SYS_PORT_E_CNPU 0x0000
#define SYS_PORT_E_CNPD 0x0000
#define SYS_PORT_E_CNEN 0x0000

#define SYS_PORT_F_ANSEL 0xFEC0
#define SYS_PORT_F_TRIS 0xFFFB
#define SYS_PORT_F_LAT 0x0000
#define SYS_PORT_F_ODC 0x0000
#define SYS_PORT_F_CNPU 0x0020
#define SYS_PORT_F_CNPD 0x0000
#define SYS_PORT_F_CNEN 0x0000

#define SYS_PORT_G_ANSEL 0x0FFC
#define SYS_PORT_G_TRIS 0x7FFF
#define SYS_PORT_G_LAT 0x0000
#define SYS_PORT_G_ODC 0x0000
#define SYS_PORT_G_CNPU 0x0000
#define SYS_PORT_G_CNPD 0x0000
#define SYS_PORT_G_CNEN 0x0000

#define SYS_PORT_H_ANSEL 0x0070
#define SYS_PORT_H_TRIS 0xEFF8
#define SYS_PORT_H_LAT 0x0000
#define SYS_PORT_H_ODC 0x0000
#define SYS_PORT_H_CNPU 0x0003
#define SYS_PORT_H_CNPD 0x0000
#define SYS_PORT_H_CNEN 0x0000

#define SYS_PORT_J_ANSEL 0x0B00
#define SYS_PORT_J_TRIS 0x5FFF
#define SYS_PORT_J_LAT 0x0000
#define SYS_PORT_J_ODC 0x0000
#define SYS_PORT_J_CNPU 0x4000
#define SYS_PORT_J_CNPD 0x0000
#define SYS_PORT_J_CNEN 0x0000

#define SYS_PORT_K_ANSEL 0xFF00
#define SYS_PORT_K_TRIS 0xFFFF
#define SYS_PORT_K_LAT 0x0000
#define SYS_PORT_K_ODC 0x0000
#define SYS_PORT_K_CNPU 0x0011
#define SYS_PORT_K_CNPD 0x0000
#define SYS_PORT_K_CNEN 0x0000


/*** File System Service Configuration ***/

#define SYS_FS_MEDIA_NUMBER 1

#define SYS_FS_VOLUME_NUMBER (1)

#define SYS_FS_AUTOMOUNT_ENABLE true
#define SYS_FS_MAX_FILES 4
#define SYS_FS_MAX_FILE_SYSTEM_TYPE 1
#define SYS_FS_MEDIA_MAX_BLOCK_SIZE 512
#define SYS_FS_MEDIA_MANAGER_BUFFER_SIZE 2048


#define SYS_FS_MEDIA_TYPE_IDX0 SYS_FS_MEDIA_TYPE_MSD
#define SYS_FS_TYPE_IDX0 FAT







#define SYS_FS_MEDIA_IDX0_MOUNT_NAME_VOLUME_IDX0 "/mnt/myDrive1"
#define SYS_FS_MEDIA_IDX0_DEVICE_NAME_VOLUME_IDX0 "/dev/sda1"


/*** Interrupt System Service Configuration ***/
#define SYS_INT true
/*** Timer System Service Configuration ***/
#define SYS_TMR_POWER_STATE SYS_MODULE_POWER_RUN_FULL
#define SYS_TMR_DRIVER_INDEX DRV_TMR_INDEX_0
#define SYS_TMR_MAX_CLIENT_OBJECTS 5
#define SYS_TMR_FREQUENCY 1000
#define SYS_TMR_FREQUENCY_TOLERANCE 10
#define SYS_TMR_UNIT_RESOLUTION 10000
#define SYS_TMR_CLIENT_TOLERANCE 10
#define SYS_TMR_INTERRUPT_NOTIFICATION false

// *****************************************************************************
// *****************************************************************************
// Section: Driver Configuration
// *****************************************************************************
// *****************************************************************************
/*** Timer Driver Configuration ***/
#define DRV_TMR_INTERRUPT_MODE true
#define DRV_TMR_INSTANCES_NUMBER 1
#define DRV_TMR_CLIENTS_NUMBER 1

/*** Timer Driver 0 Configuration ***/
#define DRV_TMR_PERIPHERAL_ID_IDX0 TMR_ID_2
#define DRV_TMR_INTERRUPT_SOURCE_IDX0 INT_SOURCE_TIMER_2
#define DRV_TMR_INTERRUPT_VECTOR_IDX0 INT_VECTOR_T2
#define DRV_TMR_ISR_VECTOR_IDX0 _TIMER_2_VECTOR
#define DRV_TMR_INTERRUPT_PRIORITY_IDX0 INT_PRIORITY_LEVEL4
#define DRV_TMR_INTERRUPT_SUB_PRIORITY_IDX0 INT_SUBPRIORITY_LEVEL0
#define DRV_TMR_CLOCK_SOURCE_IDX0 DRV_TMR_CLKSOURCE_INTERNAL
#define DRV_TMR_PRESCALE_IDX0 TMR_PRESCALE_VALUE_256
#define DRV_TMR_OPERATION_MODE_IDX0 DRV_TMR_OPERATION_MODE_16_BIT
#define DRV_TMR_ASYNC_WRITE_ENABLE_IDX0 false
#define DRV_TMR_POWER_STATE_IDX0 SYS_MODULE_POWER_RUN_FULL

 
// *****************************************************************************
// *****************************************************************************
// Section: Middleware & Other Library Configuration
// *****************************************************************************
// *****************************************************************************

/*** USB Driver Configuration ***/


/* Disable Device Support */
#define DRV_USBHS_DEVICE_SUPPORT false

/* Enables Device Support */
#define DRV_USBHS_HOST_SUPPORT true

/* Maximum USB driver instances */
#define DRV_USBHS_INSTANCES_NUMBER 1


/* Interrupt mode enabled */
#define DRV_USBHS_INTERRUPT_MODE true


/* Number of Endpoints used */
#define DRV_USBHS_ENDPOINTS_NUMBER 1







#define DRV_USBHS_HOST_NAK_LIMIT 2000
/* Provides Host pipes number */
#define DRV_USBHS_HOST_PIPES_NUMBER 10
#define DRV_USBHS_HOST_ATTACH_DEBOUNCE_DURATION 500
#define DRV_USBHS_HOST_RESET_DURATION 100
// *****************************************************************************
// *****************************************************************************
// Section: USB Device Layer Configuration
// *****************************************************************************
// *****************************************************************************
/* Provides Host pipes number */
#define USB_HOST_PIPES_NUMBER 10
/* NAK Limit for Control transfer data stage and Status Stage */
#define DRV_USB_HOST_NAK_LIMIT 200

// *****************************************************************************
// *****************************************************************************
// Section: USB Host Layer Configuration
// *****************************************************************************
// **************************************************************************
 
/* Total number of devices to be supported */
#define USB_HOST_DEVICES_NUMBER 1

/* Target peripheral list entries */
#define USB_HOST_TPL_ENTRIES 1 

/* Maximum number of configurations supported per device */
#define USB_HOST_DEVICE_INTERFACES_NUMBER 5 

#define USB_HOST_CONTROLLERS_NUMBER 1

#define USB_HOST_TRANSFERS_NUMBER 10

/* Number of Host Layer Clients */
#define USB_HOST_CLIENTS_NUMBER 1 

/* Number of MSD Function driver instances in the application */
#define USB_HOST_MSD_INSTANCES_NUMBER 1

/* Number of Logical Units */
#define USB_HOST_SCSI_INSTANCES_NUMBER 1
#define USB_HOST_MSD_LUN_NUMBERS 1








// *****************************************************************************
// *****************************************************************************
// Section: Application Configuration
// *****************************************************************************
// *****************************************************************************
/*** Application Defined Pins ***/


/*** Application Instance 0 Configuration ***/

//DOM-IGNORE-BEGIN
#ifdef __cplusplus
}
#endif
//DOM-IGNORE-END

#endif // _SYSTEM_CONFIG_H
/*******************************************************************************
 End of File
*/

 
system_init.c
/*******************************************************************************
  System Initialization File

  File Name:
    system_init.c

  Summary:
    This file contains source code necessary to initialize the system.

  Description:
    This file contains source code necessary to initialize the system. It
    implements the "SYS_Initialize" function, defines the configuration bits, 
    and allocates any necessary global system resources, such as the 
    sysObj structure that contains the object handles to all the MPLAB Harmony 
    module objects in the system.
 *******************************************************************************/

// DOM-IGNORE-BEGIN
/*******************************************************************************
Copyright (c) 2013-2015 released Microchip Technology Inc. All rights reserved.

Microchip licenses to you the right to use, modify, copy and distribute
Software only when embedded on a Microchip microcontroller or digital signal
controller that is integrated into your product or third party product
(pursuant to the sublicense terms in the accompanying license agreement).

You should refer to the license agreement accompanying this Software for
additional information regarding your rights and obligations.

SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER
CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR
OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR
CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF
SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
 *******************************************************************************/
// DOM-IGNORE-END

// *****************************************************************************
// *****************************************************************************
// Section: Included Files
// *****************************************************************************
// *****************************************************************************

#include "system_config.h"
#include "system_definitions.h"


// ****************************************************************************
// ****************************************************************************
// Section: Configuration Bits
// ****************************************************************************
// ****************************************************************************
// <editor-fold defaultstate="collapsed" desc="Configuration Bits">

/*** DEVCFG0 ***/

#pragma config DEBUG = ON
#pragma config JTAGEN = OFF
#pragma config ICESEL = ICS_PGx2
#pragma config TRCEN = OFF
#pragma config BOOTISA = MIPS32
#pragma config FECCCON = OFF_UNLOCKED
#pragma config FSLEEP = OFF
#pragma config DBGPER = PG_ALL
#pragma config EJTAGBEN = NORMAL
#pragma config CP = OFF

/*** DEVCFG1 ***/

#pragma config FNOSC = SPLL
#pragma config DMTINTV = WIN_127_128
#pragma config FSOSCEN = OFF
#pragma config IESO = OFF
#pragma config POSCMOD = OFF
#pragma config OSCIOFNC = OFF
#pragma config FCKSM = CSECME
#pragma config WDTPS = PS1048576
#pragma config WDTSPGM = STOP
#pragma config FWDTEN = OFF
#pragma config WINDIS = NORMAL
#pragma config FWDTWINSZ = WINSZ_25
#pragma config DMTCNT = DMT31
#pragma config FDMTEN = OFF
/*** DEVCFG2 ***/

#pragma config FPLLIDIV = DIV_1
#pragma config FPLLRNG = RANGE_5_10_MHZ
#pragma config FPLLICLK = PLL_FRC
#pragma config FPLLMULT = MUL_50
#pragma config FPLLODIV = DIV_2
#pragma config UPLLFSEL = FREQ_12MHZ
#pragma config UPLLEN = OFF
/*** DEVCFG3 ***/

#pragma config USERID = 0xffff
#pragma config FMIIEN = ON
#pragma config FETHIO = ON
#pragma config PGL1WAY = ON
#pragma config PMDL1WAY = ON
#pragma config IOL1WAY = ON
#pragma config FUSBIDIO = OFF

/*** BF1SEQ0 ***/

#pragma config TSEQ = 0x0000
#pragma config CSEQ = 0xffff
// </editor-fold>

// *****************************************************************************
// *****************************************************************************
// Section: Driver Initialization Data
// *****************************************************************************
// *****************************************************************************
// <editor-fold defaultstate="collapsed" desc="DRV_Timer Initialization Data">
/*** TMR Driver Initialization Data ***/

const DRV_TMR_INIT drvTmr0InitData =
{
    .moduleInit.sys.powerState = DRV_TMR_POWER_STATE_IDX0,
    .tmrId = DRV_TMR_PERIPHERAL_ID_IDX0,
    .clockSource = DRV_TMR_CLOCK_SOURCE_IDX0, 
    .prescale = DRV_TMR_PRESCALE_IDX0,
    .mode = DRV_TMR_OPERATION_MODE_IDX0,
    .interruptSource = DRV_TMR_INTERRUPT_SOURCE_IDX0,
    .asyncWriteEnable = false,
};
// </editor-fold>

// *****************************************************************************
// *****************************************************************************
// Section: System Data
// *****************************************************************************
// *****************************************************************************

/* Structure to hold the object handles for the modules in the system. */
SYSTEM_OBJECTS sysObj;

// *****************************************************************************
// *****************************************************************************
// Section: Module Initialization Data
// *****************************************************************************
// *****************************************************************************
// <editor-fold defaultstate="collapsed" desc="SYS_FS Initialization Data">
/*** File System Initialization Data ***/


const SYS_FS_MEDIA_MOUNT_DATA sysfsMountTable[SYS_FS_VOLUME_NUMBER] = 
{
    
    {
  .mountName = SYS_FS_MEDIA_IDX0_MOUNT_NAME_VOLUME_IDX0,
  .devName = SYS_FS_MEDIA_IDX0_DEVICE_NAME_VOLUME_IDX0, 
  .mediaType = SYS_FS_MEDIA_TYPE_IDX0,
  .fsType = SYS_FS_TYPE_IDX0 
    },
    



     
};




const SYS_FS_REGISTRATION_TABLE sysFSInit [ SYS_FS_MAX_FILE_SYSTEM_TYPE ] =
{
    {
        .nativeFileSystemType = FAT,
        .nativeFileSystemFunctions = &FatFsFunctions
    }
};
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="SYS_TMR Initialization Data">
/*** TMR Service Initialization Data ***/
const SYS_TMR_INIT sysTmrInitData =
{
    .moduleInit = {SYS_MODULE_POWER_RUN_FULL},
    .drvIndex = DRV_TMR_INDEX_0,
    .tmrFreq = 1000, 
};
// </editor-fold>

// *****************************************************************************
// *****************************************************************************
// Section: Library/Stack Initialization Data
// *****************************************************************************
// *****************************************************************************
// <editor-fold defaultstate="collapsed" desc="USB Host Initialization Data"> 

/****************************************************
 * Endpoint Table needed by the controller driver .
 ****************************************************/



DRV_USBHS_INIT drvUSBHSInit = 
{
    .moduleInit = {SYS_MODULE_POWER_RUN_FULL},
    .interruptSource = INT_SOURCE_USB_1,
    .interruptSourceUSBDma = INT_SOURCE_USB_1_DMA,
    .operationMode = DRV_USBHS_OPMODE_HOST,
    .operationSpeed = USB_SPEED_HIGH,
    .portIndication = NULL,
 .portOverCurrentDetect = NULL,
    .portPowerEnable = NULL,
    .rootHubAvailableCurrent = 500,
    .stopInIdle = false,
    .suspendInSleep = false,
    .usbID = USBHS_ID_0
    
};



const USB_HOST_TPL_ENTRY USBTPList[ 1 ] =
{
 
    TPL_INTERFACE_CLASS_SUBCLASS_PROTOCOL(0x08, 0x06, 0x50, NULL, USB_HOST_MSD_INTERFACE) ,






};


const USB_HOST_HCD hcdTable = 
{
    .drvIndex = DRV_USBHS_INDEX_0,
    .hcdInterface = DRV_USBHS_HOST_INTERFACE
};

const USB_HOST_INIT usbHostInitData = 
{
    .nTPLEntries = 1 ,
    .tplList = (USB_HOST_TPL_ENTRY *)USBTPList,
    .hostControllerDrivers = (USB_HOST_HCD *)&hcdTable
    
};



// </editor-fold>

// *****************************************************************************
// *****************************************************************************
// Section: System Initialization
// *****************************************************************************
// *****************************************************************************

/*******************************************************************************
  Function:
    void SYS_Initialize ( void *data )

  Summary:
    Initializes the board, services, drivers, application and other modules.

  Remarks:
    See prototype in system/common/sys_module.h.
 */

void SYS_Initialize ( void* data )
{
    /* Core Processor Initialization */
    SYS_CLK_Initialize( NULL );
    SYS_DEVCON_Initialize(SYS_DEVCON_INDEX_0, (SYS_MODULE_INIT*)NULL);
    SYS_DEVCON_PerformanceConfig(SYS_CLK_SystemFrequencyGet());
    SYS_PORTS_Initialize();
    
    
    PLIB_PORTS_PinSet(PORTS_ID_0, PORT_CHANNEL_B, PORTS_BIT_POS_5);

    /* Initialize Drivers */

    sysObj.drvTmr0 = DRV_TMR_Initialize(DRV_TMR_INDEX_0, (SYS_MODULE_INIT *)&drvTmr0InitData);

    SYS_INT_VectorPrioritySet(INT_VECTOR_T2, INT_PRIORITY_LEVEL4);
    SYS_INT_VectorSubprioritySet(INT_VECTOR_T2, INT_SUBPRIORITY_LEVEL0);
 
 
 
    /* Initialize System Services */

    /*** File System Service Initialization Code ***/
    SYS_FS_Initialize( (const void *) sysFSInit );

    /*** Interrupt Service Initialization Code ***/
    SYS_INT_Initialize();

    /*** TMR Service Initialization Code ***/
    sysObj.sysTmr = SYS_TMR_Initialize(SYS_TMR_INDEX_0, (const SYS_MODULE_INIT * const)&sysTmrInitData);
  
    /* Initialize Middleware */




     sysObj.usbHostObject0 = USB_HOST_Initialize ((SYS_MODULE_INIT *)& usbHostInitData );
    sysObj.drvUSBObject = DRV_USBHS_Initialize (DRV_USBHS_INDEX_0, (SYS_MODULE_INIT *) &drvUSBHSInit);
    
 SYS_INT_VectorPrioritySet(INT_VECTOR_USB1, INT_PRIORITY_LEVEL4);
    SYS_INT_VectorSubprioritySet(INT_VECTOR_USB1, INT_SUBPRIORITY_LEVEL0);

    /* Set the priority of the USB DMA Interrupt */
    SYS_INT_VectorPrioritySet(INT_VECTOR_USB1_DMA, INT_PRIORITY_LEVEL4);
    /* Set Sub-priority of the USB DMA Interrupt */
    SYS_INT_VectorSubprioritySet(INT_VECTOR_USB1_DMA, INT_SUBPRIORITY_LEVEL0);
        



    /* Enable Global Interrupts */
    SYS_INT_Enable();

    /* Initialize the Application */
    APP_Initialize();
}


/*******************************************************************************
 End of File
*/


 
 
Break point here,
usb_result = USB_HOST_BusIsEnabled(0);
 
USB_HOST_RESULT_FALSE == (0x00000000)
 
 
app.c
 
/*******************************************************************************
  MPLAB Harmony Application Source File
  
  Company:
    Microchip Technology Inc.
  
  File Name:
    app.c

  Summary:
    This file contains the source code for the MPLAB Harmony application.

  Description:
    This file contains the source code for the MPLAB Harmony application. It 
    implements the logic of the application's state machine and it may call 
    API routines of other MPLAB Harmony modules in the system, such as drivers,
    system services, and middleware. However, it does not call any of the
    system interfaces (such as the "Initialize" and "Tasks" functions) of any of
    the modules in the system or make any assumptions about when those functions
    are called. That is the responsibility of the configuration-specific system
    files.
 *******************************************************************************/

// DOM-IGNORE-BEGIN
/*******************************************************************************
Copyright (c) 2013-2014 released Microchip Technology Inc. All rights reserved.

Microchip licenses to you the right to use, modify, copy and distribute
Software only when embedded on a Microchip microcontroller or digital signal
controller that is integrated into your product or third party product
(pursuant to the sublicense terms in the accompanying license agreement).

You should refer to the license agreement accompanying this Software for
additional information regarding your rights and obligations.

SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER
CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR
OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR
CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF
SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
 *******************************************************************************/
// DOM-IGNORE-END


// *****************************************************************************
// *****************************************************************************
// Section: Included Files 
// *****************************************************************************
// *****************************************************************************

#include "app.h"

// *****************************************************************************
// *****************************************************************************
// Section: Global Data Definitions
// *****************************************************************************
// *****************************************************************************

// *****************************************************************************
/* Application Data

  Summary:
    Holds application data

  Description:
    This structure holds the application's data.

  Remarks:
    This structure should be initialized by the APP_Initialize function.
    
    Application strings and buffers are be defined outside this structure.
*/

APP_DATA appData;
static char appMsdWritePath[] = "/mnt/myDrive1/filename1.txt";
static uint8_t __attribute__ ((aligned (16))) appMsdWriteData[] = "Hello World!";


// *****************************************************************************
// *****************************************************************************
// Section: Application Callback Functions
// *****************************************************************************
// *****************************************************************************

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

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

void APP_SYSFSEventHandler(SYS_FS_EVENT event, void * eventData, uintptr_t context)
{
    switch (event)
    {
        case SYS_FS_EVENT_MOUNT:
            appData.msdDeviceIsConnected = true;
            break;
            
        case SYS_FS_EVENT_UNMOUNT:
            appData.msdDeviceIsConnected = false;
            break;
            
        default:
            break;
    }
}


/* state machine for the File System Write */
static void APP_MSD_WRITE_Task(void)
{
    static SYS_FS_ERROR FsError;
    static uint8_t HandleAttempts;
    static uint32_t TotalBytesWritten;
    static SYS_FS_HANDLE FileHandle;

    switch (appData.msdWriteStateMachine)
    {
        default:
        case APP_MSD_WRITE_STATE_START:
            HandleAttempts = 0;
            appData.msdWriteStateMachine = APP_MSD_WRITE_STATE_OPEN;
            break;

        case APP_MSD_WRITE_STATE_OPEN:
            /* open the file to write - create file if it does not exist */
            FileHandle = SYS_FS_FileOpen(appMsdWritePath, SYS_FS_FILE_OPEN_WRITE_PLUS);
            if (FileHandle == SYS_FS_HANDLE_INVALID)
            {
                /* try 10 times to get the handle - allow auto-mount to finish */
                if (++HandleAttempts > 10)
                {
                    FsError = SYS_FS_Error();
                    appData.msdWriteStateMachine = APP_MSD_WRITE_STATE_ERROR;
                }
            }
            else
            {
                TotalBytesWritten = 0;
                appData.msdWriteStateMachine = APP_MSD_WRITE_STATE_FILEOPS;
            }
            break;

        case APP_MSD_WRITE_STATE_FILEOPS:
            {
                size_t BytesWritten = SYS_FS_FileWrite(FileHandle, (const void *)appMsdWriteData,
                    sizeof(appMsdWriteData) - TotalBytesWritten);
                if (BytesWritten == (size_t)-1)
                {
                    /* error */
                    FsError = SYS_FS_Error();
                    appData.msdWriteStateMachine = APP_MSD_WRITE_STATE_ERROR;
                    return;
                }
                else
                {
                    TotalBytesWritten += BytesWritten;
                    /* have we written all the bytes now? */
                    if (TotalBytesWritten >= sizeof(appMsdWriteData))
                    {
                        SYS_FS_FileClose(FileHandle);
                        appData.msdWriteStateMachine = APP_MSD_WRITE_STATE_DONE;
                    }
                }
            }
            break;

        case APP_MSD_WRITE_STATE_DONE:
            break;

        /* if we get to this state - something went wrong - check FsError for status */
        case APP_MSD_WRITE_STATE_ERROR:
            break;
    }
}




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


// *****************************************************************************
// *****************************************************************************
// 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;

    /* Place the File System state machine in its initial state */
    appData.msdWriteStateMachine = APP_MSD_WRITE_STATE_START;
    
    PLIB_PORTS_PinSet(PORTS_ID_0, PORT_CHANNEL_B, PORTS_BIT_POS_5);

   /* Set the event handler and enable the bus */
    SYS_FS_EventHandlerSet(APP_SYSFSEventHandler, (uintptr_t)NULL);
    USB_HOST_BusEnable(0);

    
    /* TODO: Initialize your application's state machine and other
     * parameters.
     */
}


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

  Remarks:
    See prototype in app.h.
 */

void APP_Tasks ( void )
{

    /* Check the application's current state. */
    switch ( appData.state )
    {
        /* Application's initial state. */
        case APP_STATE_INIT:
        {
            bool appInitialized = true;
            USB_HOST_RESULT usb_result;
            usb_result = USB_HOST_BusIsEnabled(0);
            Nop();
            appInitialized = appInitialized && usb_result;
            appInitialized = appInitialized && appData.msdDeviceIsConnected;

        
            if (appInitialized)
            {
            
                appData.state = APP_STATE_SERVICE_TASKS;
            }
            break;
        }

        case APP_STATE_SERVICE_TASKS:
        {
            /* run the state machine for servicing the file system WRITE */
            APP_MSD_WRITE_Task();

        
            break;
        }

        /* TODO: implement your application state machine.*/
        

        /* The default state should never be executed. */
        default:
        {
            /* TODO: Handle error in application's state machine. */
            break;
        }
    }
}

 

/*******************************************************************************
 End of File
 */

 
 
Thanks
#1
NKurzman
A Guy on the Net
  • Total Posts : 19194
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: online
Re: How Set up USB in Harmony 2.02b 2017/01/31 16:44:29 (permalink)
0
Did you compare your App to the example App?
#2
sulivan.ganter
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2017/01/19 06:13:52
  • Location: 0
  • Status: offline
Re: How Set up USB in Harmony 2.02b 2017/02/01 07:37:06 (permalink)
0
Yes, I already tried the example for host msd. In the example "usb/host/msd_basic", the state machine stalled in:
 
case APP_STATE_WAIT_FOR_BUS_ENABLE_COMPLETE:
if(USB_HOST_BusIsEnabled(0))
{
appData.state = APP_STATE_WAIT_FOR_DEVICE_ATTACH;
}
break;
 
#3
Tez
Moderator
  • Total Posts : 480
  • Reward points : 0
  • Joined: 2006/10/04 11:09:05
  • Location: 0
  • Status: offline
Re: How Set up USB in Harmony 2.02b 2017/02/02 03:02:29 (permalink)
3 (1)
Please refer to the code examples. You need to call USB_HOST_BusEnable() function and then call the USB_HOST_BusIsEnabled() function (which must return true) before you can proceed with the rest of Application state machine.
#4
sulivan.ganter
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2017/01/19 06:13:52
  • Location: 0
  • Status: offline
Re: How Set up USB in Harmony 2.02b 2017/02/02 09:10:31 (permalink)
0
I do that, into function App_Initialize on app.c.

 /* Set the event handler and enable the bus */
    SYS_FS_EventHandlerSet(APP_SYSFSEventHandler, (uintptr_t)NULL);
    USB_HOST_BusEnable(0);

#5
sulivan.ganter
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2017/01/19 06:13:52
  • Location: 0
  • Status: offline
Re: How Set up USB in Harmony 2.02b 2017/02/02 12:19:37 (permalink)
0
I do that, into function App_Initialize on app.c.

 /* Set the event handler and enable the bus */
    SYS_FS_EventHandlerSet(APP_SYSFSEventHandler, (uintptr_t)NULL);
    USB_HOST_BusEnable(0);
#6
eks
Starting Member
  • Total Posts : 40
  • Reward points : 0
  • Joined: 2008/05/06 21:47:14
  • Location: 0
  • Status: offline
Re: How Set up USB in Harmony 2.02b 2017/02/02 23:19:02 (permalink)
3 (1)
Check if you see 5Volts at the VBUS pin of the USB connector. Also check 5Volts is measured at the VBUS pin of the PIC32MZ. 
 
#7
Paul PortSol
Super Member
  • Total Posts : 639
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: online
Re: How Set up USB in Harmony 2.02b 2017/02/03 06:03:49 (permalink)
3 (1)
Reference: http://www.microchip.com/forums/tm.aspx?tree=true&m=968245&mpage=1
1) Do you have VBUS pin connected to monitor USB Voltage? (Pin 73 on my 144pin PIC, connected to USB Socket 5V through a 100~120ohm resistor.
2) Try a new USB stick. Some, particularly older, didn't work.
3) Ensure using set: HarmonyV202b, MHCv2024, MPLABXv351, XC32v142
4) Enable under gcc: Show all warnings, and warnings are errors - the little things can bite
5) Suggest you try msd_basic on PIC32MZ EF Starter kit (if you have one), then try your project on same kit to verify nothing missed in MHC settings or code (Strip down to minimum USB code, and UART or LED status). Note some EF Kits have PIC...EFM or PIC...EFH, select correct then regenerate MHC and recompile as needed.
6) I have it working on PIC32MZ2048EFM144, so should be similar to you. If you still don't have it working I can probably strip it down and share the project - at this time I have a log_printf() that writes to a continuous file, and Mount/Unmount through UART1.
 
It was agony, but USB works now :)    ... now other things in Harmony are agony :(
Paul
#8
sulivan.ganter
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2017/01/19 06:13:52
  • Location: 0
  • Status: offline
Re: How Set up USB in Harmony 2.02b 2017/02/06 08:48:40 (permalink)
0
Hi, Paul. Thanks for your helping. About your topics:
 
1) The VBUS pin is direct connected to USB Voltage Port, without resistor, this is a problem? (The project the board is open source, you can see looking for  OliMex  PIC32-HMZ144).
2)I tried others USB Sticks, but the port never reach the true state. (USB_HOST_BusIsEnabled(0)).
3) I checked and am using: HarmonyV202b, MHCv2024, MPLABXv351, XC32v142.
4) Done, but no warning is relevant for the USB.
5) I don't have the starter kit. unfortunately.
6) I think that would help me a lot.
 
If you have any further suggestions, I'm accepting.
 
Thanks,
Sulivan
#9
Paul PortSol
Super Member
  • Total Posts : 639
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: online
Re: How Set up USB in Harmony 2.02b 2017/02/06 13:25:58 (permalink) ☄ Helpfulby sulivan.ganter 2017/03/07 14:03:47
0
Also Check:
7) Check: DRV_USBHS_INIT drvUSBHSInit, generated table probably doesn't have pointers to functions to enable USB power IC. See in my code for callbacks.
8) Double check the TPS2051*** IC exact part number. The Microchip schematic I had implied an Active Lo Enable, but when I checked the exact part number it was actually Active HI !!!! Several versions of the TPS ICs, some active high and some active low!
---------
1) Resistor recommended by Microchip Tech support
- it is unusual to route off board signal directly into MCU pin, a resistor will limit power flow in case a fault puts excess voltage on the connector pin. Without resistor the on chip ESD diodes can get fried, and other nice things... 
---------
Attached doesn't have a log_printf(), but should let you test if you can write to a FlashDrive...
   - USB_FlashDrive_v07c_CleanForZip.zip
a) normal printf() set to U1_Tx in main() //see XC comments, change/remove as needed 
b) **** using customized DRV_USBHS_INIT drvUSBHSInit so can control callbacks for signal enables/checks (search for this, you'll also see when generated)
c) USB Fault overcurrent signal isn't checked at this time
d) Set your PIC32MZ type, adjust pin Diagram, and regenerate MHC.
e) Until you generate you'll get missing file warnings, as I stripped all generated and compiled files for small zip.
f) generated system_init.c does need customization. 
g) Do a full compile if you replace a generated file with an older file (timestamps mix things up)
 
Hope it works!!
Paul
#10
Paul PortSol
Super Member
  • Total Posts : 639
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: online
Re: How Set up USB in Harmony 2.02b 2017/02/07 05:30:13 (permalink) ☼ Best Answerby sulivan.ganter 2017/03/07 14:03:32
3 (1)
another:
9) Ensure Heap is allocated, used by the USB code, Heap=500 works (Very bottom of MHC under xc32)
20170526: Try Heap=10000, 500 proved unreliable when remounting USB stick. 
10) Use crystal/oscillator/resonator to ensure accurate 24MHz for USB (FRC not reliable)
post edited by Paul PortSol - 2017/05/26 06:35:26
#11
Paul PortSol
Super Member
  • Total Posts : 639
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: online
Re: How Set up USB in Harmony 2.02b 2017/03/06 15:44:58 (permalink) ☄ Helpfulby sulivan.ganter 2017/03/07 14:04:00
0
Warning: There is a minimum clk when USB Module is enabled.
For PIC32MZ-EF see table 37-18, OS51 30MHz-200MHz, which seems to need SYSCLK 60MHz+ when PBCLK5 prescaler=2 giving PBCLK 30MHz+
#12
sulivan.ganter
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2017/01/19 06:13:52
  • Location: 0
  • Status: offline
Re: How Set up USB in Harmony 2.02b 2017/03/07 14:02:46 (permalink)
5 (1)
Hello, Paul.
 
I was working on another project and I had to put it aside for a while, I went back to work with him yesterday, and thanks to your tips I was able to make it work. Heap configuration was essential. Thank you so much.
 
Tanks,
Sulivan
#13
Paul PortSol
Super Member
  • Total Posts : 639
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: online
Re: How Set up USB in Harmony 2.02b 2017/05/26 06:38:20 (permalink)
3 (1)
Warning: Heap=500 proved unreliable for multiple files when remounting USB.
heap=10000 seems to work, but needs more testing.
Not sure what an appropriate heap setting is or how to determine it :(
The Generated code in MHC2024 and MHC2035 don't set heap for USB Files :(
 
I have a ticket in asking how to properly determine Heap setting, and how to check for heap faults/overflow/etc.
 
#14
NKurzman
A Guy on the Net
  • Total Posts : 19194
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: online
Re: How Set up USB in Harmony 2.02b 2017/05/26 08:50:20 (permalink)
3 (1)
it is 512 bytes a sector + overhead.
How many file do you have open?
Are you using any other thins that use the heap
TCP/IP, GFX, Malloc
#15
Paul PortSol
Super Member
  • Total Posts : 639
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: online
Re: How Set up USB in Harmony 2.02b 2017/05/26 10:18:47 (permalink)
3 (1)
I have 5 files open for read/write, 
so I guess I need: 5 * (512+overhead) = TBD,
or maybe 5 * 2 * (512+overhead) = TBD?  (Double for Read and Write)
 
Where did you see this info? Maybe from your pre-Harmony PIC experience (of which I have zero as never touched PIC before Harmony). 
 
(Not using TCP/IP, GFX, Malloc)
 
Paul
#16
RISC
Super Member
  • Total Posts : 6075
  • Reward points : 0
  • Status: online
Re: How Set up USB in Harmony 2.02b 2017/05/26 12:39:56 (permalink)
3 (1)
Hi,
As soon as you use a file system you must allocate heap.
This is also true for the graphics library.
There is no exact rule to calculate heap size but generally you'll know. When it is too small, it will hang up ;=)
Regards
#17
Paul PortSol
Super Member
  • Total Posts : 639
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: online
Re: How Set up USB in Harmony 2.02b 2017/05/29 04:53:56 (permalink)
0
But it didn't hang up, it ran fine until dismounted and remounted, then just ran without detecting second inserted USB stick :(
I need a much more reliable rule for our product, so I'll have to wait till ticket is answered, then I'll post what I find here.
 
 
#18
kuku
Senior Member
  • Total Posts : 145
  • Reward points : 0
  • Joined: 2012/03/03 08:05:54
  • Location: 0
  • Status: offline
Re: How Set up USB in Harmony 2.02b 2019/04/10 04:44:23 (permalink)
0
I have similar situation, APP_Tasks stay at APP_STATE_WAIT_FOR_BUS_ENABLE_COMPLETE.
I have own board with MZ2064DAH176. I try to run msd_basic example from USB host folder. So in MHC I deselect BSP, write own LED configuration, clock (12MHz crystal). Heap is set to 2048.
On my board USB jack and VBUS pin (leg45) is connected direct to 5V, I also not have ~100R resistor. USB ID (leg 52) ic connected to GND trough 10k. First time I make something with USB so my experience is low. At now one matter is not clear for me. This demo, in BSP settings use switch (RB5 pin) to supply USB connector. I simple erase it and compiler not protest- like not use in demo. of course everything was compile without warrnings. Harmony is 2.06, XC is 2.15
 
Sulivan, you win with this problem?. Any tips?

void APP_Tasks ( void )
{
    switch(appData.state)
    {
        case APP_STATE_BUS_ENABLE:
                      
           /* Set the event handler and enable the bus */
            SYS_FS_EventHandlerSet(APP_SYSFSEventHandler, (uintptr_t)NULL);
            USB_HOST_EventHandlerSet(APP_USBHostEventHandler, 0);
            USB_HOST_BusEnable(0);
            appData.state = APP_STATE_WAIT_FOR_BUS_ENABLE_COMPLETE;
            break;
            
        case APP_STATE_WAIT_FOR_BUS_ENABLE_COMPLETE:
            if(USB_HOST_BusIsEnabled(0))
            {
                appData.state = APP_STATE_WAIT_FOR_DEVICE_ATTACH;
            }
            break;
       
        case APP_STATE_WAIT_FOR_DEVICE_ATTACH:

            /* Wait for device attach. The state machine will move
             * to the next state when the attach event
             * is received. */
            if(appData.deviceIsConnected)
            {
                MyLEDOn();
                //BSP_LEDOn( APP_USB_LED_3 );
                //BSP_LEDOff( APP_USB_LED_2 );
                appData.state = APP_STATE_DEVICE_CONNECTED;
            }

            break;

        case APP_STATE_DEVICE_CONNECTED:

            /* Device was connected. We can try mounting the disk */
            MyLEDOff();
            appData.state = APP_STATE_OPEN_FILE;
            break;

        case APP_STATE_OPEN_FILE:

            /* Try opening the file for append */
            appData.fileHandle = SYS_FS_FileOpen("/mnt/myDrive1/file.txt", (SYS_FS_FILE_OPEN_APPEND_PLUS));
            if(appData.fileHandle == SYS_FS_HANDLE_INVALID)
            {
                /* Could not open the file. Error out*/
                appData.state = APP_STATE_ERROR;

            }
            else
            {
                /* File opened successfully. Write to file */
                appData.state = APP_STATE_WRITE_TO_FILE;

            }
            break;

        case APP_STATE_WRITE_TO_FILE:

            /* Try writing to the file */
            if (SYS_FS_FileWrite( appData.fileHandle, (const void *) writeData, 12 ) == -1)
            {
                /* Write was not successful. Close the file
                 * and error out.*/
                SYS_FS_FileClose(appData.fileHandle);
                appData.state = APP_STATE_ERROR;

            }
            else
            {
                /* We are done writing. Close the file */
                appData.state = APP_STATE_CLOSE_FILE;
            }

            break;

        case APP_STATE_CLOSE_FILE:

            /* Close the file */
            SYS_FS_FileClose(appData.fileHandle);

            /* The test was successful. Lets idle. */
            appData.state = APP_STATE_IDLE;
            break;

        case APP_STATE_IDLE:

            /* The application comes here when the demo has completed
             * successfully. Provide LED indication. Wait for device detach
             * and if detached, wait for attach. */

            //BSP_LEDOff( APP_USB_LED_3);
            //BSP_LEDOn( APP_USB_LED_2 );
            if(appData.deviceIsConnected == false)
            {
                appData.state = APP_STATE_WAIT_FOR_DEVICE_ATTACH;
                //BSP_LEDOff(APP_USB_LED_2);
            }
            break;

        case APP_STATE_ERROR:

            /* The application comes here when the demo
             * has failed. Provide LED indication .*/

            MyLEDToggle();
            if(SYS_FS_Unmount("/mnt/myDrive") != 0)
            {
                /* The disk could not be un mounted. Try
                 * un mounting again untill success. */

                appData.state = APP_STATE_ERROR;
            }
            else
            {
                /* UnMount was successful. Wait for device attach */
                appData.state = APP_STATE_WAIT_FOR_DEVICE_ATTACH;

            }
            break;

        default:
            break;

    }
}

 
/*******************************************************************************
  MPLAB Harmony System Configuration Header

  File Name:
    system_config.h

  Summary:
    Build-time configuration header for the system defined by this MPLAB Harmony
    project.

  Description:
    An MPLAB Project may have multiple configurations. This file defines the
    build-time options for a single configuration.

  Remarks:
    This configuration header must not define any prototypes or data
    definitions (or include any files that do). It only provides macro
    definitions for build-time configuration options that are not instantiated
    until used by another MPLAB Harmony module or application.

    Created with MPLAB Harmony Version 2.06
*******************************************************************************/

// DOM-IGNORE-BEGIN
/*******************************************************************************
Copyright (c) 2013-2015 released Microchip Technology Inc. All rights reserved.

Microchip licenses to you the right to use, modify, copy and distribute
Software only when embedded on a Microchip microcontroller or digital signal
controller that is integrated into your product or third party product
(pursuant to the sublicense terms in the accompanying license agreement).

You should refer to the license agreement accompanying this Software for
additional information regarding your rights and obligations.

SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER
CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR
OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR
CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF
SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
*******************************************************************************/
// DOM-IGNORE-END

#ifndef _SYSTEM_CONFIG_H
#define _SYSTEM_CONFIG_H

// *****************************************************************************
// *****************************************************************************
// Section: Included Files
// *****************************************************************************
// *****************************************************************************
/* This section Includes other configuration headers necessary to completely
    define this configuration.
*/


// DOM-IGNORE-BEGIN
#ifdef __cplusplus // Provide C++ Compatibility

extern "C" {

#endif
// DOM-IGNORE-END

// *****************************************************************************
// *****************************************************************************
// Section: System Service Configuration
// *****************************************************************************
// *****************************************************************************
// *****************************************************************************
/* Common System Service Configuration Options
*/
#define SYS_VERSION_STR "2.06"
#define SYS_VERSION 20600

// *****************************************************************************
/* Clock System Service Configuration Options
*/
#define SYS_CLK_FREQ 198000000ul
#define SYS_CLK_BUS_PERIPHERAL_1 99000000ul
#define SYS_CLK_BUS_PERIPHERAL_2 99000000ul
#define SYS_CLK_BUS_PERIPHERAL_3 99000000ul
#define SYS_CLK_BUS_PERIPHERAL_4 99000000ul
#define SYS_CLK_BUS_PERIPHERAL_5 99000000ul
#define SYS_CLK_BUS_PERIPHERAL_6 99000000ul
#define SYS_CLK_BUS_PERIPHERAL_7 198000000ul
#define SYS_CLK_CONFIG_PRIMARY_XTAL 12000000ul
#define SYS_CLK_CONFIG_SECONDARY_XTAL 32768ul
   
/*** Ports System Service Configuration ***/
#define SYS_PORT_A_ANSEL 0x3F20
#define SYS_PORT_A_TRIS 0xFFFF
#define SYS_PORT_A_LAT 0x0000
#define SYS_PORT_A_ODC 0x0000
#define SYS_PORT_A_CNPU 0x0000
#define SYS_PORT_A_CNPD 0x0000
#define SYS_PORT_A_CNEN 0x0000

#define SYS_PORT_B_ANSEL 0xBB8F
#define SYS_PORT_B_TRIS 0xFFEF
#define SYS_PORT_B_LAT 0x0010
#define SYS_PORT_B_ODC 0x0000
#define SYS_PORT_B_CNPU 0x0000
#define SYS_PORT_B_CNPD 0x0000
#define SYS_PORT_B_CNEN 0x0000

#define SYS_PORT_C_ANSEL 0x0FFF
#define SYS_PORT_C_TRIS 0xFFFF
#define SYS_PORT_C_LAT 0x0000
#define SYS_PORT_C_ODC 0x0000
#define SYS_PORT_C_CNPU 0x0000
#define SYS_PORT_C_CNPD 0x0000
#define SYS_PORT_C_CNEN 0x0000

#define SYS_PORT_D_ANSEL 0x8100
#define SYS_PORT_D_TRIS 0xFFFF
#define SYS_PORT_D_LAT 0x0000
#define SYS_PORT_D_ODC 0x0000
#define SYS_PORT_D_CNPU 0x0000
#define SYS_PORT_D_CNPD 0x0000
#define SYS_PORT_D_CNEN 0x0000

#define SYS_PORT_E_ANSEL 0xFFD2
#define SYS_PORT_E_TRIS 0xFFFF
#define SYS_PORT_E_LAT 0x0000
#define SYS_PORT_E_ODC 0x0000
#define SYS_PORT_E_CNPU 0x0000
#define SYS_PORT_E_CNPD 0x0000
#define SYS_PORT_E_CNEN 0x0000

#define SYS_PORT_F_ANSEL 0xFEC0
#define SYS_PORT_F_TRIS 0xFFFF
#define SYS_PORT_F_LAT 0x0000
#define SYS_PORT_F_ODC 0x0000
#define SYS_PORT_F_CNPU 0x0000
#define SYS_PORT_F_CNPD 0x0000
#define SYS_PORT_F_CNEN 0x0000

#define SYS_PORT_G_ANSEL 0x8FBC
#define SYS_PORT_G_TRIS 0xFFFF
#define SYS_PORT_G_LAT 0x0000
#define SYS_PORT_G_ODC 0x0000
#define SYS_PORT_G_CNPU 0x0000
#define SYS_PORT_G_CNPD 0x0000
#define SYS_PORT_G_CNEN 0x0000

#define SYS_PORT_H_ANSEL 0x0890
#define SYS_PORT_H_TRIS 0xFFFF
#define SYS_PORT_H_LAT 0x0000
#define SYS_PORT_H_ODC 0x0000
#define SYS_PORT_H_CNPU 0x0000
#define SYS_PORT_H_CNPD 0x0000
#define SYS_PORT_H_CNEN 0x0000

#define SYS_PORT_J_ANSEL 0x0000
#define SYS_PORT_J_TRIS 0xFFE7
#define SYS_PORT_J_LAT 0x0000
#define SYS_PORT_J_ODC 0x0000
#define SYS_PORT_J_CNPU 0x0000
#define SYS_PORT_J_CNPD 0x0000
#define SYS_PORT_J_CNEN 0x0000

#define SYS_PORT_K_ANSEL 0xFF06
#define SYS_PORT_K_TRIS 0xFFFF
#define SYS_PORT_K_LAT 0x0000
#define SYS_PORT_K_ODC 0x0000
#define SYS_PORT_K_CNPU 0x0000
#define SYS_PORT_K_CNPD 0x0000
#define SYS_PORT_K_CNEN 0x0000


/*** File System Service Configuration ***/

#define SYS_FS_MEDIA_NUMBER 1

#define SYS_FS_VOLUME_NUMBER (1)

#define SYS_FS_AUTOMOUNT_ENABLE true
#define SYS_FS_CLIENT_NUMBER 1
#define SYS_FS_MAX_FILES 1
#define SYS_FS_MAX_FILE_SYSTEM_TYPE 1
#define SYS_FS_MEDIA_MAX_BLOCK_SIZE 512
#define SYS_FS_MEDIA_MANAGER_BUFFER_SIZE 2048
#define SYS_FS_FILE_NAME_LEN 255
#define SYS_FS_CWD_STRING_LEN 1024


#define SYS_FS_MEDIA_TYPE_IDX0 SYS_FS_MEDIA_TYPE_MSD
#define SYS_FS_TYPE_IDX0 FAT








#define SYS_FS_MEDIA_IDX0_MOUNT_NAME_VOLUME_IDX0 "/mnt/myDrive1"
#define SYS_FS_MEDIA_IDX0_DEVICE_NAME_VOLUME_IDX0 "/dev/sda1"


/*** Interrupt System Service Configuration ***/
#define SYS_INT true
/*** Timer System Service Configuration ***/
#define SYS_TMR_POWER_STATE SYS_MODULE_POWER_RUN_FULL
#define SYS_TMR_DRIVER_INDEX DRV_TMR_INDEX_0
#define SYS_TMR_MAX_CLIENT_OBJECTS 5
#define SYS_TMR_FREQUENCY 1000
#define SYS_TMR_FREQUENCY_TOLERANCE 10
#define SYS_TMR_UNIT_RESOLUTION 10000
#define SYS_TMR_CLIENT_TOLERANCE 10
#define SYS_TMR_INTERRUPT_NOTIFICATION false

// *****************************************************************************
// *****************************************************************************
// Section: Driver Configuration
// *****************************************************************************
// *****************************************************************************
/*** Timer Driver Configuration ***/
#define DRV_TMR_INTERRUPT_MODE true
#define DRV_TMR_INSTANCES_NUMBER 1
#define DRV_TMR_CLIENTS_NUMBER 1

/*** Timer Driver 0 Configuration ***/
#define DRV_TMR_PERIPHERAL_ID_IDX0 TMR_ID_1
#define DRV_TMR_INTERRUPT_SOURCE_IDX0 INT_SOURCE_TIMER_1
#define DRV_TMR_INTERRUPT_VECTOR_IDX0 INT_VECTOR_T1
#define DRV_TMR_ISR_VECTOR_IDX0 _TIMER_1_VECTOR
#define DRV_TMR_INTERRUPT_PRIORITY_IDX0 INT_PRIORITY_LEVEL1
#define DRV_TMR_INTERRUPT_SUB_PRIORITY_IDX0 INT_SUBPRIORITY_LEVEL0
#define DRV_TMR_CLOCK_SOURCE_IDX0 DRV_TMR_CLKSOURCE_INTERNAL
#define DRV_TMR_PRESCALE_IDX0 TMR_PRESCALE_VALUE_256
#define DRV_TMR_OPERATION_MODE_IDX0 DRV_TMR_OPERATION_MODE_16_BIT
#define DRV_TMR_ASYNC_WRITE_ENABLE_IDX0 false
#define DRV_TMR_POWER_STATE_IDX0 SYS_MODULE_POWER_RUN_FULL


 
// *****************************************************************************
// *****************************************************************************
// Section: Middleware & Other Library Configuration
// *****************************************************************************
// *****************************************************************************

/*** USB Driver Configuration ***/


/* Disable Device Support */
#define DRV_USBHS_DEVICE_SUPPORT false

/* Enables Host Support */
#define DRV_USBHS_HOST_SUPPORT true

/* Maximum USB driver instances */
#define DRV_USBHS_INSTANCES_NUMBER 1

/* Interrupt mode enabled */
#define DRV_USBHS_INTERRUPT_MODE true


/* Number of Endpoints used */
#define DRV_USBHS_ENDPOINTS_NUMBER 1







#define DRV_USBHS_HOST_NAK_LIMIT 2000
/* Provides Host pipes number */
#define DRV_USBHS_HOST_PIPES_NUMBER 10
#define DRV_USBHS_HOST_ATTACH_DEBOUNCE_DURATION 500
#define DRV_USBHS_HOST_RESET_DURATION 100
// *****************************************************************************
// *****************************************************************************
// Section: USB Device Layer Configuration
// *****************************************************************************
// *****************************************************************************
/* Provides Host pipes number */
#define USB_HOST_PIPES_NUMBER 10

// *****************************************************************************
// *****************************************************************************
// Section: USB Host Layer Configuration
// *****************************************************************************
// **************************************************************************
 
/* Total number of devices to be supported */
#define USB_HOST_DEVICES_NUMBER 1

/* Target peripheral list entries */
#define USB_HOST_TPL_ENTRIES 1

/* Maximum number of configurations supported per device */
#define USB_HOST_DEVICE_INTERFACES_NUMBER 5

#define USB_HOST_CONTROLLERS_NUMBER 1

#define USB_HOST_TRANSFERS_NUMBER 10

/* Number of Host Layer Clients */
#define USB_HOST_CLIENTS_NUMBER 1

/* Number of MSD Function driver instances in the application */
#define USB_HOST_MSD_INSTANCES_NUMBER 1

/* Number of Logical Units */
#define USB_HOST_SCSI_INSTANCES_NUMBER 1
#define USB_HOST_MSD_LUN_NUMBERS 1








// *****************************************************************************
// *****************************************************************************
// Section: Application Configuration
// *****************************************************************************
// *****************************************************************************
/*** Application Defined Pins ***/

/*** Functions for MyLED pin ***/
#define MyLEDToggle() PLIB_PORTS_PinToggle(PORTS_ID_0, PORT_CHANNEL_B, PORTS_BIT_POS_4)
#define MyLEDOn() PLIB_PORTS_PinSet(PORTS_ID_0, PORT_CHANNEL_B, PORTS_BIT_POS_4)
#define MyLEDOff() PLIB_PORTS_PinClear(PORTS_ID_0, PORT_CHANNEL_B, PORTS_BIT_POS_4)
#define MyLEDStateGet() PLIB_PORTS_PinGetLatched(PORTS_ID_0, PORT_CHANNEL_B, PORTS_BIT_POS_4)


/*** Application Instance 0 Configuration ***/

//DOM-IGNORE-BEGIN
#ifdef __cplusplus
}
#endif
//DOM-IGNORE-END

#endif // _SYSTEM_CONFIG_H
/*******************************************************************************
 End of File
*/

post edited by kuku - 2019/04/10 05:00:32

Attached Image(s)

#19
Paul PortSol
Super Member
  • Total Posts : 639
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: online
Re: How Set up USB in Harmony 2.02b 2019/04/10 06:06:29 (permalink)
0
I suggest you try "MHC - Application - Generate Example Code" which in my experience gives code better matched to your chosen PIC than something prewritten for a different PCB/BSP. Also you can do this without selecting a BSP (or deselect BSP if it got selected) before clicking final generate button so that you don't end up with left over BSP code. (See my previous posts about "without BSP")
 
Paul
#20
Page: 12 > Showing page 1 of 2
Jump to:
© 2021 APG vNext Commercial Version 4.5