I'm trying to figure out why my watchdog scratch registers don't have the correct value in them after the watchdog reset. I must be missing something basic on how to use them. Here is my code:
And here is what I get, no matter which GPIO pin (Pin18 or Pin19) I pull low. Note that both GPIO pins perform the watchdog reset correctly. But the values are not being put into the scratch registers correctly.
Now, what's interesting, is if I disable one of the IRQs, and then pull the pin low that is still attached to the IRQ (Pin18, in this case), then I get the correct value in the scratch register.
This results in:
which is expected. So why does having two IRQs feeding two watchdog scratch registers cause issues?
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 19void gpio_callback_pin1() { 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("");}}void gpio_callback_pin2() { 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("");}}// 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) ; }}
Code:
Watchdog scratch 0 is: 0Watchdog scratch 2 is: 48879
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 19void gpio_callback_pin1() { 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("");}}void gpio_callback_pin2() { 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("");}}// 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) ; }}
Code:
Watchdog scratch 0 is: 666Watchdog scratch 2 is: 0
Statistics: Posted by Emotion8490 — Fri Apr 05, 2024 2:16 am