Define a common set of symbols for multiple projects

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

Is there a way to easily create a set of symbols that can be reused for multiple projects in Atmel Studio 7?

 

I could define the individual symbols explicitly under project options -> Toolchain -> GNU C Compiler -> Symbols -> Defined symbols. However I want to define the exact same symbols for several projects so it would be convenient to define the set just once and reuse that set for all projects.

 

Is it possible? I cannot see a way at the moment...

 

 

/Jakob Selbing

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

I believe I found what I was searching for in the "-include <file>" option.

/Jakob Selbing

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

Or simply add a #include of some shared header to each?

 

-include is a bit like as -D is to #define.

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

I find that this is a major limitation of all the IDEs I have ever used[1]:

 

They all allow you to have multiple "projects" or "configurations" or "targets" within one "solution" (the terminology varies, but the principle remains the same) - but none of them lets you have a set of options which is common to the entire "solution".

 

angry

 

So that leaves you either having to keep duplicating stuff where it needs to be the same across "projects", or resort to other means - like having a header file.

 

[1] The only exception is Segger Embedded Studio (which, AIUI, is a re-badged Rowley Crossworks).

 

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Thu. Apr 9, 2020 - 09:08 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


If you're looking for a way to manage a shared "config" header, you might want to take a look at this:

 

https://www.keil.com/pack/doc/CMSIS/Pack/html/configWizard.html

 

Although it's by ARM / Keil, it is in no way specific to either Keil tools or ARM architectures - it gives you a perfectly standard 'C' header file.

 

There is a Java utility to manage it graphically:  https://helmpcb.com/software/cmsis-configuration-wizard although I don't find it to be great.

 

I prefer to use the facility within the Keil uVision IDE:  https://devzone.nordicsemi.com/f/nordic-q-a/45362/cmsis-configuration-wizard---option-highlighting

 

 

You can use uVision purely for this purpose - it doesn't matter that you're not using it for the actual code:

 

https://devzone.nordicsemi.com/f/nordic-q-a/45366/missing-defines-in-generic-sdk_config-h/178339#178339

 

https://devzone.nordicsemi.com/f/nordic-q-a/48768/combining-2-examples/193667#193667 - has an example project.

 

The free Keil download is fine for this.

 

EDIT

 

Added screenshot

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Fri. Jul 10, 2020 - 08:38 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

Or simply add a #include of some shared header to each?

 

-include is a bit like as -D is to #define.

That would work but it would be quite impractical in this case since many files are library files. For example, I have a UART/USART driver module in my library. It can target different MCUs with one or multiple UART/USARTs. It is interrupt-driven so they use buffers internally. The source code requires that several symbols are defined, for example the TX and RX buffer sizes. 

 

So when I build I need to define the buffer sizes and several other symbols. I have several projects that use this driver so they all must define the same symbols. These projects are tightly coupled since they target the same custom PCB but with slightly different functionality. They even use the same main.c file but with lots of conditional code depending on what functionality should be included.

 

So modifying the library source code to include a project-specific header is not really practical.

 

I could however include a module-specific configuration header (like "usart_config.h") that the referencing project must provide. That is a method I used quite extensively previously. The drawback is that I would need to implement this for all library source code that the project uses. It clutters up the project a bit too.

/Jakob Selbing

Last Edited: Thu. Apr 9, 2020 - 09:10 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Perhaps some JSON/Python that runs as a pre-build step to auto-gen some of the headers etc? Then you just edit the JSON to configure the thing.

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

awneil wrote:
They all allow you to have multiple "projects" or "configurations" or "targets" within one "solution" (the terminology varies, but the principle remains the same) - but none of them lets you have a set of options which is common to the entire "solution".
[...]
So that leaves you either having to keep duplicating stuff where it needs to be the same across "projects", or resort to other means - like having a header file.

Is there anything about the -include option that does not fulfill what you request?

Here is what the docs says:

Quote:
"Process file as if  appeared as the first line of the primary source file. However, the first directory searched for file is the preprocessor’s working directory instead of the directory containing the main source file. If not found there, it is searched for in the remainder of the  search chain as normal."

-include file

/Jakob Selbing

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

clawson wrote:

Perhaps some JSON/Python that runs as a pre-build step to auto-gen some of the headers etc? Then you just edit the JSON to configure the thing.

But that sounds complicated. I am quite satisfied with the -include option.

/Jakob Selbing

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

jaksel wrote:
Is there anything about the -include option that does not fulfill what you request?

Yes - it doesn't support any way to have some things that remain common to all projects within the solution, and some that are different for different projects.

 

 

 

-include file

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Thu. Apr 9, 2020 - 09:29 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I've been in a similar situation so I took to manually editing the project files. They're just XML so I used diffuse (my favourite file diff/merge program) to keep the relevant sections synchronised.

 

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

Hi

I'm not sure if this helps but Visual Studio and AS7 support exporting templates https://docs.microsoft.com/en-us/visualstudio/ide/how-to-create-project-templates?view=vs-2015

In AS7 look under the File / Export Template menu option. I haven't tried it to see what gets saved but it may be worth a look.

Andy

Hardware and Software Design, Arduino, AVR, c, c++, c#

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

N.Winterbottom wrote:

I've been in a similar situation so I took to manually editing the project files. They're just XML so I used diffuse (my favourite file diff/merge program) to keep the relevant sections synchronised.

I do that too sometimes. But methods that require me to keep things synchronized is something I try to avoid in general. 

/Jakob Selbing

Last Edited: Sun. Apr 12, 2020 - 06:42 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jaksel wrote:
I do that too sometimes. But methods that require me to keep things synchronized is something I try to avoid in general. 

So what we both want is a #include equivalent for our project files. smiley

 

<edit>

Ooh - This looks interesting; https://stackoverflow.com/questions/5268177/is-there-anyway-to-define-constant-on-a-solution-basis

And double ooh - stackoverflow has a Dark Mode now.

</edit>

 

Last Edited: Sun. Apr 12, 2020 - 09:42 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well as I already said, I am quite satisfied with GCCs -include option. It does exactly what I want to do i.e. it allows me to define (once) a set of macros/symbols that can be reused by one or more projects.

/Jakob Selbing