Skip to content

Commit

Permalink
Independent Watchdog. Kicked from main loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
keirf committed Oct 8, 2019
1 parent d42322c commit 9a9bc53
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions inc/stm32f10x.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define PWR volatile struct pwr * const
#define BKP volatile struct bkp * const
#define RCC volatile struct rcc * const
#define IWDG volatile struct iwdg * const
#define GPIO volatile struct gpio * const
#define AFIO volatile struct afio * const
#define EXTI volatile struct exti * const
Expand All @@ -35,6 +36,7 @@ static FLASH flash = (struct flash *)FLASH_BASE;
static PWR pwr = (struct pwr *)PWR_BASE;
static BKP bkp = (struct bkp *)BKP_BASE;
static RCC rcc = (struct rcc *)RCC_BASE;
static IWDG iwdg = (struct iwdg *)IWDG_BASE;
static GPIO gpioa = (struct gpio *)GPIOA_BASE;
static GPIO gpiob = (struct gpio *)GPIOB_BASE;
static GPIO gpioc = (struct gpio *)GPIOC_BASE;
Expand Down
13 changes: 13 additions & 0 deletions inc/stm32f10x_regs.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,21 @@ struct rcc {
#define RCC_APB2ENR_IOPAEN (1u<< 2)
#define RCC_APB2ENR_AFIOEN (1u<< 0)

#define RCC_CSR_LSIRDY (1u<< 1)
#define RCC_CSR_LSION (1u<< 0)

#define RCC_BASE 0x40021000

/* Independent Watchdog */
struct iwdg {
uint32_t kr; /* 00: Key */
uint32_t pr; /* 04: Prescaler */
uint32_t rlr; /* 08: Reload */
uint32_t sr; /* 0C: Status */
};

#define IWDG_BASE 0x40003000

/* General-purpose I/O */
struct gpio {
uint32_t crl; /* 00: Port configuration low */
Expand Down
10 changes: 10 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,13 @@ int main(void)
time_t frame_time;
bool_t lost_sync, _keyboard_held;

/* Set up the Watchdog. Based on LSI at 30-60kHz (av. 40kHz). */
iwdg->kr = 0xcccc; /* Enables watchdog, turns on LSI oscillator. */
iwdg->kr = 0x5555; /* Enables access to PR and RLR. */
iwdg->pr = 3; /* Prescaler: div32 => Ticks at 937-1875Hz (1250Hz) */
iwdg->rlr = 400; /* Reload: 400 => Times out in 213-426ms (320ms) */
iwdg->kr = 0xaaaa; /* Load the new Reload value. */

/* Relocate DATA. Initialise BSS. */
if (_sdat != _ldat)
memcpy(_sdat, _ldat, _edat-_sdat);
Expand Down Expand Up @@ -683,6 +690,9 @@ int main(void)

for (;;) {

/* Reload the Watchdog. */
iwdg->kr = 0xaaaa;

canary_check();

/* Wait while displaying OSD box. This avoids modifying config values
Expand Down

0 comments on commit 9a9bc53

Please sign in to comment.