From e0733d153ee159fd235794825fada7d455828007 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Wed, 8 Jul 2020 20:59:00 +0200 Subject: [PATCH] SAMD: configurable brownout, separate the variables --- ports/atmel-samd/boards/pewpew10/mpconfigboard.h | 2 +- ports/atmel-samd/boards/pewpew_m4/mpconfigboard.h | 3 +-- ports/atmel-samd/mpconfigport.h | 14 ++++++++++---- ports/atmel-samd/supervisor/port.c | 10 ++++------ 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/ports/atmel-samd/boards/pewpew10/mpconfigboard.h b/ports/atmel-samd/boards/pewpew10/mpconfigboard.h index 940e250b46..2cb097e8dc 100644 --- a/ports/atmel-samd/boards/pewpew10/mpconfigboard.h +++ b/ports/atmel-samd/boards/pewpew10/mpconfigboard.h @@ -44,4 +44,4 @@ #define DEFAULT_UART_BUS_RX (&pin_PA01) #define DEFAULT_UART_BUS_TX (&pin_PA00) -#define BOARD_BROWNOUT_LEVEL (6) +#define SAMD21_BOD33_LEVEL (6) diff --git a/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.h b/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.h index 7da5cf14c1..4b88c89f28 100644 --- a/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.h +++ b/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.h @@ -41,5 +41,4 @@ #define IGNORE_PIN_PB10 1 #define IGNORE_PIN_PB11 1 -#define BOARD_BROWNOUT_LEVEL (6) -// 1.6V +#define SAMD5x_E5x_BOD33_LEVEL (100) diff --git a/ports/atmel-samd/mpconfigport.h b/ports/atmel-samd/mpconfigport.h index 3a5d4e1a2f..540a2f77c7 100644 --- a/ports/atmel-samd/mpconfigport.h +++ b/ports/atmel-samd/mpconfigport.h @@ -112,8 +112,11 @@ #define CIRCUITPY_DEFAULT_STACK_SIZE 4096 #endif -#ifndef BOARD_BROWNOUT_LEVEL ( -#define BOARD_BROWNLOUT_LEVEL (39) +#ifndef SAMD21_BOD33_LEVEL +// Set brownout detection to ~2.7V. Default from factory is 1.7V, +// which is too low for proper operation of external SPI flash chips +// (they are 2.7-3.6V). +#define SAMD21_BOD33_LEVEL (39) // 2.77V with hysteresis off. Table 37.20 in datasheet. #endif @@ -134,8 +137,11 @@ #define CIRCUITPY_DEFAULT_STACK_SIZE (24*1024) #endif -#ifndef BOARD_BROWNOUT_LEVEL ( -#define BOARD_BROWNLOUT_LEVEL (200) +#ifndef SAMD5x_E5x_BOD33_LEVEL +// Set brownout detection to ~2.7V. Default from factory is 1.7V, +// which is too low for proper operation of external SPI flash chips +// (they are 2.7-3.6V). +#define SAMD5x_E5x_BOD33_LEVEL (200) // 2.7V: 1.5V + LEVEL * 6mV. #endif diff --git a/ports/atmel-samd/supervisor/port.c b/ports/atmel-samd/supervisor/port.c index 5b085dc81b..65501861e0 100644 --- a/ports/atmel-samd/supervisor/port.c +++ b/ports/atmel-samd/supervisor/port.c @@ -206,11 +206,10 @@ static void rtc_init(void) { safe_mode_t port_init(void) { #if defined(SAMD21) - // Set brownout detection. Default from factory is 1.7V, - // which is too low for proper operation of external SPI flash chips (they are 2.7-3.6V). + // Set brownout detection. // Disable while changing level. SYSCTRL->BOD33.bit.ENABLE = 0; - SYSCTRL->BOD33.bit.LEVEL = BOARD_BROWNOUT_LEVEL; + SYSCTRL->BOD33.bit.LEVEL = SAMD21_BOD33_LEVEL; SYSCTRL->BOD33.bit.ENABLE = 1; #ifdef ENABLE_MICRO_TRACE_BUFFER @@ -225,11 +224,10 @@ safe_mode_t port_init(void) { #endif #if defined(SAM_D5X_E5X) - // Set brownout detection to ~2.7V. Default from factory is 1.7V, - // which is too low for proper operation of external SPI flash chips (they are 2.7-3.6V). + // Set brownout detection. // Disable while changing level. SUPC->BOD33.bit.ENABLE = 0; - SUPC->BOD33.bit.LEVEL = BOARD_BROWNOUT_LEVEL; + SUPC->BOD33.bit.LEVEL = SAMD5x_E5x_BOD33_LEVEL; SUPC->BOD33.bit.ENABLE = 1; // MPU (Memory Protection Unit) setup.