Skip to content

Commit

Permalink
avr: Fix compiling with GCC 12
Browse files Browse the repository at this point in the history
Compiling the Arduino targets with GCC 12 fails with the following:

    error: array subscript 0 is outside array bounds of 'volatile uint8_t[0]' {aka 'volatile unsigned char[]'} [-Werror=array-bounds]

Apply the workaround from the bug discussion to fix it.

Ref: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
Signed-off-by: Tim Crawford <tcrawford@system76.com>
  • Loading branch information
crawfxrd committed Jan 13, 2023
1 parent 2888297 commit 84fe76c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/arch/avr/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int16_t i2c_start(struct I2C *i2c, uint8_t addr, bool read) {
return -1;

// check if the device has acknowledged the READ / WRITE mode
uint8_t twst = TW_STATUS & 0xF8;
uint8_t twst = TW_STATUS;
if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK))
return -1;

Expand Down
7 changes: 7 additions & 0 deletions src/arch/avr/toolchain.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

CC=avr-gcc -mmcu=$(EC_VARIANT)
CFLAGS+=-Os -fstack-usage -Wall -Werror -Wl,--gc-sections -Wl,-u,vfprintf -lprintf_flt

# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
ifneq ($(findstring 12.,$(shell avr-gcc --version 2>/dev/null)),)
CFLAGS += --param=min-pagesize=0
endif

OBJCOPY = avr-objcopy

OBJ=$(sort $(patsubst src/%.c,$(BUILD)/%.o,$(SRC)))

# Run EC rom in simulator
Expand Down

0 comments on commit 84fe76c

Please sign in to comment.