#define works not in AVR Studio7 as expected

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

the following code works well in AVR Studio 4

 

#define CPU_ATtiny261           2     ; CPU = ATtiny261 old system
#define CPU_ATmega328        6     ; CPU = ATmega328  new system, multi I/O

;-------------------------------------------------------------------------------
#define CPU                  CPU_ATmega328

 

 

#define PinDef(N, P, X) \
.equ N## = PORT##P##X   \
.equ N##_PORT = PORT##P \
.equ N##_PIN = PIN##P   \
.equ N##_DDR = DDR##P   \

 

 

#if  (CPU   ==  CPU_ATmega328) ; #########################################

 

PinDef(LED1, B, 3)

 

#endif ; ###########################################################

 

basically also in AVR Studio 7

 

but with this failure message if the code is deactivated  for alternative CPU type

 

#if (CPU == CPU_ATtiny861) ; #############################################

 

PinDef(LED1, B, 3)

 

#endif ; ###########################################################

 

Severity    Code    Description    Project    File    Line    Column    Source    Project Rank
Error        Preprocessor: 'PinDef' called with 0 args, expected 3    Attiny861.ASM    127    0    Build    1

 

 

anybody any idea?

 

Thanks

discholz

 

 

 

 

This topic has a solution.

discholz

Last Edited: Wed. Oct 14, 2020 - 06:49 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Answer: compiler directives DO NOT take a following semicolon! 

 

If you must, then

 

#if  (CPU   ==  CPU_ATmega328) // #########################################

 

Also, I don't think that you can use an equality test that way in a directive.

 

Also, to post code well, please use the "<>" button up in the tool bar.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

I'm guessing that the semicolon is meant to start a line comment in the assembler.

 

But before that happens, the preprocessor is doing text substitution,

"CPU" gets defined to be "6     ; CPU = ATmega328  new system, multi I/O".

 

I can see that causing havoc in constant expressions

(like the #if, which is OK, according to K&R, 1978, p.208).

but I can't explain how it would create a PinDef call with no arguments.

 

Can you run the preprocessing stage by itself and examine that output?

 

On macos, 'cpp' doesn't complain, once I pull the comments from the #define lines.

HTH.

Mike

Last Edited: Tue. Oct 13, 2020 - 12:24 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ka7ehk wrote:
Answer: compiler directives DO NOT take a following semicolon! 
Jim he's actually using assembler not C here and in assembler semi-colon starts a comment.

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

ka7ehk wrote:
compiler directives

You meant preprocessor directives? (but see #4)

 

ka7ehk wrote:
to post code well, please use the "<>" button

+1

 

@ discholz - for illustrated instructions, see Tip #1 in my signature, below:

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...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks to all for the reply

 

well, its an assembler projekt working well with AVR Studio 4 for many controllers and building blocks,  configured this way for a particular project.

 

Even if I remove all comments ( either asm type ';' or C type '//') there is that magic behavior in AVR Studio 7 in the same way

 

But its only that  issue with preprocessor. writing any other bullshit into file (which normaly leads to an error) is ignored as expected.

 

How to create in an assembler project a preprocessor output? as from Mike: Can you run the preprocessing stage by itself and examine that output?

 

discholz

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

If this is AVRAsm2 then it's not the "normal" C preprocessor that is being used (as you might find when using avr-as). Atmel's assembler has it's own curios implementation of C preprocessing and, no, unlike the GNU pre-pro I don't think you can intercept the result after preprocessing but before assembly.

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

You do know that the AVR Assembler in Studio7 is an upgrade over the default assembler in AVRTudio4 (actually it was optionally available there as AVR Assembler 2)

 

Did you read the Microchip AVR Assembler Documentation ?

The AVR Assembler is the assembler formerly known as AVR Assembler 2 (AVRASM2). The former AVRASM distributed with AVR Studio® 4 has now been obsoleted and will not be distributed with current products.

 

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

But surely it has to be avrasm2 (whether AS4 or AS7) as the original assembler didn't have ANY preprocessor support.

 

I'm guessing it's a different version of avrasm2.

 

(might help if OP could identify exactly which assemblers (AS4 and AS7) it is that he is comparing).

 

The one in AS7 (well my copy anyway) reports as:

C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avrassembler>avrasm2 -h
AVRASM: AVR macro assembler 2.2.7 (build 69 Jul 26 2017 16:25:06)
Copyright (C) 1995-2017 ATMEL Corporation

usage: avrasm2 [options] file.asm

 Options:
    -f O|M|I|G -  output file format:
        -fO Debug info for simulation in AVR Studio (default)
            -fO1 | -fO2 - force format version 1 or 2 (default: auto)
        -fM Motorola hex
        -fI Intel hex
        -fG Generic hex format
        -f- No output file
    -o ofile   Put output in 'ofile'.
    -d dfile   Generate debug info for simulation in AVR Studio in 'dfile'.
               Can only be used with the -f [M|I|G] option.
    -l lfile   Generate listing in 'lfile'
    -m mfile   Generate map in 'mfile'
    -e efile   Place EEPROM contents in 'efile'
    -w         Relative jumps are allowed to wrap for program ROM
               up to 4k words in size
    -C ver     Specify AVR core version
    -c         Case sensitive
    -1/-2      Turn on/off AVR Assembler version 1 compatibility.
    -p1|0      Set/unset AVRASM1 implicit .device include (also set by -1)
    -I dir     Preprocessor: Add 'dir' to include search path
    -i file    Preprocessor: Explicitly pre-include file
    -D name[=value] Preprocessor: Define symbol. If =value is
               omitted, it is set to 1.
    -U name    Preprocessor: Undefine symbol.
    -S file    Produce include/label info file for AVR Studio
    -v verbosity [0-9][s]:
        -vs Include target resource usage statistics
        -vl Output low-level assembly code to stdout
        -vk Keep output files if source file empty
        -v0 Silent, only error messages printed
        -v1 Error and warning messages printed
        -v2 Error, warning, and  info messages printed (default)
        -v3-v9 Unspecified, increasing amounts of assembler internal dumps.
    -V         Format map and list files for Verilog.
    -8 -|+     Force Disable/Ebable 8kB check for JMP/CALL
    -O i|w|e   Overlap report: ignore|warning|error [error]
    -W-b|+bo|+bi Byte operand out of range warning disable|overflow|integer
    -W+ie|+iw  Unsupported instruction error | warning
    -W+fw      Label slip caused by forward ref accepted (DANGEROUS)
    -FD|Tfmt   __DATE__ | __TIME__ format, using strftime(3) format string
    -h         this help

So it is 2.2.7 b69

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

well, for sure I use AVRASM2 since years. I found tree installed versions, and made a hard copy of these versions to AVR Studio 7

the help gives the same output, except the line (which comes propably with avrstudio 7

 -8 -|+     Force Disable/Ebable 8kB check for JMP/CALL

 

 

Target "CoreBuild" in file "C:\Program Files (x86)\Atmel\Studio\7.0\Vs\Assembler.targets" from project "D:\Dieter\Projects\DCF77\Software\DCFCLOCK_7\DCFCLOCK\DCFCLOCK.asmproj" (target "Build" depends on it):

Using "RunAssemblerTask" task from assembly "C:\Program Files (x86)\Atmel\Studio\7.0\Extensions\Application\AvrAssembler.dll".

Task "RunAssemblerTask"

C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avrassembler\avrasm2.exe -fI -o "DCFCLOCK.hex"  -m "DCFCLOCK.map"  -l "DCFCLOCK.lss"  -S "DCFCLOCK.tmp"  -W+ie -I"C:\Program Files (x86)\Atmel\AVR Tools\AvrAssembler2\Appnotes" -I"C:/Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.0.118\avrasm\inc"  -im328pdef.inc -d "D:\Dieter\Projects\DCF77\Software\DCFCLOCK_7\DCFCLOCK\default\DCFCLOCK.obj"  "D:\Dieter\Projects\DCF77\Software\DCFCLOCK_7\DCFCLOCK\ASM_CONF.ASM"  -I "C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avrassembler\Include"

AVRASM: AVR macro assembler 2.1.42 (build 1796 Sep 15 2009 10:48:36)

 

run w/o error

 

 

Target "CoreBuild" in file "C:\Program Files (x86)\Atmel\Studio\7.0\Vs\Assembler.targets" from project "D:\Dieter\Projects\DCF77\Software\DCFCLOCK_7\DCFCLOCK\DCFCLOCK.asmproj" (target "Build" depends on it):

Using "RunAssemblerTask" task from assembly "C:\Program Files (x86)\Atmel\Studio\7.0\Extensions\Application\AvrAssembler.dll".

Task "RunAssemblerTask"

C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avrassembler\avrasm2.exe -fI -o "DCFCLOCK.hex"  -m "DCFCLOCK.map"  -l "DCFCLOCK.lss"  -S "DCFCLOCK.tmp"  -W+ie -I"C:\Program Files (x86)\Atmel\AVR Tools\AvrAssembler2\Appnotes" -I"C:/Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.0.118\avrasm\inc"  -im328pdef.inc -d "D:\Dieter\Projects\DCF77\Software\DCFCLOCK_7\DCFCLOCK\default\DCFCLOCK.obj"  "D:\Dieter\Projects\DCF77\Software\DCFCLOCK_7\DCFCLOCK\ASM_CONF.ASM"  -I "C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avrassembler\Include"

AVRASM: AVR macro assembler 2.1.57 (build 16 Aug 27 2014 16:39:43)

D:\Dieter\Projects\DCF77\Software\DCFCLOCK_7\DCFCLOCK\ATiny861.ASM(131,0): error: Preprocessor: 'PinDef' called with 0 args, expected 3

 

Target "CoreBuild" in file "C:\Program Files (x86)\Atmel\Studio\7.0\Vs\Assembler.targets" from project "D:\Dieter\Projects\DCF77\Software\DCFCLOCK_7\DCFCLOCK\DCFCLOCK.asmproj" (target "Build" depends on it):

Using "RunAssemblerTask" task from assembly "C:\Program Files (x86)\Atmel\Studio\7.0\Extensions\Application\AvrAssembler.dll".

Task "RunAssemblerTask"

C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avrassembler\avrasm2.exe -fI -o "DCFCLOCK.hex"  -m "DCFCLOCK.map"  -l "DCFCLOCK.lss"  -S "DCFCLOCK.tmp"  -W+ie -I"C:\Program Files (x86)\Atmel\AVR Tools\AvrAssembler2\Appnotes" -I"C:/Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.0.118\avrasm\inc"  -im328pdef.inc -d "D:\Dieter\Projects\DCF77\Software\DCFCLOCK_7\DCFCLOCK\default\DCFCLOCK.obj"  "D:\Dieter\Projects\DCF77\Software\DCFCLOCK_7\DCFCLOCK\ASM_CONF.ASM"  -I "C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avrassembler\Include"

AVRASM: AVR macro assembler 2.2.7 (build 69 Jul 26 2017 16:25:06)

D:\Dieter\Projects\DCF77\Software\DCFCLOCK_7\DCFCLOCK\ATiny861.ASM(131,0): error: Preprocessor: 'PinDef' called with 0 args, expected 3

 

  • Confirmation:
    it depends from avrasm2 version,
    the version 2.1.42 from avrstudio4 works well without errors
     
  • The version 2.1.57 (may be from avrstudio 6) and
    the version 2.1.57 from avrstudio 7 returns the described error
     
  • But this doesnot helps really, because I think I need the newest version for the new controller types
    and don't want to waste my available sources and configuration method

    It's still not clear to me,  why the preprocessor tries to analyze an excluded part of source code 

    any idea for a workaround?

 

 

 

 

discholz

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well I couldn't believe this so I tried your code for myself using AVRASM: AVR macro assembler 2.2.7 (build 69 Jul 26 2017 16:25:06)

 

Hmmpf! It doesn't build; same error as you get. WTF ?

 

I suspect a bug is at play here but I did discover a workaround:

Simply indent the conditional line by one space and it actually builds OK.

 

Now; if they only tested AVRASM using conditional instructions which are naturally indented they wouldn't have spotted the bug.

 

This Works:

#if (CPU == CPU_ATmega328)
 PinDef(LED1, B, 3)
#endif

 

 

Last Edited: Tue. Oct 13, 2020 - 07:42 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@ N.Winterbottom   great!

 

yes, one whitespace seems to be a functional workaround. magic to find this fix, compliments.

 

and, true, in C or  other languages I use intented code, but not in assembler

 

nevertheless, crazy behavior

 

Thanks

discholz