Page 1 of 1

won't compile - variable must be const

Posted: Sat Feb 04, 2012 6:19 pm
by funkenregen
hi i am trying to compile an example but i get errors when executing 'make hex'.
the machine is fedora f16, avr-gcc (Fedora 4.6.2-1.fc16) 4.6.2

output:

Code: Select all


[...]vusb-20120109/examples/hid-data/firmware % make hex
avr-gcc -Wall -Os -DF_CPU=16500000    -Iusbdrv -I. -DDEBUG_LEVEL=0 -mmcu=attiny45 -c usbdrv/usbdrv.c -o usbdrv/usbdrv.o
In file included from usbdrv/usbdrv.c:12:0:
usbdrv/usbdrv.h:455:6: error: variable 'usbDescriptorDevice' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
usbdrv/usbdrv.h:461:6: error: variable 'usbDescriptorConfiguration' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
usbdrv/usbdrv.h:467:6: error: variable 'usbDescriptorHidReport' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
usbdrv/usbdrv.h:473:6: error: variable 'usbDescriptorString0' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
usbdrv/usbdrv.h:479:5: error: variable 'usbDescriptorStringVendor' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
usbdrv/usbdrv.h:485:5: error: variable 'usbDescriptorStringDevice' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
usbdrv/usbdrv.h:491:5: error: variable 'usbDescriptorStringSerialNumber' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
usbdrv/usbdrv.c:70:14: error: variable 'usbDescriptorString0' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
usbdrv/usbdrv.c:80:14: error: variable 'usbDescriptorStringVendor' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
usbdrv/usbdrv.c:89:14: error: variable 'usbDescriptorStringDevice' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
usbdrv/usbdrv.c:111:14: error: variable 'usbDescriptorDevice' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
usbdrv/usbdrv.c:142:14: error: variable 'usbDescriptorConfiguration' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
make: *** [usbdrv/usbdrv.o] Error 1


is this a beginners mistake or is something broken on my machine?

thanks in advance,
funkenregen

Re: won't compile

Posted: Mon Feb 06, 2012 7:37 pm
by funkenregen
i fixed it myself with some help of the trusty interwebs.

newer avr-gcc versions demand that everything put in progmem is defined const [1].
so i just put a const in front of every PROGMEM line where the compiler complained. changes were necessary in usbdrv.h, usbdrv.c and the main program (the usbHidReportDescriptor is in progmem too).

now everything works fine.
i think this change would be very easy to implement and would not break backwards compatibility.

i hope this helps anyone who encounters this problem sometime in the future.

regards, funkenregen

----
[1] http://old.nabble.com/VUSB-problem-td32560584.html

Re: won't compile - variable must be const

Posted: Mon Aug 13, 2012 3:30 am
by trmcderm
Thanks! Just had the same problem.

Re: won't compile - variable must be const

Posted: Thu Aug 23, 2012 11:29 am
by abd_rmdn
i had this problem and i did what u did....but the problem is that the circuit isnt working
i check my circuit like 200 times ..... i tried every possible circuit and still no changes ...
could it be because of the "const"...!!?!
i mean i even bought another MCU "atmega8" instead of the one i have "atmega32A".... and still nothing is working ??!
it keeps saying ::
-----------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------"USB Device not Recognized"-------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------
i'm really kind of desperate right now !!....
do u have any suggestion .....?!
im not using the makeFile .... does this effects my code ....?!

hope u've got any new ideas i can benefit of ... :)
thanks in advance.