Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiler warnings atmel328p #51

Open
sjomae opened this issue Sep 21, 2023 · 1 comment
Open

compiler warnings atmel328p #51

sjomae opened this issue Sep 21, 2023 · 1 comment

Comments

@sjomae
Copy link

sjomae commented Sep 21, 2023

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
Copy link
Owner

hexagon5un commented Sep 22, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants