Errors on preprocessor errors

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

I 'm converting the files in 'ComponentTester-1.33m.tgz' from here to a Solution for Atmel Studio.

 

In compilation I get an error on this line:

#else
  #error <<< No or wrong MCU type selected! >>>
#endif

How can I correct this?

Last Edited: Wed. May 20, 2020 - 03:23 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

panoss wrote:
In compilation I get an error on this line

What do you mean by that?

 

The whole point of that line is precisely to generate an error!

 

Or do you mean that the compiler is complaining about the line itself?

 

Post the actual build output.

 

EDIT

 

For how to find the build output, see: https://www.avrfreaks.net/commen...

 

 

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: Wed. May 20, 2020 - 03:07 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is the build output:

 

------ Rebuild All started: Project: ComponentTester, Configuration: Debug AVR ------
Build started.
Project "ComponentTester.cproj" (ReBuild target(s)):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreRebuild" in file "C:\Program Files\Atmel\Atmel Studio 6.0\Vs\Compiler.targets" from project "C:\Users\Panagiotis\Documents\Atmel Studio\ComponentTester\ComponentTester\ComponentTester.cproj" (target "ReBuild" depends on it):
    Task "RunCompilerTask"
        C:\Program Files\Atmel\Atmel Studio 6.0\make\make.exe clean all
        rm -rf  ADC.o adjust.o ADS7843.o cap.o commands.o main.o display.o HD44780.o I2C.o ILI9163.o ILI9341.o inductor.o IR.o pause.o PCD8544.o probes.o resistor.o semi.o serial.o SPI.o SSD1306.o ST7565R.o ST7735.o ST7920.o tools.o user.o wait.o ADC.d adjust.d ADS7843.d cap.d commands.d main.d display.d HD44780.d I2C.d ILI9163.d ILI9341.d inductor.d IR.d pause.d PCD8544.d probes.d resistor.d semi.d serial.d SPI.d SSD1306.d ST7565R.d ST7735.d ST7920.d tools.d user.d  
        rm -rf "ComponentTester.elf" "ComponentTester.a" "ComponentTester.hex" "ComponentTester.lss" "ComponentTester.eep" "ComponentTester.map" "ComponentTester.srec"
        Building file: .././ADC.c
        Invoking: AVR/GNU C Compiler : (AVR_8_bit_GNU_Toolchain_3.4.1_830) 4.6.2
        "C:\Program Files\Atmel\Atmel Studio 6.0\extensions\Atmel\AVRGCC\3.4.1.95\AVRToolchain\bin\avr-gcc.exe" -funsigned-char -funsigned-bitfields -O1 -fpack-struct -fshort-enums -g2 -Wall -c -std=gnu99 -MD -MP -MF "ADC.d" -MT"ADC.d" -MT"ADC.o"  -mmcu=atmega328p   -o"ADC.o" ".././ADC.c"
        In file included from .././ADC.c:24:0:
C:\Users\Panagiotis\Documents\Atmel Studio\ComponentTester\ComponentTester\config.h(640,4): #error <<< No or wrong MCU type selected! >>>
        In file included from .././common.h:25:0,
                         from .././ADC.c:25:
c:\program files\atmel\atmel studio 6.0\extensions\atmel\avrgcc\3.4.1.95\avrtoolchain\bin\../lib/gcc/avr/4.6.2/../../../../avr/include/util/delay.h(90,3): #warning "F_CPU not defined for <util/delay.h>" [-Wcpp]
        In file included from .././ADC.c:28:0:
C:\Users\Panagiotis\Documents\Atmel Studio\ComponentTester\ComponentTester\config_644.h(663,4): #error <<< No or wrong MCU type selected! >>>
        make: *** [ADC.o] Error 1
    Done executing task "RunCompilerTask" -- FAILED.
Done building target "CoreRebuild" in project "ComponentTester.cproj" -- FAILED.
Done building project "ComponentTester.cproj" -- FAILED.

Build FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

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

If you actually open that line in that file, you'll see that this only supports the ATmega324P, ATmega644 and, ATmega1284 , not ATmega328P

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

 

The postings on this site are my own and do not represent Microchip’s positions, strategies, or opinions.

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

meolsen wrote:

If you actually open that line in that file, you'll see that this only supports the ATmega324P, ATmega644 and, ATmega1284 , not ATmega328P

What??!! Oh s$$$it!!

Thank you guys, I must be blind, I was so sure it was for ATmega328P!blush

 

Ok, I changed the solution 's device to an ATmega324P, now I get another error ('ADC_CLOCK_DIV' undeclared (first use in this function)):

 

------ Rebuild All started: Project: ComponentTester, Configuration: Debug AVR ------
Build started.
Project "ComponentTester.cproj" (ReBuild target(s)):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreRebuild" in file "C:\Program Files\Atmel\Atmel Studio 6.0\Vs\Compiler.targets" from project "C:\Users\Panagiotis\Documents\Atmel Studio\ComponentTester\ComponentTester\ComponentTester.cproj" (target "ReBuild" depends on it):
    Task "RunCompilerTask"
        C:\Program Files\Atmel\Atmel Studio 6.0\make\make.exe clean all
        rm -rf  ADC.o adjust.o ADS7843.o cap.o commands.o main.o display.o HD44780.o I2C.o ILI9163.o ILI9341.o inductor.o IR.o pause.o PCD8544.o probes.o resistor.o semi.o serial.o SPI.o SSD1306.o ST7565R.o ST7735.o ST7920.o tools.o user.o wait.o ADC.d adjust.d ADS7843.d cap.d commands.d main.d display.d HD44780.d I2C.d ILI9163.d ILI9341.d inductor.d IR.d pause.d PCD8544.d probes.d resistor.d semi.d serial.d SPI.d SSD1306.d ST7565R.d ST7735.d ST7920.d tools.d user.d  
        rm -rf "ComponentTester.elf" "ComponentTester.a" "ComponentTester.hex" "ComponentTester.lss" "ComponentTester.eep" "ComponentTester.map" "ComponentTester.srec"
        Building file: .././ADC.c
        Invoking: AVR/GNU C Compiler : (AVR_8_bit_GNU_Toolchain_3.4.1_830) 4.6.2
        "C:\Program Files\Atmel\Atmel Studio 6.0\extensions\Atmel\AVRGCC\3.4.1.95\AVRToolchain\bin\avr-gcc.exe" -funsigned-char -funsigned-bitfields -O1 -fpack-struct -fshort-enums -g2 -Wall -c -std=gnu99 -MD -MP -MF "ADC.d" -MT"ADC.d" -MT"ADC.o"  -mmcu=atmega324p   -o"ADC.o" ".././ADC.c"
        In file included from .././common.h:25:0,
                         from .././ADC.c:25:
c:\program files\atmel\atmel studio 6.0\extensions\atmel\avrgcc\3.4.1.95\avrtoolchain\bin\../lib/gcc/avr/4.6.2/../../../../avr/include/util/delay.h(90,3): #warning "F_CPU not defined for <util/delay.h>" [-Wcpp]
        Finished building: .././ADC.c
        Building file: .././adjust.c
        Invoking: AVR/GNU C Compiler : (AVR_8_bit_GNU_Toolchain_3.4.1_830) 4.6.2
        "C:\Program Files\Atmel\Atmel Studio 6.0\extensions\Atmel\AVRGCC\3.4.1.95\AVRToolchain\bin\avr-gcc.exe" -funsigned-char -funsigned-bitfields -O1 -fpack-struct -fshort-enums -g2 -Wall -c -std=gnu99 -MD -MP -MF "adjust.d" -MT"adjust.d" -MT"adjust.o"  -mmcu=atmega324p   -o"adjust.o" ".././adjust.c"
        In file included from .././common.h:25:0,
                         from .././adjust.c:25:
c:\program files\atmel\atmel studio 6.0\extensions\atmel\avrgcc\3.4.1.95\avrtoolchain\bin\../lib/gcc/avr/4.6.2/../../../../avr/include/util/delay.h(90,3): #warning "F_CPU not defined for <util/delay.h>" [-Wcpp]
        Finished building: .././adjust.c
        Building file: .././ADS7843.c
        Invoking: AVR/GNU C Compiler : (AVR_8_bit_GNU_Toolchain_3.4.1_830) 4.6.2
        "C:\Program Files\Atmel\Atmel Studio 6.0\extensions\Atmel\AVRGCC\3.4.1.95\AVRToolchain\bin\avr-gcc.exe" -funsigned-char -funsigned-bitfields -O1 -fpack-struct -fshort-enums -g2 -Wall -c -std=gnu99 -MD -MP -MF "ADS7843.d" -MT"ADS7843.d" -MT"ADS7843.o"  -mmcu=atmega324p   -o"ADS7843.o" ".././ADS7843.c"
        Finished building: .././ADS7843.c
        Building file: .././cap.c
        Invoking: AVR/GNU C Compiler : (AVR_8_bit_GNU_Toolchain_3.4.1_830) 4.6.2
        "C:\Program Files\Atmel\Atmel Studio 6.0\extensions\Atmel\AVRGCC\3.4.1.95\AVRToolchain\bin\avr-gcc.exe" -funsigned-char -funsigned-bitfields -O1 -fpack-struct -fshort-enums -g2 -Wall -c -std=gnu99 -MD -MP -MF "cap.d" -MT"cap.d" -MT"cap.o"  -mmcu=atmega324p   -o"cap.o" ".././cap.c"
        In file included from .././common.h:25:0,
                         from .././cap.c:25:
c:\program files\atmel\atmel studio 6.0\extensions\atmel\avrgcc\3.4.1.95\avrtoolchain\bin\../lib/gcc/avr/4.6.2/../../../../avr/include/util/delay.h(90,3): #warning "F_CPU not defined for <util/delay.h>" [-Wcpp]
        .././cap.c: In function 'SmallCap':
C:\Users\Panagiotis\Documents\Atmel Studio\ComponentTester\ComponentTester\cap.c(1126,12): 'ADC_CLOCK_DIV' undeclared (first use in this function)
C:\Users\Panagiotis\Documents\Atmel Studio\ComponentTester\ComponentTester\cap.c(1126,12): each undeclared identifier is reported only once for each function it appears in
        make: *** [cap.o] Error 1
    Done executing task "RunCompilerTask" -- FAILED.
Done building target "CoreRebuild" in project "ComponentTester.cproj" -- FAILED.
Done building project "ComponentTester.cproj" -- FAILED.

Build FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Last Edited: Wed. May 20, 2020 - 03:28 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I took a better look, ok it doesn't support ATmega328P but it does support ATmega328:

 

#if defined(__AVR_ATmega328__)

  #include "config_328.h"

/*
 *  ATmega 324P/324PA/644/644P/644PA/1284/1284P
 */

#elif defined(__AVR_ATmega324P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega1284__)

  #include "config_644.h"

 

Last Edited: Wed. May 20, 2020 - 03:48 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

panoss wrote:
now I get another error ('ADC_CLOCK_DIV' undeclared (first use in this function)):
OK so I downloaded that and searched:

D:\ComponentTester-1.33m>grep ADC_CLOCK_DIV *
grep: bitmaps: Is a directory
cap.c:  ADC_Mask = (1 << ADSC) | (1 << ADEN) | (1 << ADIF) | ADC_CLOCK_DIV;
cap.c:  ADC_Mask = (1 << ADSC) | (1 << ADEN) | (1 << ADIF) | ADC_CLOCK_DIV;
cap.c:  ADCSRA = ADC_CLOCK_DIV;               /* disable ADC, but keep clock dividers */
cap.c:  ADCSRA = (1 << ADEN) | (1 << ADIF) | ADC_CLOCK_DIV;
cap.c:  ADCSRA = ADC_CLOCK_DIV;               /* disable ADC, but keep clock dividers */
cap.c:  ADCSRA = (1 << ADEN) | (1 << ADIF) | ADC_CLOCK_DIV;
config.h:  #define ADC_CLOCK_DIV (1 << ADPS1)
config.h:  #define ADC_CLOCK_DIV (1 << ADPS1) | (1 << ADPS0)
config.h:  #define ADC_CLOCK_DIV (1 << ADPS2)
config.h:  #define ADC_CLOCK_DIV (1 << ADPS2) | (1 << ADPS0)
config.h:  #define ADC_CLOCK_DIV (1 << ADPS2) | (1 << ADPS1)
config.h:  #define ADC_CLOCK_DIV (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0)
inductor.c:  ADCSRA = ADC_CLOCK_DIV;               /* disable ADC, but keep clock dividers */
inductor.c:  ADCSRA = (1 << ADEN) | (1 << ADIF) | ADC_CLOCK_DIV;
main.c:  ADCSRA = (1 << ADEN) | ADC_CLOCK_DIV;      /* enable ADC and set clock divider */

Several things use ADC_CLOCK_DIV but it's clear the place it "comes from" is config.h so take a look at that:

#if CPU_FREQ / ADC_FREQ == 4
  #define ADC_CLOCK_DIV (1 << ADPS1)
#endif

/* 1MHz/125kHz 2MHz/250kHz */
#if CPU_FREQ / ADC_FREQ == 8
  #define ADC_CLOCK_DIV (1 << ADPS1) | (1 << ADPS0)
#endif

/* 2MHz/125kHz 4MHz/250kHz */
#if CPU_FREQ / ADC_FREQ == 16
  #define ADC_CLOCK_DIV (1 << ADPS2)
#endif

/* 4MHz/125kHz 8MHz/250kHz */
#if CPU_FREQ / ADC_FREQ == 32
  #define ADC_CLOCK_DIV (1 << ADPS2) | (1 << ADPS0)
#endif

/* 8MHz/125kHz 16MHz/250kHz */
#if CPU_FREQ / ADC_FREQ == 64
  #define ADC_CLOCK_DIV (1 << ADPS2) | (1 << ADPS1)
#endif

/* 16MHz/125kHz 20MHz/156.25kHz */
#if CPU_FREQ / ADC_FREQ == 128
  #define ADC_CLOCK_DIV (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0)
#endif

so it's only going to get defined when CPU_FREQ is some exact multiple of ADC_FREQ. The latter, in turn appears to come from:

#if CPU_FREQ == 20000000
  /* 20MHz MCU clock */
  #define ADC_FREQ    156250
#else
  /* all other MCU clocks */
  #define ADC_FREQ    125000
#endif

Clearly 2MHz is a "special case" but otherwise ADC_FREQ is going to be 125000 so that implies that CPU_FREQ must then be some multiple (4, 8, 16, 32, 64) of this. In the file there is also:

#define CPU_FREQ    F_CPU

so this is all going to be predicated on what you have F_CPU set to (and where). Looking for that one finds:

D:\ComponentTester-1.33m>grep F_CPU *
grep: bitmaps: Is a directory
config.h:#define CPU_FREQ    F_CPU
Makefile:CFLAGS += -DF_CPU=${FREQ}000000UL

and then searching for FREQ one finds:

D:\ComponentTester-1.33m>grep -w FREQ *
grep: bitmaps: Is a directory
Makefile:FREQ = 8
Makefile:CFLAGS += -DF_CPU=${FREQ}000000UL
Makefile:  ifeq (${FREQ},1)
Makefile:  ifeq (${FREQ},8)
Makefile:  ifeq (${FREQ},16)
Makefile:  ifeq (${FREQ},20)

So the original Makefile has FREQ=8 and F_CPU (consequently) as 8000000UL which in turn leads to ADC_FREQ=125000 and therefor it makes this the active case:

/* 8MHz/125kHz 16MHz/250kHz */
#if CPU_FREQ / ADC_FREQ == 64
  #define ADC_CLOCK_DIV (1 << ADPS2) | (1 << ADPS1)
#endif

because 8000000 / 125000 = 64.

 

So where in your project are you defining this stuff? A typical line of compilation in your AS7 version (where the project settings need to replace the Makefile) is:

        "C:\Program Files\Atmel\Atmel Studio 6.0\extensions\Atmel\AVRGCC\3.4.1.95\AVRToolchain\bin\avr-gcc.exe" -funsigned-char -funsigned-bitfields -O1 -fpack-struct -fshort-enums -g2 -Wall -c -std=gnu99 -MD -MP -MF "adjust.d" -MT"adjust.d" -MT"adjust.o"  -mmcu=atmega324p   -o"adjust.o" ".././adjust.c"

I don't see anything like "-DF_CPU=8000000UL" in that (or maybe even "-DFREQ=8" ?) as you would actually need to convert this Makefile project into an AS7 project.

 

Of course this is only part of the challenge. You can't just blithely set F_CPU to 8MHz and just hope everything will be OK. There could be stuff here that really needs the CPU to be running at 8MHz so you also need to do whatever is necessary to also achieve that.

 

Usually you'd work all this backwards. Pick a CPU speed, set things like FREQ and F_CPU to reflect whatever speed that is but now it appears that you need to take the config.h stuff into account as it's imposing certain limits on exactly what your CPU speed choiices can actually be.

 

PS just realised this while thread is in the "Arduino" forum. That almost certainly means F_CPU==16000000UL in fact, you may not get a choice. That should be OK because 16000000 is a multiple of 125000 but the build still needs to be told these things!

Last Edited: Wed. May 20, 2020 - 04:14 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

 

#if CPU_FREQ == 20000000
  /* 20MHz MCU clock */
  #define ADC_FREQ    156250
#else
  /* all other MCU clocks */
  #define ADC_FREQ    125000
#endif

 

Clearly 2MHz is a "special case" but otherwise ADC_FREQ is going to be 125000 so that implies that CPU_FREQ must then be some multiple (4, 8, 16, 32, 64) of this. In the file there is also:

 

 

I guess you mean 20MHz, not 2.

 

Thank you so much for this very good explanation and the time you spent to help!

Last Edited: Wed. May 20, 2020 - 04:47 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yup 20MHz. I am never very good at counting lots of zeroes with these glasses. I'd have the same problem with:

uint16_t bin_constant = 0b1000000000;

don't ask me what bit position that is either! 

 

In this case I think I would actually plump for:

uint16_t bin_constant = (1 << 9);

in the config.h example I would have been tempted by:

#if CPU_FREQ == 20E6

;-)