#include #include #include #include "ee14lib.h" void delay_us(unsigned int us) { // 4MHz clock, while loop is 4 cycles? volatile int i = us; while(i--){} } // This function is called by printf() to handle the text string // We want it to be sent over the serial terminal, so we just delegate to that function int _write(int file, char *data, int len) { serial_write(USART2, data, len); return len; } int main() { uint32_t csr = RCC->CSR; // Get the reset cause RCC->CSR |= RCC_CSR_RMVF; // Clear the reset cause flags host_serial_init(9600); // Set up the watchdog RCC->APB1ENR1 |= RCC_APB1ENR1_WWDGEN; // Enable power to the watchdog peripheral WWDG->CFR = (0b11 << WWDG_CFR_WDGTB_Pos) | 0x7F; // 8x prescaler, window at max val (off) WWDG->CR = WWDG_CR_WDGA | 0x7F; // Enable watchdog and set timer to 0x7F (max val) printf("Starting up...\n"); while(1){ printf("CSR: %08x\n", csr); delay_us(100000); WWDG->CR = 0x7F; // Feed the watchdog } return 0; }