Skip to content

cpu/atmega328p: linker/memory issue? #13016

@wosym

Description

@wosym

Description

I noticed that there are (linker?) memory issues with the atmega328p. Several innocuous lines of code cause the same errors when compiling:

/usr/lib/gcc/avr/5.4.0/../../../avr/bin/ld: address 0x8008b9 of /home/wouter/Programming/cv_controller/bin/atmega328p/cv_controller.elf section `.bss' is not within region `data'
/usr/lib/gcc/avr/5.4.0/../../../avr/bin/ld: address 0x8008bb of /home/wouter/Programming/cv_controller/bin/atmega328p/cv_controller.elf section `.noinit' is not within region `data'
/usr/lib/gcc/avr/5.4.0/../../../avr/bin/ld: address 0x8008b9 of /home/wouter/Programming/cv_controller/bin/atmega328p/cv_controller.elf section `.bss' is not within region `data'
/usr/lib/gcc/avr/5.4.0/../../../avr/bin/ld: address 0x8008bb of /home/wouter/Programming/cv_controller/bin/atmega328p/cv_controller.elf section `.noinit' is not within region `data'

I've encountered this behavior several times in the last couple of weeks, always in different scenario's. The last one, only after adding the conditional in the following pseudocode:

val = functioncall()
    if(val == -1) {
    puts("Error!");
    return -1;
}
printf("Val = %d", val);

When removing the inner puts(), the bug is solved. Strangely enough. When removing the printf outside of the conditional, the bug also disappears!

Steps to reproduce the issue

I was able to create a minimal code sample which triggers the errors shown above:

static int test(int argc, char **argv)
{
        (void) argc;
        (void) argv;
//        puts("test aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); 
        printf("%d test  %d %lf\n ", 5, 10, 10.1);
        return 0;
}

static const shell_command_t shell_commands[] = {
    { "test", "test", test},
    { NULL, NULL, NULL }
};

int main(void)
{
    puts("Hello World!");

    printf("You are running RIOT on a(n) %s board.\n", RIOT_BOARD);
    printf("This board features a(n) %s MCU.\n", RIOT_MCU);

    char line_buf[SHELL_DEFAULT_BUFSIZE]; 
    shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);

    //(void) shell_commands;
    //test(1, NULL);

    return 0;
}

The above code will compile and run just fine. However, when uncommenting the long puts() in test() the errors will show up.
It can be fixed by commenting out the functions that enable the shell, and then manually call the test() function (uncomment last two lines). This will work fine. However, if you would increase the string length of the puts() in test() even more, it will break again.

Related PR?

In #11122 @roberthartung reports a similar issue while testing. However, since it was merged I'm assuming this issue got fixed? I'm also not sure if it's related at all...

Sidenote

I'm not even sure this is an actual bug. Maybe the m328p is just too weak to run RIOT.
Of course, inserting extremely large strings like this is something you shouldn't do, but:

  1. This was only to trigger the errors. It also occurred several times while doing very normal and basic things (see the pseudocode above).
  2. Imo it should warn you that your variables are too large. (even though I'm convinced this isn't the actual issue)

Metadata

Metadata

Assignees

Labels

Platform: AVRPlatform: This PR/issue effects AVR-based platforms

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions