hexagon5un / AVR-Programming

Code examples for the book "Make: AVR Programming"
http://littlehacks.org/AVR-Programming
MIT License
725 stars 340 forks source link

compiler warnings atmel328p #51

Open sjomae opened 9 months ago

sjomae commented 9 months ago

Chapter 07 using the atmel328P

Wondering why I get these compile warnings. slowScope is working here anyway.

$ sudo make flash avr-gcc -Os -g -std=gnu99 -Wall -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -DF_CPU=16000000UL -DBAUD=9600UL -I. -I../../AVR-Programming-Library -mmcu=atmega328p -c -o slowScope.o slowScope.c In file included from /usr/avr/include/avr/io.h:99, from slowScope.c:4: In function 'initFreerunningADC', inlined from 'main' at slowScope.c:27:3: slowScope.c:13:3: warning: array subscript 0 is outside array bounds of 'volatile uint8_t[0]' {aka 'volatile unsigned char[]'} [-Warray-bounds=] 13 | ADMUX |= (1 << REFS0); /* reference voltage on AVCC */ | ^~~~~ In function 'main': cc1: note: source object is likely at address zero In function 'initFreerunningADC', inlined from 'main' at slowScope.c:27:3: slowScope.c:13:9: warning: array subscript 0 is outside array bounds of 'volatile uint8_t[0]' {aka 'volatile unsigned char[]'} [-Warray-bounds=] 13 | ADMUX |= (1 << REFS0); /* reference voltage on AVCC */ | ^ In function 'main': cc1: note: source object is likely at address zero In function 'initFreerunningADC', inlined from 'main' at slowScope.c:27:3: slowScope.c:15:3: warning: array subscript 0 is outside array bounds of 'volatile uint8_t[0]' {aka 'volatile unsigned char[]'} [-Warray-bounds=] 15 | ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0); /* ADC clock prescaler /16 */ | ^~~~~~ In function 'main': cc1: note: source object is likely at address zero In function 'initFreerunningADC', inlined from 'main' at slowScope.c:27:3: slowScope.c:15:10: warning: array subscript 0 is outside array bounds of 'volatile uint8_t[0]' {aka 'volatile unsigned char[]'} [-Warray-bounds=] 15 | ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0); /* ADC clock prescaler /16 */ | ^ In function 'main': cc1: note: source object is likely at address zero In function 'initFreerunningADC', inlined from 'main' at slowScope.c:27:3: slowScope.c:17:3: warning: array subscript 0 is outside array bounds of 'volatile uint8_t[0]' {aka 'volatile unsigned char[]'} [-Warray-bounds=] 17 | ADMUX |= (1 << ADLAR); /* left-adjust result, return only 8 bits */ | ^~~~~ In function 'main': cc1: note: source object is likely at address zero In function 'initFreerunningADC', inlined from 'main' at slowScope.c:27:3: slowScope.c:17:9: warning: array subscript 0 is outside array bounds of 'volatile uint8_t[0]' {aka 'volatile unsigned char[]'} [-Warray-bounds=] 17 | ADMUX |= (1 << ADLAR); /* left-adjust result, return only 8 bits */ | ^ In function 'main': cc1: note: source object is likely at address zero In function 'main': cc1: note: source object is likely at address zero In function 'initFreerunningADC', inlined from 'main' at slowScope.c:27:3: slowScope.c:19:3: warning: array subscript 0 is outside array bounds of 'volatile uint8_t[0]' {aka 'volatile unsigned char[]'} [-Wa 19 | ADCSRA |= (1 << ADEN); /* enable ADC */ | ^~~~~~ In function 'main': cc1: note: source object is likely at address zero In function 'initFreerunningADC', inlined from 'main' at slowScope.c:27:3: slowScope.c:19:10: warning: array subscript 0 is outside array bounds of 'volatile uint8_t[0]' {aka 'volatile unsigned char[]'} [-W 19 | ADCSRA |= (1 << ADEN); /* enable ADC */ | ^ In function 'main': cc1: note: source object is likely at address zero In function 'initFreerunningADC', inlined from 'main' at slowScope.c:27:3: slowScope.c:20:3: warning: array subscript 0 is outside array bounds of 'volatile uint8_t[0]' {aka 'volatile unsigned char[]'} [-Wa 20 | ADCSRA |= (1 << ADATE); /* auto-trigger enable */ | ^~~~~~ In function 'main': cc1: note: source object is likely at address zero In function 'initFreerunningADC', inlined from 'main' at slowScope.c:27:3: slowScope.c:20:10: warning: array subscript 0 is outside array bounds of 'volatile uint8_t[0]' {aka 'volatile unsigned char[]'} [-W 20 | ADCSRA |= (1 << ADATE); /* auto-trigger enable */ | ^ In function 'main': cc1: note: source object is likely at address zero In function 'initFreerunningADC', inlined from 'main' at slowScope.c:27:3: slowScope.c:21:3: warning: array subscript 0 is outside array bounds of 'volatile uint8_t[0]' {aka 'volatile unsigned char[]'} [-Wa 21 | ADCSRA |= (1 << ADSC); /* start first conversion */ | ^~~~~~ In function 'main': cc1: note: source object is likely at address zero In function 'initFreerunningADC', inlined from 'main' at slowScope.c:27:3: slowScope.c:21:10: warning: array subscript 0 is outside array bounds of 'volatile uint8_t[0]' {aka 'volatile unsigned char[]'} [-W 21 | ADCSRA |= (1 << ADSC); /* start first conversion */ | ^ In function 'main': cc1: note: source object is likely at address zero slowScope.c:30:5: warning: array subscript 0 is outside array bounds of 'volatile uint8_t[0]' {aka 'volatile unsigned char[]'} [-Wa 30 | transmitByte(ADCH); /* transmit the high byte, left-adjusted */ | ^~~~~~~~~~~~~~~~~~ cc1: note: source object is likely at address zero avr-gcc -Wl,-Map,slowScope.map -Wl,--gc-sections -mmcu=atmega328p slowScope.o ../../AVR-Programming-Library/USART.o -o slowScope avr-objcopy -j .text -j .data -O ihex slowScope.elf slowScope.hex avrdude -c usbasp -p atmega328p -P usb -U flash:w:slowScope.hex avrdude: AVR device initialized and ready to accept instructions

hexagon5un commented 9 months ago

Hi,

That's very probably due to a recent change in GCC. https://wellys.com/posts/avr_c_gcc_error/

See the very bottom of the post for the solution:

In a nutshell, one has to add “–param=min-pagesize=0” to their CFLAGS in the Makefile as in:
CFLAGS = -Os -mcall-prologues -g3 -std=gnu99 -Wall -Werror -Wundef --param=min-pagesize=0
If the version of GCC is less than 12, this will break GCC as this is a new parameter. Once I did, the warning went away, the 
error went away (due to Werror) and everything was fine again.

As you noted, it's a false alarm. But leaving your compiler report filled with false alarms can lead you to miss out when it matters. Better to add the flag into the Makefile and make the compiler warnings reflect actual mistakes.

Good catch!