Embedded Systems Shape The World Course Notes
Last Updated: September 15, 2018 by Pepe Sandoval
If you find the information in this page useful and want to show your support, you can make a donation
Use PayPal
This will help me create more stuff and fix the existent content...
This notes are to setup Keil and Eclipse to work with the TM4C123GXL launchpad in Windows using Eclipse is completely option you can program and debug only with Keil (which is my recommendation) since that's the fastest way to get started if you plan to use windows
Follow the steps which will import a Keil Project and set up eclipse to use Keil when compiling and debugging.
Eclipse will launch Keil to compile and debug when needed but all the interactions and editing will be done ONLY through Eclipse so you won't need to interact with Keil at all or switch to it during your development.
Create a Keil project
Open Keil, go to the menu Project and select New µVision Project
Select the folder to store all the projects files and give a name to the .uvproj file (Creating a folder for this with the same name of the project is recommend)
Select the target device (Stellaris Launchpad uses: TM4C123GH6PM)
Click Yes when asked to add the .s startup files
Right click of the 'Source Group 1' and select Add existing files to group 'Source Group 1'...
Locate and Add the system device file usually called startup_<device>.c (for Stellaris its called system_TM4C123.c and it is in the C:\Keil\ARM\Startup\TI\TM4C123 directory)
Right click on the 'Source Group 1' and select Add new item to group 'Source Group 1'... ; select C File (.c), name it main.c in the Name field and click the Add button.
Creating a file with this method might not add it automatically so use Add existing files to group 'Source Group 1'... option in that case
Add a main function to the main.c file and save it:
int main(void){ while(1){} }
Now the code is ready to be compiled and downloaded to the target (In the menu Flash -> Configure Flash Tool... check the Debug tab)
It's recommended to rename the Target 1 and Source Group 1 folders
c:\keil\uv4\uv4.exe -b ProjectName.uvproj -o errors.txt type errors.txt
Make sure to change the ProjectName to the name of your project
Open Keil and click on Project -> New uVision Project...
Create a folder with the project name and save the .uvproj
file there
Select CPU -> TM4C123GH6PM and select Yes when asked whether to add Startup
file
In the Manage Project Items (Project -> Manage -> Components, Environments, Books...) In the Project Targets Column Rename from Target 1 to the name of your project
Create a new file File -> New... and save it to the folder of the project (Use File -> Save As...) usually main.c
Add code and add it your project with Right-click over Sources Group 1 and select Add Existing Files to Group Sources Group 1
#define GPIO_PORTF_DATA_R (*((volatile unsigned long *) 0x400253FC))
#define GPIO_PORTF_DIR_R (*((volatile unsigned long *) 0x40025400))
#define GPIO_PORTF_AFSEL_R (*((volatile unsigned long *) 0x40025420))
#define GPIO_PORTF_PUR_R (*((volatile unsigned long *) 0x40025510))
#define GPIO_PORTF_DEN_R (*((volatile unsigned long *) 0x4002551C))
#define GPIO_PORTF_LOCK_R (*((volatile unsigned long *) 0x40025520))
#define GPIO_PORTF_CR_R (*((volatile unsigned long *) 0x40025524))
#define GPIO_PORTF_AMSEL_R (*((volatile unsigned long *) 0x40025528))
#define GPIO_PORTF_PCTL_R (*((volatile unsigned long *) 0x4002552C))
#define SYSCTL_RCGC2_R (*((volatile unsigned long *) 0x400FE108))
unsigned long SW1,SW2; // input from PF4,PF0
unsigned long Out; // outputs to PF3,PF2,PF1 (multicolor LED)
// Function Prototypes
void PortF_Init(void);
void Delay(void);
int main(void){
PortF_Init(); // make PF1 out (PF1 built-in LED)
while(1){
SW1 = GPIO_PORTF_DATA_R&0x10; // read PF4 into SW1
SW2 = GPIO_PORTF_DATA_R&0x01; // read PF0 into SW2
if (SW1 == 0 && SW2 == 0) // both pressed
{
GPIO_PORTF_DATA_R = 0x04; // LED is blue
} else if (SW1 == 0 && SW2 != 0) // just SW1 pressed
{
GPIO_PORTF_DATA_R = 0x02; // LED is red
} else if (SW1 != 0 && SW2 == 0) // just SW2 pressed
{
GPIO_PORTF_DATA_R = 0x08; // LED is green
}else // neither switch
{
GPIO_PORTF_DATA_R = 0x00; // LED is off
}
}
}
void PortF_Init(void){
volatile unsigned long delay;
SYSCTL_RCGC2_R |= 0x00000020; // 1) F clock
delay = SYSCTL_RCGC2_R; // delay
GPIO_PORTF_LOCK_R = 0x4C4F434B; // 2) unlock PortF PF0
GPIO_PORTF_CR_R = 0x1F; // allow changes to PF4-0
GPIO_PORTF_AMSEL_R = 0x00; // 3) disable analog function
GPIO_PORTF_PCTL_R = 0x00000000; // 4) GPIO clear bit PCTL
GPIO_PORTF_DIR_R = 0x0E; // 5) PF4,PF0 input, PF3,PF2,PF1 output
GPIO_PORTF_AFSEL_R = 0x00; // 6) no alternate function
GPIO_PORTF_PUR_R = 0x11; // enable pullup resistors on PF4,PF0
GPIO_PORTF_DEN_R = 0x1F; // 7) enable digital pins PF4-PF0
}
void Delay(void){
unsigned long volatile time;
time = 145448; // 0.1sec
while(time){
time--;
}
}
In the Target Options (Project -> Options For Target) in the Target tab change Floating Point Hardware Field to Not Used
In the Target Options (Project -> Options For Target) in the Target tab change make sure Stellaris ICDI is selected in the Use Field
-dLaunchPad
in the Dialog DLL -> Parameter in case you want to use simulatorIf you want to run code before reaching main
you can define a ``void SystemInit(void)` function and will be called before the main
.uvproj
and .uvopt
files.uvproj
) and clean it (Project -> Clean Target)Install Keil plugin (MDK-ARM Plug-in)
Import your Keil project
Set up the build command
You can now build your project but the errors might not be correctly or in a nice way to configure that you can optionally define a custom error parser
Severity | Pattern |
---|---|
Error | Error: (.*)\((\d+)\):\s+error:\s+(.*) |
Warning | Warning: (.*)\((\d+)\):\s+warning:\s+(.*) |
Info | Info: (.*)\((\d+)\):\s+info(.*) |
Once you have successfully imported a Keil Project It can be debugged right away from Eclipse if the Keil Plug-In was installed successfully so you just have to right click over the project and select Debug As... -> µVision Project
To Change between the on board simulator and the actual on board debugger follow these steps:
This one time setup will allow you to build/compile, load and debug code on the Stellaris Launchpad on Linux
Install dependencies
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install flex bison libgmp3-dev libmpfr-dev libncurses5-dev libmpc-dev autoconf texinfo build-essential libftdi-dev python-yaml zlib1g-dev libtool
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386
sudo apt-get install libusb-1.0-0 libusb-1.0-0-dev
Install the gcc-arm-none-eabi
mkdir ~/embedded
tar -xvf ~/Downloads/gcc-arm-none-eabi-5_2-2015q4-20151219-linux.tar.bz2 -C ~/embedded
export PATH=$PATH:$HOME/embedded/gcc-arm-none-eabi-5_2-2015q4/bin
sudo apt install gcc-arm-none-eabi
Install and build TivaWare for Tiva C Series
mkdir ~/embedded/tivaware
mv ~/Downloads/SW-EK-TM4C123GXL-2.1.2.111.exe ~/embedded/tivaware/.
unzip ~/embedded/tivaware/SW-EK-TM4C123GXL-2.1.2.111.exe -d ~/embedded/tivaware/.
(cd ~/embedded/tivaware/; make)
Get lm4flash and build it. This is used to load binaries into our board
(cd ~/embedded; git clone https://github.com/utzig/lm4tools.git)
(cd ~/embedded/lm4tools/lm4flash/; make)
Optionally you can add an
alias
on your.bashrc
file to flash bins using only the command lm4flash. Add:alias lm4flash='sudo ~/embedded/lm4tools/lm4flash/lm4flash'
Get OpenOCD, build and install it
cd ~/embedded
git clone http://git.code.sf.net/p/openocd/code openocd
cd openocd
./bootstrap
./configure --enable-maintainer-mode --enable-ti-icdi --prefix=`pwd`/.
make -j3
sudo make install
This should install OpenOCD in /usr/local/
cp -r ~/embedded/tivaware/examples/boards/ek-tm4c123gxl/blinky <path_to_project>
<path_to_project>/Makefile
accordingly, usually you just need to modify the paths to TivaWare<path_to_project>/<compiler>
folder using lm4flashsudo ~/embedded/lm4tools/lm4flash/lm4flash <path_to_project>/<compiler>/<bin_name>.bin
sudo ~/embedded/lm4tools/lm4flash/lm4flash ~/embedded/test/gcc/main.bin
Build your project as you did on the Create, Build and Load section to get the .bin and .out files
Open a new terminal and start OpenOCD with the right .cfg file
sudo openocd --file ~/embedded/openocd/tcl/board/ek-tm4c123gxl.cfg
Open a new terminal and execute gdb and give the .out as input
arm-none-eabi-gdb -ex 'target remote localhost:3333;' <path_to_project>/build/<bin_name>.out
arm-none-eabi-gdb -ex 'target remote localhost:3333;' ~/embedded/tiva-template/build/a.out
Once gdb has started execute the following commands
(gdb) monitor reset halt
(gdb) load
(gdb) monitor reset init
After this you can execute regular gdb commands to debug. To test this execute the continue
gdb command to run the program
You can use
ctrl+c
on the terminal where you executed thecontinue
command to stop executing the program on the board and then usequit
to exit gdb if prompt for active debug session hit yes (y
)
Alternatively you can create a .in file with the previous gdb commands so you don't have type them every time
vim gdb_comms.in
) # Specify remote target
target extended-remote :3333
# Reset to known state
monitor reset halt
load
monitor reset init
# Set a breakpoint at main().
break main
# Run to the breakpoint.
continue
OpenOCD must be running as we did on the Debug using gdb section
Execute arm-none-eabi-gdb
, use the --command
and give the .in file that has the gdb commands
arm-none-eabi-gdb --command=<path_to_project>/gdb_comms.in <path_to_project>/build/<bin_name>.out
arm-none-eabi-gdb --command=./gdb_comms.in build/a.out
Here are the links I used to put up this Note, basically I copied everything from other people 😜
sleep 7
xterm -hold -e 'sudo openocd --file ~/embedded/openocd/tcl/board/ek-tm4c123gxl.cfg' &
If you find the information in this page useful and want to show your support, you can make a donation
Use PayPal
This will help me create more stuff and fix the existent content...