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.
This commit is contained in:
Radomir Dopieralski 2020-07-08 19:59:53 +02:00
parent 9b4b655b03
commit 83a27edd20
4 changed files with 18 additions and 3 deletions

View File

@ -43,3 +43,5 @@
#define DEFAULT_UART_BUS_RX (&pin_PA01)
#define DEFAULT_UART_BUS_TX (&pin_PA00)
#define BOARD_BROWNOUT_LEVEL (6)

View File

@ -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

View File

@ -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

View File

@ -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.