Reply
Highlighted
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.

new_proj_1.png

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.

new_proj_2.png

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.

new_proj_3_1.png

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.

new_proj_3_2.png

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'

new_proj_4.png

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

new_proj_4_2.png

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

new_proj_5_1_1.png

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.

new_proj_5_2.png

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.

new_proj_5_3.png

Select the main.c file and press open.

new_proj_5_4.png

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:

new_proj_5.png

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.

new_proj_6.png

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.

new_proj_6_1.png

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.

new_proj_7.png

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

new_proj_8.png

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

new_proj_9.png

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:

new_proj_10.png

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.

new_proj_11.png

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.

new_proj_12.png

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.

new_proj_13.png

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.

new_proj_14.png

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

new_proj_15.png

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

new_proj_16.png

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.

new_proj_19.png

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.