Starting a Blank IAR Project for EFM32

https://eewiki.net/display/microcontroller/Getting+Started+with+EFM32+Giant+Gecko+ARM+Cortex-M3

https://www.eewiki.net/pages/viewpage.action?pageId=29884493#GettingStartedwithEFM32GiantGeckoARMCortex-M3-Purpose


Silicon Labs recommends using Simplicity Studio to locate example code and documentation.  They recommend cloning existing projects for IAR instead of starting a blank IAR project from scratch.  This is because all of the App Notes and example code written for these micros use a hierarchy that is non-typical for IAR projects.  The examples also setup your include file paths and setup your debug link for you.  You can then use CMSIS and em_lib libraries to call functions from your main.c file to develop your application.

Although it's not necessarily recommended, you can start a blank IAR project by using the following procedure.  This procedure parallels the example found here.  However, I setup my project in a unique project directory rather than the default location used by Simplicity Studio.

 


 
Procedure for Starting a Template IAR Project for EFM32

This procedure outlines how to start a blank IAR project and setup the necessary project settings.  However, we will use this process to setup a template project.  Once we have a template created, we can simply copy&paste and rename the project whenever we wish to start a new EFM32 Giant Gecko project.  Even if you don't want to use the emlib libraries, you should still follow all of these steps to properly setup your project.

  1. Open IAR and navigate to Project -> Create New Project

  2. In the "Create New Project" dialog box, ensure 'ARM' is selected as the Toolchain.  Select 'Empty Project' and click 'OK'.

  3. Now a "Save As" dialog should pop up and you can select a location for your project.

    Silicon Labs recommends placing each of your projects in the application note (an) directory that gets created when you install Simplicity Studio.  However, we are going to create a unique location for all of our EFM32 projects.  

    For my personal use, I created a "My_EFM32_Projects" folder within an "Energy Micro" folder on my desktop.  This is where I store all of my new EFM32 projects.  For this demo, since we are using a Giant Gecko microcontroller, inside the "My_EFM32_Projects" folder, I've created a folder called "Template_EFM32GG".  You can name it whatever you wish.  However, I like to be able to sort my projects by micro type.  It's an easy identifier for me to recognize which specific micro I used for that project if I include it in the name of the project folder.  Alternatively, you could create another folder for individual micros if you wanted, but I like to keep my folder count down if possible.  My project directory now has the following hierarchy:

    <desktop> -> "Energy Micro" -> "My_EFM32_Projects" -> "Template_EFM32GG"

    Once you have your project directory setup, create an "iar" folder and save the project file as "Template_EFM32GG.ewp".

  4. Now that your project has been created, you can add some groups to the project.  Right-click the project in the workspace browser and select 'Add Group'.

  5. Let's name the first group 'source'.  This is standard for all EFM32 projects.

  6. Now we can create our 'main.c' file.  Navigate to File -> New -> File

  7. An untitled file should open.  Select File -> Save As

  8. Navigate to your project directory (one level above the 'iar' folder you saved the project file in) and save the file as 'main.c'.  In my case the project directory is: <desktop> -> "Energy Micro" -> "My_EFM32_Projects" -> "Template_EFM32GG"

  9. Now that the 'main.c' file has been created, we have to actually add it to our workspace.  Right-click on the 'source' group you created and select Add -> Add Files.

  10. Select the 'main.c' file you just created.


  11. Add two more groups to your workspace and call them 'CMSIS' and 'emlib'.  This is standard for EFM32 projects.
  12. Right-click the 'CMSIS' group and select Add -> Add File.  

  13. When Simplicity Studio is installed, it saves all documentation as well as CMSIS, emlib, and device files in:   C:\Users\<user name>\AppData\Roaming\energymicro
    In the 'energymicro' folder, navigate to Device -> EnergyMicro -> EFM32GG -> Source  (if you aren't using a Giant Gecko, navigate to the appropriate EFM32xx folder).

    Select the 'system_efm32gg.c' file and click 'Open' to add the file to your workspace.  This file is included for all standard EFM32 projects.

  14. Right-click the 'CMSIS' group and again select Add -> Add File.  Navigate to C:\Users\<user name>\App Data\Roaming\energymicro\Device\EnergyMicro\EFM32GG\Source\IAR and open the 'startup_efm32gg.s' file to add it to your workspace.  This file is needed in order to properly program the device.

  15. Now you can add source files to the 'emlib' group that you previously created.  You can add only the ones you need, or add all of them if you wish.  Navigate to the 'emlib' folder which is located at C:\Users\<user name>\AppData\Roaming\energymicro.
    Inside the 'emlib' folder you can open the 'src' folder and add any or all of the peripheral emlib libraries.  I would recommend adding all of them to your workspace for you to easily browse through the available functions.  That way you can view any file without having to navigate to each one using windows explorer.  Use 'Ctrl'+'left mouse button' to select individual files and click 'Open' to add them to your workspace.
    Note:  Even if you don't want to use the emlib libraries, you should still add the 'em_system.c' file to the emlib group so that you can call the Chip_Init() function at the beginning of your 'main.c' file.  Chip_Init() addresses any known errata for your device and applies any known software fixes.

  16. In order to use the functions located in these emlib files, you need to add #include for the respective header file in your 'main.c' file.  For example, if you wanted to use any of the prewritten ADC functions in your 'main.c' file, you would need to include the 'em_adc.h' header file as shown in the following example.  'em_system.h' and 'em_chip.h' should be added to every EFM32 project.  You can also add a blank main() function to your 'main.c' file.

  17. Now let's setup the project options.  Right-click on "Template_EFM32GG.ewp" in the workspace explorer and select 'Options'.

  18. In the 'General Options' category, under the 'Target' tab, make sure the 'Device' button is selected and click the 'list' icon on the right.  Navigate to EnergyMicro and select your specific device.  For this demo, I selected EFM32GG990F1024 which is loaded on the EFM32GG Starter Kit.

  19. In the 'C/C++ Compiler Settings' category, under the 'Preprocessor' tab, you can add include directories for your device.  You will need to add the paths to the include files for the CMSIS library and the emlib library if you wish to use the emlib API (recommended).  You will also need to link to the 'Include' folder for the specific device.  Example projects found in Energy Micro app notes use relative paths from the project directory to link to these directories.  You can use hard-coded paths if you know the location of these won't change.  For my personal use, I hard code the paths directly in the Project Options (rather than using relative path).  Silicon Labs recommends you use relative paths for portability.  It's completely up to you, but you need to always be aware of where the files are located and how you are linking to them.  

    In the 'Defined symbols' box, you also need to define your device symbol.  For my project, I've defined the symbol EFM32GG990F1024.  Here's an example of hard-coding the path to the default install directory.



  20. In the 'Output Converter' category, check 'Generate additional output' and select 'binary' for output format.

  21. In the 'Linker' category, select 'Override default' and navigate to the .icf file for your device.  The file should be located in the IAR install directory, not the Simplicity Studio install directory:  
    C:\Program Files (x86)\IAR Systems\Embedded Workbench 6.x\arm\config\linker\EnergyMicro.

  22. In the 'Debugger' category, under the 'Setup' tab, select 'J-Link/J-Trace' as the Driver since we are using the J-link debugger included on the EFM32GG Starter Kit.  If you are using a different debugger, these settings may change.

  23. Still in the 'Debugger' category, under the 'Download' tab, check the 'Verify download' and 'Use flash loader(s)' boxes.

  24. In the 'J-Link' category, under the 'Connection' tab, select 'SWD' as the Interface.  Click 'OK' to apply the project options.

  25. Select File -> Save All.  Save the workspace in the 'iar' folder within your project directory.

  26. Right click on the project and click 'Make' to build the project

  27. Now we have a template project with all of the necessary project settings.  Whenever we wish to start a new EFM32 project for Giant Gecko, we can simply copy&paste the template project in whatever location we desire because we used hard-coded include paths.  Once you paste a copy of the template, simply rename the project folder to whatever you wish.  Also, I would recommend renaming the workspace file to match the project name.  All other files can keep "Template" in the file name and the project will still build properly.

            

 

You are on your way!  Now let's look at some code examples...


猜你喜欢

转载自blog.csdn.net/gaoguoxin2/article/details/79912944