Hello World in C for Bare-Metal Targets

This tutorial takes you through creating, configuring, and building a simple bare-metal program using Arm DS-5.To run your application once it is built, the tutorial then takes you through the steps of configuring a debug connection to a system model implemented in software.

Introduction

After installing and acquiring a license to work with DS-5, this tutorial takes you through creating, configuring, and building a simple bare-metal program.

To run your application once it is built, the tutorial then takes you through the steps of configuring a debug connection to a system model implemented in software. These models are called Fixed Virtual Platforms (FVP) and some are provided with DS-5. This tutorial uses the VE_Cortex_A9x1FVP model which is based on the Cortex-A9 processor.

Creating a New C Project

  1. From the DS-5 main menu, select File > New > C Project to display the C Project dialog.
  2. In the C Project dialog:
    1. In Project name field, enter HelloWorld as the name of your project.
    2. Under Project type, select Executable > Empty Project.

      When selecting the Executable 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.

    3. Under Toolchains, select Arm Compiler 5.

      C Project dialog options

    4. Click Finish to create a C project called Hello World.

      You can view the project in the Project Explorer view.

      Project Explorer - Hello World

Specifying a RAM Base Address

To load and execute the application on the target, before compiling the application, we need to tell the linker the target RAM base address. This ensures that the application is built correctly for the particular target.

The VE global model memory map contains the memory address details required for the VE FVP model used in this tutorial.

We can see that the memory address range for VE FVP models (4GB DRAM (in 32-bit address space)) is between 80000000 and FFFFFFFF. This gives us the RAM base address as 0x80000000.

  1. In Project Explorer, right-click the project and select Properties.
  2. In the Properties dialog:
    1. Browse to C/C++ Build > Settings.
    2. Under the Tool Settings tab, browse to Arm Linker 5 > Image Layout.
    3. In the RO base address (--ro_base) field, enter 0x80000000.

      RO Base address

    4. Click OK to close the dialog and apply the changes.

Creating the Source Code and Building the Project

  1. In the Project Explorer view, right-click the Hello World project and select New > Source File.

    Hello World New Source file

  2. In the New Source File dialog, enter the file name hello_world.c.

    Enter file name

  3. Click Finish to create the source file and open it in the code editing view.

    Code Editing view

    The source file is also visible in the Project Explorer view, under the Hello World project.

    Hello World in Project Explorer view

  4. Add the following code to the new source file, and press CTRL+S to save it.
    #include <stdio.h> int main() { printf("Hello World\n"); }
  5. 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 HelloWorldproject.

The .axf file contains both the object code and debug symbols that enable the debugger to perform source-level debugging.