Skip to content

Commit 83a27ed

Browse files
committed
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.
1 parent 9b4b655 commit 83a27ed

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

ports/atmel-samd/boards/pewpew10/mpconfigboard.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@
4343

4444
#define DEFAULT_UART_BUS_RX (&pin_PA01)
4545
#define DEFAULT_UART_BUS_TX (&pin_PA00)
46+
47+
#define BOARD_BROWNOUT_LEVEL (6)

ports/atmel-samd/boards/pewpew_m4/mpconfigboard.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@
4040
#define IGNORE_PIN_PB09 1
4141
#define IGNORE_PIN_PB10 1
4242
#define IGNORE_PIN_PB11 1
43+
44+
#define BOARD_BROWNOUT_LEVEL (6)
45+
// 1.6V

ports/atmel-samd/mpconfigport.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@
112112
#define CIRCUITPY_DEFAULT_STACK_SIZE 4096
113113
#endif
114114

115+
#ifndef BOARD_BROWNOUT_LEVEL (
116+
#define BOARD_BROWNLOUT_LEVEL (39)
117+
// 2.77V with hysteresis off. Table 37.20 in datasheet.
118+
#endif
119+
115120
// Smallest unit of flash that can be erased.
116121
#define FLASH_ERASE_SIZE NVMCTRL_ROW_SIZE
117122

@@ -129,6 +134,11 @@
129134
#define CIRCUITPY_DEFAULT_STACK_SIZE (24*1024)
130135
#endif
131136

137+
#ifndef BOARD_BROWNOUT_LEVEL (
138+
#define BOARD_BROWNLOUT_LEVEL (200)
139+
// 2.7V: 1.5V + LEVEL * 6mV.
140+
#endif
141+
132142
// Smallest unit of flash that can be erased.
133143
#define FLASH_ERASE_SIZE NVMCTRL_BLOCK_SIZE
134144

ports/atmel-samd/supervisor/port.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,11 @@ static void rtc_init(void) {
206206
safe_mode_t port_init(void) {
207207
#if defined(SAMD21)
208208

209-
// Set brownout detection to ~2.7V. Default from factory is 1.7V,
209+
// Set brownout detection. Default from factory is 1.7V,
210210
// which is too low for proper operation of external SPI flash chips (they are 2.7-3.6V).
211211
// Disable while changing level.
212212
SYSCTRL->BOD33.bit.ENABLE = 0;
213-
SYSCTRL->BOD33.bit.LEVEL = 39; // 2.77V with hysteresis off. Table 37.20 in datasheet.
213+
SYSCTRL->BOD33.bit.LEVEL = BOARD_BROWNOUT_LEVEL;
214214
SYSCTRL->BOD33.bit.ENABLE = 1;
215215

216216
#ifdef ENABLE_MICRO_TRACE_BUFFER
@@ -229,7 +229,7 @@ safe_mode_t port_init(void) {
229229
// which is too low for proper operation of external SPI flash chips (they are 2.7-3.6V).
230230
// Disable while changing level.
231231
SUPC->BOD33.bit.ENABLE = 0;
232-
SUPC->BOD33.bit.LEVEL = 200; // 2.7V: 1.5V + LEVEL * 6mV.
232+
SUPC->BOD33.bit.LEVEL = BOARD_BROWNOUT_LEVEL;
233233
SUPC->BOD33.bit.ENABLE = 1;
234234

235235
// MPU (Memory Protection Unit) setup.

0 commit comments

Comments
 (0)