Skip to content

[AVR] -mrelax does not work for a simple LED blink program #133579

Open
@benshi001

Description

@benshi001

the following a.cc

// clang --target=avr -gdwarf-4 --sysroot /data/home/bennshi/.arduino15/packages/arduino/tools/avr-gcc/ a.c -mrelax -Os -Wall -mmcu=atmega328
volatile unsigned int bas[200] = {0x20, 0x00, 60000};

void delay(unsigned int a) {
        for (volatile int i = 0; i < a; i++) {}
}

int main() {
        volatile char *p0 = (char *) 0x24;
        volatile char *p1 = (char *) 0x25;
        *p0 = 0x20;
        for (;;)  {
                delay(bas[2]);
                *p1 = bas[0];
                delay(bas[2]);
                *p1 = bas[1];
        }
        return 0;
}

if it is built with -mrelax, we can not see the LED blinking, with -mno-relax it works.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions