When I started programming a Stellaris device, I could at once run samples from Stellarisware,
and modify them to fit my needs. That could be done without too much trouble.
However, the disadvantage is that I couldn't get a full understanding of what the software does
because for a given sample code that includes device drivers, there was a lot of included files that
were not actually used by the sample application.
This time, I have decided to go back to the basics and try to build a program of my own, by
simply using the different peripherals definitions and nothing more (only the processor-specific
.h file). No lib of any sort for the time being. The development board I am using is ek-lm3s6965.
The flow of the present tutorial is as follows:
1. Development environment
2. Creating a workspace
3. Creating a project
4. Create a main function
5. Create a configuration file.
6. Enhancing the first program
7. Conclusion
1. Development environment
Here are the OS, IDE and development board I have used in this experiment:
1.1 Windows 7 Ultimate
1.2 Code Composer Studio 4.2.4
Click image to enlarge.
1.3 ek-lm3s6965 development board
Debug interface: ek-lm3s6965 on board emulator (connects directly to PC via USB).
2. Creating a workspace
Start CCS. It should automatically point you to a default workspace. If you want
to choose your own workspace, that the good timig to change it. In my case, I use
several workspaces for other development environments. They are all located in
my own user directory in the Develop folder. In this folder, I have created a new
folder which will be used as a container for my default workspace: CodeWerkStellaris.
As I create one workspace per project family, I have created CCS_DevTest. The open
file panel looks like this:
Click image to enlarge.
Note that these folders will be automatically created if they don't exist. In case you didn't
install Flash on your computer, CCS will ask you if you want to. You can just ignore and press
“Don't Install” as Flash is not used for Stellaris development. This is up to you, you can also
choose install if you like fancy (and useless) gadgets.
Click image to enlarge.
After clicking either of the 2 solutions, you areYou can now just close the welcome panel
(cross on the right of its tab).
Click image to enlarge.
This will bring you directly to the workspace which should look more or less like the following picture.
Click image to enlarge.
The first step is done. We are now going to create a project.
3. Creating a project
Open the file menu → New → CCS Project
Click image to enlarge.
The project name in this case is CCEDevTest1.
Pressing next, we get the following window:
Click image to enlarge.
Just verify that the setting is “ARM” (change to ARM if not) and press next.
Click image to enlarge.
As the purpose of this tutorial is to start from scratch, no referenced project. Press next.
Click image to enlarge.
You have to select the processor to be used (here lm3s6965).
In “device variant”, change <select filter> to Cortex M. The “Generic ARM11 device” will
change and give you a list of the existing Stellaris Cortex M3. Go towards the bottom of the
list and choose lm3s6965. The endianness changes automatically to little, the output format
to ELF. The result is as follows:
Click image to enlarge.
Press “finish”.
Now we have to enter a minimal main program to check whether it compiles.
- Code: Select all
int main(void) {
return 0;
}
From File menu, select “new file”. In the file panel, set the file name (in my case CCSDevTest1.cpp)
and click “open”. A new empty file is created. You can see this file in the IDE's left pane (C/C++
projects pane). Here is the upper left part of the window.
Click image to enlarge.
By double-clicking a file name in the left pane, you can edit it. In the above picture, CCSDevTest1.cpp
is opened in an editor in the center pane of the IDE. You can now enter some text (the main function).
Note that a star appears as soon as you enter text, indicating that the file is not saved.
Compiling the file:
By pressing the button that looks like a green bug, you can compile and run your software. Let's try this.
An information panel pops up, saying that we need a target configuration file. At this point, we have no
other choice, so we will create a target configuration file, whatever it is. Click yes.
Click image to enlarge.
The IDE asks for a name for this configuration file. Let's enter ccsdevtest.ccxml.
Click image to enlarge.
Press finish.
The target configuration file shows up directly in its editor. The following image is the center part of the IDE.
Click image to enlarge.
The “Connection” field states what the editor will connect to. You should choose “Stellaris in-circuit debug
interface” or change accordingly it you use an external JTAG emulator.
In the Device field, check “Stellaris LM3S6965”, and press Save.
Now this time, if you press again the bug-like button (debug launch), the program will be loaded to the
board and execute. When the program is loaded, the current execution line has a green background color
(provided you didn't change the the defaults).
Now we are going to do a little bit more: fill an array and look at some variables, look at the memory.
I have modified the program as follows :
Click image to enlarge.
The program simply fills an array with a Fibonacci series and returns after 64 steps. As this consists only
in additions, there is no need of any library. Not the blue point at line 13. it is a brealpoint that you can
toggle by double-clicking in the gray zone at the left of the line numbers. Run it in debug mode (green
bug-like button).
Now when you are in debug mode, you can go to the view menu and choose memory. The IDE will
display a memory pane among its subpanes. Note that you can rearrange the subpanes as you wish.
Click image to enlarge.
You can proceed to the next breakpoint by pressing the Run button (right green arrow).
Now if you choose to view the memory you will get the following output:
In this case, I have entered the name of the array I am using (arr) and the IDE automatically displays its contents.
Click image to enlarge.
At this point, since the program does nothing useful (no output), you may wonder if the program
is really loaded to the target board. Stop the program by pressing the red button in the control toolbar.
Unplug the board and try to run again in debug mode. You will get an error panel which disappears
if you plug the board again.
That's it, you've just built your first program from scratch.
6. Enhancing the first program
This time, we are going to add some useful code, some code that does something.
The hello-world like program in the embedded world is probably a led blinking program.
We are going to use a program which exists in StellarisWare. This program makes exactly what we want.
It is located in $STELLARIS_WARE/Boards/ek-lm3s6965/blinky, $STELLARIS_WARE being the place
where you installed it.
Let's replace our main program file by blinky.c. Now we will also take the lm3s6965.h file and copy
it locally in the current workspace. Let's try to run it (press the bug-like debug button, then press on
the green right arrow: it runs at once and the status led blinks.
Free run. As the program is in flash memory, it should run in standalone when the board is plugged.
Let's stop the IDE, unplug the board (from USB) and plug it again.
It does not work.
The reason is that at this point another file is needed.
When using the IDE, the debugger somewhat knows where to point the program to.
When running in standalone, this has to be set.
In $STELLARIS_WARE/Boards/ek-lm3s6965/blinky, there is a series of files called "startup_xx.c".
_xx is the environment you use, in this case startup_ccs.c.
Let's simply copy this file to our workspace.
By pressing "run debug", the startup_ccs.c file is compiled and linked to our program. It runs the same
way. But this time, if we try to use our demo in standalone, it works.
7. Conclusion
In this tutorial, we have shown how to build a minimal program from scratch, without using
anything else than a plain .h configuration file. This allows to better understand the minimal requirements
for a stellaris program. Basically we have shown that a minimal program using ports needs 3 files:
- A main program file (CCSDevTest.cpp)
- A chip-specific configuration file (lm3s6965.h)
- An IDE-specific startup file (startup_ccs.c).
That's it for today.
Next time I would like to experiment with C++ in order to explore C++ capabilities on ARM.
In embedded world, a restricted version of C++ is used, but the embedded c++ specification was
originally very poor. The next tutorial will explore what is included and what is not in CCS.
Pascal
