I’m going to post a summary of how to create a library using a standard C compiler as an archive that can be linked with EasyC code. I’m not going to make this a full tutorial as, to be honest, it’s probably beyond the capability of 95% of EasyC users, but if anyone needs more details they can contact me directly. It’s deliberately a bit vague on certain steps, if you are an advanced programmer you will figure things out for yourself.
The idea to do this was sparked by some recent work that I did to document the steps needed to compile EasyC compatible projects using the eclipse IDE. I’m not publicly releasing any of that (yet) as there are some possible license issues in using EasyC headers and runtime libraries outside of the EasyC environment. The creation of a library, however, does not need an EasyC installation or use any of the installed EasyC header or other files.
The steps are as follows.
Make sure you have a Java runtime on the PC.
Install Eclipse for C/C++ development. I prefer last years version called Indigo, you can get that from here.
- Install Sourcery G++ lite, the version that EasyC 184.108.40.206 is using (Sourcery G++ Lite 2010.09-51) is from 2010 and can be downloaded from here. Older or newer versions of EasyC may need a different version of Sourcery.
- Launch eclipse and add support for cross compilation. Cross compile is part of the CDT (C/C++ development toolkit). In eclipse goto “Install new software…” and use this path in the “work with” text box.
This is for indigo, for different version of eclipse this would differ.
Select C/C++ GCC Cross Compile Support under the CDT Optional Features.
- Create a new C project, choose “cross compile project” under “static library”. Select next.
5a. Set the tool command prefix as arm-none-eabi- (note the trailing -)
5b. Set the tool command path to the “bin” directory for Sourcery G++ lite, for windown XP this is usually
C:\Program Files\CodeSourcery\Sourcery G++ Lite\bin
5c. uncheck Debug, we are just going to create a release library. select finish.
- pull up the project properties and go to the C/C++ build setting panel.
7a. add the following symbol definitions
7b. Set optimization and debugging to none
7b. Set the following as miscellaneous other flags, remove the existing ones first.
-MD -c -fsigned-char -mthumb -mcpu=cortex-m3 -ffunction-sections -mlittle-endian
7c. Click OK and accept the settings.
Add your source code.
Build the project, you should end up with an archive file in the Release sub-directory under your main project directory.
At this point you have created your library file, if your project was called “jim” then there will be a libjim.a file.
- Navigate to the EasyC folder with support for the STM32, under Windows XP this is at the following path.
C:\Program Files\Intelitek\easyC V4 for Cortex#Tools\STM32F103VD
There are a number of folders in this location
Go into the Link folder, there will be a couple of other files there, copy your “libjim.a” library file into this location.
Go into the scripts folder, edit the following file - easyCRuntime.elf.ld
(disclaimer - remember that you are now changing an EasyC file that controls the link process, be careful). The contents of this file are as follows.
STARTUP("Startup.o") INPUT("easyCRuntimeLib.lib") EXTERN( __io_putchar ) EXTERN( _write ) INPUT("STM32x_io_putchar_thumb.a") INPUT("e_stdio_thumb.a") OUTPUT("easyCRuntime.elf") INCLUDE "STM32F103_384K_64K_FLASH.ld"
Add the following line (change the library name to your library) under the second INPUT line.
save the file.
- Create a new EasyC project and use your new library, obviously you will need to add any headers that are associated with the library but if you have made it this far then that should be easy.