Posts: 457
Registered: ‎06-01-2012

Create a new project in IAR

Read this first: This is not the preferred way to start coding for the EFM32. The recommended procedure is actually to just copy an example project folder from either the application note folder or kit-example folder after having installed Simplicity Studio. Copy the whole example/application note folder, place it at the same directory level as the original folder and start modifying the source code, add source files etc.

This guide is intended as a reference to document all the steps needed to create a new project in IAR for an Energy Micro device.

1: Open IAR and select 'Create New Project' from the Project menu.


2: Select Empty project and press OK. The reason for not choosing the C and main.c template option is that we want the project files and source files to reside in different directories, this will make the project compatible with the way application note and example projects are created. That means that include paths/source code paths etc. are the same, which makes it much easier to borrow code from appnotes and examples.


3.1: We will create this new project in a new folder called 'test_project' which we put inside the 'an' -application note folder. Please install simplicity studio to get the 'energymicro\an' folder created. Note the path in the following picture.

3.2: After the 'test_project' -folder is created, create an empty folder called 'iar' within it.


3.3: Now save the project file as 'test.ewp' inside the 'iar' folder. All of these steps (3.1, 3.2, 3.3) can be done in the 'new project' dialogue that pops up after selecting the empty project.


4.1: Now that a new project is created, we will add some groups to the project. Right click the project in the workspace browser and select 'Add Group'


4.2: Name the first group 'source', this will contain custom source code for this project.


5.1: Now we will create a new 'main.c' file. Select New->File from the File menu.


5.2: Save the main.c file in the 'test_project' directory. This is the difference from the standard IAR new C-project template which have source files and project in the same folder by default.


5.3: Now it is time to add the newly created main.c file to the source group in our project. Right click the source group in the workspace browser and select Add->Add Files.


Select the main.c file and press open.


5.4: Now add two more groups to the project, call them 'CMSIS' and 'emlib'. After this is done, the workspace browser should look like this:


6.1: It is time to add source files to the CMSIS and emlib groups. Start by right-clicking the CMSIS group and go to 'Add->Add File'. In the open dialogue, navigate to the 'energymicro\Device\EnergyMicro\EFM32TG\Source' folder. Change EFM32TG folder as needed if you are making a project for another family.

Select the 'system_efm32tg.c' file and click open.


6.2: Now add the startup_efm32tg.s file to the CMSIS group as well. For IAR it is located in the IAR folder next to the system_efm32tg.c file in the previous step. It is important that this file is the correct one for your device family, it includes the interrupt vector table which is different between families.


7: Right click the emlib group and add sourcefiles as needed. I have selected the em_cmu.c, em_emu.c and em_system.c files. These files are located within the 'emlib'-folder at the same level as the 'an'-folder. I recommend to add at least the cmu and emu file, as they are needed for any basic clock or energy mode operation with the em peripheral library.


8: Now add a simple main() function and the necessary include files as shown in the next screenshot.


9: Now it is time to modify the project options. Right click the 'test' -project and select 'Options'.


10: In the Options window, first go to general Options and select your Device (be sure to select Device, not Core). I have selected the EFM32TG210F32 device:


11: Go to the next Category which is C/C++ Compiler Settings. Here it is only the preprocessor tab that need modifications. Add include directories as the next screenshot shows. Add more include directories here if needed. Also add your device define to the Defined symbols text box. Note the $PROJ_DIR$ macro which is relative to your test.ewp project file. This is more convenient than absolute file paths because it allows the project folder to be copied to other systems, only the simplicity studio directory need to have the same internal structure.


12: In the Output Converter Category, select Generate Additional output and select binary format. This will generate binary files that can be used by eAcommander or the EFM32 default bootloader.


13: In the Linker Category, select 'Override default' and select the correct *.icf file for your device. This should be located within the IAR install directory.


14: The next few steps are for the kit J-link debugger settings, please check with your debugger manual if you are using a different debugger.

Select J-Link as Driver.


15: In the download tab, select 'verify' and 'Use Flashloader', the correct flashloader should be chose automatically if selected correctly in the linker tab.


16: Go down to the J-Link sub-category and select SWD in the connection tab.


17: Now all that is left to do is to build the project. Either right click the project and select Make, or press the green arrow to start a debug session, which will also build the project. Now a 'save' window should pop up that wants to save a test.eww workspace file. Save this file within the iar folder that you created early on inside the test_project folder.


18: As a final exercise, have a look at the test.ewp. It is a normal xml-type text-file that includes all the project options, folder paths, file paths, include directories etc. In many cases it is just as easy to modify this file compared to changing/adding include directories in IAR through the project option window.