Building bare-metal applications in DS-5 using GCC compiler
Building bare-metal applications in DS-5 using GCC compiler
Including set-up for bare-metal debug sessions on Fixed Virtual Platforms
To debug applications for bare-metal targets in Arm DS-5 Development Studio, you can use GCC "Launchpad" compiler toolchain. However, in general we recommend use of Arm Compiler for building bare-metal applications in DS-5.
This tutorial shows you how to set up your project to use the GCC bare-metal compiler. It
then guides you through creating a simple bare-metal Hello World
application and finally running it on a debug configuration on a
Cortex-A9 Fixed Virtual Platform (FVP) provided with DS-5.
Prerequisites
- Download, install, and acquire a license for DS-5. If you haven't, see the Getting Started with Arm DS-5 tutorial for more information.
- Download and install the GCC bare-metal toolchain:
- If you are compiling for Cortex-A, select a toolchain from linaro.org.
- For more information regarding the Linaro Toolchain releases, support, and selection, go to https://wiki-archive.linaro.org/WorkingGroups/ToolChain/FAQ.
- If you are compiling for Cortex-R or Cortex-M, select a toolchain from GNU Arm Embedded Toolchain.
- For more information regarding the GNU Arm Embedded Toolchain releases, support, and selection, go to https://developer.arm.com/open-source/gnu-toolchain/gnu-rm.
- If you need help adding a new toolchain to Arm DS-5, see the tutorial on Adding New Compiler Toolchains to DS-5.
Creating a new C project
- From the DS-5 main menu, select File > New > C Project to display the C Project dialog.
- In the C Project dialog:
- In the Project name field, enter HelloWorld as the name of your project.
- Under Project type, select Executable
> Empty Project.
When selecting a Bare-metal toolchain option, the toolchain assumes that the application is executed directly on the hardware instead of on top of a complex operating system such as Linux.
- Under Toolchains, select the name of the GCC toolchain you have downloaded.
Note: if the toolchain that you downloaded is not listed, you need to add it to the list. - Click Finish to create a C project called HelloWorld.
You can view the project in the Project Explorer view.
You might see a on the project which
indicates that the project configuration is incomplete, depending on your version of DS-5. The sections below explain how
to set up the rest of the settings for the project.
Configuring the settings for the project
You need to be aware that when configuring settings for a project using a compiler not shipped with DS-5 (but supported by DS-5), there might be options and settings that you will have to investigate before applying any changes. For example, you need to know the processor you are compiling your code for and you might also need to investigate the RAM starting address for your target, so you can specify it in the linker script.
For this tutorial, we are going to customize the project to:
- Set up the appropriate commands and flags for the GCC C Compiler, GCC Assembler, and GCC C Linker. This tells the project to use specific switches when compiling the program.
- Configure the project environment to locate and use the GCC compiler executable.
- Modify the GCC linker script to set the RAM starting address.
Setting up the commands and flags for the GCC C Compiler, GCC Assembler, and GCC C Linker
Once you have created your project, you need to specify the commands and flags required to compile it.
Note: This configuration exists on a per-project basis. You must separately reconfigure all projects that you want to use with the new toolchain.
Setting up project commands and flags:
- Locate your project in the Project Explorer view, right-click it, and select Properties.
- In the Properties dialog:
- Navigate to C/C++ Build > Settings.
- Select All configurations in the Configuration list.
- Select GCC C Compiler, and confirm that you are using an
arm-none-eabi-gcc
toolchain, then check if the command is available under Commands. Similarly, confirm the command is available under GCC Assembler, and GCC C Linker. - Select Target and in the CPU (-mcpu)
field, enter
cortex-a9
. - Select GCC C Linker > Libraries, and:
- Click
to Add a library, and in the Enter Value dialog, enter
c
. - Click
to Add a library again, and in the Enter Value dialog, enter
rdimon
.rdimon
enables semihosting on your target.Semihosting is a mechanism that enables code running on an ARM target to communicate and use the Input/Output facilities on a host computer that is running a debugger.
For more information about semihosting, see:
What is semihosting? - Select GCC C Linker > Miscellaneous and in the
Other flags field, enter:
--specs=nano.specs --specs=rdimon.specs -mcpu=cortex-a9 -T ../gcc.ld
The
gcc.ld
is the shared linker script that we will add to the project and modify at a later step.
- Click
The commands and flags for the GCC compiler to compile code using the appropriate libraries and processor switches are now set up.
Now, you need to set up the project environment variable to point to the GCC compiler executable which is installed separately from DS-5.
Leave the project Properties dialog open to configure the project Environment settings.
Check out this blog for some information about GCC command line options for Arm Cortex-A processors:
Set up the project environment to use the GCC compiler executable.
To ensure DS-5 can find the GCC compiler executable, add its location to the
PATH
environment variable.
Note: This configuration exists on a per-project basis. You must separately reconfigure all projects that you want to use with the new toolchain.
In the project Properties dialog:
- Navigate to C/C++ Build > Environment.
- Ensure the Append variables to native environment option is
selected.
- Click Add.
- In the New variable dialog:
- In the Name field, enter
PATH
. - In the Value field, enter the path where the GCC compiler
is installed. For example:
C:\Program Files (x86)\GNU Tools ARM Embedded\4.7 2013q3\bin
- Click OK to save the changes and close the Edit variable dialog.
- In the Name field, enter
- Click OK to save the changes and close the project Properties dialog.
Modifying the GCC shared linker script
After setting up the new project with appropriate flags, you now need to copy and modify the GCC shared linker script so that the linker knows what the RAM starting address for the FVP is.
- Locate the
gcc.ld
file in:C:\Program Files (x86)\GNU Tools ARM Embedded\4.7 2013q3\share\gcc-arm-none-eabi\samples\ldscripts
- Drag and drop the file from the location on your computer to the project in DS-5.
- In the File Operation dialog, select Copy files
and click OK to copy the file and close the dialog.
- Expand the project to view the copied file.
- Double-click to open the
gcc.ld
file in the default editor set up in DS-5. - Change:
MEMORY { FLASH (rx) : ORIGIN = 0x0, LENGTH = 0x20000 /* 128K */ RAM (rwx) : ORIGIN = 0x10000000, LENGTH = 0x2000 /* 8K */ }
To
MEMORY { RAM (rwx) : ORIGIN = 0x80000000, LENGTH = 0x2000 /* 8K */ }
Where can I locate more information about Versatile Express FVPs and their memory maps?
The Fixed Virtual Platforms FVP Reference Guide contains more information.
See VE - model memory map for information specific to VE memory maps.
- Locate
ENTRY(Reset_Handler)
and change it toENTRY(_start)
. - Locate all instances of
} > FLASH
and change it to} > RAM
. - Save the file.
After creating the shared linker script, you need to create a target initialization debugger script.
Creating the source code and building the project
Now that the project is set up, we can start creating code for it and build the application. After a successful build, we can then create a debug configuration, and run the application on the target.
- In the Project Explorer view, right-click the HelloWorld project and select New > Source File.
- In the New Source File dialog, enter the file name hello_world.c.
- Click Finish to create the source file and open it in the code
editing view.
The source file is also visible in the Project Explorer view, under the Hello World project.
- Add the following code to the new source file, and press
CTRL+S
to save it.#include <stdio.h> int main(int argc, char** argv) { printf("Hello world\n"); return 0; }
- In the Project Explorer view, right-click on the Hello World project and select Build Project.
You can view the output image hello_world.axf
in the Debug
folder under the HelloWorld project.
The .axf
file contains both the object code and debug symbols that enable
the debugger to perform source-level debugging.
Creating a DS-5 debug configuration and connecting to the FVP
- From the DS-5 main menu, select Run > Debug Configurations.
- In the Debug Configurations dialog:
- Select DS-5 Debugger.
- Click the New launch configurations button.
This creates a new DS-5 debug configuration and displays the various tabs required to specify settings for loading your application on the target.
- In the Debug Configurations dialog:
- Give a name to the debug configuration. For example,
HelloWorld_GCC_FVP
. - In the Connection tab, select Arm FVP >
VE_Cortex_A9x4 > Bare-Metal Debug > Debug
Cortex-A9_0.
- Select the Files tab, and:
- Under Target Configuration in the
Application on host to download field,
click Workspace.
The Workspace contains the
HelloWorld.axf
application file you created when you built the Hello World project.Note: Ensure that the Load symbols option is selected.
- Select
HelloWorld.axf
. - Click OK to load the file.
- Under Target Configuration in the
Application on host to download field,
click Workspace.
- Select the Debugger tab, and ensure the
Debug from symbol option is selected and set to
main
. - Click Debug to load the application on the FVP, and load the debug information into the debugger.
- In the Confirm Perspective Switch dialog that
appears, click Yes. DS-5 connects to the FVP and
displays the connection status in the Debug Control
view.
The application is loaded on the target, and has stopped at the
main()
function, ready to run. - Click
to continue running the application.
You can view the application output in the Target Console view.
- Give a name to the debug configuration. For example,