/Tiva_Make

Makefile for Texas Instruments' Tiva-C microcontroller

Primary LanguageC

Tiva_Make

Makefile for Texas Instruments' Tiva-C microcontroller

Description

Uses a Makefile to build an app for the Tiva-C that blinks an onboard LED and prints "Hello World!" to a UART. Pretty simple, but the Makefile also supports fancier stuff, especially floating-point math on the Tiva, which can be a pain to figure out from scratch.

Setup

The setup instructions closely follow this extremely helpful reference.

In particular, the instructions on that page have you create a single Embedded folder, within which you install Tivaware and lm4tools. This simplifies the Makefile, as we'll see below.

  • For Linux users, the path to Embedded is ~/Embedded.
  • For Windows users, the path to Embedded is C:\Users\<user_name>\Embedded (replace <user_name> with your user name).

If you follow the instructions linked above, you can also install OpenOCD, the Open On-Chip Debugger, but we don't need it for now, so I won't get into it in this project template.

All users: complete Step 1 of the reference linked above. Linux users: also complete Step 2 of the reference linked above.

Install the software listed below, then clone this repo into your newly-created Embedded folder.

What you need to install

  • Windows users: MinGW (default path is C:\MinGW, this is fine.)
  • Windows users: PuTTY (the installer automatically adds PuTTY to the Windows PATH variable, this is fine.)
  • Linux users: screen (sudo apt-get install screen)
  • Windows users: LM Flash Programmer is TI's firmware-flashing tool (GUI and command line). Take note of where the installer puts it (C:\Program Files (x86)\Texas Instruments\Stellaris\LM Flash Programmer\); you'll need to enter this location in the Makefile later. You must also install Stellaris ICDI drivers, which you can do by following TI's instructions.
  • Linux users: lm4tools is a user-developed open-source alternative to TI's LM Flash Programmer. This repo contains lm4flash, a command-line firmware flashing tool which our Makefile will use. Clone the repo to ~/Embedded, then cd ~/Embedded/lm4tools/lm4flash/ and finally make.
  • All users: download and install the GNU Arm Embedded Toolchain. This toolchain includes arm-none-eabi-gcc (a GCC cross compiler) and arm-none-eabi-ld (a GCC linker).
    • Windows users: just download and run the Windows installer.
    • Linux users: download and extract the tarball (.tar.bz2)
    • Once installed, you will need to add the bin subfolder to your path, permanently (Linux users: edit your .bashrc file and then source it; Windows users add the folder to 'Path' using the environment variable editor).
  • All users: download the topmost executable (.exe) file from the Tivaware download list.
    • Windows users: just download and run the installer. Take note of where the files are installed, because you'll need to enter this location in the Makefile.
    • Linux users: rename the file extension to .zip and extract the file to a folder ~/Embedded/tivaware. Compile with make. If make throws an errors and says it can't find the compiler, enter sudo apt-get install gcc-arm-none-eabi.

Linux users: using LM4flash without sudo privileges

You will have to set up some udev rules to communicate with your device via USB (for example, using lm4flash) without using sudo (references: this post and this post).

These rules won't take effect until you reboot.

dan@thinkpad$ cd /etc/udev/rules.d
dan@thinkpad:/etc/udev/rules.d$ echo "SUBSYSTEM=="usb", ATTRS{idVendor}=="1cbe", ATTRS{idProduct}=="00fd", MODE="0660"" | sudo tee 99-tiva-launchpad.rules

dan@thinkpad:/etc/udev/rules.d$ sudo touch /etc/udev/rules.d/10-local.rules
dan@thinkpad:/etc/udev/rules.d$ cat /etc/udev/rules.d/10-local.rules
ATTR{idVendor}=="15ba", ATTR{idProduct}=="0004", GROUP="plugdev", MODE="0660" # Olimex Ltd. OpenOCD JTAG TINY
ATTR{idVendor}=="067b", ATTR{idProduct}=="2303", GROUP="plugdev", MODE="0660" # Prolific Technology, Inc. PL2303 Serial Port
ATTR{idVendor}=="10c4", ATTR{idProduct}=="ea60", GROUP="plugdev", MODE="0660" # USB Serial
ATTR{idVendor}=="1cbe", ATTR{idProduct}=="00fd", GROUP="plugdev", MODE="0660" # TI Stellaris Launchpad

dan@thinkpad:/etc/udev/rules.d$ sudo udevadm control --reload-rules
dan@thinkpad:/etc/udev/rules.d$ sudo groupadd plugdev
dan@thinkpad:/etc/udev/rules.d$ sudo usermod -aG plugdev,dialout $USER

# Remember to unplug and logout:
dan@thinkpad:/etc/udev/rules.d$ sudo reboot

After rebooting, you should be able to run make flash without sudo, but you aren't ready to test it yet; follow the instructions in the next section first!

Project structure

Your project should reside in a folder. For example, this project resides in a folder called Tiva_Make. You can begin a new project by making a duplicate of Tiva_Make and renaming it.

In the project's root folder, there must be (at minimum) a Makefile, a bootloader (TM4C123GH6PM.ld) and three subfolders: src, inc, and build.

  • C files (.c) that you write go in src.
  • Header files (.h) that you write go in inc.
  • Files produced during building (compiling and linking) are automatically stored in the build folder. You don't need to do anything yourself in the build folder.

With one exception, you shouldn't copy any Tivaware code to your project folder. That one exception is tivaware/utils/uartstdio.c: copy that file to your src folder.

What you need to modify in the Makefile

Only modify the part of the Makefile sandwiched between

#######################################
# user configuration:
#######################################

and

#######################################
# end of user configuration
#######################################

Everything else is off-limits unless you know what you're doing!

Although the folder structure described earlier simplifies and standardizes the build process, the Makefile needs to know where a few other things are.

Editing paths in the Makefile

The relevant part of the Makefile is shown below. Simply edit each variable (XC_PATH, PORT, etc.) according to the OS-specific comments (Makefile comments begin with a #) directly above that variable.

# Path to the ARM cross-compiler:
# Linux users: the path will be $(HOME)/Embedded/gcc-arm-none-eabi-5_4-2016q3/bin
# Windows users: the path will be "C:/Program Files (x86)/GNU Tools ARM Embedded/5.4 2016q3/bin"
XC_PATH = $(HOME)/Embedded/gcc-arm-none-eabi-5_4-2016q3/bin

# Serial port:
# Linux users: the port will be something like /dev/ttyACM0
# Windows users: the port will be something like COM4
PORT=/dev/ttyACM0

# Terminal emulator:
# Linux: the terminal emulator is screen
# Windows: the terminal emulator is putty (all lowercase)
TERMEMU=screen

# TIVAWARE_PATH: path to tivaware folder
TIVAWARE_PATH = $(HOME)/Embedded/tivaware

# FLASH_PATH: path to lm4flash (Linux) or LM Flash Programmer (Windows)
# Linux: $(HOME)/Embedded/lm4tools/lm4flash
# Windows: "C:/Program Files (x86)/Texas Instruments/Stellaris/LM Flash Programmer"
FLASH_PATH = $(HOME)/Embedded/lm4tools/lm4flash

# additional libraries
# libdriver.a path: tivaware/driverlib/gcc/
DRIVERLIB_PATH = $(TIVAWARE_PATH)/driverlib/gcc

Operation

Once you're in the top folder of your project (where the Makefile is), build the project simply by entering make at a command prompt.

Entering make clean will delete all the files in the build\ folder but nothing else.

Entering make flash will flash the built binary file to the Tiva microcontroller.

To verify that everything works, enter make screen (Linux) or make putty (Windows)

If everything worked, you should now see Hello World! repeatedly printing to your terminal emulator.