From 85779e19aec5e06fd87823a28883acff189bb787 Mon Sep 17 00:00:00 2001 From: Whinis Date: Sat, 17 Apr 2021 14:17:01 -0400 Subject: [PATCH] Adds ability to set wait states in the board.h files for devices that use voltages below 2.7v or clocks below 48mhz --- inc/main.h | 2 ++ src/init_samd21.c | 2 +- src/init_samd51.c | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/inc/main.h b/inc/main.h index 31f23a8a..cc9b849a 100644 --- a/inc/main.h +++ b/inc/main.h @@ -32,7 +32,9 @@ #define CPU_FREQUENCY 48000000 +#ifndef FLASH_WAIT_STATES //allow for other wait states #define FLASH_WAIT_STATES 1 +#endif #ifndef BOOT_USART_MODULE #define BOOT_USART_MODULE SERCOM3 diff --git a/src/init_samd21.c b/src/init_samd21.c index dd4ace9f..1db1c74e 100644 --- a/src/init_samd21.c +++ b/src/init_samd21.c @@ -26,7 +26,7 @@ static void dfll_sync(void) { void system_init(void) { - NVMCTRL->CTRLB.bit.RWS = 1; + NVMCTRL->CTRLB.bit.RWS = FLASH_WAIT_STATES; #if defined(CRYSTALLESS) /* Configure OSC8M as source for GCLK_GEN 2 */ diff --git a/src/init_samd51.c b/src/init_samd51.c index a4525ffc..7f587f6d 100644 --- a/src/init_samd51.c +++ b/src/init_samd51.c @@ -5,7 +5,7 @@ uint32_t current_cpu_frequency_MHz = 48; void system_init(void) { // Automatic wait states. - NVMCTRL->CTRLA.bit.AUTOWS = 1; + NVMCTRL->CTRLA.bit.AUTOWS = FLASH_WAIT_STATES; // Output GCLK0 to Metro M4 D5. This way we can see if/when we mess it up. // PORT->Group[1].PINCFG[14].bit.PMUXEN = true;