Quick Start: Sourcery CodeBench for Bare Metal Embedded Application Development

Version 3

    These steps give an example of using the Sourcery CodeBench IDE to  create and debug an application that will run on a target that does not  have an operating system. The example in this Quick Start use Sourcery  CodeBench for ARM EABI, but the steps are the same for Sourcery  CodeBench for MIPS ELF, Power EABI, Kinetis EABI, Stellaris, EABI, and  other Sourcery CodeBench editions that allow you to develop applications  for targets that are bare metal.

    Prerequisites

     

     

    Procedure

    1. Start CodeBench:

      1. On Windows, select Start > All Programs > CodeSourcery > Sourcery CodeBench for ARM EABI.
      2. On Linux, from your home folder (~), type ./Sourcery_CodeBench_for_ARM_EABI or invoke CodeBench from the installation directory: ./<Install Directory>/CodeBench/Sourcery_CodeBench_for_ARM_EABI/bin/sourcerygxx-ide.
      3. Select a Workspace for your projects.

        Sourcery  CodeBench stores your projects in a folder called a workspace. You can  have multiple workspaces. You setup your workspace when starting  CodeBench and can change workspaces from the IDE.

        TIP: To change workspaces from the IDE, select File > Switch Workspace and then enter a new workspace location.
      4. The  first time you open CodeBench, the Welcome screen appears.  Use the  links on the Welcome screen to learn more about CodeBench or to get  help.

        1. To close the Welcome screen, click X. This opens the C/C++ Perspective.
        2. To reopen the Welcome screen later, select Help  > Welcome.
    2. Create a project. From CodeBench, select File > New > C Project (or C++ Project). The New Project wizard opens. Note that you could also create a C++ Project.

      1. Give your project a name.
      2. Select the type of project to create:
        • Executable - The CodeBench IDE manages your build. Tip: To start with example code, from the Project type area, select Executable > Factorial C Project.
        • Shared Library - select to create a shared library.
        • Static Library - select to create a static library.
        • Makefile  Project - select this if you have existing code with a makefile or if  you want to write a makefile to control your build.
      3. Click Next. This opens the Configuration page of the Project wizard.
      4. Select your Board.
        1. If you have not decided on a board and want to simulate your design, select one of the QEMU CPU Emulators.
        2. If your board is not listed, select Configure Manually and from the Processor list, select your processor.
      5. Default property values are set based on your board selection.  Optionally, modify them.
      6. Click Finish to create your project.
    3. Write your application.
      1. To create new files, select File > New > Source File or Header File.
      2. To import existing files, select your Project and select import.
        1. On the Select page of the Import wizard, select General > File System and click Next.
          On the File System page of the Import wizard:
          1. In the From directory field, enter the path to the directory your source code resides in.
          2. Below the From directory field, select the source files to import.
        2. Click Finish. This imports the source into your project.

    4. Add the path to the include files and libraries in your project:
      1. From the Project Explorer, right-click the project and select Properties.This opens the Properties dialog box for the project.
      2. On the left of the Properties dialog box, expand C/C++ Build and select Settings.This displays the Settings pane on the right side of the Properties window.
      3. From the Settings pane, select the Tool Settings tab.
        1. To add include paths, expand Sourcery CodeBench C/C++ Compiler and select Includes.
        2. To  add library paths, expand Sourcery CodeBench C Linker and select  Libraries. Add any libraries that your project uses to the Libraries  list.
      4. Click Apply to apply your changes.
      5. Click OK to close the Properties dialog box.
    5. Build your project and check for problems:
      1. Right-click the project and select Build Project.
      2. View the build log in the Console window.
      3. View build errors and warnings in the Problems window. TIP: Double-click an error to go to the location of the error.
      4. Fix errors, and rebuild.
    6. Set up the debugger:

        1. Select your project in the Project Explorer.
        2. Select Run > Debug Configurations. This opens the Debug Configurations dialog box.
        3. To initializes the target and loads your application onto it, right-click the Sourcery CodeBench Debug launch group and select New.  To attach the debugger to an application is already running on the target, use the Sourcery CodeBench Debug (Attach) launch group.
        4. Select the Main tab of the launch configuration.
        5. Enter a Name for your debug launch configuration.
        6. Select  your project, Note that if your project was selected in the Project  Explorer when you opened the Debug Configuration dialog box, your  project name should already be in the Project field.
        7. Select the C/C++ Application to debug. TIP: Click Search Project to browse and select an application from your project.
        8. To configure the debug interface for your target, select the Debugger tab for the launch configuration and select the Debug Interface for your target:
          1. If  you don't have a target and you selected QEMU as your target board when  you created your project, you can run and debug your application using  the QEMU emulator instead of target hardware. The QEMU emulator provides  an easy way to try out your program without requiring target hardware:

            1. From the Debug Interface list, select Sourcery CodeBench QEMU CPU Emulator.
            2. Optionally, select a Processor.
            3. Click Apply.
          2. If  your target does not have an operating system and you want to download  your application to the target and debug it using serial or TCP  communication:

            1. From the Debug Interface list. select Sourcery CodeBench External Embedded Server.
            2. Select the Connection tab and do the following:
              1. From the Type pull-down, select TCP or Serial.
              2. For TCP, enter the Host name or IP address for the target and set the Port number to 10000.
              3. For a Serial connection, enter the Device and the Speed of the serial device.
              4. Click Apply.
          3. If you have a Stellaris board that has a USB debug port:
            1. From the Debug Interface list, select Stellaris USB.
            2. In the Board field, select the <target>.xml file for your board.  TIP: <target.xml> files for targets that are supported by CodeBench reside in the <INSTALL_DIRECTORY>/CodeSourcery/Sourcery_CodeBench_for_ARM_EABI/arm-none-eabi/lib/boards directory.
          4. If you have a Kinetis board:
            1. From the Debug Interface list, select Kinetis P&E.
            2. In the Board field, select the <target>.xml file for your board.  TIP: <target.xml> files for targets that are supported by CodeBench reside in the <INSTALL_DIRECTORY>/CodeSourcery/Sourcery_CodeBench_for_ARM_EABI/arm-none-eabi/lib/boards directory.
          5. If your target has a JTAG port and you have a Mentor Embedded Sourcery Probe (MESP) Personal or Professional:
            1. From the Debug Interface list, select Sourcery Probe.
            2. In the Probe hostname field, enter the IPADDRESS for your probe.
            3. In the Board field, select the <target>.xml file for your board.
            4. On the Sourcery Probe tab of the Debugger Options area:
              1. Verify your CPU ID.
              2. If your board has more than one core, select Core and specify which core to use.
              3. Set other options as needed.
          6. For information about other debug interfaces, view section 4.3.2 of the Sourcery CodeBench Getting Started Guide (Help > Help Contents).
        9. Click Apply.
      1. Debug your application:
        1. Click Debug to download your application to target and begin debugging.
        2. If the Confirm Perspective Switch dialog box appears, click Yes to open the debug perspective.

          The  debug perspective displays the stack, local variables, and the current  location.  By default, the debugger automatically stops on the first  line of main.  The currently active source line is  highlighted. The pane at the upper left shows the application threads  and the stack associated with each thread. The pane at the upper right  shows the values of local variables.

        3. Use the debugger controls to set breakpoints and step through code, for example select Run > Step Over (F6) to go to the next line of code or Run > Step Into (F5) to step into a function.  To add a breakpoint, select a line of code and select Run > Toggle Breakpoint or double-click the blue area to the left of the line of code.
        4. Use the Variables view to view and modify variables.
        5. To view machine registers, select the Registers tab, and expand the General Registers register group. When the values of registers change, the registers are  highlighted in the IDE. Right-click a register to add it to the watch  list.
        6. To see the instructions being executed, select Window > Show View > Disassembly.  You can set breakpoints on particular machine instructions in  disassembly view in the same way that you can set breakpoints on source  lines in the source code editor views in the debugger.

          The Step Over and Step Into commands normally operate at the source level, advancing program  execution to the next C or C++ statement. To step by machine  instructions instead, click on the Instruction Stepping Mode button on the Debug toolbar. Click this button again to return to stepping by source lines.

      2. For more information about debugging, select Help > Help Contents and browse to the Sourcery CodeBench Getting Started Guide.