IDE&SDCC_C_Compiler.doc - RPI ECSE

__sfr __at (0xE1) PCA0CPL5 ; /* PCA 0 MODULE 5 CAPTURE/COMPARE -
LOW BYTE */ ..... __sbit __at (0xCA) TR3 ; /* TIMER 3 ON/OFF CONTROL */.

Part of the document


ECSE-4790 Microprocessor Systems
8051 IDE Use & SDCC C Compiler
by Alexey Gutin (revised 8/2011) References SDCC Compiler User Guide; C8051F12x Development Kit User's Guide; C8051F120
Reference Manual; C8051F120.h; SDCC libdoc.txt; ASCII table. (These last 3
are attached at the end of this file.)
Introduction In MPS we you will be developing code for the C8051F120 EVB (evaluation
board). This board is from Silicon Laboratories (SiLabs). For that purpose,
you will be using a x86 based PC (your laptop, a desktop, or coprocessor
card in a Sun Ultra 10 workstation) to write and compile the controller
programs. This type of development is called Cross Platform Development.
After generating the machine code for the target environment and before you
can run it you must download it to the C8051F120. When doing cross platform development, extra knowledge of the target
environment is needed. It is important to be able to answer the following
questions: . What is the target processor?
Silicon Laboratories C8051F120 (http://www.silabs.com) . What memory resources does the execution environment have?
128 kBytes of FLASH ROM that extends from 00000 to 0x1FFFF and 8
kBytes of RAM. The compiler - and more specifically the linker - have
been configured to make use of this memory address space. . Are we dealing with only hardware or is there an interface program we
have to go through?
All communication to the C8051F120 evaluation board is currently
through the IDE (integrated development environment) from Silicon
Laboratories running on the PC. The SiLabs IDE is a convenient way to edit, compile, and download source
code written for the microcontroller. While SiLabs provides a nice
interface for making source code changes and easily downloading them to the
development boards, it lacks the actual compiler portion that converts C
code into hex files, the common format used by the 8051. To do this, a
free and widely used open source tool called Small Device C Compiler (SDCC)
is used. SDCC compiles the C code written, and automatically optimizes and
converts it to hex. Due to its popularity, support for SDCC in the SiLabs
IDE comes standard, making it easy and convenient to use. Installing SDCC To install SDCC, follow the simple instructions below: 1. Open the following URL: http://sdcc.sourceforge.net/ . Click on the
Download link under SDCC Home, and click on Sourceforge download page.
Download the latest under Download Now! (should be the latest package
version for Windows). A copy can also be obtained from the course
website:
http://www.ecse.rpi.edu/courses/CStudio/SDCC%20Compiler/sdcc-2.9.0-
setup.exe
2. Open the executable that was just downloaded and allow the installation
wizard to step you through the process of installing SDCC on your
computer. It is recommended that you leave all of the configuration
options and installation paths the same as suggested by the installation
wizard, so that it will be easier to assist you should problems arise.
3. To ensure SDCC was properly installed, click on:
Start Menu(All Programs
and ensure that SDCC shows up on your programs list. If it does, you have
successfully installed SDCC. Installing SiLabs IDE To install the SiLabs IDE, follow the simple instructions below: 1. Open the following URL:
http://www.silabs.com/products/mcu/Pages/8-bit-microcontroller-
software.aspx Click on Silicon Labs IDE (under Download Now). A copy can
also be obtained from the course website:
http://www.ecse.rpi.edu/courses/CStudio/Silabs/mcu_ide_4.10.exe .
2. Open the executable that just downloaded and allow the installation
wizard to step you through the installation process. Once again, it is
recommended that you leave everything at the default settings. If this is
a second install - check the "Maintain or update the instance of this
application ..."
3. To check that SDCC was properly installed, click on:
Start Menu(All Programs
and ensure that Silicon Laboratories shows up on your programs list. If
it does, you have successfully installed the SiLabs IDE. Configuring SiLabs IDE with SDCC To configure SDCC as the compiler in the SiLabs IDE, follow the
instructions below: 1. Click on:
Start(All Programs(Silicon Laboratories(Silicon Laboratories IDE
2. Once open, click on:
Projects(Tool Chain Integration
3. You will see a Preset Name dropdown box under Tool Definition Presets.
Select SDCC 3.x from this menu. The values under Tool Definition should
all change to the correct defaults.
4. Next, you will notice that the Assembler tab is selected by default.
Click on Browse to tell SiLabs where SDCC is installed. If you kept all
the paths to the default as recommended, the path should be:
C:\Program Files\SDCC\bin\sdas8051.exe (or asx8051.exe)
For Windows 7 it may be: C:\Program Files (x86)\SDCC\bin\sdas8051.exe
5. After the assembler path is configured, you will need to configure the
compiler path. To do this, click on the Compiler tab. Once again, click
Browse and select the path to where SDCC is installed. If you kept all
the paths to their defaults, the full path should be:
C:\Program Files\SDCC\bin\sdcc.exe
For Windows 7 it may be: C:\Program Files (x86)\SDCC\bin\sdcc.exe
Check the Command line flags and replace "-l"C:SiLabs/MCU/inc"" with "--
nogcse", leaving all other existing flags as they were ( should be: -c --
debug --use-stdout -V --nogcse).
6. Finally, to configure the linker, select the Linker tab. Click Browse
and select the path where SDCC is installed. The full path for a default
installation should be:
C:\Program Files\SDCC\bin\sdcc.exe
For Windows 7 it may be: C:\Program Files (x86)\SDCC\bin\sdcc.exe
The linker flags should be: --debug --use-stdout -V
7. Once you have made these changes, click on Save As under Tool Definition
Presets, enter MPS as the Preset Name and click OK. Now click OK in the
Tool Chain Integration panel. It is very important that you do not change
anything outside of what has been mentioned above, especially the command
line flags passed to SDCC. Unfortunately, whenever a new project is
created (see below), you must select MPS as the Preset Name and select No
for Save Modified Presets. This seems to be a bug in the current IDE,
otherwise it will not default to these correct MPS settings.
8. You have successfully set up SiLabs IDE to use SDCC! Creating a Project NOTE: project files have the extension .wsp. Clicking on this file will
start up the SiLabs IDE. 1. Copy C source code into a text file with a .c extension (ex. Hello.c)
and move it to a desired folder to be used for the new project (ex.
C:\SiLabs\NEW_PROJ).
2. To create a new project, click on:
Project(New Project...
Pick C8051F12x_13x in the "New" window for Select Device Family:,
specify a Project Name: (ex. NEW_PROJ), then select the Location: (ex.
C:\SiLabs\NEW_PROJ), set Project Type: to Blank Project, and click OK. This
will create an empty project.
3. Use Project(Add Files to Project... to add your C source file (ex.
Hello.c) and header file (putget.h) to the project. After this, right-
click on the source file name in the left side "File ..." window and
select Add xxx to build. Do the same with the header file.
4. The file will now be part of the project, and can be compiled. Save the
project by clicking on:
Project(Save Project
5. The SDCC has some default compiler flags that may cause trouble in
programs using interrupt routines. To turn off those features, make sure
you made the changes to Tool Chain Integration outlined above in
Configuring SiLabs IDE with SDCC. Unfortunately, you may need to specify
MPS in Tool Definition Presets for every new project; the defaults can't
seem to be changed on some installations. Compiling a Project You will be using the SDCC cross compiler. The compiler generates
executable files with the extension .exe from the C source files. To create an executable program that runs on the C8051F120 processor from C
code, there are three steps that must be taken. First the compiler takes
the C source file (.c) and creates an object file (.hex). A linker takes
the object file from the compiler and adds in the language library routines
to create a link file. Finally a hex converter (or loader) takes the link
file and generates a downloadable executable file that can be passed to the
C8051F120 by the IDE. The IDE program downloads the .out file into the
C8051F120 for execution. Fortunately there are menu items that will perform all these operations.
For a C source file in an opened IDE Project, the menu commands to generate
the .exe download file are: 1. To compile your project, first verify that all of your code is correct.
If it's not, don't worry, the compiler will catch your mistakes.
2. Click on:
Project(Assemble/Compile File ( or icon)
This will compile your project source code. The window at the bottom of
the IDE will alert you of any errors or warnings it finds in your code.
If there are errors, correct them first before moving on to the next
step. If there are warnings, you may or may not want to correct them,
depending on the nature of the warning.
3. Next click on:
Project(Build/Make Project ( or icon)
This will link your compiled file. Any errors detected by the linker will
be displayed. Transferring the Executable Machine Code to the C8051F120 4. A