Other Parts Discussed in Thread: TM4C1232D5PM
Hello,
I have the problem that the Write Complete Bit in Watchdog 1 will not always be set. As per datasheet prior every write to the WD1 register it need to be checked if writing is allowed.
The Test code enables the WD1 and should feed WD1 while counting up ui32cnt. But ui32cnt is only incremented to 1 and then we are hanging in
while((HWREG(WATCHDOG1_BASE + WDT_O_CTL) & WDT_CTL_WRC) == 0)
{}
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_gpio.h"
#include "inc/hw_watchdog.h"
#include "driverlib/sysctl.h"
#include "driverlib/watchdog.h"
#include "driverlib/interrupt.h"
#include "driverlib/rom.h"
// Frequenzy in Hz of Watchdog 1 clock source
#define WATCHDOG1_CLK 16000000
// Timeout of Watchdog 1 in seconds
#define WATCHDOG1_TIMEOUT 10
//*****************************************************************************
static void WaitForWD1ReadyToWrite(void)
{
while((HWREG(WATCHDOG1_BASE + WDT_O_CTL) & WDT_CTL_WRC) == 0)
{}
}
int32_t ui32cnt;
int32_t main(void)
{
//
// Fix Errata WDT#01: Watchdog Timer 1 Module Cannot be Used Without Enabling Other Peripherals First
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
//
// Enable the Watchdog
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_WDOG1);
while (SysCtlPeripheralReady(SYSCTL_PERIPH_WDOG1) ==0)
{}
//
// Unock the watchdog registers the can be changed.
//
WaitForWD1ReadyToWrite();
WatchdogUnlock(WATCHDOG1_BASE);
//
// Enables stalling of the watchdog timer during debug events.
//
WaitForWD1ReadyToWrite();
WatchdogStallEnable(WATCHDOG1_BASE);
WaitForWD1ReadyToWrite();
WatchdogReloadSet(WATCHDOG1_BASE, WATCHDOG1_CLK * WATCHDOG1_TIMEOUT);
//
// Enable the watchdog timer.
//
WaitForWD1ReadyToWrite();
WatchdogEnable(WATCHDOG1_BASE);
//
// Lock the watchdog registers for writing.
//
WaitForWD1ReadyToWrite();
WatchdogLock(WATCHDOG1_BASE);
while(1)
{
ui32cnt++;
SysCtlDelay(10000);
//
// Unlock the Watchdog registers for writing
//
WaitForWD1ReadyToWrite();
WatchdogUnlock(WATCHDOG1_BASE);
//
// Feed the Watchdog by writing the load value
//
WaitForWD1ReadyToWrite();
HWREG(WATCHDOG1_BASE + WDT_O_LOAD) = WATCHDOG1_CLK * WATCHDOG1_TIMEOUT;
//
// Lock the Watchdog registers
//
WaitForWD1ReadyToWrite();
WatchdogLock(WATCHDOG1_BASE);
}
}
Thanks
Kilian