Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4832

SDK • Re: Issue with Watchdog Scratch Registers

$
0
0
I can confirm that the following code gives the same output.

Code:

#include <stdio.h>#include "pico/stdlib.h"#include "hardware/watchdog.h"#include "fw-info.h"// The LED is connected to GPIO 25#define LED_PIN 25#define PIN1 18#define PIN2 19bool flag1 = false; bool flag2 = false; void gpio_callback_pin1() {    flag1 = true; }void gpio_callback_pin2() {    flag2 = true; }// Main (runs on core 0)int main() {        stdio_init_all();    // Initialize the LED pin    gpio_init(LED_PIN);    gpio_set_dir(LED_PIN, GPIO_OUT);    sleep_ms(2000);     printf("Watchdog scratch 0 is: %d\n", watchdog_hw->scratch[0]);    printf("Watchdog scratch 2 is: %d\n", watchdog_hw->scratch[2]);        gpio_init(PIN1) ;    gpio_pull_up(PIN1) ;        gpio_init(PIN2) ;    gpio_pull_up(PIN2) ;    // Configure GPIO interrupt    gpio_set_irq_enabled_with_callback(PIN1, GPIO_IRQ_EDGE_FALL, true, &gpio_callback_pin1);    gpio_set_irq_enabled_with_callback(PIN2, GPIO_IRQ_EDGE_FALL, true, &gpio_callback_pin2);    // Loop    while (true) {        gpio_put(LED_PIN, 0) ;        sleep_ms(250) ;        gpio_put(LED_PIN, 1) ;        sleep_ms(1000) ;        if(flag1){            hw_clear_bits(&watchdog_hw->ctrl, WATCHDOG_CTRL_ENABLE_BITS);            watchdog_hw->scratch[0]=666 ;            watchdog_reboot(0, 0, 0) ;            while (1) {        tight_loop_contents();        asm("");        }        }        if(flag2){            hw_clear_bits(&watchdog_hw->ctrl, WATCHDOG_CTRL_ENABLE_BITS);            watchdog_hw->scratch[2]=0xBEEF ;            watchdog_reboot(0, 0, 0) ;            while (1) {        tight_loop_contents();        asm("");        }        }    }}
Now, here's the interesting part. Using the debugger, I can confirm that pulling Pin1 low puts me into the Pin2 GPIO ISR. Why? If I comment out enabling the Pin2 GPIO ISR, like this:

Code:

#include <stdio.h>#include "pico/stdlib.h"#include "hardware/watchdog.h"#include "fw-info.h"// The LED is connected to GPIO 25#define LED_PIN 25#define PIN1 18#define PIN2 19bool flag1 = false; bool flag2 = false; void gpio_callback_pin1() {    flag1 = true; }void gpio_callback_pin2() {    flag2 = true; }// Main (runs on core 0)int main() {        stdio_init_all();    // Initialize the LED pin    gpio_init(LED_PIN);    gpio_set_dir(LED_PIN, GPIO_OUT);    sleep_ms(2000);     printf("Watchdog scratch 0 is: %d\n", watchdog_hw->scratch[0]);    printf("Watchdog scratch 2 is: %d\n", watchdog_hw->scratch[2]);    gpio_init(PIN1) ;    gpio_pull_up(PIN1) ;       gpio_init(PIN2) ;    gpio_pull_up(PIN2) ;    // Configure GPIO interrupt    gpio_set_irq_enabled_with_callback(PIN1, GPIO_IRQ_EDGE_FALL, true, &gpio_callback_pin1);    //gpio_set_irq_enabled_with_callback(PIN2, GPIO_IRQ_EDGE_FALL, true, &gpio_callback_pin2);    // Loop    while (true) {        gpio_put(LED_PIN, 0) ;        sleep_ms(250) ;        gpio_put(LED_PIN, 1) ;        sleep_ms(1000) ;        if(flag1){            hw_clear_bits(&watchdog_hw->ctrl, WATCHDOG_CTRL_ENABLE_BITS);            watchdog_hw->scratch[0]=666 ;            watchdog_reboot(0, 0, 0) ;            while (1) {        tight_loop_contents();        asm("");        }        }        if(flag2){            hw_clear_bits(&watchdog_hw->ctrl, WATCHDOG_CTRL_ENABLE_BITS);            watchdog_hw->scratch[2]=0xBEEF ;            watchdog_reboot(0, 0, 0) ;            while (1) {        tight_loop_contents();        asm("");        }        }    }}
Then I can confirm that pulling Pin1 low puts me into the Pin1 ISR. Hmm.

Statistics: Posted by Emotion8490 — Fri Apr 05, 2024 2:31 am



Viewing all articles
Browse latest Browse all 4832

Trending Articles