/************************************************************************************//** ** \brief Initializes the microcontroller. ** \return none. ** ****************************************************************************************/ static void Init(void) { /* set the clocking to run at 50MHz from the PLL */ SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); #if (BOOT_COM_UART_ENABLE > 0) #if (BOOT_COM_UART_CHANNEL_INDEX == 0) /* enable and configure UART0 related peripherals and pins */ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); #endif #elif (BOOT_FILE_LOGGING_ENABLE > 0) /* log info strings to UART during firmware updates from local file storage */ /* enable and configure UART0 related peripherals and pins */ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); /* enable the UART0 peripheral */ SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); /* configure the UART0 baudrate and communication parameters */ UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 57600, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); #endif #if (BOOT_COM_USB_ENABLE > 0) /* enable the GPIO peripheral used for USB, and configure the USB pins */ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL); GPIOPinTypeUSBAnalog(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); GPIOPinTypeUSBAnalog(GPIO_PORTL_BASE, GPIO_PIN_6 | GPIO_PIN_7); #endif /* enable the GPIO port to which the SELECT button is connected */ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM); /* configure the SELECT button pin as an input with pull-up */ GPIODirModeSet(GPIO_PORTM_BASE, GPIO_PIN_4, GPIO_DIR_MODE_IN); GPIOPadConfigSet(GPIO_PORTM_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); } /*** end of Init ***/
void stellaris_usbc_init(void) { LTRACE_ENTRY; SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); SysCtlPeripheralReset(SYSCTL_PERIPH_USB0); SysCtlUSBPLLEnable(); GPIOPinTypeUSBAnalog(GPIO_PORTD_AHB_BASE, GPIO_PIN_4 | GPIO_PIN_5); USBDevMode(USB0_BASE); USBPHYPowerOn(USB0_BASE); #if LOCAL_TRACE usbc_dump_regs(); printf("addr %lu\n", USBDevAddrGet(USB0_BASE)); printf("ep0 status 0x%lx\n", USBEndpointStatus(USB0_BASE, USB_EP_0)); #endif NVIC_EnableIRQ(INT_USB0 - 16); USBIntDisableControl(USB0_BASE, USB_INTCTRL_ALL); LTRACE_EXIT; }
/* * ======== EKS_LM4F232_initUSB ======== * This function just turns on the USB */ Void EKS_LM4F232_initUSB(EKS_LM4F232_USBMode usbMode) { /* Enable the USB peripheral and PLL */ SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); SysCtlUSBPLLEnable(); /* Setup pins for USB operation */ GPIOPinTypeUSBAnalog(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); GPIOPinTypeUSBAnalog(GPIO_PORTL_BASE, GPIO_PIN_6 | GPIO_PIN_7); /* Additional configurations for Host mode */ if (usbMode == EKS_LM4F232_USBHOST) { /* Configure the pins needed */ GPIOPinConfigure(GPIO_PG4_USB0EPEN); GPIOPinConfigure(GPIO_PG5_USB0PFLT); GPIOPinTypeUSBDigital(GPIO_PORTG_BASE, GPIO_PIN_4 | GPIO_PIN_5); } }
/* * ======== EK_TM4C123GXL_initUSB ======== * This function just turns on the USB */ void EK_TM4C123GXL_initUSB(EK_TM4C123GXL_USBMode usbMode) { /* Enable the USB peripheral and PLL */ SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); SysCtlUSBPLLEnable(); /* Setup pins for USB operation */ GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5); if (usbMode == EK_TM4C123GXL_USBHOST) { System_abort("USB host not supported\n"); } }
/* * ======== EK_TM4C123GXL_initUSB ======== * This function just turns on the USB */ void EK_TM4C123GXL_initUSB(EK_TM4C123GXL_USBMode usbMode) { /* Enable the USB peripheral and PLL */ MAP_SysCtlPeripheralEnable(INEEDMD_USB_SYSCTL_PERIPH); MAP_SysCtlUSBPLLEnable(); EK_TM4C123GXL_initDMA(); /* Setup pins for USB operation */ GPIOPinTypeUSBAnalog(INEEDMD_USB_GPIO_PORT, INEEDMD_USBDP_PIN | INEEDMD_USBDM_PIN); if (usbMode == EK_TM4C123GXL_USBHOST) { System_abort("USB host not supported\n"); } }
int main (void) { SysCtlClockSet (SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // Konfiguracja GPIO // // Enable the GPIO port that is used for the on-board LED. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3); // Konfiguracja USB // Enable the GPIO peripheral used for USB, and configure the USB // pins. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOD); GPIOPinTypeUSBAnalog(GPIO_PORTD_AHB_BASE, GPIO_PIN_4 | GPIO_PIN_5); // // Set the USB stack mode to Device mode. // USBStackModeSet(0, eUSBModeForceDevice, 0); void *pvDevice = USBDHIDKeyboardInit(0, &g_sKeyboardDevice); GPIOPinWrite (GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); if (!pvDevice) { while (1); } GPIOPinWrite (GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_PIN_3); uint32_t ui32Loop; while (1) { USBDHIDKeyboardKeyStateChange (pvDevice, 0, 0x04, true); // DELAY for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++) { } } }
//***************************************************************************** // // This is the main loop that runs the application. // //***************************************************************************** int main(void) { ROM_FPULazyStackingEnable(); // Set the clocking to run from the PLL at 50MHz. ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // Configure USB pins SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5); // Set the system tick to fire 100 times per second. ROM_SysTickEnable(); ROM_SysTickIntEnable(); ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); // Initialize the on board buttons ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // Right button is muxed so you need to unlock and configure HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY_DD; HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01; HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0; ROM_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_4 |GPIO_PIN_0); ROM_GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4 |GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // Enable Output Status Light ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); // Set initial LED Status to RED to indicate not connected ROM_GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 2); // Set the USB stack mode to Device mode with VBUS monitoring. USBStackModeSet(0, USB_MODE_DEVICE, 0); // Pass the USB library our device information, initialize the USB // controller and connect the device to the bus. USBDHIDCustomHidInit(0, (tUSBDHIDCustomHidDevice *)&g_sCustomHidDevice); // Drop into the main loop. while(1) { // Wait for USB configuration to complete. while(!g_bConnected) { ROM_GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 2); } // Update the status to green when connected. ROM_GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 8); // Now keep processing the customhid as long as the host is connected. while(g_bConnected) { // If it is time to check the buttons and send a customhid report then do so. if(HWREGBITW(&g_ulCommands, TICK_EVENT) == 1) { HWREGBITW(&g_ulCommands, TICK_EVENT) = 0; CustomHidChangeHandler(); } } } }
//***************************************************************************** // // This is the main loop that runs the application. // //***************************************************************************** int main(void) { // // Set the clocking to run from the PLL at 50MHz. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Enable the UART. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioInit(0); UARTprintf("\033[2JMouse device application\n"); // Configure USB pins, according to // http://forum.stellarisiti.com/topic/353-work-around-stellaris-launchpad-usb-serial-example-not-enumerating-correctly/?p=1544 // Enable the GPIO port so we can configure it SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // Setup the port to be in USB analog mode. Routes incoming signals to // on-chip USB PHY GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5); // // Set the system tick to fire 100 times per second. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Set the USB stack mode to Device mode with VBUS monitoring. // USBStackModeSet(0, USB_MODE_DEVICE, 0); // // Pass the USB library our device information, initialize the USB // controller and connect the device to the bus. // USBDHIDMouseInit(0, (tUSBDHIDMouseDevice *)&g_sMouseDevice); // // Drop into the main loop. // while(1) { // // Tell the user what we are doing. // UARTprintf("Waiting for host...\n"); // // Wait for USB configuration to complete. // while(!g_bConnected) { } // // Update the status. // UARTprintf("Host connected...\n"); // // Now keep processing the mouse as long as the host is connected. // while(g_bConnected) { // // If it is time to move the mouse then do so. // if(HWREGBITW(&g_ulCommands, TICK_EVENT) == 1) { HWREGBITW(&g_ulCommands, TICK_EVENT) = 0; MoveHandler(); } } // // Update the status. // UARTprintf("Host disconnected...\n"); } }
//***************************************************************************** // // This is the main loop that runs the application. // //***************************************************************************** int main(void) { unsigned long ulButton, ulPrevious, ulLastTickCount; tBoolean bLastSuspend; // // Set the clocking to run from the PLL at 50MHz. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Enable USB pins // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5); // // Enable the UART. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioInit(0); UARTprintf("\033[2JKeyboard device application\n"); // // Enable the GPIO that is used for the on-board push button. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_4); ROM_GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // // Enable the GPIO that is used for the on-board LED. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1); ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0); // // Not configured initially. // g_bConnected = false; g_bSuspended = false; bLastSuspend = false; // // Set the USB stack mode to Device mode with VBUS monitoring. // USBStackModeSet(0, USB_MODE_DEVICE, 0); // // Pass our device information to the USB HID device class driver, // initialize the USB // controller and connect the device to the bus. // USBDHIDKeyboardInit(0, &g_sKeyboardDevice); // // Set the system tick to fire 100 times per second. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // The main loop starts here. We begin by waiting for a host connection // then drop into the main keyboard handling section. If the host // disconnects, we return to the top and wait for a new connection. // ulPrevious = 1; setup(); while(1) { // // Tell the user what we are doing and provide some basic instructions. // UARTprintf("Waiting for host...\n"); // // Wait for USB configuration to complete. // while(!g_bConnected) { } // // Update the status. // UARTprintf("Host connected...\n"); // // Enter the idle state. // g_eKeyboardState = STATE_IDLE; // // Assume that the bus is not currently suspended if we have just been // configured. // bLastSuspend = false; // // Keep transferring characters from the UART to the USB host for as // long as we are connected to the host. // while(g_bConnected) { // // Remember the current time. // ulLastTickCount = g_ulSysTickCount; // // Has the suspend state changed since last time we checked? // if(bLastSuspend != g_bSuspended) { // // Yes - the state changed so update the display. // bLastSuspend = g_bSuspended; UARTprintf(bLastSuspend ? "Bus suspended...\n" : "Host connected...\n"); } // // See if the button was just pressed. // ulButton = num; if(ulButton != ulPrevious) { // // If the bus is suspended then resume it. Otherwise, type // some "random" characters. // if(g_bSuspended) { // // We are suspended so request a remote wakeup. // USBDHIDKeyboardRemoteWakeupRequest( (void *)&g_sKeyboardDevice); } else { char s[2] = {0x30+num,0}; SendString(s); } } ulPrevious = ulButton; // // Wait for at least 1 system tick to have gone by before we poll // the buttons again. // while(g_ulSysTickCount == ulLastTickCount) { // // Hang around doing nothing. // } } // // Dropping out of the previous loop indicates that the host has // disconnected so go back and wait for reconnection. // if(g_bConnected == false) { UARTprintf("Host disconnected...\n"); } } }