コード例 #1
0
//*****************************************************************************
//
// Initialize the USB for OTG mode on the platform.
//
//*****************************************************************************
void
USBOTGInit(uint32_t ui32ClockRate, tUSBModeCallback pfnModeCallback)
{
    uint32_t ui32PLLRate;

    //
    // Enable USB controller.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);

    //
    // Set the current processor speed to provide more accurate timing
    // information to the USB library.
    //
    ui32PLLRate = 480000000;
    USBOTGFeatureSet(0, USBLIB_FEATURE_CPUCLK, &ui32ClockRate);
    USBOTGFeatureSet(0, USBLIB_FEATURE_USBPLL, &ui32PLLRate);

    //
    // Initialize the USB OTG mode and pass in a mode callback.
    //
    USBStackModeSet(0, eUSBModeOTG, pfnModeCallback);
}
コード例 #2
0
//*****************************************************************************
//
// This is the main application entry function.
//
//*****************************************************************************
int
main(void)
{
    uint32_t ui32TxCount, ui32RxCount, ui32Fullness, ui32SysClock, ui32PLLRate;
    tRectangle sRect;
    char pcBuffer[16];
#ifdef USE_ULPI
    uint32_t ui32Setting;
#endif

    //
    // Set the system clock to run at 120MHz from the PLL.
    //
    ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                           SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
                                           SYSCTL_CFG_VCO_480), 120000000);

    //
    // Configure the device pins.
    //
    PinoutSet();

#ifdef USE_ULPI
    //
    // Switch the USB ULPI Pins over.
    //
    USBULPIPinoutSet();

    //
    // Enable USB ULPI with high speed support.
    //
    ui32Setting = USBLIB_FEATURE_ULPI_HS;
    USBOTGFeatureSet(0, USBLIB_FEATURE_USBULPI, &ui32Setting);

    //
    // Setting the PLL frequency to zero tells the USB library to use the
    // external USB clock.
    //
    ui32PLLRate = 0;
#else
    //
    // Save the PLL rate used by this application.
    //
    ui32PLLRate = 480000000;
#endif

    //
    // Enable the system tick.
    //
    ROM_SysTickPeriodSet(ui32SysClock / TICKS_PER_SECOND);
    ROM_SysTickIntEnable();
    ROM_SysTickEnable();

    //
    // Not configured initially.
    //
    g_ui32Flags = 0;

    //
    // Initialize the display driver.
    //
    Kentec320x240x16_SSD2119Init(ui32SysClock);

    //
    // Initialize the graphics context.
    //
    GrContextInit(&g_sContext, &g_sKentec320x240x16_SSD2119);

    //
    // Draw the application frame.
    //
    FrameDraw(&g_sContext, "usb-dev-serial");

    //
    // Fill the top 15 rows of the screen with blue to create the banner.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.i16YMax = 23;
    GrContextForegroundSet(&g_sContext, ClrDarkBlue);
    GrRectFill(&g_sContext, &sRect);

    //
    // Put a white box around the banner.
    //
    GrContextForegroundSet(&g_sContext, ClrWhite);
    GrRectDraw(&g_sContext, &sRect);

    //
    // Show the various static text elements on the color STN display.
    //
    GrContextFontSet(&g_sContext, TEXT_FONT);
    GrStringDraw(&g_sContext, "Tx bytes:", -1, 8, 80, false);
    GrStringDraw(&g_sContext, "Tx buffer:", -1, 8, 105, false);
    GrStringDraw(&g_sContext, "Rx bytes:", -1, 8, 160, false);
    GrStringDraw(&g_sContext, "Rx buffer:", -1, 8, 185, false);
    DrawBufferMeter(&g_sContext, 150, 105);
    DrawBufferMeter(&g_sContext, 150, 185);

    //
    // Enable the UART that we will be redirecting.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    //
    // Change the UART clock to the 16 MHz PIOSC.
    //
    UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);

    //
    // Set the default UART configuration.
    //
    ROM_UARTConfigSetExpClk(UART0_BASE, UART_CLOCK,
                            DEFAULT_BIT_RATE, DEFAULT_UART_CONFIG);
    ROM_UARTFIFOLevelSet(UART0_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8);

    //
    // Configure and enable UART interrupts.
    //
    ROM_UARTIntClear(UART0_BASE, ROM_UARTIntStatus(UART0_BASE, false));
    ROM_UARTIntEnable(UART0_BASE, (UART_INT_OE | UART_INT_BE | UART_INT_PE |
                      UART_INT_FE | UART_INT_RT | UART_INT_TX | UART_INT_RX));

    //
    // Tell the user what we are up to.
    //
    DisplayStatus(&g_sContext, " Configuring USB... ");

    //
    // Initialize the transmit and receive buffers.
    //
    USBBufferInit(&g_sTxBuffer);
    USBBufferInit(&g_sRxBuffer);

    //
    // Set the USB stack mode to Device mode with VBUS monitoring.
    //
    USBStackModeSet(0, eUSBModeDevice, 0);

    //
    // Tell the USB library the CPU clock and the PLL frequency.  This is a
    // new requirement for TM4C129 devices.
    //
    USBDCDFeatureSet(0, USBLIB_FEATURE_CPUCLK, &ui32SysClock);
    USBDCDFeatureSet(0, USBLIB_FEATURE_USBPLL, &ui32PLLRate);

    //
    // Pass our device information to the USB library and place the device
    // on the bus.
    //
    USBDCDCInit(0, (tUSBDCDCDevice *)&g_sCDCDevice);

    //
    // Wait for initial configuration to complete.
    //
    DisplayStatus(&g_sContext, " Waiting for host... ");

    //
    // Clear our local byte counters.
    //
    ui32RxCount = 0;
    ui32TxCount = 0;
    g_ui32UARTTxCount = 0;
    g_ui32UARTRxCount = 0;
#ifdef DEBUG
    g_ui32UARTRxErrors = 0;
#endif

    //
    // Enable interrupts now that the application is ready to start.
    //
    ROM_IntEnable(INT_UART0);

    //
    // Main application loop.
    //
    while(1)
    {
        //
        // Have we been asked to update the status display?
        //
        if(HWREGBITW(&g_ui32Flags, FLAG_STATUS_UPDATE))
        {
            //
            // Clear the command flag
            //
            HWREGBITW(&g_ui32Flags, FLAG_STATUS_UPDATE) = 0;

            DisplayStatus(&g_sContext, g_pcStatus);
        }

        //
        // Has there been any transmit traffic since we last checked?
        //
        if(ui32TxCount != g_ui32UARTTxCount)
        {
            //
            // Take a snapshot of the latest transmit count.
            //
            ui32TxCount = g_ui32UARTTxCount;

            //
            // Update the display of bytes transmitted by the UART.
            //
            usnprintf(pcBuffer, 16, "%d ", ui32TxCount);
            GrStringDraw(&g_sContext, pcBuffer, -1, 150, 80, true);

            //
            // Update the RX buffer fullness. Remember that the buffers are
            // named relative to the USB whereas the status display is from
            // the UART's perspective. The USB's receive buffer is the UART's
            // transmit buffer.
            //
            ui32Fullness = ((USBBufferDataAvailable(&g_sRxBuffer) * 100) /
                          UART_BUFFER_SIZE);

            UpdateBufferMeter(&g_sContext, ui32Fullness, 150, 105);
        }

        //
        // Has there been any receive traffic since we last checked?
        //
        if(ui32RxCount != g_ui32UARTRxCount)
        {
            //
            // Take a snapshot of the latest receive count.
            //
            ui32RxCount = g_ui32UARTRxCount;

            //
            // Update the display of bytes received by the UART.
            //
            usnprintf(pcBuffer, 16, "%d ", ui32RxCount);
            GrStringDraw(&g_sContext, pcBuffer, -1, 150, 160, true);

            //
            // Update the TX buffer fullness. Remember that the buffers are
            // named relative to the USB whereas the status display is from
            // the UART's perspective. The USB's transmit buffer is the UART's
            // receive buffer.
            //
            ui32Fullness = ((USBBufferDataAvailable(&g_sTxBuffer) * 100) /
                          UART_BUFFER_SIZE);

            UpdateBufferMeter(&g_sContext, ui32Fullness, 150, 185);
        }
    }
}
コード例 #3
0
ファイル: usb_host_hub.c プロジェクト: AlexGeControl/tiva-c
//*****************************************************************************
//
// The main application loop.
//
//*****************************************************************************
int
main(void)
{
    int32_t i32Status, i32Idx;
    uint32_t ui32SysClock, ui32PLLRate;
#ifdef USE_ULPI
    uint32_t ui32Setting;
#endif

    ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                           SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
                                           SYSCTL_CFG_VCO_480), 120000000);

    //
    // Set the part pin out appropriately for this device.
    //
    PinoutSet();

#ifdef USE_ULPI
    //
    // Switch the USB ULPI Pins over.
    //
    USBULPIPinoutSet();

    //
    // Enable USB ULPI with high speed support.
    //
    ui32Setting = USBLIB_FEATURE_ULPI_HS;
    USBOTGFeatureSet(0, USBLIB_FEATURE_USBULPI, &ui32Setting);

    //
    // Setting the PLL frequency to zero tells the USB library to use the
    // external USB clock.
    //
    ui32PLLRate = 0;
#else
    //
    // Save the PLL rate used by this application.
    //
    ui32PLLRate = 480000000;
#endif

    //
    // Initialize the hub port status.
    //
    for(i32Idx = 0; i32Idx < NUM_HUB_STATUS; i32Idx++)
    {
        g_psHubStatus[i32Idx].bConnected = false;
    }

    //
    // Enable Clocking to the USB controller.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);

    //
    // Enable Interrupts
    //
    ROM_IntMasterEnable();

    //
    // Initialize the USB stack mode and pass in a mode callback.
    //
    USBStackModeSet(0, eUSBModeHost, 0);

    //
    // Register the host class drivers.
    //
    USBHCDRegisterDrivers(0, g_ppHostClassDrivers, g_ui32NumHostClassDrivers);

    //
    // Open the Keyboard interface.
    //
    KeyboardOpen();
    MSCOpen(ui32SysClock);

    //
    // Open a hub instance and provide it with the memory required to hold
    // configuration descriptors for each attached device.
    //
    USBHHubOpen(HubCallback);

    //
    // Initialize the power configuration. This sets the power enable signal
    // to be active high and does not enable the power fault.
    //
    USBHCDPowerConfigInit(0, USBHCD_VBUS_AUTO_HIGH | USBHCD_VBUS_FILTER);

    //
    // Tell the USB library the CPU clock and the PLL frequency.
    //
    USBOTGFeatureSet(0, USBLIB_FEATURE_CPUCLK, &ui32SysClock);
    USBOTGFeatureSet(0, USBLIB_FEATURE_USBPLL, &ui32PLLRate);

    //
    // Initialize the USB controller for Host mode.
    //
    USBHCDInit(0, g_pui8HCDPool, sizeof(g_pui8HCDPool));

    //
    // Initialize the display driver.
    //
    Kentec320x240x16_SSD2119Init(ui32SysClock);

    //
    // Initialize the graphics context.
    //
    GrContextInit(&g_sContext, &g_sKentec320x240x16_SSD2119);

    //
    // Draw the application frame.
    //
    FrameDraw(&g_sContext, "usb-host-hub");

    //
    // Calculate the number of characters that will fit on a line.
    // Make sure to leave a small border for the text box.
    //
    g_ui32CharsPerLine = (GrContextDpyWidthGet(&g_sContext) - 16) /
                         GrFontMaxWidthGet(g_psFontFixed6x8);

    //
    // Calculate the number of lines per usable text screen.  This requires
    // taking off space for the top and bottom banners and adding a small bit
    // for a border.
    //
    g_ui32LinesPerScreen = (GrContextDpyHeightGet(&g_sContext) -
                           (2*(DISPLAY_BANNER_HEIGHT + 1)))/
                           GrFontHeightGet(g_psFontFixed6x8);

    //
    // Initial update of the screen.
    //
    UpdateStatus(0);
    UpdateStatus(1);
    UpdateStatus(2);
    UpdateStatus(3);

    g_ui32CmdIdx = 0;
    g_ui32CurrentLine = 0;

    //
    // Initialize the file system.
    //
    FileInit();

    //
    // The main loop for the application.
    //
    while(1)
    {
        //
        // Print a prompt to the console.  Show the CWD.
        //
        WriteString("> ");

        //
        // Is there a command waiting to be processed?
        //
        while((g_ui32Flags & FLAG_CMD_READY) == 0)
        {
            //
            // Call the YSB library to let non-interrupt code run.
            //
            USBHCDMain();

            //
            // Call the keyboard and mass storage main routines.
            //
            KeyboardMain();
            MSCMain();
        }

        //
        // Pass the line from the user to the command processor.
        // It will be parsed and valid commands executed.
        //
        i32Status = CmdLineProcess(g_pcCmdBuf);

        //
        // Handle the case of bad command.
        //
        if(i32Status == CMDLINE_BAD_CMD)
        {
            WriteString("Bad command!\n");
        }
        //
        // Handle the case of too many arguments.
        //
        else if(i32Status == CMDLINE_TOO_MANY_ARGS)
        {
            WriteString("Too many arguments for command processor!\n");
        }
        //
        // Otherwise the command was executed.  Print the error
        // code if one was returned.
        //
        else if(i32Status != 0)
        {
            WriteString("Command returned error code\n");
            WriteString((char *)StringFromFresult((FRESULT)i32Status));
            WriteString("\n");
        }

        //
        // Reset the command flag and the command index.
        //
        g_ui32Flags &= ~FLAG_CMD_READY;
        g_ui32CmdIdx = 0;
    }
}
コード例 #4
0
//*****************************************************************************
//
// The main application loop.
//
//*****************************************************************************
int
main(void)
{
    uint32_t ui32SysClock, ui32PLLRate;
#ifdef USE_ULPI
    uint32_t ui32Setting;
#endif

    //
    // Set the application to run at 120 MHz with a PLL frequency of 480 MHz.
    //
    ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                           SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
                                           SYSCTL_CFG_VCO_480), 120000000);

    //
    // Set the part pin out appropriately for this device.
    //
    PinoutSet();

#ifdef USE_ULPI
    //
    // Switch the USB ULPI Pins over.
    //
    USBULPIPinoutSet();

    //
    // Enable USB ULPI with high speed support.
    //
    ui32Setting = USBLIB_FEATURE_ULPI_HS;
    USBOTGFeatureSet(0, USBLIB_FEATURE_USBULPI, &ui32Setting);

    //
    // Setting the PLL frequency to zero tells the USB library to use the
    // external USB clock.
    //
    ui32PLLRate = 0;
#else
    //
    // Save the PLL rate used by this application.
    //
    ui32PLLRate = 480000000;
#endif

    //
    // Initialize the connection status.
    //
    g_sStatus.bConnected = false;

    //
    // Initially there are no modifiers set.
    //
    g_sStatus.ui32Modifiers = 0;

    //
    // Enable Clocking to the USB controller.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);

    //
    // Enable Interrupts
    //
    ROM_IntMasterEnable();

    //
    // Initialize the USB stack mode and pass in a mode callback.
    //
    USBStackModeSet(0, eUSBModeHost, 0);

    //
    // Register the host class drivers.
    //
    USBHCDRegisterDrivers(0, g_ppHostClassDrivers, g_ui32NumHostClassDrivers);

    //
    // Open an instance of the keyboard driver.  The keyboard does not need
    // to be present at this time, this just save a place for it and allows
    // the applications to be notified when a keyboard is present.
    //
    g_psKeyboard = USBHKeyboardOpen(KeyboardCallback, 0, 0);

    //
    // Initialize the power configuration. This sets the power enable signal
    // to be active high and does not enable the power fault.
    //
    USBHCDPowerConfigInit(0, USBHCD_VBUS_AUTO_HIGH | USBHCD_VBUS_FILTER);

    //
    // Tell the USB library the CPU clock and the PLL frequency.  This is a
    // new requirement for TM4C129 devices.
    //
    USBHCDFeatureSet(0, USBLIB_FEATURE_CPUCLK, &ui32SysClock);
    USBHCDFeatureSet(0, USBLIB_FEATURE_USBPLL, &ui32PLLRate);

    //
    // Initialize the USB controller for Host mode.
    //
    USBHCDInit(0, g_pui8HCDPool, sizeof(g_pui8HCDPool));

    //
    // Initialize the GUI elements.
    //
    UIInit(ui32SysClock);

    //
    // The main loop for the application.
    //
    while(1)
    {
        //
        // Call the USB library to let non-interrupt code run.
        //
        USBHCDMain();

        //
        // Call the keyboard and mass storage main routines.
        //
        KeyboardMain();
    }
}