Skip to content

Commit cf3f6df

Browse files
committed
doc: Completely reworked EMSK section
* Add links to useful extrenal resources. * Simplified guides. * Fixed a guide for building with support of UART.
1 parent 1a7a0bc commit cf3f6df

File tree

1 file changed

+100
-106
lines changed

1 file changed

+100
-106
lines changed

doc/baremetal/em-starter-kit.rst

Lines changed: 100 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,64 @@
66
Using GNU Toolchain to Debug Applications on EM Starter Kit
77
===========================================================
88

9+
To learn how to build and debug application using Eclipse IDE, please use
10+
:doc:`../ide/index` manual.
11+
12+
You can find all necessary information about configuring the board and
13+
connecting to UART in a User Guide which is published in
14+
`ARC EM Starter Kit section <https://github.com/foss-for-synopsys-dwc-arc-processors/ARC-Development-Systems-Forum/wiki/ARC-Development-Systems-Forum-Wiki-Home#arc-em-starter-kit-1>`_
15+
on ARC Development Systems Forum.
16+
917
Prerequisites
1018
-------------
1119

12-
Toolchain for Linux and Windows hosts can be downloaded from the `GNU Toolchain
13-
Releases page
14-
<https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/releases>`_.
15-
For Linux hosts there is a choice between complete tarballs that include
16-
toolchain, IDE and OpenOCD (like installer for Windows), and tarballs that
17-
include toolchain only.
20+
A toolchain for Linux and Windows hosts can be downloaded from the `GNU Toolchain
21+
Releases page <https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/releases>`_.
22+
OpenOCD for debugging applications on hardware boards is shipped with IDE bundle only.
23+
OpenOCD binary (``openocd`` for Linux and ``openocd.exe`` for Windows) resides in ``bin`` directory of IDE.
1824

19-
In order to use OpenOCD on Windows it is required to install appropriate WinUSB drivers,
20-
see :doc:`../ide/how-to-use-openocd-on-windows` for details.
25+
Download and install Digilent Adept `runtime and utilities <https://digilent.com/shop/software/digilent-adept/download>`_
26+
to be able to work with EM Starter Kit on Linux. In order to use OpenOCD on Windows it is required to install
27+
appropriate WinUSB drivers, see :doc:`../ide/how-to-use-openocd-on-windows` for details.
2128

2229

23-
Building an application
24-
-----------------------
30+
Building a Simple Application
31+
-----------------------------
2532

26-
To learn how to build and debug application with Eclipse IDE, please use
27-
:doc:`../ide/index` manual.
33+
Consider this simple application (assume that it's saved in ``main.c``):
34+
35+
.. code-block:: c
36+
37+
int main()
38+
{
39+
return 0;
40+
}
41+
42+
Different core templates in EM Starter Kit use different memory maps.
43+
It means that you need to use a special memory map file with ``.x`` extension
44+
to be able to compile and run your application on EM Starter Kit.
45+
46+
In first, clone `toolchain <https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain>`_
47+
repository and look into ``extras/dev_systems`` directory. This directory contains
48+
memory map files for different boards and cores. For example, ``sk2.3_em7d.x``
49+
is a memory map file for EM7D core of EM Starter Kit 2.3. You need to put that memory map
50+
file to the current directory, rename it to ``memory.x`` and use ``-Wl,-marcv2elfx``
51+
option while compiling your application. Please refer to :doc:`linker` for more details
52+
about ``memory.x`` files.
2853

29-
Different core templates in EM Starter Kit use different memory maps, so
30-
different memory map files are required to compile applications that work
31-
properly on those configurations. This "toolchain" repository includes memory
32-
maps for all supported EM Starter Kit versions and configurations. They can be
33-
found at
34-
https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/tree/arc-staging/extras/dev_systems
35-
Memory map files in that directory have ``.x`` extension and file to be used
36-
should be renamed to ``memory.x``, because ``arcv2elfx`` linker emulation
37-
doesn't support ability to override that file name. Please refer to
38-
:doc:`linker` for more details about ``memory.x`` files.
54+
That is how we compile the application for EM7D core of EM Starter Kit 2.3::
3955

40-
For example for EM Starter Kit v2.3 EM7D to build an application::
56+
cp -a toolchain/extras/dev_systems/sk2.3_em7d.x memory.x
57+
arc-elf32-gcc -g -Wl,-marcv2elfx -specs=nosys.specs -mcpu=em4_dmips main.c -o main.elf
4158

42-
$ cp -a toolchain/extras/dev_systems/sk2.3_em7d.x memory.x
43-
$ arc-elf32-gcc -Wl,-marcv2elfx --specs=nosys.specs -mcpu=em4_dmips -O2 -g \
44-
test.c -o test.elf
59+
We use ``libnosys`` (``--specs=nosys.specs``) her to force standard IO functions
60+
to do nothing - they will set ``errno = ENOSYS`` and return -1 in most cases.
4561

46-
.. table:: List of compiler flags corresponding to particular CPUs
62+
You need to use correct ``-mcpu`` and other additional options for building your
63+
application for particular board and core. You can find all necessary options
64+
for any EM Starter Kit configuration in this table:
65+
66+
.. table::
4767

4868
+------+--------+------------------------------------------------------------+
4969
|EM SK | CPU | Flags |
@@ -78,41 +98,43 @@ For example for EM Starter Kit v2.3 EM7D to build an application::
7898
| | EM11D | -mcpu=em4_fpuda -mfpu=fpuda_all |
7999
+------+--------+------------------------------------------------------------+
80100

101+
Building an Application With Support of UART
102+
--------------------------------------------
103+
104+
Consider this application (assume that it's saved in ``hello.c``):
81105

82-
C library for GNU Toolchain for ARC provides basic support for UART module of EM
83-
Starter Kit, which allows to use standard C function for input and output:
84-
``printf()``, ``scanf()``, etc. Memory map files are also provided for processor
85-
configurations of EM Starter Kit. Both of those features are available via
86-
special "specs" files: ``emsk_em9d.specs`` and ``emsk_em11d.specs`` (there is no
87-
separate file for EM7D of EM Starter Kit, it is identical to EM9D). Usage
88-
example is following::
106+
.. code-block:: c
89107
90-
$ cat hello_world.c
91-
#include <stdio.h>
92-
int main() {
93-
printf("hello world\n");
94-
return 0;
95-
}
108+
#include<stdio.h>
96109
97-
$ arc-elf32-gcc --specs=emsk_em9d.specs -mcpu=em4_dmips hello_world.c
110+
int main()
111+
{
112+
printf("Hello, World!\n");
113+
return 0;
114+
}
98115
99-
Note that it is still required to specify valid ``-mcpu`` option value - it is
100-
not set by the specs file.
116+
You need to use ``emsk_em9d.specs`` (for EM7D or EM9D) or ``emsk_em11d.specs``
117+
(for EM11D) specs files instead of ``nosys.specs`` to enable support of UART.
118+
It allows using standard C function for input and output: ``printf()``, ``scanf()``,
119+
etc.
101120

121+
That is how we compile the application for EM7D core of EM Starter Kit 2.3::
102122

123+
cp -a toolchain/extras/dev_systems/sk2.3_em7d.x memory.x
124+
arc-elf32-gcc -g -Wl,-marcv2elfx -specs=emsk_em9d.specs -mcpu=em4_dmips main.c -o main.elf
103125

104126
Running an application with OpenOCD
105127
-----------------------------------
106128

129+
OpenOCD is used for connecting to development boards, running a GDB
130+
server and loading programs to the boards using GDB.
131+
107132
Starting OpenOCD
108133
^^^^^^^^^^^^^^^^
109134

110-
Parameters of a particular target board are described in the OpenOCD
111-
configuration files. OpenOCD repository from Synopsys already includes several
112-
configuration files made specifically for Synopsys own development platforms:
113-
ARC EM Starter Kit and ARC SDP. Due to differences between different versions
114-
of ARC EM Starter Kit hardware, there are separate configuration files for
115-
different ARC EM Starter Kit versions:
135+
OpenOCD uses configuration files for describing different boards. OpenOCD
136+
is shipped with different configuration files for different EM Starter Kit
137+
versions:
116138

117139
* ``snps_em_sk_v1.cfg`` - for ARC EM Starter Kit v1.x.
118140
* ``snps_em_sk_v2.1.cfg`` - for ARC EM Starter Kit versions 2.0 and 2.1.
@@ -121,66 +143,52 @@ different ARC EM Starter Kit versions:
121143
* ``snps_em_sk.cfg`` - this is a configuration for ARC EM Starter Kit 2.0 and
122144
2.1, preserved for compatibility.
123145

124-
Following documentation would assume the usage of the latest ARC EM Starter Kit
125-
version 2.3 which is similar to 2.2.
146+
Assume that EM Starter Kit 2.3 is used. If you've downloaded IDE bundle for
147+
Linux then you can run OpenOCD this way (replace ``<ide>`` by a path to
148+
the directory of IDE bundle)::
126149

127-
Start OpenOCD::
150+
<ide>/bin/openocd -s <ide>/share/openocd/scripts -c 'gdb_port 49101' -f board/snps_em_sk_v2.3.cfg
128151

129-
# On Linux (for manually built OpenOCD):
130-
$ openocd -c 'gdb_port 49101' -f board/snps_em_sk_v2.3.cfg
152+
If you've built and installed OpenOCD manually then you can run OpenOCD this way::
131153

132-
# On Linux (for prebuilt OpenOCD from IDE package):
133-
$ $ide_dir/bin/openocd -s $ide_dir/share/openocd/scripts \
134-
-c 'gdb_port 49101' -f board/snps_em_sk_v2.3.cfg
154+
openocd -c 'gdb_port 49101' -f board/snps_em_sk_v2.2.cfg
135155

136-
@rem on Windows:
137-
> openocd -s C:\arc_gnu\share\openocd\scripts -c "gdb_port 49101" ^
138-
-f board\snps_em_sk_v2.3.cfg
156+
If you've downloaded and installed IDE bundle for Windows then you can run OpenOCD this way:
139157

140-
OpenOCD will be waiting for GDB connections on TCP port specified as an
141-
argument to ``gdb_port`` command, in this example it is 49101. When
142-
``gdb_port`` command hasn't been specified, OpenOCD will use its default port,
143-
which is 3333, however this port might be already occupied by some other
144-
software. In our experience we had a case, where port 3333 has been occupied,
145-
however no error messages has been printed but OpenOCD and GDB wasn't printing
146-
anything useful as well, instead it was just printing some ambiguous error
147-
messages after timeout. In that case another application was occupying TCP port
148-
only on localhost address, thus OpenOCD was able to start listening on other IP
149-
addresses of system, and it was possible to connect GDB to it using that
150-
another IP address. Thus it is recommended to use TCP ports which are unlikely
151-
to be used by anything, like 49001-49150, which are not assigned to any
152-
application.
153-
154-
OpenOCD can be closed by CTRL+C. It is also possible to start OpenOCD from Eclipse
155-
as an external application.
158+
.. code-block:: winbatch
156159
160+
openocd -s C:\arc_gnu\share\openocd\scripts -c "gdb_port 49101" -f board\snps_em_sk_v2.3.cfg
161+
162+
OpenOCD will be waiting for GDB connections on TCP port specified as an
163+
argument to ``gdb_port`` command (49101 in our case). If ``gdb_port`` is not
164+
passed then the default port 3333 is used. It's recommended not to use a default
165+
port since it may be occupied by another application. OpenOCD can be closed by CTRL+C.
157166

158167
Connecting GDB to OpenOCD
159168
^^^^^^^^^^^^^^^^^^^^^^^^^
160169

161-
Write a sample application:
170+
Write a sample application and save it to ``simple.c``:
162171

163172
.. code-block:: c
164173
165-
/* simple.c */
166-
int main(void) {
167-
int a, b, c;
168-
a = 1;
169-
b = 2;
170-
c = a + b;
171-
return c;
172-
}
174+
int main()
175+
{
176+
int a = 1;
177+
int b = 2;
178+
int c = a + b;
179+
return c;
180+
}
173181
182+
Build the application for EM7D core of EM Starter Kit 2.3::
174183

175-
Compile it - refer to "Building application" section for details, creation of
176-
``memory.x`` is not shown in this example::
184+
cp -a toolchain/extras/dev_systems/sk2.3_em7d.x memory.x
185+
arc-elf32-gcc -g -Wl,-marcv2elfx -specs=nosys.specs -mcpu=em4_dmips main.c -o main.elf
177186

178-
$ arc-elf32-gcc -Wl,-marcv2elfx --specs=nosys.specs -mcpu=em4_dmips -O2 -g \
179-
simple.c -o simple_sk2.3_em7d.elf
187+
Start OpenOCD as it described earlier and start GDB, connect to target and run it:
180188

181-
Start GDB, connect to target and run it::
189+
.. code-block:: text
182190
183-
$ arc-elf32-gdb --quiet simple_sk2.1_em5d.elf
191+
$ arc-elf32-gdb -quiet main.elf
184192
# Connect. Replace 3333 with port of your choice if you changed it when starting OpenOCD
185193
(gdb) target remote :3333
186194
# Increase timeout, because OpenOCD sometimes can be slow
@@ -199,25 +207,11 @@ Start GDB, connect to target and run it::
199207
# For example, check exit code of application
200208
(gdb) info reg r0
201209
202-
Execution should stop at function ``exit``. Value of register ``r0`` should be
203-
``3``.
204-
210+
Execution should stop at function ``exit``. Value of register ``r0`` should be ``3``.
205211

206212
Known issues and limitations
207213
----------------------------
208214

209-
* Out of the box it is impossible to perform any input/output operations, like
210-
printf, scanf, file IO, etc.
211-
212-
* When using an nSIM hostlink (GCC option ``--specs=nsim.specs``), calling
213-
any of those function in application will result in a hang (unhandled
214-
system call to be exact).
215-
* When using libnosys (``--specs=nosys.specs``), standard IO functions will
216-
simply do nothing - they will set ``errno = ENOSYS`` and return -1 at most.
217-
* It is possible to use UART for text console I/O operations, but that is
218-
not implemented by default in GNU toolchain. Consult EM Starter Kit
219-
documentation and examples for details.
220-
221215
* Bare metal applications has nowhere to exit, and default implementation of
222216
exit is an infinite loop. To catch exit from application you should set
223217
breakpoint at function ``exit`` like in the example.

0 commit comments

Comments
 (0)