//***************************************************************************** // // This example demonstrates how to setup the PWM block to generate signals. // //***************************************************************************** int main(void) { unsigned long ulPeriod; // // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_1); // // Initialize 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); // // Tell the user what is happening. // UARTprintf("\033[2JGenerating PWM on PD0 and PD1\n"); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // // Set GPIO D0 and D1 as PWM pins. They are used to output the PWM0 and // PWM1 signals. // GPIOPinConfigure(GPIO_PD0_PWM0); GPIOPinConfigure(GPIO_PD1_PWM1); ROM_GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Compute the PWM period based on the system clock. // ulPeriod = ROM_SysCtlClockGet() / 440; // // Set the PWM period to 440 (A) Hz. // ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC); ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ulPeriod); // // Set PWM0 to a duty cycle of 25% and PWM1 to a duty cycle of 75%. // ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, ulPeriod / 4); ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, (ulPeriod * 3) / 4); // // Enable the PWM0 and PWM1 output signals. // ROM_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, true); // // Enable the PWM generator. // ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_0); // // Loop forever while the PWM signals are generated. // while(1) { } }
//***************************************************************************** // // This example demonstrates how to use the uDMA controller to transfer data // between memory buffers and to and from a peripheral, in this case a UART. // The uDMA controller is configured to repeatedly transfer a block of data // from one memory buffer to another. It is also set up to repeatedly copy a // block of data from a buffer to the UART output. The UART data is looped // back so the same data is received, and the uDMA controlled is configured to // continuously receive the UART data using ping-pong buffers. // // The processor is put to sleep when it is not doing anything, and this allows // collection of CPU usage data to see how much CPU is being used while the // data transfers are ongoing. // //***************************************************************************** int main(void) { static unsigned long ulPrevSeconds; static unsigned long ulPrevXferCount; static unsigned long ulPrevUARTCount = 0; unsigned long ulXfersCompleted; unsigned long ulBytesTransferred; unsigned long ulButton; // // Set the clocking to run from the PLL at 50 MHz. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Enable peripherals to operate when CPU is in sleep. // ROM_SysCtlPeripheralClockGating(true); // // Set the push button as an input with a pull-up. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_4, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // // Initialize the UART. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioInit(0); UARTprintf("\033[2JuDMA Example\n"); // // Show the clock frequency and exit instructions. // UARTprintf("Stellaris @ %u MHz\n", ROM_SysCtlClockGet() / 1000000); UARTprintf("Press button to use debugger.\n\n"); // // Show statistics headings. // UARTprintf("CPU Memory UART\n"); UARTprintf("Usage Transfers Transfers\n"); // // Configure SysTick to occur 100 times per second, to use as a time // reference. Enable SysTick to generate interrupts. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Initialize the CPU usage measurement routine. // CPUUsageInit(ROM_SysCtlClockGet(), SYSTICKS_PER_SECOND, 2); // // Enable the uDMA controller at the system level. Enable it to continue // to run while the processor is in sleep. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UDMA); // // Enable the uDMA controller error interrupt. This interrupt will occur // if there is a bus error during a transfer. // ROM_IntEnable(INT_UDMAERR); // // Enable the uDMA controller. // ROM_uDMAEnable(); // // Point at the control table to use for channel control structures. // ROM_uDMAControlBaseSet(ucControlTable); // // Initialize the uDMA memory to memory transfers. // InitSWTransfer(); // // Initialize the uDMA UART transfers. // InitUART1Transfer(); // // Remember the current SysTick seconds count. // ulPrevSeconds = g_ulSeconds; // // Remember the current count of memory buffer transfers. // ulPrevXferCount = g_ulMemXferCount; // // Loop until the button is pressed. The processor is put to sleep // in this loop so that CPU utilization can be measured. When the // processor is sleeping a lot, it can be hard to connect to the target // with the debugger. Pressing the button will cause this loop to exit // and the processor will no longer sleep. // while(1) { // // Check for the select button press. If the button is pressed, // then exit this loop. // ulButton = ROM_GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_4); if(!ulButton) { break; } // // Check to see if one second has elapsed. If so, the make some // updates. // if(g_ulSeconds != ulPrevSeconds) { // // Print a message to the display showing the CPU usage percent. // The fractional part of the percent value is ignored. // UARTprintf("\r%3d%% ", g_ulCPUUsage >> 16); // // Remember the new seconds count. // ulPrevSeconds = g_ulSeconds; // // Calculate how many memory transfers have occurred since the last // second. // ulXfersCompleted = g_ulMemXferCount - ulPrevXferCount; // // Remember the new transfer count. // ulPrevXferCount = g_ulMemXferCount; // // Compute how many bytes were transferred in the memory transfer // since the last second. // ulBytesTransferred = ulXfersCompleted * MEM_BUFFER_SIZE * 4; // // Print a message showing the memory transfer rate. // if(ulBytesTransferred >= 100000000) { UARTprintf("%3d MB/s ", ulBytesTransferred / 1000000); } else if(ulBytesTransferred >= 10000000) { UARTprintf("%2d.%01d MB/s ", ulBytesTransferred / 1000000, (ulBytesTransferred % 1000000) / 100000); } else if(ulBytesTransferred >= 1000000) { UARTprintf("%1d.%02d MB/s ", ulBytesTransferred / 1000000, (ulBytesTransferred % 1000000) / 10000); } else if(ulBytesTransferred >= 100000) { UARTprintf("%3d KB/s ", ulBytesTransferred / 1000); } else if(ulBytesTransferred >= 10000) { UARTprintf("%2d.%01d KB/s ", ulBytesTransferred / 1000, (ulBytesTransferred % 1000) / 100); } else if(ulBytesTransferred >= 1000) { UARTprintf("%1d.%02d KB/s ", ulBytesTransferred / 1000, (ulBytesTransferred % 1000) / 10); } else if(ulBytesTransferred >= 100) { UARTprintf("%3d B/s ", ulBytesTransferred); } else if(ulBytesTransferred >= 10) { UARTprintf("%2d B/s ", ulBytesTransferred); } else { UARTprintf("%1d B/s ", ulBytesTransferred); } // // Calculate how many UART transfers have occurred since the last // second. // ulXfersCompleted = (g_ulRxBufACount + g_ulRxBufBCount - ulPrevUARTCount); // // Remember the new UART transfer count. // ulPrevUARTCount = g_ulRxBufACount + g_ulRxBufBCount; // // Compute how many bytes were transferred by the UART. The number // of bytes received is multiplied by 2 so that the TX bytes // transferred are also accounted for. // ulBytesTransferred = ulXfersCompleted * UART_RXBUF_SIZE * 2; // // Print a message showing the UART transfer rate. // if(ulBytesTransferred >= 1000000) { UARTprintf("%1d.%02d MB/s ", ulBytesTransferred / 1000000, (ulBytesTransferred % 1000000) / 10000); } else if(ulBytesTransferred >= 100000) { UARTprintf("%3d KB/s ", ulBytesTransferred / 1000); } else if(ulBytesTransferred >= 10000) { UARTprintf("%2d.%01d KB/s ", ulBytesTransferred / 1000, (ulBytesTransferred % 1000) / 100); } else if(ulBytesTransferred >= 1000) { UARTprintf("%1d.%02d KB/s ", ulBytesTransferred / 1000, (ulBytesTransferred % 1000) / 10); } else if(ulBytesTransferred >= 100) { UARTprintf("%3d B/s ", ulBytesTransferred); } else if(ulBytesTransferred >= 10) { UARTprintf("%2d B/s ", ulBytesTransferred); } else { UARTprintf("%1d B/s ", ulBytesTransferred); } // // Print a spinning line to make it more apparent that there is // something happening. // UARTprintf("%c", g_pcTwirl[ulPrevSeconds % 4]); } // // Put the processor to sleep if there is nothing to do. This allows // the CPU usage routine to measure the number of free CPU cycles. // If the processor is sleeping a lot, it can be hard to connect to // the target with the debugger. // ROM_SysCtlSleep(); }
//***************************************************************************** // // This example application demonstrates the use of the timers to generate // periodic interrupts. // //***************************************************************************** int main(void) { tRectangle sRect; // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPULazyStackingEnable(); // // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Initialize the display driver. // CFAL96x64x16Init(); // // Initialize the graphics context and find the middle X coordinate. // GrContextInit(&g_sContext, &g_sCFAL96x64x16); // // Fill the top part of the screen with blue to create the banner. // sRect.i16XMin = 0; sRect.i16YMin = 0; sRect.i16XMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.i16YMax = 9; GrContextForegroundSet(&g_sContext, ClrDarkBlue); GrRectFill(&g_sContext, &sRect); // // Change foreground for white text. // GrContextForegroundSet(&g_sContext, ClrWhite); // // Put the application name in the middle of the banner. // GrContextFontSet(&g_sContext, g_psFontFixed6x8); GrStringDrawCentered(&g_sContext, "timers", -1, GrContextDpyWidthGet(&g_sContext) / 2, 4, 0); // // Initialize timer status display. // GrContextFontSet(&g_sContext, g_psFontFixed6x8); GrStringDraw(&g_sContext, "Timer 0:", -1, 16, 26, 0); GrStringDraw(&g_sContext, "Timer 1:", -1, 16, 36, 0); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); // // Enable processor interrupts. // ROM_IntMasterEnable(); // // Configure the two 32-bit periodic timers. // ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC); ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet()); ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, ROM_SysCtlClockGet() / 2); // // Setup the interrupts for the timer timeouts. // ROM_IntEnable(INT_TIMER0A); ROM_IntEnable(INT_TIMER1A); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); // // Enable the timers. // ROM_TimerEnable(TIMER0_BASE, TIMER_A); ROM_TimerEnable(TIMER1_BASE, TIMER_A); // // Loop forever while the timers run. // while(1) { } }
//***************************************************************************** // // This example demonstrates how to send a string of data to the UART. // //***************************************************************************** int main(void) { tRectangle sRect; tContext sContext; // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPULazyStackingEnable(); // // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Initialize the display driver. // CFAL96x64x16Init(); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sCFAL96x64x16); // // Fill the top part of the screen with blue to create the banner. // sRect.i16XMin = 0; sRect.i16YMin = 0; sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1; sRect.i16YMax = 9; GrContextForegroundSet(&sContext, ClrDarkBlue); GrRectFill(&sContext, &sRect); // // Change foreground for white text. // GrContextForegroundSet(&sContext, ClrWhite); // // Put the application name in the middle of the banner. // GrContextFontSet(&sContext, g_psFontFixed6x8); GrStringDrawCentered(&sContext, "uart-echo", -1, GrContextDpyWidthGet(&sContext) / 2, 4, 0); // // Initialize the display and write some instructions. // GrStringDrawCentered(&sContext, "Connect a", -1, GrContextDpyWidthGet(&sContext) / 2, 20, false); GrStringDrawCentered(&sContext, "terminal", -1, GrContextDpyWidthGet(&sContext) / 2, 30, false); GrStringDrawCentered(&sContext, "to UART0.", -1, GrContextDpyWidthGet(&sContext) / 2, 40, false); GrStringDrawCentered(&sContext, "115000,N,8,1", -1, GrContextDpyWidthGet(&sContext) / 2, 50, false); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); // // Enable processor interrupts. // ROM_IntMasterEnable(); // // Set GPIO A0 and A1 as UART pins. // ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Configure the UART for 115,200, 8-N-1 operation. // ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); // // Enable the UART interrupt. // ROM_IntEnable(INT_UART0); ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); // // Prompt for text to be entered. // UARTSend((uint8_t *)"Enter text: ", 12); // // Loop forever echoing data through the UART. // while(1) { } }