Friday, 25 December 2015

ARM DS-5 Tutorial

Getting started with  ARM DS-5 Development Studio

Download ARM DS-5 Development Studio from http://ds.arm.com/downloads/

Installation is pretty straight forward. ARM Ltd. grants a free 30 day  trial license for ARM DS-5.The software is fully functional with no limitations.

Keil MDK is a good software for developing code for Cortex M and ARM7 family of processors. When it comes with Cortex A processors found in tablets and smartphones, Keil MDK is unsuitable and hence ARM DS-5.ARM processors are not generally found as standalone chips but as SoCs(System On Chips).

In this tutorial I use ARM DS-5 Ultimate Edition v5.22 . ARM DS-5 is an enterprise class software which enables development and debugging software for low end ARM7 to Cortex M ,Cortex R, Cortex A processors and high end 64 bit ARM Cortex A53 and A57 processors found in Samsung Galaxy Note 5 and Galaxy S6.
To know more in detail, visit www.arm.com and ds.arm.com

This tutorial is for people who would like take a dive to ARM programming without prior knowledge in working with IDEs.

To start working ARM DS-5

1.Click Start ---> ARM DS-5 vx.xx ---> Eclipse for DS-5 vx.xx


2.You'll be prompted to select a workspace,change location or leave it as such and click OK



3.Click File ---> New ---> C Project


4.The C project window opens up. Type the Project Name, Choose Project type as Executable -->Empty Project and Toolchain as ARM Compiler (DS-5 built-in) and click Next.



5. Check the Debug , Release option checkboxes and click Finish.

6.Now to add a Assembly source file to the project, right click on the Project , select New ---> File.



7.Create a file named main.s or any name you want but ensure that is extension is s(Assembly source file) and click Finish.

8.Now the project is setup and it is time to start coding.

9.Nearly all assembly languages irrespective of architecture(be it Intel x86,8051,AVR or ARM) have an instruction named MOV. Type the below code in the IDE.

AREA anyname,CODE,READONLY
ENTRY
MOV r0,#0x22
END

The keywords AREA , ENTRY ,END are specific to ARM assembler developed by ARM Ltd.GNU ARM assembler uses different directives. For time being understand them as a ritual followed while writing ARM assembly programs as we do write void main() in C language.


10.Now right click the Project and click Build Project.



11. Now you see that errors are thrown by the assembler.

Expanded Problems 


The code is right and but why does the assembler throw error. The ARM assembler behaves in a similar way like Python language .It expects the indentations to be right.Indent the code by pressing TAB key.
Indent the code with TAB key(preferably 2 TABs) like the one below.





12.Now right click the Project and click Build Project. The Project has been built successfully except for the warnings. The 2 warnings are related to licensing and can be ignored .A Debug folder is also created.


Expand the Debug folder,you can see object files(*.o) ,an AXF file(also known as ELF) and some  files which are related with the makeutility(*.d ,makefile,*.mk)



AXF file is something like EXE file.Double clicking AXF will reveal the information regarding the file.Using a text editor to open AXF will not give you a clear picture.Click Sections,Segments,Symbol Table,Disassembly Tabs to know more.


There is no need of hardware to test the program.ARM DS-5 has inbuilt emulator for ARM processors. We will use that to debug the code.

14.Native application debugging is simpler since the host and target processor are same. But things get slightly difficult when the code is native(x86_64 should run an emulator to run ARM code).We have to configure the debugger.
Click on Debug   icon and select Debug configuration.Debug configuration opens up.Click DS-5 debugger and click New button.


15.A new configuration is created .Name it as you want. I name it ARM Cortex Debugger. Select Target as ARM FVP(Installed with DS-5) ---> VE_CortexA9x1 ---> Bare Metal Debug ---> Debug Cortex A9 . We choose Bare Metal since we don't use any OS. The processor is a single core processor and hence the suffix x1. Cortex A9 processors were featured in former flagship phone such as Samsung Galaxy Note(Dual Core Cortex A9) and Note2 (Quad core Cortex A9).


16.Click the Files Tab. Click Workspace button in Target Configuration.


17.Choose the .axf file in Debug folder of the project. In my case it was Simple.axf



Finally click Apply Button and Debug button
18.Debug Perspective Switch Window opens up.Click Yes.

Also allow Windows Firewall to unblock the DS-5 debugger by clicking  Allow Access.

19.Now you can start executing code. On the right hand side you see the ARM  core registers. Pressing F5 will execute the code instruction by instruction.


After executing  MOV r0,#0x22 ,PC(Program Counter) gets incremented by 4. A single ARM instruction is 32 bit wide and memory architecture is 8-bit, 4 locations are required to store 32 bits and hence PC+4.The changes in registers are highlighted by yellow color.


To close Debug perspective Debug icon --> Close.You can modify code,rebuild and debug again. IT IS NOT REQUIRED TO SETUP DECONFIGURATION AGAIN !!!!


20.Now we'll write a program to add two numbers 0x22 and 0x06

              AREA anyname,CODE,READONLY
              ENTRY
              MOV r0,#0x22
              MOV r1,#0x06
              ADD r2,r0,r1
       stop   B stop
              END


 The code performs the following    r0  <--- 0x22
                                                                  r1 <--- 0x06
                                                                  r2 <--- r0 + r1

stop B stop will put a hold to the program counter.'stop' is just a label.It can be anything like cat,dog,etc.,.B is unconditional branch  instruction like SJMP and LJMP in 8051.while(1); statement in C is an equivalent of this assembly statement.
Build the code.Click Debug icon and select ARM Cortex Debugger configuration we created earlier



The Register Window showing the results after execution


Numerous assembly programs like can be tried out in ARM DS-5 to get good understanding of ARM architecture.

To get help for any instruction or assembler directive , just place the cursor on the instruction and press F3





Good books for learning ARM assembly language and C programming are

1.ARM Assembly Language ,Fundamentals and Techniques by William Hohl and Christopher Hinds

2.ARM System Developer's guide by Andrew N Sloss, Dominic Symes and Chris Wright


No comments:

Post a Comment