I would like to use watchdog_reboot() to catch watchdog resets and print some FreeRTOS task statuses.
If I use the watchdog_reboot() function in the SDK, it seems to have a problem... One of the calling parameters is "pc". In the code it doesn't use the passed parameter value of "pc", but rather the value of the actual Program Counter. Bug???
I copied the code from watchdog_reboot() , and put it into in my program code, but I still can't get it to work.
I assume the boot sees the magic 0xb007c0d3 in scratch[4] and sets the PC & SP to jump to my function rather than the C Runtime initialization???
The catch function...
I enable the watchdog, but don't reload the counter, so 8 seconds after starting, it should execute the watchdogCatch() function, but I don't see any output on UART0.
Are the __no_inline_not_in_flash_func functions still there, or is RAM erased before the watchdogCatch() is called?
If I use the watchdog_reboot() function in the SDK, it seems to have a problem... One of the calling parameters is "pc". In the code it doesn't use the passed parameter value of "pc", but rather the value of the actual Program Counter. Bug???
I copied the code from watchdog_reboot() , and put it into in my program code, but I still can't get it to work.
I assume the boot sees the magic 0xb007c0d3 in scratch[4] and sets the PC & SP to jump to my function rather than the C Runtime initialization???
Code:
#if 0 watchdog_reboot( (uint32_t)watchdogCatch, SRAM_END-16, WATCHDOG_TIMEOUT );#else hw_clear_bits(&watchdog_hw->ctrl, WATCHDOG_CTRL_ENABLE_BITS); uint32_t __pc = (uint32_t)watchdogCatch;#ifndef __riscv __pc |= 1u; // thumb mode#endif watchdog_hw->scratch[4] = 0xb007c0d3; watchdog_hw->scratch[5] = __pc ^ -0xb007c0d3; watchdog_hw->scratch[6] = SRAM_END-16; watchdog_hw->scratch[7] = __pc; watchdog_enable( WATCHDOG_TIMEOUT, false);#endifCode:
//////////////////////////////////////////////// land here on watchdog reboot//////////////////////////////////////////////static void watchdogCatch(void){uart_deinit (uart0);uart_init(uart0, 115200);gpio_set_function(PICO_UART0_TX_PIN,GPIO_FUNC_UART);gpio_set_function(PICO_UART0_RX_PIN,GPIO_FUNC_UART);watchdog_hw->scratch[4] = 0;safe_puts((uart_hw_t *) uart0,"Task dump...\r\n");for ( uint8_t _i = 0; _i < numTaskParams; _i++ ){if ( pTaskParams[_i] != NULL ){safe_puts((uart_hw_t *) uart0,pTaskParams[_i]->taskName);safe_putc((uart_hw_t *) uart0,'\r');safe_putc((uart_hw_t *) uart0,'\n');}}}/////////////////////// safe putc / puts////////////////////void __no_inline_not_in_flash_func(safe_putc)(uart_hw_t*_uart, char _char ){while((_uart->fr & UART_UARTFR_TXFF_BITS)) {}_uart->dr = (_char);}void __no_inline_not_in_flash_func(safe_puts)(uart_hw_t*_uart, char *_pChar ){while( *_pChar!= 0 ) {safe_putc( _uart, *_pChar);_pChar++;}}I enable the watchdog, but don't reload the counter, so 8 seconds after starting, it should execute the watchdogCatch() function, but I don't see any output on UART0.
Are the __no_inline_not_in_flash_func functions still there, or is RAM erased before the watchdogCatch() is called?
Statistics: Posted by ronter — Sat Sep 12, 2026 9:22 pm — Replies 3 — Views 56





