fogbound.net




Sun, 22 Jul 2012

Teensy board example code “usb_debug_only.c” and gcc > 4.6

— SjG @ 9:44 pm

Wow, now there’s a blog title that will have very limited appeal 🙂

I was trying to validate my toolchain worked for building Teensy/ATMEGA32u4 applications. I used the mac port avr-gcc, avr-bintools, avr-libc install, and it failed to build the sample “blinky.c” program. I tried using the recommended AVR CrossPack, just in case it had different versions of the tools, but I got the same results:


samuelg$ make
-------- begin --------
avr-gcc (GCC) 4.7.0
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Compiling C: usb_debug_only.c
avr-gcc -c -mmcu=atmega32u4 -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

Google didn’t immediately help me with this. Eventually, I actually went ahead and read the error messages, and then tried following directions, i.e., I looked at line 96, and changed


static uint8_t PROGMEM device_descriptor[] = {

to


static const uint8_t PROGMEM device_descriptor[] = {

That’s all it took to make gcc happy with that line. Repeat the process for all of the error lines, and it compiles and builds correctly.

Evidently, the change to gcc happened between 4.5.3 and 4.6, and, once I knew what to look for, I found numerous discussions of why and wherefore (although these discussions were quite frankly beyond my comprehension). I was, however, happy to find the simple solution detailed above.