Skip to content

Diferent behavor between website and vscode extension (rp2040 - timer) #1004

Open
@rafaelcorsi

Description

@rafaelcorsi

Target: Rasp Pico 1 sdk
Example project: https://wokwi.com/projects/430756341381772289

Code:

When I run it on the webpage I got the timers been canceled and created as expected, but when I run on the vs code extension, it won't create a new timer. To solve the problem I need to add a sleep between cancel and add a new timer.

        cancel_repeating_timer(&timer_b);
+       sleep_ms(10);
        add_repeating_timer_ms(300, timer_b_callback, NULL, &timer_b);
                 sleep_ms(1000);

Example code:

#include <stdio.h>
#include "pico/stdlib.h"

const int LED_PIN_R = 4;

volatile int cnt = 0;

bool timer_b_callback(repeating_timer_t* rt) {
    printf("timer %d\n", cnt++);
    return true; // keep repeating
}

int main() {
    stdio_init_all();
    gpio_init(LED_PIN_R);
    gpio_set_dir(LED_PIN_R, GPIO_OUT);

    repeating_timer_t timer_b;

    add_repeating_timer_ms(100, timer_b_callback, NULL, &timer_b);
    sleep_ms(1000);

    while (true) {
      printf("Canceled timer\n");
        cancel_repeating_timer(&timer_b);
        add_repeating_timer_ms(300, timer_b_callback, NULL, &timer_b);
                 sleep_ms(1000);

    }
}

online it creates the new timer:

Image

on vscode it get stuck

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions