fix(el18): Prevent power on when USB is disconnected while radio is charging (#3325)
This commit is contained in:
@@ -18,7 +18,7 @@
|
|||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
#include "boards/generic_stm32/module_ports.h"
|
#include "boards/generic_stm32/module_ports.h"
|
||||||
|
|
||||||
@@ -166,7 +166,7 @@ void boardInit()
|
|||||||
|
|
||||||
// detect NV14 vs EL18
|
// detect NV14 vs EL18
|
||||||
hardwareOptions.pcbrev = boardGetPcbRev();
|
hardwareOptions.pcbrev = boardGetPcbRev();
|
||||||
|
|
||||||
#if defined(DEBUG)
|
#if defined(DEBUG)
|
||||||
serialInit(SP_AUX1, UART_MODE_DEBUG);
|
serialInit(SP_AUX1, UART_MODE_DEBUG);
|
||||||
#endif
|
#endif
|
||||||
@@ -195,19 +195,23 @@ void boardInit()
|
|||||||
if (UNEXPECTED_SHUTDOWN()) {
|
if (UNEXPECTED_SHUTDOWN()) {
|
||||||
pwrOn();
|
pwrOn();
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// prime debounce state...
|
// prime debounce state...
|
||||||
usbPlugged();
|
uint8_t usb_state = usbPlugged();
|
||||||
|
usb_state |= usbPlugged();
|
||||||
while (usbPlugged()) {
|
while (usb_state) {
|
||||||
|
pwrOn();
|
||||||
uint32_t now = get_tmr10ms();
|
uint32_t now = get_tmr10ms();
|
||||||
if (pwrPressed()) {
|
if (pwrPressed()) {
|
||||||
press_end = now;
|
press_end = now;
|
||||||
if (press_start == 0) press_start = now;
|
if (press_start == 0) press_start = now;
|
||||||
if ((now - press_start) > POWER_ON_DELAY) {
|
if ((now - press_start) > POWER_ON_DELAY) {
|
||||||
pwrOn();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else if (!usbPlugged()){
|
||||||
|
delay_ms(20);
|
||||||
|
if(!usbPlugged()){
|
||||||
|
boardOff();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
uint32_t press_end_touch = press_end;
|
uint32_t press_end_touch = press_end;
|
||||||
if (touchPanelEventOccured()) {
|
if (touchPanelEventOccured()) {
|
||||||
@@ -235,8 +239,8 @@ void boardInit()
|
|||||||
#if defined(RTCLOCK)
|
#if defined(RTCLOCK)
|
||||||
rtcInit(); // RTC must be initialized before rambackupRestore() is called
|
rtcInit(); // RTC must be initialized before rambackupRestore() is called
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if defined(DEBUG)
|
#if defined(DEBUG)
|
||||||
DBGMCU_APB1PeriphConfig(
|
DBGMCU_APB1PeriphConfig(
|
||||||
DBGMCU_IWDG_STOP | DBGMCU_TIM1_STOP | DBGMCU_TIM2_STOP |
|
DBGMCU_IWDG_STOP | DBGMCU_TIM1_STOP | DBGMCU_TIM2_STOP |
|
||||||
@@ -249,7 +253,7 @@ void boardInit()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void boardOff()
|
void boardOff()
|
||||||
{
|
{
|
||||||
lcdOff();
|
lcdOff();
|
||||||
|
|
||||||
while (pwrPressed()) {
|
while (pwrPressed()) {
|
||||||
@@ -289,7 +293,7 @@ void boardOff()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// We reach here only in forced power situations, such as hw-debugging with external power
|
// We reach here only in forced power situations, such as hw-debugging with external power
|
||||||
// Enter STM32 stop mode / deep-sleep
|
// Enter STM32 stop mode / deep-sleep
|
||||||
// Code snippet from ST Nucleo PWR_EnterStopMode example
|
// Code snippet from ST Nucleo PWR_EnterStopMode example
|
||||||
#define PDMode 0x00000000U
|
#define PDMode 0x00000000U
|
||||||
@@ -303,7 +307,7 @@ void boardOff()
|
|||||||
|
|
||||||
/* Set SLEEPDEEP bit of Cortex System Control Register */
|
/* Set SLEEPDEEP bit of Cortex System Control Register */
|
||||||
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
|
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
|
||||||
|
|
||||||
// To avoid HardFault at return address, end in an endless loop
|
// To avoid HardFault at return address, end in an endless loop
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user