IAR C question

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi there,

I am working on an IAR C project that builds hex files for more than one similar products.

Some of the products use the ATmega48V and some other use the ATmega88V, because of it's larger memories. I mean that some functions don't used by some products, so they excluded by the compiler instructions (#ifdef, #ifndef e.t.c.)

So each time I have to build a file for product uses the ATmega48:

1. I have to sellect the product name:

#define product1
//#define product2
//#define product3
//#define product4
//#define product5

2. I have to change the type of the microcontroller at general options/target

3. I have to change the .xcl file, at linker/config.

Is there any other way to do this automatically. I don't want to split my project, in order to have one for the ATmega48V products and one for the ATmega88V, because each time I update the code I want to update all products.

Thanks for your time,

Michael.

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well I'm sure IAR supports -D on the command line so rather than edit the #define's just have two (or more) makefiles, one that specifies -Dproduct1 and one that specifies -Dproduct2 and so on. Presumably the controller type can also be specified in such a Makefile and equally the Makefile can presumably direct to a specific linker script? So then it'd simply become a choice of:

make -f Product1.mak

or

make -f Product2.mak

Cliff

(of course this all relies on being able to use Makefiles and I know IAR "hides" them from you by the GUI IDE presentation but, behind the scenes, I believe it can be driven via make and makefiles too)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Cliff IAR is not a make based environment. (though you can use it with make if you like)

Michael there are a number of predefined macros that you can use to identify what target the code is being compiled for. Perhaps you could use those to set your "product" defines. This way all you should have to do is change the target in the project options (and .XCL)

If you get rid of the .XCL, and use the project options to define the memory areas (and use the defaults) All you will have to do is change the target in the project options.

The alternative, as Cliff suggested, is to move to a command line approach, and use something like make to control the various builds.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I did something else,

I have compiled my code, while all configurations are based on the ATmega88V. The final hex file was smaller that 4Kb, so I programmed an ATmega48V. The program looks to wark perfect.

Is this accepted? What is your opinion?

Michael.

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Another approach is to create separate build profiles for each target.

In IAR 5.10A (probably the same in most newer versions) goto Project -> Edit Configurations

Then select new and answer the prompts. Name one new profile Atmega88V and the other Atmega48V.

Then select whichever configuration you want from the drop down list in the workspace window (where you select from debug/release ordinarily), and setup the profiles using the built in GUI.

If you do this you can setup different preprocessor directives for conditional compiling and should be able to point to different linker files. Then you can choose between the two simply using the drop-down control before you build.