Defining symbols for both C and ASM in Atmel Studio

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

I usually define symbols (e.g. F_CPU) that may be used in multiple files in the Project/Properties/Toolchain/C Compilers/Symbols section.

I currently have a need to use one of those symbols (actually F_CPU) in both .c and .S files; however, the assembler does not use the compiler symbols (at least so it seems).

Is there a way (in Atmel Studio) to share a symbol between both .c and .S files other than create a .h containing the defined symbol and including it wherever needed?

David (aka frog_jr)

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

Are you talking about -D's? The fact is that the project config in AS7 has separate areas for entering the -D's for C and Asm. I've been caught by this myself when defining F_CPU and the Asm code did not see it. I wish As7 had a composite area to define -D symbols to be passed into both or some way to say "this one applies to both C and Asm".

 

I guess your choices are either:

 

a) enter the symbol in two places in the IDE

b) go with your original idea of a .h that can be included by both C and Asm
 

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

Thanks clawson, I had forgotten I can add the -D in the "Assembler Flags" section (I use assembly very rarely anymore).

I'll just have to make sure I document this for the next guy to see the code.

(Setting the symbols twice in AS7 will be less typing since there are going to be several asm files sharing the symbols with C files.)

 

David (aka frog_jr)

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

If it were me I'd be tempted to find out where such -D's are written into the .vcproj files and then write a tool in Python that edits the XML and enters whatever you choose in both places. It does seem quite ridiculous to me that the IDE itself does not allow you to nominate where symbols apply. I'm pretty sure in Eclipse it does this with tick boxes so you can say where a particular setting applies.

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

You can hack'it by using a assembly include file, that will contain required symbol(s)

This file can be automatically generated pre-compile, by reading .cproj XML file and parse for original -D symbol.

You can do this in C# very easily.

 

.equ F_CPU, 8000000

In assembly file, just include

 

.include "file.h"

Then, use ASM flags in AS

 

-Wa,-I"..\..\path_to_that_file"

I had the same problem using some Atmel 1 wire driver, that instead using _delay_us() part of libc, they preferred to re-write their own assembly __delay_us() routine which does the same thing.

 

Perhaps ? (didn't tried)

 

-Wa, -DF_CPU
-Wa,-I"..\..\path_to_h"
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is the underlying compiler gnuavr?

 

I had the same problem and the solution was using the assembler file extension .sx which then uses the c preprocessor for assembler files.   I then put the constants into a C header file and can include that in assembler and C files.

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

The usual choice is .S

 

.s means assemble only

.S means preprocess first then assemble.

 

Obviously you can use #include and #define and so on in .S. In fact usually the first thing you do is:

#define __SFR_OFFSET 0
#include <avr/io.h>

 

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

I think I tried .S but I cannot be sure.   So is .S the same as .sx?

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

Yup, it is according to the user manual

 

https://gcc.gnu.org/onlinedocs/g...

 

so .sx is OK - it's just the "standard" in the specific case of AVR tends to be .S

 

(of course when one uses a crap operating system that doesn't always understand the difference between s and S then sometimes compromises are required)

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

Well I believe I am using a good operating system but maybe I used .sx because the .S in my otherwise all lower case filenames did not look pleasing to the eye.   My .sx could also originate from ARM systems (We are using the same build process over all platforms / compilers).   Actually I found somewhere yesterday that Keil ARM does not seem to adhere to this scheme, only .sx was preprocessed otherwise .s and .S were treated the same.   Maybe that was a typo; google won't find it for me any more.

 

So if .S is preprocessed where is the OPs problem?   You simply include a C header file.

Last Edited: Sun. Sep 25, 2016 - 07:07 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@hugo_habicht: You must not have seen the query in post #1 asking how to do this "other than create a .h containing the defined symbol and including it wherever needed?"

David (aka frog_jr)