Thursday, October 21, 2010

Software tools required to work with ARM

To work with any microcontroller you will require an IDE, a compiler, and a flasher or code burning program (if you are not using a bootloader). Today I will talk about the basic software requirements to start working with an ARM cored microcontroller.



1. IDE (Integrated Development Environment)
Eclipse-CPP_Galileo is a good IDE available freely. Eclipse is basically a multi-language software development environment which is written in Java. So you will require java to run eclipse. You can download Eclipse-CPP_Galileo here. No installation is required. Just un-rar the file and start using it.

2. Compiler
There are many good compilers available out there. But not many of them are free and even if you get the evaluation version, there will be a code limit of 32kB or so. So we searched a lot for better free compilers available for ARM. And finally we got the CodeSourcery. CodeSourcery G++ is a complete software development environment based on the GNU Toolchain and it can be used with Eclipse IDE.You can download it here.

3. Flasher (Required if you are not using a bootloader)
H-JTAG is a simple tool used to flash the micorcontroller through JTAG. For this you need a JTAG progammer. JTAG Wiggler is one of the simplest JTAG programmers available. To build one for yourself see this and this. Or you can buy USB JTAG or Parallel Port JTAG programmer boards.

After getting all these follow the following steps to create and run your own program on the ARM core based  controller.

 
1. Installing CodeSourcery

Start the installation wizard of the CodeSourcery-arm-none-eabi.


Press next and accept the terms and conditions. Choose the typical, minimal or custom installation according to your wish. Select a directory path for installation and install it. It will take 1 or 2 minutes to install.


2. Using Eclipse for code development and integrating CodeSourcery with Eclipse

When you open the Eclipse for the first time it will look somewhat like this.


a. The CodeSourcery will be automatically integrated into the Eclipse. So there is no need to change any settings.

b. Now go to NEW -> C project. Select the project type as "Makefile project -> Empty project", give a suitable project name and click FINISH.

c. Now you will see a folder with the name of your project in the Project explorer window.

d. You need to add the makefile, startup code, linker file etc. etc. to your folder. The makefile basically instructs the compiler as to what it should do and what all files should it create Example : BIN file, HEX file. The startup and system initialization code will initialize the PLL, will set the interrupt handlers etc. The linker file contains information as which all files should be linked and compiled together, and where should the user code start, the starting RAM address etc. So now to add these files right click on the project folder in the Project window and select IMPORT.



Then select "File System" and click next and then add the folder where you have the startup codes and click select all or you can select only the file that are required. Here is a sample Startup requirement code for LPC1768.


If you want you can change the user code starting address or frequency of operation by changing the values in  LPC17xx.ld and system_LPC17xx.c respectively. A brief tutorial explaining the startup code will be written later.

e. After doing this go to main.c and type your custom code. Then Build the project and burn it on to the microcontroller.


3. Using H-JTAG to flash the HEX file onto the microcontroller

Go to H-JTAG. If you have connected the microcontroller through JTAG you should get the info of the chip when you press refresh. If you do not see it then may be JTAG link is not connected or may be the microcontroller is not powered up. Go to INIT and disable the auto init script option. Some settings that need to be made are shown in the following pictures. Please configure your H-JTAG if you are using Parallel Port JTAG connector as shown below










Then go to H-Flasher and select the target chip.


The H-Flasher will not reset the controller after flashing it. So if you want the chip to reset after burning do the following setting.



Select the HEX file and program the chip!!


Other popular IDE and compiling softwares available are Keil (uVision IDE and Keil compiler), WinARM, GNU-ARM etc.

The USB bootloader tutorial and the code for Secondary USB bootloader for LPC17xx (modified code for Blueboard-LPC1768-H) is available here.

EDIT:
The code base or the startup code that I have provided in this tutorial seems to have some problems. So please use the modified correct startup code

17 comments:

Sagar said...

Good write up.
One tiny thing
"CodeSourcery G++ is a complete software development environment based on the GNU Toolchain and the Eclipse IDE"

Codesourcery is a compiler but not "based" on eclipse. Its independent. Codesourcery can be used right from the command line or integrated into other IDE's just as eclipse can use other compilers.

go4download said...

Thanks for the step by step guidance! very helpful..appreciate your time and efforts put into!@Sara
Drivers Download

Anonymous said...

Hello,

Thanks for the step by step instructions. Unfortunately, I'm getting this error when I try to build the project after cleaning:

cc1.exe: error: unrecognized command line option '-fpromote-loop-indices'

I'm using Eclipse Indigo with the latest Sourcery G++ Lite (arm-none-eabi). I also installed the CDT-Master 8.0.0.

Have you experienced this problem? I'm a newbie and would really appreciate some assistance!

Thejasvi said...

@^^ hey I really do not know what that error means but my friend said that it might get corrected if you try and upgrade to a newer version.

Can you trace the error to any specific place in the makefile or something. Some specifics might help me to dig more into it.

Anonymous said...

Hi, you mentioned you'd do a brief tutorial for explaining the startup code, but I couldn't find it in your newer posts. Is there a link I can go to in order to get a clearer picture of what the code is doing? Thanks in advance!

Thejasvi said...

@^
Sorry for not putting the detailed explanation of the startup code.

The startup code will setup the vector interrupt table, reset handlers, PLL, stack etc. for you. If you need more detailed explanation please do ask, I will put up a new tutorial when I find time.

Thanks for your interest and reading my blog

Anonymous said...

Hi, that'll be great! I have only a basic understanding of what goes in to the code by referring to the user manual for lpc1768, but I don't have a strong grasp of what really happens as a whole program. Thanks in advance!

Anonymous said...

Hi,

I've done everything posted here, except that I'm using Flash Magic instead of H-JTAG since I'm using UART to communicate (using the FT2232 chip - USB to serial).

The code is able to compile and I'm able to download the program without any errors, but I'm still unable to start my oscillator. I tried to blink my LED on the Reset_Handler() method, but my code doesn't even reach here. Apparently I was told that I'm missing the CRC value at 0xC - somehow my hex file doesn't generate this - any idea how I can do this?

Thejasvi said...

@ ^

Do you definitely know that the problem is in HEX file? If yes, then I would recommend you to just reinstall or get the latest version of code sourcery.

Or may be there is some problem with the code base you are using. You can use this code base that I was using. This is actually CMSIS's code base modified by me and my colleague.

If you still cant solve the problem post your code (if you are ok with sharing it) and the complied .hex and .bin files. I will have a look at it and see if I can detect the source of the problem.

I suggest you to use the USB bootloader. It simplifies your work a lot. Here is a tutorial on that if you are interested. By using the USB bootloader you just need to copy the .bin file to the LPC17xx's drive.

Anonymous said...

Hey,

I used your code base, and voila! It works! Thank you so much! I don't quite know why the original code that was provided in the link (on this tutorial post) didn't work. Whatever it is, the changes you made were really magic! It'd be great if you could share the changes (or have you actually posted it and I might have missed the post?)

Thanks once again!

Thejasvi said...

@ ^

Sorry for the trouble I gave you by posting the startup code which dose not work. Actually I made those changes to the startup code very long back but might have forgotten to update the post. I now do not remember what I changed back then. Anyway I have updated the post with the link for the new startup code.

Thanks for pointing out the error.

Anonymous said...

Hi again!

I'm so glad my 7-segment LED worked based on your startup code. However, right now I'm trying to play around with the Ethernet module. There is a sample software available - http://code.google.com/p/32bitmicro/source/browse/trunk/src/nxp/lpc17xx/LPC17xxSampleSoftware/EMAC/
Since I'm not using Keil, I am told (in the readme.txt) that the compiler needs to set up the include path to a particular folder (I believe I have to add this folder). I've tried adding that folder to the "inc" folder of my MingW folder (compiler for Eclipse?), but I still get this error in Eclipse:
make all
Makefile:30: ../Makefile.rules: No such file or directory
make: *** No rule to make target `../Makefile.rules'. Stop.
I don't quite know what went wrong. Any help from you is greatly appreciated.

Thejasvi said...

@ ^

The error is in the makefile provided in the EMAC library.

The startup code that I have provided requires you to put all the library .c or .cpp files you are using in the "src" directory and all the header files in the "inc" directory. You can make a subdirectory in "src" say "EMAC" and then put all the *.c files in it. Similarly create a subdirectory "EMAC" in the "inc" directory and put all the *.h files in it. And ignore the makefile provided along with the EMAC library. The makefile provided in the startup code is sufficient to compile all the files.

CAUTION: If you are integrating this library with your own C++ code, then you might need to add the extern "C" thing while including those headers. Here is a brief explanation of how to do it.

Hope it helps. If this does not solve your issue. Repost the problem. I will try my best to help you.

Anonymous said...

Hi!

Thanks for the explanation. I was looking at some of the "common" files, and noticed some differences. Some of the differences are easy to change, but I'm not sure about these:

File: core_cm3.h
================
static __INLINE void __setBASEPRI(uint32_t basePri)
(Yours) __regBasePri = (basePri & 0xff);
(the Other) __regBasePri = (basePri & 0x1ff);

static __INLINE void NVIC_setPriorityGrouping (uint32_t PriorityGroup)
(Y) reg_value &= ~((0xFFFFU << 16) | (7ul << 8));
(O) reg_value &= ~((0xFFFFU << 16) | (0x0F << 8));

static __INLINE uint32_t NVIC_GetPriorityGrouping(void)
(Y) return ((SCB->AIRCR >> 8) & 0x07);
(O) return ((SCB->AIRCR & 0x07) >> 8);
===============

In system_LPC17xx.h, there are also differences in certain values (ie. PLL0CFG_Val, PLL1CFG_Val and FLASHCFG_Val).

As for the naming differences in a few other files, it should not be difficult to change it accordingly.

The file that I need to add to your startup code also requires a type.h file:
#include

#ifndef __TYPE_H__
#define __TYPE_H__

#ifndef NULL
#define NULL ((void *)0)
#endif

#ifndef FALSE
#define FALSE (0)
#endif

#ifndef TRUE
#define TRUE (1)
#endif


typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus;
typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState;

#endif
====================
but I'm wondering if this file has already been declared in your startup code but has been named differently? I couldn't find this file in your "inc" folder, but I might have missed it out.

Thanks once again!

Thejasvi said...

@^

I did not understand your problem clearly. Are you trying to add the type.h to your project and is it not getting added? I also did not understand the need for you to change the names in core_cm3.h and system_LPC17xx.h

I think there is no type.h file in the startup code I have provided.

Anonymous said...

Hey thejasvi,

Sorry, I forgot to update that I was able to compile the code based on your previous explanation (with some changes to the defintions eg. SC [in original file] changed to LPC_SC). Yes, I added the type.h eventually - but I was just wondering if it was necessary since TRUE, FALSE and NULL are "already known" by compilers? But anyway, that wasn't a major problem.

Unfortunately, I have to work with a DM9161 chip while the code was used for a DP83848 chip. I managed to find a project link which uses DM9161, http://code.google.com/p/nxp-lpc/source/browse/trunk/NXP-LPC/RT-Thread/bsp/lpc2468/?r=250
- but when comparing the emac files (and some others associated with it), some methods are similar, while others are totally different.

My problem now is, I'm not sure if I can simply use the emac.c file in my earlier post for a DM9161 chip - with of course, changes to definitions of DP83848 (to DM9161 instead). 'Coz when I looked at the project for DM9161, there were way too many differences in the methods (when I compared both emac.c files), but I wasn't sure if the emac.c file was created to accomodate to the project - or to the specific chip?

My apologies once again for the trouble. I really appreciate your help a lot. :) Thank you!

Thejasvi said...

I do not know much about these chips and the emac.c files. I think it is best if you use the emac.c provided with the library that you are using. Again I think it is best if you ask about this to the person who has provided the library.