From 5098d06067b7e8400e1d45fd6f0d6cdb2f411a94 Mon Sep 17 00:00:00 2001 From: Dawid Wojtas Date: Fri, 3 Feb 2023 15:45:50 +0100 Subject: [PATCH] [BH-1627] Enable brownout detection There is the possibility of hanging the MCU due to a power glitch if the voltage drops to 2.8V and the system wants to use some peripherals like the eink or the backlight. To prevent this situation brownout detection has been enabled which monitors the 1.1V and 2.5V LDO regulators. If the voltage will drop to the trigger voltages then the interrupt is invoked. The interrupt checks the source of the interrupt and then reset the MCU using WDOG_B pin which is connected to the main power source. After restarting, the MCU checks the voltage. If it is too low the system enters SNVS mode. --- module-bsp/board/rt1051/bellpx/CMakeLists.txt | 2 ++ .../board/rt1051/bellpx/board/brownout.hpp | 8 +++++ module-bsp/board/rt1051/bellpx/brownout.cpp | 33 +++++++++++++++++++ .../board/rt1051/bellpx/bsp/lpm/RT1051LPM.cpp | 15 ++++++++- .../board/rt1051/bellpx/bsp/lpm/RT1051LPM.hpp | 5 ++- module-bsp/board/rt1051/bellpx/irq_gpio.cpp | 25 +++++++++++++- .../board/rt1051/bsp/lpm/RT1051LPMCommon.cpp | 4 +-- .../board/rt1051/bsp/lpm/RT1051LPMCommon.hpp | 6 ++-- module-bsp/board/rt1051/common/board.cpp | 2 ++ module-bsp/board/rt1051/puretx/CMakeLists.txt | 2 ++ .../board/rt1051/puretx/board/brownout.hpp | 8 +++++ module-bsp/board/rt1051/puretx/brownout.cpp | 8 +++++ .../board/rt1051/puretx/bsp/lpm/RT1051LPM.cpp | 12 ++++++- .../board/rt1051/puretx/bsp/lpm/RT1051LPM.hpp | 5 ++- .../BellHybrid/BinaryAssetsVersions.cmake | 2 +- 15 files changed, 126 insertions(+), 11 deletions(-) create mode 100644 module-bsp/board/rt1051/bellpx/board/brownout.hpp create mode 100644 module-bsp/board/rt1051/bellpx/brownout.cpp create mode 100644 module-bsp/board/rt1051/puretx/board/brownout.hpp create mode 100644 module-bsp/board/rt1051/puretx/brownout.cpp diff --git a/module-bsp/board/rt1051/bellpx/CMakeLists.txt b/module-bsp/board/rt1051/bellpx/CMakeLists.txt index d0e294285d242d1c189495de12bf377b1bde23b2..b9eb503b93fb106c3eb5cb40c8b6845fd5499328 100644 --- a/module-bsp/board/rt1051/bellpx/CMakeLists.txt +++ b/module-bsp/board/rt1051/bellpx/CMakeLists.txt @@ -30,10 +30,12 @@ target_sources( irq_gpio.cpp pin_mux.c board.cpp + brownout.cpp PUBLIC eink-config.h board/pin_mux.h board/clock_config.h board/irq_gpio.hpp + board/brownout.hpp ) diff --git a/module-bsp/board/rt1051/bellpx/board/brownout.hpp b/module-bsp/board/rt1051/bellpx/board/brownout.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6d55f909646830573a1c4d2e3775901d2a78f8f5 --- /dev/null +++ b/module-bsp/board/rt1051/bellpx/board/brownout.hpp @@ -0,0 +1,8 @@ +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once +namespace bsp +{ + void Brownout_init(void); +} diff --git a/module-bsp/board/rt1051/bellpx/brownout.cpp b/module-bsp/board/rt1051/bellpx/brownout.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ca74cca8ce8bcab88c48b2c2de86b8c0717b9713 --- /dev/null +++ b/module-bsp/board/rt1051/bellpx/brownout.cpp @@ -0,0 +1,33 @@ +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include +#include +#include + +namespace bsp +{ + namespace + { + constexpr std::uint32_t OutputVoltage1P1 = 0x19; // 1.275V + constexpr std::uint32_t OutputVoltage2P5 = 0x1F; // 2.875V + + constexpr std::uint32_t OffsetVoltage1P1 = 0x05; // 5*25mv + constexpr std::uint32_t OffsetVoltage2P5 = 0x03; // 3*25mv + } // namespace + + void Brownout_init() + { + // Config LDO Regulatorsand config Brownout voltage offsets + PMU_1P1EnableBrownout(PMU, true); + PMU_1P1SetRegulatorOutputVoltage(PMU, OutputVoltage1P1); + PMU_1P1SetBrownoutOffsetVoltage(PMU, OffsetVoltage1P1); + PMU_1P1EnableOutput(PMU, true); + + PMU_2P5nableBrownout(PMU, true); + PMU_2P5SetRegulatorOutputVoltage(PMU, OutputVoltage2P5); + PMU_2P5SetBrownoutOffsetVoltage(PMU, OffsetVoltage2P5); + PMU_2P5EnableOutput(PMU, true); + } + +} // namespace bsp diff --git a/module-bsp/board/rt1051/bellpx/bsp/lpm/RT1051LPM.cpp b/module-bsp/board/rt1051/bellpx/bsp/lpm/RT1051LPM.cpp index a50b1a2c295e495599e455c2ee7c3f7da585cf3b..0d474dafa821cbb98ad58c901719a40a0ad39a8c 100644 --- a/module-bsp/board/rt1051/bellpx/bsp/lpm/RT1051LPM.cpp +++ b/module-bsp/board/rt1051/bellpx/bsp/lpm/RT1051LPM.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "RT1051LPM.hpp" @@ -12,4 +12,17 @@ namespace bsp void RT1051LPM::DisableDcdcPowerSaveMode() {} + + void RT1051LPM::SwitchToRegularModeLDO() + { + RT1051LPMCommon::RegularLDOMode(); + NVIC_ClearPendingIRQ(ANATOP_EVENT0_IRQn); + EnableIRQ(ANATOP_EVENT0_IRQn); + } + + void RT1051LPM::SwitchToLowPowerModeLDO() + { + DisableIRQ(ANATOP_EVENT0_IRQn); + RT1051LPMCommon::LowPowerLDOMode(); + } } // namespace bsp diff --git a/module-bsp/board/rt1051/bellpx/bsp/lpm/RT1051LPM.hpp b/module-bsp/board/rt1051/bellpx/bsp/lpm/RT1051LPM.hpp index 7ac17e217ad796982db63aa0f6a64126af28c2ec..4aac802b8ccaaf30dbbf860e18e64830235b875d 100644 --- a/module-bsp/board/rt1051/bellpx/bsp/lpm/RT1051LPM.hpp +++ b/module-bsp/board/rt1051/bellpx/bsp/lpm/RT1051LPM.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -11,6 +11,9 @@ namespace bsp public: void EnableDcdcPowerSaveMode() final; void DisableDcdcPowerSaveMode() final; + + void SwitchToRegularModeLDO() final; + void SwitchToLowPowerModeLDO() final; }; } // namespace bsp diff --git a/module-bsp/board/rt1051/bellpx/irq_gpio.cpp b/module-bsp/board/rt1051/bellpx/irq_gpio.cpp index dabeffe346e1ef546c6717d23e9ba255fb1fd722..271239b37f56c3605b8769e9724a1ca513535c20 100644 --- a/module-bsp/board/rt1051/bellpx/irq_gpio.cpp +++ b/module-bsp/board/rt1051/bellpx/irq_gpio.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "board/irq_gpio.hpp" @@ -10,6 +10,7 @@ #include "fsl_common.h" #include #include +#include #include "board/rt1051/bsp/eink/bsp_eink.h" #include @@ -71,6 +72,10 @@ namespace bsp NVIC_ClearPendingIRQ(RTWDOG_IRQn); EnableIRQ(RTWDOG_IRQn); + + // Enable PMU brownout interrupt + NVIC_ClearPendingIRQ(ANATOP_EVENT0_IRQn); + EnableIRQ(ANATOP_EVENT0_IRQn); } extern "C" @@ -194,5 +199,23 @@ namespace bsp // Way to do it is via WDOG1 built-in assertion, RTWDOG does not provide it WDOG1->WCR &= ~WDOG_WCR_WDA_MASK; } + + // Enable PMU brownout interrupt + void ANATOP_EVENT0_IRQHandler(void) + { + const uint32_t status = PMU_GetStatusFlags(PMU); + + // If the PMU brownout detects to low voltage + // immediately reset the CPU using the WDOG_B pin + if (status & kPMU_1P1BrownoutOnOutput) { + WDOG1->WCR &= ~WDOG_WCR_WDA_MASK; + } + + if (status & kPMU_2P5BrownoutOnOutput) { + WDOG1->WCR &= ~WDOG_WCR_WDA_MASK; + } + + NVIC_ClearPendingIRQ(ANATOP_EVENT0_IRQn); + } } } // namespace bsp diff --git a/module-bsp/board/rt1051/bsp/lpm/RT1051LPMCommon.cpp b/module-bsp/board/rt1051/bsp/lpm/RT1051LPMCommon.cpp index 66e9f0d45ef6d8f82104439ffb54821c1d683094..1e541d20a1a203a5c3350c8fc46d52a2fb12acac 100644 --- a/module-bsp/board/rt1051/bsp/lpm/RT1051LPMCommon.cpp +++ b/module-bsp/board/rt1051/bsp/lpm/RT1051LPMCommon.cpp @@ -175,7 +175,7 @@ namespace bsp DCDC->REG1 |= DCDC_REG1_REG_RLOAD_SW_MASK; } - void RT1051LPMCommon::SwitchToRegularModeLDO() + void RT1051LPMCommon::RegularLDOMode() { // Enable regular 2P5 and wait it stable PMU->REG_2P5_SET = PMU_REG_2P5_ENABLE_LINREG_MASK; @@ -191,7 +191,7 @@ namespace bsp PMU->REG_1P1_CLR = PMU_REG_1P1_ENABLE_WEAK_LINREG_MASK; } - void RT1051LPMCommon::SwitchToLowPowerModeLDO() + void RT1051LPMCommon::LowPowerLDOMode() { // Enable weak 2P5 and turn off regular 2P5 PMU->REG_2P5 |= PMU_REG_2P5_ENABLE_WEAK_LINREG_MASK; diff --git a/module-bsp/board/rt1051/bsp/lpm/RT1051LPMCommon.hpp b/module-bsp/board/rt1051/bsp/lpm/RT1051LPMCommon.hpp index 64d0e456b24780af8f1d7e6008bd79ca2a68005e..5038b64d365f2c5a51d6a15cd7bde3d0ae0e5bde 100644 --- a/module-bsp/board/rt1051/bsp/lpm/RT1051LPMCommon.hpp +++ b/module-bsp/board/rt1051/bsp/lpm/RT1051LPMCommon.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -23,8 +23,8 @@ namespace bsp void DisconnectInternalLoadResistor() final; void ConnectInternalLoadResistor() final; - void SwitchToRegularModeLDO() final; - void SwitchToLowPowerModeLDO() final; + void RegularLDOMode(); + void LowPowerLDOMode(); private: CpuFrequencyMHz onChangeUp(CpuFrequencyMHz freq, CpuFrequencyMHz newFrequency); diff --git a/module-bsp/board/rt1051/common/board.cpp b/module-bsp/board/rt1051/common/board.cpp index 6614b2c384d810293ea222fccde8bab5eb9766a2..113172cce7af7a5d39ed177b4135eabc3b492107 100644 --- a/module-bsp/board/rt1051/common/board.cpp +++ b/module-bsp/board/rt1051/common/board.cpp @@ -17,6 +17,7 @@ extern "C" } #include "chip.hpp" #include "board/irq_gpio.hpp" +#include "board/brownout.hpp" #include #include @@ -167,6 +168,7 @@ namespace bsp board::initDebugConsole(); + Brownout_init(); irq_gpio_Init(); // SNVS init. is required for proper operation of the RTC when Secure Boot is used diff --git a/module-bsp/board/rt1051/puretx/CMakeLists.txt b/module-bsp/board/rt1051/puretx/CMakeLists.txt index 2117f7c4d764e49d93847ba80e65434e0c3fb18d..367e15176762a9b5a1f0260e92067a4aa816bea5 100644 --- a/module-bsp/board/rt1051/puretx/CMakeLists.txt +++ b/module-bsp/board/rt1051/puretx/CMakeLists.txt @@ -26,12 +26,14 @@ target_sources( irq_gpio.cpp debug_console.cpp board.cpp + brownout.cpp PUBLIC eink-config.h board/pin_mux.h board/clock_config.h board/irq_gpio.hpp + board/brownout.hpp board/BoardDefinitions.hpp ) diff --git a/module-bsp/board/rt1051/puretx/board/brownout.hpp b/module-bsp/board/rt1051/puretx/board/brownout.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6d55f909646830573a1c4d2e3775901d2a78f8f5 --- /dev/null +++ b/module-bsp/board/rt1051/puretx/board/brownout.hpp @@ -0,0 +1,8 @@ +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once +namespace bsp +{ + void Brownout_init(void); +} diff --git a/module-bsp/board/rt1051/puretx/brownout.cpp b/module-bsp/board/rt1051/puretx/brownout.cpp new file mode 100644 index 0000000000000000000000000000000000000000..349c57a8c76e534478cd51cc47546dec6d44ec42 --- /dev/null +++ b/module-bsp/board/rt1051/puretx/brownout.cpp @@ -0,0 +1,8 @@ +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +namespace bsp +{ + void Brownout_init() + {} +} // namespace bsp diff --git a/module-bsp/board/rt1051/puretx/bsp/lpm/RT1051LPM.cpp b/module-bsp/board/rt1051/puretx/bsp/lpm/RT1051LPM.cpp index e94457e90fe4723968c2897bc35a1846a08b155f..511cb956cfdc07a17b827d245f6940adab44f3a7 100644 --- a/module-bsp/board/rt1051/puretx/bsp/lpm/RT1051LPM.cpp +++ b/module-bsp/board/rt1051/puretx/bsp/lpm/RT1051LPM.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "RT1051LPM.hpp" @@ -43,4 +43,14 @@ namespace bsp gpio_2->WritePin(static_cast(BoardDefinitions::DCDC_INVERTER_MODE_PIN), 1); } + void RT1051LPM::SwitchToRegularModeLDO() + { + RT1051LPMCommon::RegularLDOMode(); + } + + void RT1051LPM::SwitchToLowPowerModeLDO() + { + RT1051LPMCommon::LowPowerLDOMode(); + } + } // namespace bsp diff --git a/module-bsp/board/rt1051/puretx/bsp/lpm/RT1051LPM.hpp b/module-bsp/board/rt1051/puretx/bsp/lpm/RT1051LPM.hpp index b8ee299a995283283f0891e8517d51d553fe9c06..62890cdf42eaaec7bf009d8fd393310cb97d65df 100644 --- a/module-bsp/board/rt1051/puretx/bsp/lpm/RT1051LPM.hpp +++ b/module-bsp/board/rt1051/puretx/bsp/lpm/RT1051LPM.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -14,6 +14,9 @@ namespace bsp void EnableDcdcPowerSaveMode() final; void DisableDcdcPowerSaveMode() final; + void SwitchToRegularModeLDO() final; + void SwitchToLowPowerModeLDO() final; + private: std::shared_ptr gpio_1; std::shared_ptr gpio_2; diff --git a/products/BellHybrid/BinaryAssetsVersions.cmake b/products/BellHybrid/BinaryAssetsVersions.cmake index b2aa9d78c1d9929955b78cd70cd2311b914d6e81..52f6acf0b820d45122b4362fc8df0e2a9742ee17 100644 --- a/products/BellHybrid/BinaryAssetsVersions.cmake +++ b/products/BellHybrid/BinaryAssetsVersions.cmake @@ -1,7 +1,7 @@ # This file sets versions of downloaded binaries for release packaging purposes if( NOT DEFINED ECOBOOT_BIN_VERSION) - set(ECOBOOT_BIN_VERSION 2.0.0 CACHE STRING "bootloader binary version to download from bootloader release page") + set(ECOBOOT_BIN_VERSION 2.0.2 CACHE STRING "bootloader binary version to download from bootloader release page") endif() if (NOT DEFINED RECOVERY_BIN_VERSION)