UART LED Project Part 1
Overview
Modify the UART_demo project by adding a command line UI that controls the red and green LEDs via the virtual UART port.
Download the UART_demo zip file and make sure it builds and can be loaded on your STM32 board.
Refer to the UART Demo Project Setup document for instructions on setting up the project for ST Link.
Refer to the UART Virtual Terminal document for instructions on using the virtual terminal on the PC.
Feel free to use the UART LED project discussion topics in myCourses.
UI Requirements
- Implement all of your code in additional function(s) in additional C source file(s).
- The main.c function must NOT have any application code. It just calls your control function in a different source file.
- Use good modular development practices when creating your C language source files. Avoid function of over 20 lines
unless the reason for more that 20 lines is a switch statement.
- All commands are case sensitive.
- All commands are processed when the Enter key is pressed.
- Display "Invalid command" message if not a valid command.
- An incorrect key entry can be corrected by pressing the Backspace key.
This will remove the most recent key and redisplay the remaining command on the next line. NOTE -- you are
also allowed to correct the error in place on the current line. Either approach is acceptable.
- Commands are in bold followed by the description.
- NOTE: All LED ON and OFF commands override the flashing state
- RON Turn on red LED (does nothing if already on)
- ROFF Turn off red LED (does nothing if already off)
- GON Turn on green LED (does nothing if already on)
- GOFF Turn off green LED (does nothing if already off)
- RFLASH Continuous flashing of the red LED (one second on, one second off). This does nothing if red is already flashing)
- GFLASH Continuous flashing of the green LED (one second on, one second off). This does nothing if green is already flashing)
- FLASHOFF Stop all flashing (does nothing if no active flashing)
Software Design Topics
Here are some suggestions on how to design your main control loop.
- In your main control loop you need an infinite loop.
- Be sure to change your USART_Read function to be non-blocking.
- Call this USART_Read function. If it returns a character (non-zero) process that character.
- Wait one millisecond in a spin loop. You can use the USART_Delay function if you want.
- If you are in flashing mode increment a counter to record that you are finishing another loop.
- If you have counted up to 1000 then you have spent 1 second (1000 milliseconds). Change the state
of your LED or LEDs to the opposite state and reset your counter back to 0.
- Pseudo code:
- forever loop
- call USART_Read and save its return value
- If return value is non-zero
- If Enter key see if we have a valid command
- Else if a Backspace remove the previous character from the command buffer and display result
- Else echo the character and add it to the command buffer
- Delay one millisecond (you can use USART_Delay for this if you want)
- If one or both LEDs are flashing
- Increment the loop counter
- If loop counter is 1000 then change state of LEDs and reset counter to 0
- end of forever loop
Startup Code and References
Rubric and Late Policy
100 possible points as described below.
- Demo Sheet
- 5 -- Characters entered by the user must be echoed. An Enter key will result in a CR and LF.
- 10 -- Correct use of the UART.c non-blocking function with the ability to enter at least two letters per second.
- 10 -- Commands must be all upper case and are processed in response to an Enter key.
- 10 -- The four ON and OFF commands work correctly including overriding the flashing state for that LED.
Full credit is possible with no actual flashing operation as long as the project has a flag for controlling flashing.
- 10 -- The "Invalid command" message is displayed when a misspelled command of one or more letters is entered.
The behavior when pressing the Enter key with no letters entered is not specified and is not tested.
- 10 -- Pressing the Backspace key will remove the most recent character and redisplay the shortened line.
The alternate approach of correcting the display in place on the current line is also acceptable.
There are 5 points for the redisplay of the shortened line and the other 5 points for it actually working.
The behavior when pressing the Backspace key on an empty line is not specified and is not tested.
- 10 -- A spin loop function or code exists that will produce a delay from 1 ms. up to 1 sec.
- 15 -- The three flash commands all function correctly. The timing shall be from 0.5 to 1.5 seconds on and 0.5 to 1.5 seconds off.
The only behavior specified is that controlling flashing does function. The initial and terminal states of the LEDs
when controlling flashing is not specified and is not tested.
- 10 -- The code shows a fair attempt at good variable naming and formatting with appropriate comments.
- 10 -- Good modular software design as specified in the requirements.
- Late penalties of 5% per day apply.
Submission
Submit your UART LED source code and project files in a zip file to the UART LED project Part 1 dropbox. Do not include
the project work directories in that zip file. Specifically, do not include DebugConfig, Listings, Objects, and RTE.
In class demos will be on the class day after the project is due.