diff --git a/examples/light-switch-app/silabs/SiWx917/include/AppTask.h b/examples/light-switch-app/silabs/SiWx917/include/AppTask.h index de8ab5ce947e8e..cd4ea4d557e74a 100644 --- a/examples/light-switch-app/silabs/SiWx917/include/AppTask.h +++ b/examples/light-switch-app/silabs/SiWx917/include/AppTask.h @@ -40,6 +40,8 @@ *********************************************************/ // Button specific defines for SiWx917 #define SL_SIMPLE_BUTTON_PRESSED 1U +#define SL_SIMPLE_BUTTON_RELEASED 0U + #define SIWx917_BTN0 0 #define SIWx917_BTN1 1 diff --git a/examples/platform/silabs/SiWx917/BaseApplication.cpp b/examples/platform/silabs/SiWx917/BaseApplication.cpp index 081bbfa1055419..1a4e044a661102 100644 --- a/examples/platform/silabs/SiWx917/BaseApplication.cpp +++ b/examples/platform/silabs/SiWx917/BaseApplication.cpp @@ -37,6 +37,9 @@ #endif // DISPLAY_ENABLED #include "SiWx917DeviceDataProvider.h" +#include "rsi_board.h" +#include "rsi_chip.h" +#include "siwx917_utils.h" #include #include #include @@ -56,8 +59,9 @@ * Defines and Constants *********************************************************/ -#define FACTORY_RESET_TRIGGER_TIMEOUT 3000 +#define FACTORY_RESET_TRIGGER_TIMEOUT 7000 #define FACTORY_RESET_CANCEL_WINDOW_TIMEOUT 3000 +#define FACTORY_RESET_LOOP_COUNT 5 #ifndef APP_TASK_STACK_SIZE #define APP_TASK_STACK_SIZE (4096) #endif @@ -242,41 +246,22 @@ void BaseApplication::FunctionEventHandler(AppEvent * aEvent) { return; } +} - // If we reached here, the button was held past FACTORY_RESET_TRIGGER_TIMEOUT, - // initiate factory reset - if (mFunctionTimerActive && mFunction == kFunction_StartBleAdv) - { - SILABS_LOG("Factory Reset Triggered. Release button within %ums to cancel.", FACTORY_RESET_CANCEL_WINDOW_TIMEOUT); - - // Start timer for FACTORY_RESET_CANCEL_WINDOW_TIMEOUT to allow user to - // cancel, if required. - StartFunctionTimer(FACTORY_RESET_CANCEL_WINDOW_TIMEOUT); - -#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1 - StartStatusLEDTimer(); -#endif // CHIP_DEVICE_CONFIG_ENABLE_SED - - mFunction = kFunction_FactoryReset; +void BaseApplication::FunctionFactoryReset(void) +{ + SILABS_LOG("#################################################################"); + SILABS_LOG("################### Factory reset triggered #####################"); + SILABS_LOG("#################################################################"); -#ifdef ENABLE_WSTK_LEDS - // Turn off LED before starting blink to make sure blink is - // co-ordinated. - sStatusLED.Set(false); - sStatusLED.Blink(500); -#endif // ENABLE_WSTK_LEDS - } - else if (mFunctionTimerActive && mFunction == kFunction_FactoryReset) - { - // Actually trigger Factory Reset - mFunction = kFunction_NoneSelected; + // Actually trigger Factory Reset + mFunction = kFunction_NoneSelected; #if CHIP_DEVICE_CONFIG_ENABLE_SED == 1 - StopStatusLEDTimer(); + StopStatusLEDTimer(); #endif // CHIP_DEVICE_CONFIG_ENABLE_SED - chip::Server::GetInstance().ScheduleFactoryReset(); - } + chip::Server::GetInstance().ScheduleFactoryReset(); } void BaseApplication::LightEventHandler() @@ -367,6 +352,8 @@ void BaseApplication::LightEventHandler() void BaseApplication::ButtonHandler(AppEvent * aEvent) { + uint8_t count = FACTORY_RESET_LOOP_COUNT; + // To trigger software update: press the APP_FUNCTION_BUTTON button briefly (< // FACTORY_RESET_TRIGGER_TIMEOUT) To initiate factory reset: press the // APP_FUNCTION_BUTTON for FACTORY_RESET_TRIGGER_TIMEOUT + @@ -376,44 +363,63 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent) // start blinking within the FACTORY_RESET_CANCEL_WINDOW_TIMEOUT if (aEvent->ButtonEvent.Action == SL_SIMPLE_BUTTON_PRESSED) { - if (!mFunctionTimerActive && mFunction == kFunction_NoneSelected) + if ((!mFunctionTimerActive) && (mFunction == kFunction_NoneSelected)) { - StartFunctionTimer(FACTORY_RESET_TRIGGER_TIMEOUT); - mFunction = kFunction_StartBleAdv; + mFunction = kFunction_FactoryReset; + + // Wait for sometime to determine button is pressed for Factory reset + // other functionality + vTaskDelay(1000); // Delay of 1sec before we check the button status } } - else + + while (!(RSI_NPSSGPIO_GetPin(NPSS_GPIO_0))) { - // If the button was released before factory reset got initiated, start BLE advertissement in fast mode - if (mFunctionTimerActive && mFunction == kFunction_StartBleAdv) + if (count == 0) { - CancelFunctionTimer(); - mFunction = kFunction_NoneSelected; - -#ifdef SL_WIFI - if (!ConnectivityMgr().IsWiFiStationProvisioned()) -#else - if (!ConnectivityMgr().IsThreadProvisioned()) -#endif /* !SL_WIFI */ - { - // Enable BLE advertisements - ConnectivityMgr().SetBLEAdvertisingEnabled(true); - ConnectivityMgr().SetBLEAdvertisingMode(ConnectivityMgr().kFastAdvertising); - } - else { SILABS_LOG("Network is already provisioned, Ble advertissement not enabled"); } + FunctionFactoryReset(); + break; } - else if (mFunctionTimerActive && mFunction == kFunction_FactoryReset) - { - CancelFunctionTimer(); + +#ifdef ENABLE_WSTK_LEDS + // Turn off status LED before starting blink to make sure blink is + // co-ordinated. + sStatusLED.Set(false); + sStatusLED.Blink(500); +#endif // ENABLE_WSTK_LEDS + + SILABS_LOG("Factory reset triggering in %d sec release button to cancel", count--); + + // Delay of 1sec before checking the button status again + vTaskDelay(1000); + } + + if (count > 0) + { +#ifdef ENABLE_WSTK_LEDS + sStatusLED.Set(false); +#endif + SILABS_LOG("Factory Reset has been Canceled"); // button held past Timeout wait till button is released + } + + // If the button was released before factory reset got initiated, start BLE advertissement in fast mode + if (mFunction == kFunction_FactoryReset) + { + mFunction = kFunction_NoneSelected; #if CHIP_DEVICE_CONFIG_ENABLE_SED == 1 - StopStatusLEDTimer(); + StopStatusLEDTimer(); #endif - // Change the function to none selected since factory reset has been - // canceled. - mFunction = kFunction_NoneSelected; - SILABS_LOG("Factory Reset has been Canceled"); + if (!ConnectivityMgr().IsWiFiStationProvisioned()) + { + // Enable BLE advertisements + ConnectivityMgr().SetBLEAdvertisingEnabled(true); + ConnectivityMgr().SetBLEAdvertisingMode(ConnectivityMgr().kFastAdvertising); + } + else + { + SILABS_LOG("Network is already provisioned, Ble advertissement not enabled"); } } } diff --git a/examples/platform/silabs/SiWx917/BaseApplication.h b/examples/platform/silabs/SiWx917/BaseApplication.h index 2c0e07edb35289..82d229c53bf390 100644 --- a/examples/platform/silabs/SiWx917/BaseApplication.h +++ b/examples/platform/silabs/SiWx917/BaseApplication.h @@ -138,6 +138,13 @@ class BaseApplication */ static void FunctionTimerEventHandler(TimerHandle_t xTimer); + /** + * @brief Factory reset trigger function + * Trigger factory if called + * + */ + static void FunctionFactoryReset(void); + /** * @brief Timer Event processing function * Trigger factory if Press and Hold duration is respected diff --git a/examples/platform/silabs/SiWx917/SiWx917/hal/rsi_hal_mcu_platform_init.c b/examples/platform/silabs/SiWx917/SiWx917/hal/rsi_hal_mcu_platform_init.c index 1cf672c1508dc1..4907bd86ff4940 100644 --- a/examples/platform/silabs/SiWx917/SiWx917/hal/rsi_hal_mcu_platform_init.c +++ b/examples/platform/silabs/SiWx917/SiWx917/hal/rsi_hal_mcu_platform_init.c @@ -32,6 +32,10 @@ #define ICACHE_DISABLE #define DEBUG_DISABLE +/* QSPI clock config params */ +#define INTF_PLL_500_CTRL_VALUE 0xD900 +#define INTF_PLL_CLK 160000000 /* PLL out clock 160MHz */ + #define PMU_GOOD_TIME 31 /*Duration in us*/ #define XTAL_GOOD_TIME 31 /*Duration in us*/ @@ -55,6 +59,8 @@ */ int soc_pll_config(void) { + int32_t status = RSI_OK; + RSI_CLK_SocPllLockConfig(1, 1, 7); RSI_CLK_SocPllRefClkConfig(2); @@ -77,7 +83,19 @@ int soc_pll_config(void) RSI_CLK_M4SocClkConfig(M4CLK, M4_SOCPLLCLK, 0); #ifdef SWITCH_QSPI_TO_SOC_PLL - RSI_CLK_QspiClkConfig(M4CLK, QSPI_INTFPLLCLK, 0, 0, 0); + /* program intf pll to 160Mhz */ + SPI_MEM_MAP_PLL(INTF_PLL_500_CTRL_REG9) = INTF_PLL_500_CTRL_VALUE; + status = RSI_CLK_SetIntfPllFreq(M4CLK, INTF_PLL_CLK, SOC_PLL_REF_FREQUENCY); + if (status != RSI_OK) + { + SILABS_LOG("Failed to Config Interface PLL Clock, status:%d", status); + } + else + { + SILABS_LOG("Configured Interface PLL Clock to %d", INTF_PLL_CLK); + } + + RSI_CLK_QspiClkConfig(M4CLK, QSPI_INTFPLLCLK, 0, 0, 1); #endif /* SWITCH_QSPI_TO_SOC_PLL */ return 0; @@ -100,13 +118,13 @@ void RSI_Wakeupsw_config(void) RSI_NPSSGPIO_InputBufferEn(NPSS_GPIO_2, 1); /*Configure the NPSS GPIO mode to wake up */ - RSI_NPSSGPIO_SetPinMux(NPSS_GPIO_2, 2); + RSI_NPSSGPIO_SetPinMux(NPSS_GPIO_2, NPSSGPIO_PIN_MUX_MODE2); /*Configure the NPSS GPIO direction to input */ RSI_NPSSGPIO_SetDir(NPSS_GPIO_2, NPSS_GPIO_DIR_OUTPUT); - /* Enables rise edge interrupt detection for UULP_VBAT_GPIO_0 */ - RSI_NPSSGPIO_SetIntLevelLowEnable(NPSS_GPIO_2_INTR); + /* Enables fall edge interrupt detection for UULP_VBAT_GPIO_0 */ + RSI_NPSSGPIO_SetIntFallEdgeEnable(NPSS_GPIO_2_INTR); /* Un mask the NPSS GPIO interrupt*/ RSI_NPSSGPIO_IntrUnMask(NPSS_GPIO_2_INTR); @@ -118,9 +136,9 @@ void RSI_Wakeupsw_config(void) RSI_NPSSGPIO_ClrIntr(NPSS_GPIO_2_INTR); /*Enable the NPSS GPIO interrupt slot*/ - NVIC_EnableIRQ(21); + NVIC_EnableIRQ(NPSS_TO_MCU_GPIO_INTR_IRQn); - NVIC_SetPriority(21, 7); + NVIC_SetPriority(NPSS_TO_MCU_GPIO_INTR_IRQn, 7); } void RSI_Wakeupsw_config_gpio0(void) @@ -140,8 +158,8 @@ void RSI_Wakeupsw_config_gpio0(void) /* Set the GPIO to wake from deep sleep */ RSI_NPSSGPIO_SetWkpGpio(NPSS_GPIO_0_INTR); - /* Enables rise edge interrupt detection for UULP_VBAT_GPIO_0 */ - RSI_NPSSGPIO_SetIntLevelLowEnable(NPSS_GPIO_0_INTR); + /* Enables fall edge interrupt detection for UULP_VBAT_GPIO_0 */ + RSI_NPSSGPIO_SetIntFallEdgeEnable(NPSS_GPIO_0_INTR); /* Un mask the NPSS GPIO interrupt*/ RSI_NPSSGPIO_IntrUnMask(NPSS_GPIO_0_INTR); @@ -153,8 +171,8 @@ void RSI_Wakeupsw_config_gpio0(void) RSI_NPSSGPIO_ClrIntr(NPSS_GPIO_0_INTR); // 21 being the NPSS_TO_MCU_GPIO_INTR_IRQn - NVIC_EnableIRQ(21); - NVIC_SetPriority(21, 7); + NVIC_EnableIRQ(NPSS_TO_MCU_GPIO_INTR_IRQn); + NVIC_SetPriority(NPSS_TO_MCU_GPIO_INTR_IRQn, 7); } /*==============================================*/ diff --git a/examples/platform/silabs/SiWx917/ldscripts/SiWx917.ld b/examples/platform/silabs/SiWx917/ldscripts/SiWx917.ld index 13f0b226a4d9f6..2b6ef77ca22790 100644 --- a/examples/platform/silabs/SiWx917/ldscripts/SiWx917.ld +++ b/examples/platform/silabs/SiWx917/ldscripts/SiWx917.ld @@ -18,8 +18,8 @@ MEMORY { - FLASH (rx) : ORIGIN = 0x08012000, LENGTH = 0x200000 - RAM (rwx) : ORIGIN = 0xC, LENGTH = 262144 + FLASH (rx) : ORIGIN = 0x08012000, LENGTH = 0x400000 + RAM (rwx) : ORIGIN = 0xC, LENGTH = 0x4FC00 } /* Linker script to place sections and symbol values. Should be used together