How to add blinking LED to FreeRTOS/EV-LM3S811
Using the FreeRTOS demo code for the EV-LM3S811, I added a simple task to blink the User LED. It was a good way to begin to understand how FreeRTOS works.
All of the changes are to the 'main.c' file. First, add some #defines (near the 'Demo Board Specifics' #defines):
#define mainUSER_LED GPIO_PIN_5
Right after that, add a #define for the blink rate (1000 ms = 1 second):
#define mainLED_DELAY ((portTickType) 1000/portTICK_RATE_MS)
Add a prototype for the task function:
static void vUserLEDTask(void *pvParameter);
In the main() function, add the call to create the task after the other demo tasks (modelled exactly after the other task create calls):
xTaskCreate(vUserLEDTask, "UserLED", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL);
In the prvSetupHardware() function, add a line to configure the GPIO pin as an output, immediately after the section that configures the push button input:
GPIODirModeSet(GPIO_PORTC_BASE, mainUSER_LED, GPIO_DIR_MODE_OUT);
And finally, add the actual blinking task after the other tasks:
static void vUserLEDTask(void *pvParameter) {
for(;;) { GPIOPinWrite(GPIO_PORTC_BASE, mainUSER_LED, mainUSER_LED); // let it shine vTaskDelay(mainLED_DELAY); GPIOPinWrite(GPIO_PORTC_BASE, mainUSER_LED, 0); // take a break vTaskDelay(mainLED_DELAY); } }
That's it! I hope the long lines don't get too mangled. You might have to drop some of the other demo tasks to get it to fit using the code-limited linker. You could also try space optimizations. Let me know if you have any questions or suggestions about this little experiement.
Dale Wheat
login or register to reply
|