Newbie question about compiling blinky.

Last post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm a complete newbie. I haven't played with C for years but I want something that no one makes and I think an AVR board will be the easiest way to make it.

Anyway I dusted off the old PRJC teensy 1.0 and managed to load the fast blinker. Yay.

Now I decided to try compiling blinky and when reading the source I saw something that might be problematic.

// Teensy 2.0: LED is active high
#if defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB1286__)
#define LED_ON		(PORTD |= (1<<6))
#define LED_OFF		(PORTD &= ~(1<<6))

// Teensy 1.0: LED is active low
#else
#define LED_ON	(PORTD &= ~(1<<6))
#define LED_OFF	(PORTD |= (1<<6))
#endif

Since I have a 1.0 I don't think that this will be a problem. But I am concerned that I can't find where these are defined. There is no comment in the code saying to define such and such if you have this or that board.

Where are these #defines (__AVR_ATmega32U4__ and __AVR_AT90USB128__)?

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

It is defined by the compiler when you specify -mmcu=atmega32u4 etc. (which comes from MCU = atmega32u4 in the Makefile).

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

Quote:
Where are these #defines (__AVR_ATmega32U4__ and __AVR_AT90USB128__)?

you know that || means OR instead of AND right????

Don't know if AS makes its own makefile or does it another way, but if you in your project you define the right processor and use the internal makefile it should all work well.

If you are not sure if things will compile as expected in the els statement add:

#error this error should never be seen during project compilation

If for any reason not one of the 2 CPUs are defined then you get an error message thus warning you that something did not go as planned/thought.

1)Datasheet and application notes checked?
2)tutorial forum
3)Newbie start here

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

Great, I fount the relevant lines Makefile and uncommented and commented the relevant lines.

Yet, when I compiled, I got errors.

Compiling C: usb_debug_only.c
avr-gcc -c -mmcu=at90usb162        -I. -gdwarf-2 -DF_CPU=16000000UL -Os -funsigned-char -funsigned-bitfields -ffunction-sections -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=./usb_debug_only.lst  -std=gnu99 -MMD -MP -MF .dep/usb_debug_only.o.d usb_debug_only.c -o usb_debug_only.o 
usb_debug_only.c:96:24: error: variable ‘device_descriptor’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
usb_debug_only.c:113:24: error: variable ‘hid_report_descriptor’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
usb_debug_only.c:128:24: error: variable ‘config1_descriptor’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
usb_debug_only.c:175:52: error: variable ‘string0’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
usb_debug_only.c:180:52: error: variable ‘string1’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
usb_debug_only.c:185:52: error: variable ‘string2’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
usb_debug_only.c:198:11: error: variable ‘descriptor_list’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
make: *** [usb_debug_only.o] Error 1

Did they just neglect to define PROGMEM as a 'const' in usb_debug_only.c or .h? or is there some switch somewhere?

Could this have something to do with the fact that I'm using avr-gcc on Ubuntu?

I'm sorry I'm being a pain in the ass but the only way I can learn this type of stuff is to start with something that works and then change one thing at a time an see what happens.

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

I believe that the const requirement was added to avr-gcc well after the code was written.

Regards,
Steve A.

The Board helps those that help themselves.

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

So, should I just go ahead and add it to the relevant lines?