Skip to content

Sleep on one core negatively impacts execution on the other core #873

@JonnyHaystack

Description

@JonnyHaystack

Hi, I originally opened an issue for this in arduino-pico (see earlephilhower/arduino-pico#637) before discovering the issue happens even using the Pico SDK directly. There are more details in that issue, but basically calling sleep_us() on one core while the other core is working seems to have a huge impact on the other core that interrupts its execution part way and is causing communication failures for me even though I'm using the PIO for my comms and it's 100% stable when I'm not using multicore.

Code to reproduce:

#include <pico/multicore.h>
#include <pico/stdlib.h>

bool gp1;

void blah();

int main(void) {
    gpio_init(1);
    gpio_init(2);
    gpio_set_dir(1, GPIO_OUT);
    gpio_set_dir(2, GPIO_OUT);

    multicore_reset_core1();
    multicore_launch_core1(blah);

    while (true) {
        gp1 = !gp1;
        gpio_put(1, gp1);
    }
}

void blah() {
    while (1) {
        gpio_put(2, 1);
        sleep_us(50);
        gpio_put(2, 0);
    }
}

Every time core 1 is about to come out of a sleep, core 0 appears to "stall" in some way. It's not exactly a stall, because it doesn't just continue where it left off. Instead, it actually never does things that it should have, or gets interrupted halfway through doing something and never finishes it.

Logic analyzer trace of the above code:

image

I just tested this with core 0 and core 1's roles swapped and the result is not exactly the same but there is clearly still some impact:

#include <pico/multicore.h>
#include <pico/stdlib.h>

bool gp1;

void blah();

int main(void) {
    gpio_init(1);
    gpio_init(2);
    gpio_set_dir(1, GPIO_OUT);
    gpio_set_dir(2, GPIO_OUT);

    multicore_reset_core1();
    multicore_launch_core1(blah);

    while (true) {
        gpio_put(2, 1);
        sleep_us(50);
        gpio_put(2, 0);
    }
}

void blah() {
    while (1) {
        gp1 = !gp1;
        gpio_put(1, gp1);
    }
}

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions