summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRadomir Dopieralski <openstack@sheep.art.pl>2020-07-08 19:59:53 +0200
committerRadomir Dopieralski <openstack@sheep.art.pl>2020-07-08 19:59:53 +0200
commit83a27edd20de293927e8070da8585b11cb2f8ef7 (patch)
tree7c577a7f4ef1edeacabc8ff0768c88bc5fbb245d
parent9b4b655b031c82dd319803ecf66bd0994edc200e (diff)
SAMD: make the brownout detection level configurable per board
Not all boards have external flash or other components that make them require 2.7V -- sometimes we can get considerably longer battery life by decreasing this requirement. In particular, pewpew10 and pewpew_m4 are powered directly from battery, with no LDO, and should work fine down to 1.6V.
-rw-r--r--ports/atmel-samd/boards/pewpew10/mpconfigboard.h2
-rw-r--r--ports/atmel-samd/boards/pewpew_m4/mpconfigboard.h3
-rw-r--r--ports/atmel-samd/mpconfigport.h10
-rw-r--r--ports/atmel-samd/supervisor/port.c6
4 files changed, 18 insertions, 3 deletions
diff --git a/ports/atmel-samd/boards/pewpew10/mpconfigboard.h b/ports/atmel-samd/boards/pewpew10/mpconfigboard.h
index 6b3b4aa15..940e250b4 100644
--- a/ports/atmel-samd/boards/pewpew10/mpconfigboard.h
+++ b/ports/atmel-samd/boards/pewpew10/mpconfigboard.h
@@ -43,3 +43,5 @@
#define DEFAULT_UART_BUS_RX (&pin_PA01)
#define DEFAULT_UART_BUS_TX (&pin_PA00)
+
+#define BOARD_BROWNOUT_LEVEL (6)
diff --git a/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.h b/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.h
index 60cd8d754..7da5cf14c 100644
--- a/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.h
+++ b/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.h
@@ -40,3 +40,6 @@
#define IGNORE_PIN_PB09 1
#define IGNORE_PIN_PB10 1
#define IGNORE_PIN_PB11 1
+
+#define BOARD_BROWNOUT_LEVEL (6)
+// 1.6V
diff --git a/ports/atmel-samd/mpconfigport.h b/ports/atmel-samd/mpconfigport.h
index 354097ce4..3a5d4e1a2 100644
--- a/ports/atmel-samd/mpconfigport.h
+++ b/ports/atmel-samd/mpconfigport.h
@@ -112,6 +112,11 @@
#define CIRCUITPY_DEFAULT_STACK_SIZE 4096
#endif
+#ifndef BOARD_BROWNOUT_LEVEL (
+#define BOARD_BROWNLOUT_LEVEL (39)
+// 2.77V with hysteresis off. Table 37.20 in datasheet.
+#endif
+
// Smallest unit of flash that can be erased.
#define FLASH_ERASE_SIZE NVMCTRL_ROW_SIZE
@@ -129,6 +134,11 @@
#define CIRCUITPY_DEFAULT_STACK_SIZE (24*1024)
#endif
+#ifndef BOARD_BROWNOUT_LEVEL (
+#define BOARD_BROWNLOUT_LEVEL (200)
+// 2.7V: 1.5V + LEVEL * 6mV.
+#endif
+
// Smallest unit of flash that can be erased.
#define FLASH_ERASE_SIZE NVMCTRL_BLOCK_SIZE
diff --git a/ports/atmel-samd/supervisor/port.c b/ports/atmel-samd/supervisor/port.c
index e892e6cde..5b085dc81 100644
--- a/ports/atmel-samd/supervisor/port.c
+++ b/ports/atmel-samd/supervisor/port.c
@@ -206,11 +206,11 @@ static void rtc_init(void) {
safe_mode_t port_init(void) {
#if defined(SAMD21)
- // Set brownout detection to ~2.7V. Default from factory is 1.7V,
+ // 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).
// Disable while changing level.
SYSCTRL->BOD33.bit.ENABLE = 0;
- SYSCTRL->BOD33.bit.LEVEL = 39; // 2.77V with hysteresis off. Table 37.20 in datasheet.
+ SYSCTRL->BOD33.bit.LEVEL = BOARD_BROWNOUT_LEVEL;
SYSCTRL->BOD33.bit.ENABLE = 1;
#ifdef ENABLE_MICRO_TRACE_BUFFER
@@ -229,7 +229,7 @@ safe_mode_t port_init(void) {
// which is too low for proper operation of external SPI flash chips (they are 2.7-3.6V).
// Disable while changing level.
SUPC->BOD33.bit.ENABLE = 0;
- SUPC->BOD33.bit.LEVEL = 200; // 2.7V: 1.5V + LEVEL * 6mV.
+ SUPC->BOD33.bit.LEVEL = BOARD_BROWNOUT_LEVEL;
SUPC->BOD33.bit.ENABLE = 1;
// MPU (Memory Protection Unit) setup.