Lesson 012: Full Peripheral Application

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:

  1. Use newlib-nano
  2. Use float with nano printf
  3. Use float with nano scanf
  4. 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:
S5:1: ON
S5:2: OFF
S5:3: OFF
S5:4: ON
S5:5: ON
S5:6: ON
S5:7: OFF
S5:8: OFF

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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s