Lesson 12 is a much larger program that what we’ve seen so far. There is code for most of the peripherals that have been covered so far. These include:
- Analog To Digital Converter (ADC)
- Digital To Analog Converter (DAC)
- GPIO output with Timers
- GPIO input
- UART with input and output redirection
The code itself is pretty straight forward. It’s posted on GitHub (https://github.com/lycannon/ajwrs).
I’ll cover some project settings, the overall idea of the program, and some specifics on a few areas.
First, to handle input and output redirection to UART (or any other device), there are a few project settings.
Right click on your project, and click Renesas Tool Settings.
Under Cross ARM C Linker=>Miscellaneous, set the following:
- Use newlib-nano
- Use float with nano printf
- Use float with nano scanf
- Other linker flags: Replace any text that may be there with –specs=nosys.specs
Items 1, 2 are for printf. Including option 2 will increase the size of the executable (not sure by how much).
Item 3 is not required for this project since all the inputs are integers, but I’ve included it just in case. Like float with printf, float with scanf will increase the size of your executable.
Item 4 is necessary to redirect STDIN. Be default, ARM microcontrollers use the USB debug connection to take STDIN from the debug console. In order to get STDIN to use UART, we need to turn off the debug settings.
Click OK to close the Properties window.
On the S7-DK board, set the following switches:
The hal_entry.c file initializes all the peripherals and enters an infinite loop calling MenuPrint() from Menu.c.
The MenuPrint() prints out information and action choices on the UART.
At the bottom of the printed menu, a loop starts and waits for user input. If the user enters a valid menu option, the application performs the requested function and exits the loop. If an invalid choice is provided, the user is notified of an invalid choice and is prompted again.
The MenuRead function uses scanf to grab a single character from the UART console.
The Uart.c file overwrites _read and _write for scanf and printf functionality. Both functions rely on interrupts and callbacks set in the Synergy Configuration file.