Skip to content
Anthony Kolesov edited this page Nov 14, 2013 · 34 revisions

This is a draft document, it is not complete and may describe features that may not yet exist.

This document describes how to use GNU tools for ARC with EM Starter Kit.

Building application

Different core templates in EM Starter Kit use different memory maps, and custom linker scripts are required to compile applications that work properly on those templates.

EM4

EM4 template has ICCM starting at 0x100 and DCCM at 0x80000000. Linker script and custom crt0.s file can be downloaded from Gist: https://gist.github.com/anthony-kolesov/7214970. To compile applciation use following command:

$ arc-elf-gcc -mEM -Wl,-Tem4.lds -nostartfiles crt0.s test.c

EM4_16CR

GNU tools for ARC do not support cores with reduced register set.

EM6

EM6 template has ICCM starting at 0x100 address and 256 MiB RAM starting at 0x10000000. It is assumed that both code and data segments are mapped to RAM and ICCM is not used. Linker script and custom start up file can be downloaded this Gist https://gist.github.com/anthony-kolesov/7214970. To compile applciation use following command:

$ arc-elf-gcc -mEM -Wl,-Tem6.lds -nostartfiles crt0.s test.c

Prerequisites

Windows

Windows installer can be downloaded here. It includes GNU tools, OpenOCD and Eclipse IDE with ARC GNU plugin installed (NB: installer is not provided at the momemnt of writing, should be done with 4.8-R2 release).

Linux

Toolchain for Linux hosts can be downloaded from Synopsys website as a prebuilt package. It includes GNU tools only. OpenOCD should be built separately. Documentation is available in OpenOCD GitHub repository. In a nutshell:

$ git clone https://github.com/foss-for-synopsys-dwc-arc-processors/openocd.git
$ cd openocd
$ ./bootstrap
$ ./configure --enable-maintainer-mode --disable-werror
$ make
$ make install

Starting OpenOCD

OpenOCD for ARC cores works only with FTDI 2232H USB/UART chips only. These chips are used in Digilent HS-1 cable and EM Start Kit.

Download and install 2232H drivers from FTDI web page: http://www.ftdichip.com/Drivers/D2XX.htm

Ensure that FTDI chip is recognized by your OS. On Linux it is possible to use lsusb command to see a list of USB devices. On Windows use "Devices Manager" configuration panel.

Start OpenOCD:

# On Linux:
$ openocd -f /usr/local/share/openocd/scripts/target/snps_starter_kit_arc-em.cfg -c init -c halt -c 'reset halt'

@rem on Windows:
> openocd -f C:\ARC48\share\openocd\scripts\target\snps_starter_kit_arc-em.cfg -c init -c halt -c "reset halt"

OpenOCD will be waiting for GDB connections on TCP port 3333. It can be closed by CTRL+C. It is possible to start OpenOCD from Eclise as an external application.

Connecting GDB to OpenOCD

Write a sample application:

/* simple.c */
int main(void) {
    int a, b, c;
    a = 1;
    b = 2;
    c = a + b;
    return c;
}

Compile it (refer to "Building application" section for details):

$ arc-elf-gcc -mEM -Wl,-Tem4.lds -nostartfiles crt0.s simple.c

Run GDB, connect to target and run it:

$ arc-elf32-gdb --quiet simple.elf
# connect
(gdb) target remote :3333
# Increase timeout, because OpenOCD sometimes can be slow
(gdb) set remotetimeout 15
# load application into target
(gdb) load
# Go to start of main function
(gdb) break main
(gdb) continue
# Resume with usual GDB commands
(gdb) step
(gdb) next
# Go to end of the application
(gdb) break _exit_halt
(gdb) continue
(gdb) info reg r0 

Execution should stop at function _exit_halt(). Value of register r0 should be 3.

Known Issues and Limitations

  • Communication between OpenOCD and hardware target is slow in some situations. To avoid possible communication issues between GDB and OpenOCD it is recommended to set remote timeout to around 10-15 seconds (default is 2). That also means that loading application into target could take noticeable amount of time, depending on size of application.
  • Out of the box it is impossible to perform any input/output operations, like printf, scanf, file IO, etc. Calling any of those function in application will result in a hang (unhandled system call to be exact). It is possible to use UART for text console I/O operations, consult EM Starter Kit documentation and examples for details.
  • Baremetal applications has nowhere to exit, and default implementation of exit is an infinite loop. To catch exit from application you should set breakpoint at function _exit_halt() like in the example. Note that _exit_halt() is defined in crt0.s.

Big-endian Targets Support

Both OpenOCD and GDB support big-endian applications and target. No special build of those applications is required to support big-endian, however other parts of toolchain must be build for big-endian. Refer to toolchain readme for details on building big-endian toolchain.

EM Starter Kit doesn't have built-in big-endian configuration, however it is possible to program its FPGA with big-endian image. Consult EM Starter Kit databook for details on FPGA programming. Following steps assume that your FPGA system (either EM Starter Kit, or another) is already flashed with big-endian image.

Build target application:

$ arceb-elf-gcc -mEM -Wl,-Tem4.lds -nostartfiles crt0.s simple.c

Edit OpenOCD configuration script (EM Starter Kit is assumed):

--- snps_starter_kit_arc-em.cfg 2013-11-13 17:03:21.556183900 +0400
+++ snps_starter_kit_arc-em_eb.cfg      2013-11-13 17:03:17.858983900 +0400
@@ -36,7 +36,7 @@
 echo "Using dbgbase = [format 0x%x $_dbgbase]"

 target create $_TARGETNAME arc32 -chain-position $_TARGETNAME \
-  -coreid 0 -dbgbase $_dbgbase -endian little
+  -coreid 0 -dbgbase $_dbgbase -endian big

 # SRAM: 56KiB at 0x4030.0000
 $_TARGETNAME configure -work-area-phys 0x00000000 \

Subsequent steps are same as for littl-endian targets. Note that there is no real difference between arc-elf32-gdb and arceb-elf32-gdb GDB executables.

Clone this wiki locally