From 66b8e2a311bae6caec7e14cd51d56315f3560196 Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Tue, 11 Feb 2025 16:12:45 +0100 Subject: [PATCH] fix(core): fix stwlc38 deinitialization [no changelog] --- core/embed/sys/powerctl/stwlc38/stwlc38.c | 9 ++++++++- core/embed/sys/powerctl/stwlc38/stwlc38.h | 5 +---- core/embed/sys/powerctl/stwlc38/stwlc38_defs.h | 5 +---- core/embed/sys/powerctl/stwlc38/stwlc38_internal.h | 5 +---- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/core/embed/sys/powerctl/stwlc38/stwlc38.c b/core/embed/sys/powerctl/stwlc38/stwlc38.c index 6112205ca7..c7d6f196d1 100644 --- a/core/embed/sys/powerctl/stwlc38/stwlc38.c +++ b/core/embed/sys/powerctl/stwlc38/stwlc38.c @@ -22,7 +22,6 @@ #include #include -#include #include #include "stwlc38.h" @@ -75,6 +74,10 @@ static void stwlc38_fsm_continue(stwlc38_driver_t *drv); void stwlc38_deinit(void) { stwlc38_driver_t *drv = &g_stwlc38_driver; + NVIC_DisableIRQ(STWLC38_EXTI_INTERRUPT_NUM); + + stwlc38_enable(false); + i2c_bus_close(drv->i2c_bus); systimer_delete(drv->timer); memset(drv, 0, sizeof(stwlc38_driver_t)); @@ -320,6 +323,10 @@ void STWLC38_EXTI_INTERRUPT_HANDLER(void) { // Clear the EXTI line pending bit __HAL_GPIO_EXTI_CLEAR_FLAG(STWLC38_INT_PIN); + if (!drv->initialized) { + return; + } + if (drv->state == STWLC38_STATE_POWER_DOWN) { // Inform the powerctl module about the WPC // wakeup_flags_set(WAKEUP_FLAGS_WPC); diff --git a/core/embed/sys/powerctl/stwlc38/stwlc38.h b/core/embed/sys/powerctl/stwlc38/stwlc38.h index 5aed0cb062..4f512c313c 100644 --- a/core/embed/sys/powerctl/stwlc38/stwlc38.h +++ b/core/embed/sys/powerctl/stwlc38/stwlc38.h @@ -17,8 +17,7 @@ * along with this program. If not, see . */ -#ifndef TREZORHAL_STWLC38_H -#define TREZORHAL_STWLC38_H +#pragma once #include @@ -120,5 +119,3 @@ bool stwlc38_patch_and_config(); // Gets the current report from the STWLC38 bool stwlc38_get_report(stwlc38_report_t* status); - -#endif // TREZORHAL_STWLC38_H diff --git a/core/embed/sys/powerctl/stwlc38/stwlc38_defs.h b/core/embed/sys/powerctl/stwlc38/stwlc38_defs.h index 096c1f510b..49b033518e 100644 --- a/core/embed/sys/powerctl/stwlc38/stwlc38_defs.h +++ b/core/embed/sys/powerctl/stwlc38/stwlc38_defs.h @@ -17,8 +17,7 @@ * along with this program. If not, see . */ -#ifndef TREZORHAL_STWLC38_DEFS_H -#define TREZORHAL_STWLC38_DEFS_H +#pragma once // I2C address of the STWLC38 on the I2C bus. #define STWLC38_I2C_ADDRESS 0x61 @@ -95,5 +94,3 @@ #define STWLC38_ERR_INVALID_CHIP_ID 0x80000006U #define STWLC38_ERR_NVM_ID_MISMATCH 0x80000007U #define STWLC38_ERR_NVM_DATA_CORRUPTED 0x80000008U - -#endif // TREZORHAL_STWLC38_DEFS_H diff --git a/core/embed/sys/powerctl/stwlc38/stwlc38_internal.h b/core/embed/sys/powerctl/stwlc38/stwlc38_internal.h index edf8486fb2..458a1b4a12 100644 --- a/core/embed/sys/powerctl/stwlc38/stwlc38_internal.h +++ b/core/embed/sys/powerctl/stwlc38/stwlc38_internal.h @@ -18,8 +18,7 @@ * along with this program. If not, see . */ -#ifndef TREZORHAL_STWLC38_INTERNAL_H -#define TREZORHAL_STWLC38_INTERNAL_H +#pragma once #include #include @@ -99,5 +98,3 @@ typedef struct { extern stwlc38_driver_t g_stwlc38_driver; #endif // KERNEL_MODE - -#endif // TREZORHAL_STWLC38_INTERNAL_H