This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

USBH - USB_CM3

Hi,
i want to use USB host controller on LPC1778 with USB_CM3.lib and usbh_ohci_lpc177x_8x driver. The board is custom and there are no ISP1301. In driver - usbh_ohci_lpc177x_8x i saw functions for working with I2C(ISP1301). When i calling "usbh_init(0)" and "usbh_engine(0)" I2C functions are too calling. Is it possible to modify driver to work without ISP1301 as host only?

Thank's in advance !

Parents
  • /*------------------------- usbh_ohci_hw_delay_ms ------------------------------
     *
     *  Delay execution (in milliseconds)
     *  Calibration is done if global variable calDelay is 0
     *
     *  Parameter:  ms:         Number of milliseconds to delay execution for
     *  Return:
     *----------------------------------------------------------------------------*/
    
    void usbh_ohci_hw_delay_ms (U32 ms) {
      U32 cnt = 0, vals = 0, vale = 0;
    
    start:
      if (!calDelay) {                      /* If not calibrated                  */
        cnt = 1000;
        if (!(SysTick->CTRL & SysTick_CTRL_ENABLE_Msk)) {
                                            /* If SysTick timer not running       */
          vals = 0xFFFFFF;
          SysTick->LOAD  = 0xFFFFFF;
          SysTick->VAL   = 0xFFFFFF;
          SysTick->CTRL  = SysTick_CTRL_CLKSOURCE_Msk |
                           SysTick_CTRL_ENABLE_Msk;
        } else {
          vals = SysTick->VAL;              /* Timer start value                  */
        }
      } else {
        cnt = ms * calDelay;
      }
    
      while (cnt--);
    
      if (!calDelay) {                      /* If not calibrated                  */
        vale = SysTick->VAL;                /* Timer end value                    */
        if (vale >= vals)                   /* If timer reloaded                  */
          vals += SysTick->LOAD;
        SystemCoreClockUpdate();            /* Update SystemCoreClock variable    */
        calDelay = SystemCoreClock / (vals - vale);   /* Calibrated value         */
        if (vals == 0xFFFFFF)               /* Stop timer if we started it        */
          SysTick->CTRL  = 0;
        goto start;
      }
    }
    
    
    
    /*------------------------- usbh_ohci_hw_pins_cfg ------------------------------
     *
     *  Configurate or unconfigurate pins used by the USB Host.
     *
     *  Parameter:  on:         __TRUE = configurate, __FALSE = unconfigurate
     *  Return:                 __TRUE = Ok, __FALSE = error
     *----------------------------------------------------------------------------*/
    
    BOOL usbh_ohci_hw_pins_config (BOOL on) {
    
      if (on) {
        /* Set pin functions                                                      */
        LPC_IOCON->P0_29 = 1;               /* USB_D+1                            */
        LPC_IOCON->P0_30 = 1;               /* USB_D-1                            */
    //    LPC_IOCON->P0_31 = 1;             /* USB_D+2                            */
                                            /* USB_D-2 is dedicated pin           */
    
        LPC_IOCON->P1_18 = 1;               /* USB_UP_LED1                        */
                    LPC_IOCON->P1_19 = 2;               /* !USB_PPWR1                         */
                    LPC_IOCON->P1_22 = 2;               /* USB_PWRD1                          */
        LPC_IOCON->P1_27 = 2;               /* !USB_OVRCR1                        */
    
        LPC_IOCON->P0_12 = 1 | (1 << 7);    /* !USB_PPWR2                         */
        LPC_IOCON->P0_13 = 1 | (1 << 7);    /* USB_UP_LED2                        */
        LPC_IOCON->P0_14 = 1;               /* !USB_HSTEN2                        */
        LPC_IOCON->P1_30 = 1 | (1 << 7);    /* USB_PWRD2                          */
        LPC_IOCON->P1_31 = 1 | (1 << 7);    /* !USB_OVRCR2                        */
      } else {
        /* Reset pin functions                                                    */
        LPC_IOCON->P0_12 = 0xD0;
        LPC_IOCON->P0_13 = 0xD0;
        LPC_IOCON->P0_14 = 0x30;
        LPC_IOCON->P1_30 = 0xD0;
        LPC_IOCON->P1_31 = 0xD0;
    
        LPC_IOCON->P1_18 = 0x30;
                    LPC_IOCON->P1_19 = 0x30;
              LPC_IOCON->P1_22 = 0x30;
        LPC_IOCON->P1_27 = 0x30;
    
        LPC_IOCON->P0_29 = 0;
        LPC_IOCON->P0_30 = 0;
    //    LPC_IOCON->P0_31 = 0;
      }
    
      return (__TRUE);
    }
    
    
    /*------------------------- usbh_ohci_hw_init ----------------------------------
     *
     *  Initialize or uninitialize the USB Host Controller.
     *
     *  Parameter:  on:         __TRUE = initialize, __FALSE = uninitialize
     *  Return:                 __TRUE = Ok, __FALSE = error
     *----------------------------------------------------------------------------*/
    
    BOOL usbh_ohci_hw_init (BOOL on) {
      S32 tout;
    
      if (on) {
        usbh_ohci_hw_delay_ms (10);         /* Calibrate delay                    */
    
        /* Initialize memory pool for data                                        */
        if (!usbh_mem_init(0, (U32 *)&usbh_ohci_mpool, sizeof(usbh_ohci_mpool)))
          return (__FALSE);
    
        LPC_SC->PCONP       |=  (1UL << 31);/* Enable USB interface power/clock   */
        LPC_USB->OTGClkCtrl |=  0x19;       /* Enable Host, OTG, AHB mster clk    */
    
        tout = 10100;
        while (!((LPC_USB->OTGClkSt & 0x19) == 0x19)) {   /* Wait clock enable    */
          if (tout-- <= 100) {
            if (tout == 0)
              return (__FALSE);
            usbh_ohci_hw_delay_ms (10);                   /* Wait ~10 ms          */
          }
        }
    
        LPC_USB -> StCtrl   |=  0x03;          // 11: U1 = host, U2 = device
    
        NVIC_SetPriority (USB_IRQn, 0);     /* Set USB interrupt highest priority */
      } else {
        LPC_USB->StCtrl     &= ~0x03;       /* Deselect port function             */
    
        LPC_USB->OTGClkCtrl &= ~0x1F;       /* Disable Host,I2C,OTG, AHB mster clk*/
    
        for (tout = 100; ; tout--) {
          if ((LPC_USB->OTGClkSt & 0x1F) == 0)/* Wait for clocks disabled         */
            break;
          if (!tout)
            return (__FALSE);
        }
    
        LPC_SC->PCONP       &= ~(1UL << 31);/* Disable USB interface power/clock  */
      }
    
      return (__TRUE);
    }
    

    When i call usbh_init(0); return 1-Success, but when i call usbh_hid_status(0,0);
    return 0 - HID device not connected.Where i am wrong?

Reply
  • /*------------------------- usbh_ohci_hw_delay_ms ------------------------------
     *
     *  Delay execution (in milliseconds)
     *  Calibration is done if global variable calDelay is 0
     *
     *  Parameter:  ms:         Number of milliseconds to delay execution for
     *  Return:
     *----------------------------------------------------------------------------*/
    
    void usbh_ohci_hw_delay_ms (U32 ms) {
      U32 cnt = 0, vals = 0, vale = 0;
    
    start:
      if (!calDelay) {                      /* If not calibrated                  */
        cnt = 1000;
        if (!(SysTick->CTRL & SysTick_CTRL_ENABLE_Msk)) {
                                            /* If SysTick timer not running       */
          vals = 0xFFFFFF;
          SysTick->LOAD  = 0xFFFFFF;
          SysTick->VAL   = 0xFFFFFF;
          SysTick->CTRL  = SysTick_CTRL_CLKSOURCE_Msk |
                           SysTick_CTRL_ENABLE_Msk;
        } else {
          vals = SysTick->VAL;              /* Timer start value                  */
        }
      } else {
        cnt = ms * calDelay;
      }
    
      while (cnt--);
    
      if (!calDelay) {                      /* If not calibrated                  */
        vale = SysTick->VAL;                /* Timer end value                    */
        if (vale >= vals)                   /* If timer reloaded                  */
          vals += SysTick->LOAD;
        SystemCoreClockUpdate();            /* Update SystemCoreClock variable    */
        calDelay = SystemCoreClock / (vals - vale);   /* Calibrated value         */
        if (vals == 0xFFFFFF)               /* Stop timer if we started it        */
          SysTick->CTRL  = 0;
        goto start;
      }
    }
    
    
    
    /*------------------------- usbh_ohci_hw_pins_cfg ------------------------------
     *
     *  Configurate or unconfigurate pins used by the USB Host.
     *
     *  Parameter:  on:         __TRUE = configurate, __FALSE = unconfigurate
     *  Return:                 __TRUE = Ok, __FALSE = error
     *----------------------------------------------------------------------------*/
    
    BOOL usbh_ohci_hw_pins_config (BOOL on) {
    
      if (on) {
        /* Set pin functions                                                      */
        LPC_IOCON->P0_29 = 1;               /* USB_D+1                            */
        LPC_IOCON->P0_30 = 1;               /* USB_D-1                            */
    //    LPC_IOCON->P0_31 = 1;             /* USB_D+2                            */
                                            /* USB_D-2 is dedicated pin           */
    
        LPC_IOCON->P1_18 = 1;               /* USB_UP_LED1                        */
                    LPC_IOCON->P1_19 = 2;               /* !USB_PPWR1                         */
                    LPC_IOCON->P1_22 = 2;               /* USB_PWRD1                          */
        LPC_IOCON->P1_27 = 2;               /* !USB_OVRCR1                        */
    
        LPC_IOCON->P0_12 = 1 | (1 << 7);    /* !USB_PPWR2                         */
        LPC_IOCON->P0_13 = 1 | (1 << 7);    /* USB_UP_LED2                        */
        LPC_IOCON->P0_14 = 1;               /* !USB_HSTEN2                        */
        LPC_IOCON->P1_30 = 1 | (1 << 7);    /* USB_PWRD2                          */
        LPC_IOCON->P1_31 = 1 | (1 << 7);    /* !USB_OVRCR2                        */
      } else {
        /* Reset pin functions                                                    */
        LPC_IOCON->P0_12 = 0xD0;
        LPC_IOCON->P0_13 = 0xD0;
        LPC_IOCON->P0_14 = 0x30;
        LPC_IOCON->P1_30 = 0xD0;
        LPC_IOCON->P1_31 = 0xD0;
    
        LPC_IOCON->P1_18 = 0x30;
                    LPC_IOCON->P1_19 = 0x30;
              LPC_IOCON->P1_22 = 0x30;
        LPC_IOCON->P1_27 = 0x30;
    
        LPC_IOCON->P0_29 = 0;
        LPC_IOCON->P0_30 = 0;
    //    LPC_IOCON->P0_31 = 0;
      }
    
      return (__TRUE);
    }
    
    
    /*------------------------- usbh_ohci_hw_init ----------------------------------
     *
     *  Initialize or uninitialize the USB Host Controller.
     *
     *  Parameter:  on:         __TRUE = initialize, __FALSE = uninitialize
     *  Return:                 __TRUE = Ok, __FALSE = error
     *----------------------------------------------------------------------------*/
    
    BOOL usbh_ohci_hw_init (BOOL on) {
      S32 tout;
    
      if (on) {
        usbh_ohci_hw_delay_ms (10);         /* Calibrate delay                    */
    
        /* Initialize memory pool for data                                        */
        if (!usbh_mem_init(0, (U32 *)&usbh_ohci_mpool, sizeof(usbh_ohci_mpool)))
          return (__FALSE);
    
        LPC_SC->PCONP       |=  (1UL << 31);/* Enable USB interface power/clock   */
        LPC_USB->OTGClkCtrl |=  0x19;       /* Enable Host, OTG, AHB mster clk    */
    
        tout = 10100;
        while (!((LPC_USB->OTGClkSt & 0x19) == 0x19)) {   /* Wait clock enable    */
          if (tout-- <= 100) {
            if (tout == 0)
              return (__FALSE);
            usbh_ohci_hw_delay_ms (10);                   /* Wait ~10 ms          */
          }
        }
    
        LPC_USB -> StCtrl   |=  0x03;          // 11: U1 = host, U2 = device
    
        NVIC_SetPriority (USB_IRQn, 0);     /* Set USB interrupt highest priority */
      } else {
        LPC_USB->StCtrl     &= ~0x03;       /* Deselect port function             */
    
        LPC_USB->OTGClkCtrl &= ~0x1F;       /* Disable Host,I2C,OTG, AHB mster clk*/
    
        for (tout = 100; ; tout--) {
          if ((LPC_USB->OTGClkSt & 0x1F) == 0)/* Wait for clocks disabled         */
            break;
          if (!tout)
            return (__FALSE);
        }
    
        LPC_SC->PCONP       &= ~(1UL << 31);/* Disable USB interface power/clock  */
      }
    
      return (__TRUE);
    }
    

    When i call usbh_init(0); return 1-Success, but when i call usbh_hid_status(0,0);
    return 0 - HID device not connected.Where i am wrong?

Children
No data