From dd8cbca6d34655a57291a9a2feff8d7605c01fb3 Mon Sep 17 00:00:00 2001 From: shasaicha Date: Mon, 24 Apr 2023 14:41:02 +0530 Subject: [PATCH 01/50] SPI multiplex changes for rs911x --- examples/platform/silabs/display/demo-ui.c | 14 +-- examples/platform/silabs/display/lcd.cpp | 16 ++- .../silabs/efr32/rs911x/hal/efx_spi.c | 75 +++++++++++- .../platform/silabs/efr32/rs911x/rs911x.gni | 1 + .../platform/silabs/efr32/spi_multiplex.c | 111 +++++++++++++++++- .../platform/silabs/efr32/spi_multiplex.h | 29 ++++- .../silabs/efr32/OTAImageProcessorImpl.cpp | 21 ++-- third_party/open-iot-sdk/sdk | 2 +- third_party/silabs/matter_support | 2 +- 9 files changed, 242 insertions(+), 29 deletions(-) diff --git a/examples/platform/silabs/display/demo-ui.c b/examples/platform/silabs/display/demo-ui.c index 68b53ba5a804c9..1c5222b06b2ce2 100644 --- a/examples/platform/silabs/display/demo-ui.c +++ b/examples/platform/silabs/display/demo-ui.c @@ -25,7 +25,7 @@ #include "glib.h" #include #include -#if (defined(EFR32MG24) && defined(WF200_WIFI)) +#if (defined(EFR32MG24) && defined(SL_WIFI)) #include "spi_multiplex.h" #endif @@ -108,11 +108,11 @@ void demoUIDisplayHeader(char * name) { GLIB_drawStringOnLine(&glibContext, name, 5, GLIB_ALIGN_CENTER, 0, 0, true); } -#if (defined(EFR32MG24) && defined(WF200_WIFI)) +#if (defined(EFR32MG24) && defined(SL_WIFI)) pre_lcd_spi_transfer(); #endif DMD_updateDisplay(); -#if (defined(EFR32MG24) && defined(WF200_WIFI)) +#if (defined(EFR32MG24) && defined(SL_WIFI)) post_lcd_spi_transfer(); #endif } @@ -121,11 +121,11 @@ void demoUIDisplayApp(bool on) { GLIB_drawBitmap(&glibContext, APP_X_POSITION, APP_Y_POSITION, APP_BITMAP_WIDTH, APP_BITMAP_HEIGHT, (on ? OnStateBitMap : OffStateBitMap)); -#if (defined(EFR32MG24) && defined(WF200_WIFI)) +#if (defined(EFR32MG24) && defined(SL_WIFI)) pre_lcd_spi_transfer(); #endif DMD_updateDisplay(); -#if (defined(EFR32MG24) && defined(WF200_WIFI)) +#if (defined(EFR32MG24) && defined(SL_WIFI)) post_lcd_spi_transfer(); #endif } @@ -138,11 +138,11 @@ void demoUIDisplayProtocol(demoUIProtocol protocol, bool isConnected) (protocol == DEMO_UI_PROTOCOL1 ? PROT1_BITMAP_HEIGHT : PROT2_BITMAP_HEIGHT), (protocol == DEMO_UI_PROTOCOL1 ? (isConnected ? PROT1_BITMAP_CONN : PROT1_BITMAP) : (isConnected ? PROT2_BITMAP_CONN : PROT2_BITMAP))); -#if (defined(EFR32MG24) && defined(WF200_WIFI)) +#if (defined(EFR32MG24) && defined(SL_WIFI)) pre_lcd_spi_transfer(); #endif DMD_updateDisplay(); -#if (defined(EFR32MG24) && defined(WF200_WIFI)) +#if (defined(EFR32MG24) && defined(SL_WIFI)) post_lcd_spi_transfer(); #endif } diff --git a/examples/platform/silabs/display/lcd.cpp b/examples/platform/silabs/display/lcd.cpp index 561c02451686ee..7c223e53c32262 100644 --- a/examples/platform/silabs/display/lcd.cpp +++ b/examples/platform/silabs/display/lcd.cpp @@ -31,7 +31,7 @@ #include "sl_board_control.h" -#if (defined(EFR32MG24) && defined(WF200_WIFI)) +#if (defined(EFR32MG24) && defined(SL_WIFI)) #include "spi_multiplex.h" #endif #define LCD_SIZE 128 @@ -71,6 +71,12 @@ CHIP_ERROR SilabsLCD::Init(uint8_t * name, bool initialState) err = CHIP_ERROR_INTERNAL; } +#if (defined(EFR32MG24) && defined(RS911X_WIFI)) + if (pr_type != LCD) + { + pr_type = LCD; + } +#endif /* Initialize the DMD module for the DISPLAY device driver. */ status = DMD_init(0); if (DMD_OK != status) @@ -121,11 +127,11 @@ int SilabsLCD::DrawPixel(void * pContext, int32_t x, int32_t y) int SilabsLCD::Update(void) { int status; -#if (defined(EFR32MG24) && defined(WF200_WIFI)) +#if (defined(EFR32MG24) && defined(SL_WIFI)) pre_lcd_spi_transfer(); #endif status = DMD_updateDisplay(); -#if (defined(EFR32MG24) && defined(WF200_WIFI)) +#if (defined(EFR32MG24) && defined(SL_WIFI)) post_lcd_spi_transfer(); #endif /* @@ -194,12 +200,12 @@ void SilabsLCD::WriteQRCode() } } } -#if (defined(EFR32MG24) && defined(WF200_WIFI)) +#if (defined(EFR32MG24) && defined(SL_WIFI)) pre_lcd_spi_transfer(); #endif DMD_updateDisplay(); -#if (defined(EFR32MG24) && defined(WF200_WIFI)) +#if (defined(EFR32MG24) && defined(SL_WIFI)) post_lcd_spi_transfer(); #endif } diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index 507523a2f6e03e..4f7899a790b41b 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -68,14 +68,21 @@ extern SPIDRV_Handle_t sl_spidrv_exp_handle; #define SPI_HANDLE sl_spidrv_exp_handle #elif defined(EFR32MG24) #include "sl_spidrv_eusart_exp_config.h" +#include "spi_multiplex.h" +StaticSemaphore_t spi_sem_peripharal; +SemaphoreHandle_t spi_sem_sync_hdl; +peripheraltype_t pr_type = EXP_HDR; extern SPIDRV_Handle_t sl_spidrv_eusart_exp_handle; #define SPI_HANDLE sl_spidrv_eusart_exp_handle #else #error "Unknown platform" #endif +static unsigned int tx_dma_channel; +static unsigned int rx_dma_channel; + extern void rsi_gpio_irq_cb(uint8_t irqnum); -//#define RS911X_USE_LDMA +// #define RS911X_USE_LDMA /******************************************************** * @fn sl_wfx_host_gpio_init(void) @@ -90,6 +97,11 @@ void sl_wfx_host_gpio_init(void) // Enable GPIO clock. CMU_ClockEnable(cmuClock_GPIO, true); +#if defined(EFR32MG24) + // Set CS pin to high/inactive + GPIO_PinModeSet(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN, gpioModePushPull, PINOUT_SET); +#endif + GPIO_PinModeSet(WFX_RESET_PIN.port, WFX_RESET_PIN.pin, gpioModePushPull, PINOUT_SET); GPIO_PinModeSet(WFX_SLEEP_CONFIRM_PIN.port, WFX_SLEEP_CONFIRM_PIN.pin, gpioModePushPull, PINOUT_CLEAR); @@ -141,6 +153,11 @@ void rsi_hal_board_init(void) spiTransferLock = xSemaphoreCreateBinaryStatic(&xEfxSpiIntfSemaBuffer); xSemaphoreGive(spiTransferLock); +#if defined(EFR32MG24) + spi_sem_sync_hdl = xSemaphoreCreateBinaryStatic(&spi_sem_peripharal); + xSemaphoreGive(spi_sem_sync_hdl); +#endif + /* GPIO INIT of MG12 & MG24 : Reset, Wakeup, Interrupt */ sl_wfx_host_gpio_init(); @@ -148,6 +165,34 @@ void rsi_hal_board_init(void) sl_wfx_host_reset_chip(); } +#if defined(EFR32MG24) +/**************************************************************************** + * @fn sl_status_t sl_wfx_host_spi_cs_assert() + * @brief + * Assert chip select. + * @param[in] None + * @return returns SL_STATUS_OK + *****************************************************************************/ +sl_status_t sl_wfx_host_spi_cs_assert() +{ + GPIO_PinOutClear(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN); + return SL_STATUS_OK; +} + +/**************************************************************************** + * @fn sl_status_t sl_wfx_host_spi_cs_deassert() + * @brief + * De-Assert chip select. + * @param[in] None + * @return returns SL_STATUS_OK + *****************************************************************************/ +sl_status_t sl_wfx_host_spi_cs_deassert() +{ + GPIO_PinOutSet(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN); + return SL_STATUS_OK; +} +#endif + /***************************************************************************** *@brief * Spi dma transfer is complete Callback @@ -169,6 +214,16 @@ static void spi_dmaTransfertComplete(SPIDRV_HandleData_t * pxHandle, Ecode_t tra portYIELD_FROM_ISR(xHigherPriorityTaskWoken); } +#if defined(EFR32MG24) +void rsi_update_spi(void) +{ + spi_switch(EXP_HDR); + // GPIO_PinModeSet(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN, gpioModePushPull, PINOUT_SET); + /* MG24 + rs9116 combination uses EUSART driver */ + tx_dma_channel = sl_spidrv_eusart_exp_handle->txDMACh; + rx_dma_channel = sl_spidrv_eusart_exp_handle->rxDMACh; +} +#endif /********************************************************************* * @fn int16_t rsi_spi_transfer(uint8_t *tx_buf, uint8_t *rx_buf, uint16_t xlen, uint8_t mode) * @brief @@ -182,6 +237,19 @@ static void spi_dmaTransfertComplete(SPIDRV_HandleData_t * pxHandle, Ecode_t tra **************************************************************************/ int16_t rsi_spi_transfer(uint8_t * tx_buf, uint8_t * rx_buf, uint16_t xlen, uint8_t mode) { +#if defined(EFR32MG24) + /* In case of MG24, take multiplex synchronization semaphore to ensure SPI is + * available and then set CS of Exp Hdr SPI to low/enable */ + if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) + { + return SL_STATUS_TIMEOUT; + } + if (pr_type != EXP_HDR) + { + rsi_update_spi(); + } + GPIO_PinOutClear(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN); +#endif if (xlen <= MIN_XLEN || (tx_buf == NULL && rx_buf == NULL)) // at least one buffer needs to be provided { return RSI_ERROR_INVALID_PARAM; @@ -237,5 +305,10 @@ int16_t rsi_spi_transfer(uint8_t * tx_buf, uint8_t * rx_buf, uint16_t xlen, uint } xSemaphoreGive(spiTransferLock); +#if defined(EFR32MG24) + /* In case of MG24, set CS of Exp Hdr SPI to high and release multiplex synchronization semaphore*/ + GPIO_PinOutSet(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN); + xSemaphoreGive(spi_sem_sync_hdl); +#endif return rsiError; } diff --git a/examples/platform/silabs/efr32/rs911x/rs911x.gni b/examples/platform/silabs/efr32/rs911x/rs911x.gni index 0c305ce810abd1..fb725f2d395724 100644 --- a/examples/platform/silabs/efr32/rs911x/rs911x.gni +++ b/examples/platform/silabs/efr32/rs911x/rs911x.gni @@ -12,6 +12,7 @@ rs911x_src_plat = [ "${examples_plat_dir}/rs911x/hal/rsi_hal_mcu_timer.c", "${examples_plat_dir}/rs911x/hal/efx_spi.c", "${wifi_sdk_dir}/wfx_notify.cpp", + "${examples_plat_dir}/spi_multiplex.c", ] # diff --git a/examples/platform/silabs/efr32/spi_multiplex.c b/examples/platform/silabs/efr32/spi_multiplex.c index 6b8d6539d760c5..405ff8452abdea 100644 --- a/examples/platform/silabs/efr32/spi_multiplex.c +++ b/examples/platform/silabs/efr32/spi_multiplex.c @@ -26,9 +26,26 @@ #include "em_ldma.h" #include "em_usart.h" #if SL_WIFI +#include "btl_interface.h" +#include "sl_memlcd.h" #include "spi_multiplex.h" #endif /* SL_WIFI */ +#define CONCAT(A, B) (A##B) +#define SPI_CLOCK(N) CONCAT(cmuClock_USART, N) +#ifdef WF200_WIFI +#define SL_SPIDRV_FRAME_LENGTH SL_SPIDRV_EXP_FRAME_LENGTH +#else +#define SL_SPIDRV_FRAME_LENGTH 8 // default value +#endif + +const uint32_t spiBitRates[] = { [EXP_HDR] = SL_BIT_RATE_EXP_HDR, [LCD] = SL_BIT_RATE_LCD, [EXT_SPIFLASH] = SL_BIT_RATE_SPI_FLASH }; + +extern void efr32Log(const char *, ...); + +extern SPIDRV_Handle_t sl_spidrv_eusart_exp_handle; +extern SPIDRV_Init_t sl_spidrv_eusart_init_exp; + /**************************************************************************** * @fn void spi_drv_reinit() * @brief @@ -47,10 +64,14 @@ void spi_drv_reinit(uint32_t baudrate) USART_InitSync_TypeDef usartInit = USART_INITSYNC_DEFAULT; usartInit.msbf = true; usartInit.clockMode = usartClockMode0; - usartInit.baudrate = baudrate; - uint32_t databits = SL_SPIDRV_EXP_FRAME_LENGTH - 4U + _USART_FRAME_DATABITS_FOUR; - usartInit.databits = (USART_Databits_TypeDef) databits; - usartInit.autoCsEnable = true; +#ifdef WF200_WIFI + usartInit.baudrate = baudrate; +#elif RS911X_WIFI + usartInit.baudrate = spiBitRates[pr_type]; +#endif + uint32_t databits = SL_SPIDRV_FRAME_LENGTH - 4U + _USART_FRAME_DATABITS_FOUR; + usartInit.databits = (USART_Databits_TypeDef) databits; + usartInit.autoCsEnable = true; USART_InitSync(USART0, &usartInit); } @@ -95,7 +116,11 @@ void pre_bootloader_spi_transfer(void) /* * Assert CS pin for EXT SPI Flash */ +#ifdef WF200_WIFI spi_drv_reinit(SL_BIT_RATE_SPI_FLASH); +#else + spi_switch(EXT_SPIFLASH); +#endif spiflash_cs_assert(); } @@ -128,7 +153,11 @@ void pre_lcd_spi_transfer(void) { return; } +#ifdef WF200_WIFI spi_drv_reinit(SL_BIT_RATE_LCD); +#else + spi_switch(LCD); +#endif /*LCD CS is handled as part of LCD gsdk*/ } @@ -143,6 +172,78 @@ void post_lcd_spi_transfer(void) { xSemaphoreGive(spi_sem_sync_hdl); } + +#ifdef RS911X_WIFI +/**************************************************************************** + * @fn void spi_switch(pr_type) + * @brief + * Handles switching between pheripherals spi + * @param[in] prType - enum indicating type of pheripheral to switch the SPI to + * @return returns void + *****************************************************************************/ +void spi_switch(peripheraltype_t prType) +{ + efr32Log("switching spi from %u to %u", pr_type, prType); + if (pr_type != EXP_HDR && prType == EXP_HDR) + { + if (pr_type == LCD) + { + /* deinit USART of LCD*/ + USART_Enable(SL_MEMLCD_SPI_PERIPHERAL, usartDisable); + CMU_ClockEnable(SPI_CLOCK(SL_MEMLCD_SPI_PERIPHERAL_NO), false); + // USART_Reset(SL_MEMLCD_SPI_PERIPHERAL); + GPIO->USARTROUTE[SL_MEMLCD_SPI_PERIPHERAL_NO].ROUTEEN = 0; + } + else if (pr_type == EXT_SPIFLASH) + { + bootloader_deinit(); + GPIO->USARTROUTE[0].ROUTEEN = 0; + } + pr_type = EXP_HDR; + /* init EUSART of RS911x*/ + SPIDRV_Init(sl_spidrv_eusart_exp_handle, &sl_spidrv_eusart_init_exp); + } + else if (pr_type != LCD && prType == LCD) + { + if (pr_type == EXT_SPIFLASH) + { + spi_drv_reinit(SL_BIT_RATE_LCD); + pr_type = prType; + efr32Log("spi switched to %u", pr_type); + return; + } + if (pr_type == EXP_HDR) + { + efr32Log("deinited eusart of exp hdr"); + SPIDRV_DeInit(sl_spidrv_eusart_exp_handle); + GPIO->EUSARTROUTE[SL_SPIDRV_EUSART_EXP_PERIPHERAL_NO].ROUTEEN = 0; + } + pr_type = LCD; + efr32Log("inited usart for lcd"); + sl_memlcd_refresh(sl_memlcd_get()); + } + else if (pr_type != EXT_SPIFLASH && prType == EXT_SPIFLASH) + { + if (pr_type == LCD) + { + spi_drv_reinit(SL_BIT_RATE_SPI_FLASH); + pr_type = prType; + efr32Log("spi switched to %u", pr_type); + return; + } + else if (pr_type == EXP_HDR) + { + SPIDRV_DeInit(sl_spidrv_eusart_exp_handle); + GPIO->EUSARTROUTE[SL_SPIDRV_EUSART_EXP_PERIPHERAL_NO].ROUTEEN = 0; + } + pr_type = EXT_SPIFLASH; + /* init EUSART of RS911x*/ + bootloader_init(); + } + efr32Log("spi switched to %u", pr_type); +} +#endif + #if (defined(EFR32MG24) && defined(WF200_WIFI)) /**************************************************************************** * @fn void pre_uart_transfer() @@ -186,4 +287,4 @@ void post_uart_transfer(void) sl_wfx_host_enable_platform_interrupt(); sl_wfx_enable_irq(); } -#endif /* EFR32MG24 && WF200_WIFI */ +#endif /* EFR32MG24 && WF200_WIFI */ \ No newline at end of file diff --git a/examples/platform/silabs/efr32/spi_multiplex.h b/examples/platform/silabs/efr32/spi_multiplex.h index 537061f09f9006..a4c3bf125a85bc 100644 --- a/examples/platform/silabs/efr32/spi_multiplex.h +++ b/examples/platform/silabs/efr32/spi_multiplex.h @@ -23,13 +23,25 @@ extern "C" { #include "FreeRTOS.h" #include "semphr.h" #include "sl_mx25_flash_shutdown_usart_config.h" +#ifdef WF200_WIFI #include "sl_spidrv_exp_config.h" +#endif +#ifdef RS911X_WIFI +#include "sl_spidrv_eusart_exp_config.h" +#endif +#if (defined(EFR32MG24) && defined(WF200_WIFI)) #include "sl_wfx_host_api.h" +#endif +#include "em_eusart.h" #include "spidrv.h" #define SL_BIT_RATE_LCD 1100000 +#ifdef WF200_WIFI #define SL_BIT_RATE_EXP_HDR 16000000 -#define SL_BIT_RATE_SPI_FLASH 10000000 +#else +#define SL_BIT_RATE_EXP_HDR SL_SPIDRV_EUSART_EXP_BITRATE +#endif +#define SL_BIT_RATE_SPI_FLASH 16000000 #define SL_BIT_RATE_UART_CONSOLE 16000000 extern SemaphoreHandle_t spi_sem_sync_hdl; @@ -37,6 +49,21 @@ extern SemaphoreHandle_t spi_sem_sync_hdl; #ifdef RS911X_WIFI extern SPIDRV_Handle_t sl_spidrv_eusart_exp_handle; #define SL_SPIDRV_HANDLE sl_spidrv_eusart_exp_handle + +typedef enum PERIPHERAL_TYPE +{ + EXP_HDR = 0, + LCD, + EXT_SPIFLASH, +} peripheraltype_t; + +extern peripheraltype_t pr_type; + +sl_status_t sl_wfx_host_spi_cs_deassert(void); +sl_status_t sl_wfx_host_spi_cs_assert(void); + +void spi_switch(peripheraltype_t); + #endif #ifdef WF200_WIFI diff --git a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp index 6d2bce9fdfb41b..0a4f2e3bf4acd2 100644 --- a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp +++ b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp @@ -23,9 +23,11 @@ extern "C" { #include "btl_interface.h" #include "em_bus.h" // For CORE_CRITICAL_SECTION -#if (defined(EFR32MG24) && defined(WF200_WIFI)) -#include "sl_wfx_host_api.h" +#if (defined(EFR32MG24) && defined(SL_WIFI)) #include "spi_multiplex.h" +#ifdef WF200_WIFI +#include "sl_wfx_host_api.h" +#endif #endif } @@ -134,6 +136,9 @@ void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context) ChipLogProgress(SoftwareUpdate, "HandlePrepareDownload"); CORE_CRITICAL_SECTION(bootloader_init();) +#ifdef RS911X_WIFI + pr_type = EXT_SPIFLASH; +#endif mSlotId = 0; // Single slot until we support multiple images writeBufOffset = 0; mWriteOffset = 0; @@ -166,11 +171,11 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context) writeBuffer[writeBufOffset] = 0; writeBufOffset++; } -#if (defined(EFR32MG24) && defined(WF200_WIFI)) +#if (defined(EFR32MG24) && defined(SL_WIFI)) pre_bootloader_spi_transfer(); #endif CORE_CRITICAL_SECTION(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, kAlignmentBytes);) -#if (defined(EFR32MG24) && defined(WF200_WIFI)) +#if (defined(EFR32MG24) && defined(SL_WIFI)) post_bootloader_spi_transfer(); #endif if (err) @@ -194,7 +199,7 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) // Force KVS to store pending keys such as data from StoreCurrentUpdateInfo() chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().ForceKeyMapSave(); -#if (defined(EFR32MG24) && defined(WF200_WIFI)) +#if (defined(EFR32MG24) && defined(SL_WIFI)) pre_bootloader_spi_transfer(); #endif CORE_CRITICAL_SECTION(err = bootloader_verifyImage(mSlotId, NULL);) @@ -219,7 +224,7 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) // This reboots the device CORE_CRITICAL_SECTION(bootloader_rebootAndInstall();) -#if (defined(EFR32MG24) && defined(WF200_WIFI)) +#if (defined(EFR32MG24) && defined(SL_WIFI)) xSemaphoreGive(spi_sem_sync_hdl); #endif } @@ -272,11 +277,11 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context) if (writeBufOffset == kAlignmentBytes) { writeBufOffset = 0; -#if (defined(EFR32MG24) && defined(WF200_WIFI)) +#if (defined(EFR32MG24) && defined(SL_WIFI)) pre_bootloader_spi_transfer(); #endif CORE_CRITICAL_SECTION(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, kAlignmentBytes);) -#if (defined(EFR32MG24) && defined(WF200_WIFI)) +#if (defined(EFR32MG24) && defined(SL_WIFI)) post_bootloader_spi_transfer(); #endif if (err) diff --git a/third_party/open-iot-sdk/sdk b/third_party/open-iot-sdk/sdk index 152061529ebeca..f2ffb845311828 160000 --- a/third_party/open-iot-sdk/sdk +++ b/third_party/open-iot-sdk/sdk @@ -1 +1 @@ -Subproject commit 152061529ebeca4488c81f2562a0db9c60b7b325 +Subproject commit f2ffb845311828af0c5a8ecdbacdc104cb03c703 diff --git a/third_party/silabs/matter_support b/third_party/silabs/matter_support index 2bc3f28d778850..53c27ef4ed0cff 160000 --- a/third_party/silabs/matter_support +++ b/third_party/silabs/matter_support @@ -1 +1 @@ -Subproject commit 2bc3f28d778850417f34c7201cbe78bd72e3ee78 +Subproject commit 53c27ef4ed0cff01ad913b9e25d57ccb58cd49f4 From 63d73753dc46dbfb8740f3788cafcef34d505071 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Fri, 28 Apr 2023 20:03:20 +0530 Subject: [PATCH 02/50] Adds intermediate changes with cleanup --- examples/platform/silabs/display/demo-ui.c | 12 +- examples/platform/silabs/display/lcd.cpp | 14 +- .../silabs/efr32/rs911x/hal/efx_spi.c | 143 +++++----- .../platform/silabs/efr32/spi_multiplex.c | 251 +----------------- .../platform/silabs/efr32/spi_multiplex.h | 139 +++++++--- examples/platform/silabs/efr32/uart.cpp | 4 +- .../platform/silabs/efr32/wf200/efr_spi.c | 169 ++++++------ .../silabs/efr32/OTAImageProcessorImpl.cpp | 15 +- 8 files changed, 289 insertions(+), 458 deletions(-) diff --git a/examples/platform/silabs/display/demo-ui.c b/examples/platform/silabs/display/demo-ui.c index 1c5222b06b2ce2..fff63ead654351 100644 --- a/examples/platform/silabs/display/demo-ui.c +++ b/examples/platform/silabs/display/demo-ui.c @@ -109,11 +109,11 @@ void demoUIDisplayHeader(char * name) GLIB_drawStringOnLine(&glibContext, name, 5, GLIB_ALIGN_CENTER, 0, 0, true); } #if (defined(EFR32MG24) && defined(SL_WIFI)) - pre_lcd_spi_transfer(); + sl_wfx_host_pre_lcd_spi_transfer(); #endif DMD_updateDisplay(); #if (defined(EFR32MG24) && defined(SL_WIFI)) - post_lcd_spi_transfer(); + sl_wfx_host_post_lcd_spi_transfer(); #endif } @@ -122,11 +122,11 @@ void demoUIDisplayApp(bool on) GLIB_drawBitmap(&glibContext, APP_X_POSITION, APP_Y_POSITION, APP_BITMAP_WIDTH, APP_BITMAP_HEIGHT, (on ? OnStateBitMap : OffStateBitMap)); #if (defined(EFR32MG24) && defined(SL_WIFI)) - pre_lcd_spi_transfer(); + sl_wfx_host_pre_lcd_spi_transfer(); #endif DMD_updateDisplay(); #if (defined(EFR32MG24) && defined(SL_WIFI)) - post_lcd_spi_transfer(); + sl_wfx_host_post_lcd_spi_transfer(); #endif } @@ -139,11 +139,11 @@ void demoUIDisplayProtocol(demoUIProtocol protocol, bool isConnected) (protocol == DEMO_UI_PROTOCOL1 ? (isConnected ? PROT1_BITMAP_CONN : PROT1_BITMAP) : (isConnected ? PROT2_BITMAP_CONN : PROT2_BITMAP))); #if (defined(EFR32MG24) && defined(SL_WIFI)) - pre_lcd_spi_transfer(); + sl_wfx_host_pre_lcd_spi_transfer(); #endif DMD_updateDisplay(); #if (defined(EFR32MG24) && defined(SL_WIFI)) - post_lcd_spi_transfer(); + sl_wfx_host_post_lcd_spi_transfer(); #endif } diff --git a/examples/platform/silabs/display/lcd.cpp b/examples/platform/silabs/display/lcd.cpp index 7c223e53c32262..fcd495d4c4aedb 100644 --- a/examples/platform/silabs/display/lcd.cpp +++ b/examples/platform/silabs/display/lcd.cpp @@ -71,12 +71,6 @@ CHIP_ERROR SilabsLCD::Init(uint8_t * name, bool initialState) err = CHIP_ERROR_INTERNAL; } -#if (defined(EFR32MG24) && defined(RS911X_WIFI)) - if (pr_type != LCD) - { - pr_type = LCD; - } -#endif /* Initialize the DMD module for the DISPLAY device driver. */ status = DMD_init(0); if (DMD_OK != status) @@ -128,11 +122,11 @@ int SilabsLCD::Update(void) { int status; #if (defined(EFR32MG24) && defined(SL_WIFI)) - pre_lcd_spi_transfer(); + sl_wfx_host_pre_lcd_spi_transfer(); #endif status = DMD_updateDisplay(); #if (defined(EFR32MG24) && defined(SL_WIFI)) - post_lcd_spi_transfer(); + sl_wfx_host_post_lcd_spi_transfer(); #endif /* * TO-DO; Above logic can be optimised by writing a common API @@ -201,12 +195,12 @@ void SilabsLCD::WriteQRCode() } } #if (defined(EFR32MG24) && defined(SL_WIFI)) - pre_lcd_spi_transfer(); + sl_wfx_host_pre_lcd_spi_transfer(); #endif DMD_updateDisplay(); #if (defined(EFR32MG24) && defined(SL_WIFI)) - post_lcd_spi_transfer(); + sl_wfx_host_post_lcd_spi_transfer(); #endif } diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index 4f7899a790b41b..31071f92ccbabc 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -36,10 +36,11 @@ #endif #include "spidrv.h" -#include "silabs_utils.h" +#include "btl_interface.h" #include "gpiointerrupt.h" #include "sl_device_init_clocks.h" +#include "sl_memlcd.h" #include "sl_status.h" #include "FreeRTOS.h" @@ -58,6 +59,12 @@ #include "sl_power_manager.h" #endif +#define CONCAT(A, B) (A##B) +#define SPI_CLOCK(N) CONCAT(cmuClock_USART, N) + +StaticSemaphore_t spi_sem_peripheral; +SemaphoreHandle_t spi_sem_sync_hdl; + StaticSemaphore_t xEfxSpiIntfSemaBuffer; static SemaphoreHandle_t spiTransferLock; static TaskHandle_t spiInitiatorTaskHandle = NULL; @@ -65,22 +72,13 @@ static TaskHandle_t spiInitiatorTaskHandle = NULL; #if defined(EFR32MG12) #include "sl_spidrv_exp_config.h" extern SPIDRV_Handle_t sl_spidrv_exp_handle; -#define SPI_HANDLE sl_spidrv_exp_handle +#define SL_SPIDRV_HANDLE sl_spidrv_exp_handle #elif defined(EFR32MG24) -#include "sl_spidrv_eusart_exp_config.h" #include "spi_multiplex.h" -StaticSemaphore_t spi_sem_peripharal; -SemaphoreHandle_t spi_sem_sync_hdl; -peripheraltype_t pr_type = EXP_HDR; -extern SPIDRV_Handle_t sl_spidrv_eusart_exp_handle; -#define SPI_HANDLE sl_spidrv_eusart_exp_handle #else #error "Unknown platform" #endif -static unsigned int tx_dma_channel; -static unsigned int rx_dma_channel; - extern void rsi_gpio_irq_cb(uint8_t irqnum); // #define RS911X_USE_LDMA @@ -154,9 +152,9 @@ void rsi_hal_board_init(void) xSemaphoreGive(spiTransferLock); #if defined(EFR32MG24) - spi_sem_sync_hdl = xSemaphoreCreateBinaryStatic(&spi_sem_peripharal); + spi_sem_sync_hdl = xSemaphoreCreateBinaryStatic(&spi_sem_peripheral); xSemaphoreGive(spi_sem_sync_hdl); -#endif +#endif /* EFR32MG24 */ /* GPIO INIT of MG12 & MG24 : Reset, Wakeup, Interrupt */ sl_wfx_host_gpio_init(); @@ -166,32 +164,75 @@ void rsi_hal_board_init(void) } #if defined(EFR32MG24) -/**************************************************************************** - * @fn sl_status_t sl_wfx_host_spi_cs_assert() - * @brief - * Assert chip select. - * @param[in] None - * @return returns SL_STATUS_OK - *****************************************************************************/ sl_status_t sl_wfx_host_spi_cs_assert() { + configASSERT(spi_sem_sync_hdl); + if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) + { + return SL_STATUS_TIMEOUT; + } + SPIDRV_DeInit(SL_SPIDRV_HANDLE); + SPIDRV_Init(SL_SPIDRV_HANDLE, &sl_spidrv_eusart_init_exp); GPIO_PinOutClear(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN); return SL_STATUS_OK; } -/**************************************************************************** - * @fn sl_status_t sl_wfx_host_spi_cs_deassert() - * @brief - * De-Assert chip select. - * @param[in] None - * @return returns SL_STATUS_OK - *****************************************************************************/ sl_status_t sl_wfx_host_spi_cs_deassert() { GPIO_PinOutSet(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN); + SPIDRV_DeInit(SL_SPIDRV_HANDLE); + GPIO->EUSARTROUTE[SL_SPIDRV_EUSART_EXP_PERIPHERAL_NO].ROUTEEN = 0; + xSemaphoreGive(spi_sem_sync_hdl); return SL_STATUS_OK; } -#endif + +void sl_wfx_host_spiflash_cs_assert(void) +{ + GPIO_PinOutClear(SL_MX25_FLASH_SHUTDOWN_CS_PORT, SL_MX25_FLASH_SHUTDOWN_CS_PIN); +} + +void sl_wfx_host_spiflash_cs_deassert(void) +{ + GPIO_PinOutSet(SL_MX25_FLASH_SHUTDOWN_CS_PORT, SL_MX25_FLASH_SHUTDOWN_CS_PIN); +} + +void sl_wfx_host_pre_bootloader_spi_transfer(void) +{ + if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) + { + return; + } + bootloader_init(); + sl_wfx_host_spiflash_cs_assert(); +} + +void sl_wfx_host_post_bootloader_spi_transfer(void) +{ + bootloader_deinit(); + GPIO->USARTROUTE[0].ROUTEEN = 0; + sl_wfx_host_spiflash_cs_deassert(); + xSemaphoreGive(spi_sem_sync_hdl); +} + +void sl_wfx_host_pre_lcd_spi_transfer(void) +{ + if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) + { + return; + } + SPIDRV_ReInit(SL_BIT_RATE_LCD); + sl_memlcd_refresh(sl_memlcd_get()); +} + +void sl_wfx_host_post_lcd_spi_transfer(void) +{ + USART_Enable(SL_MEMLCD_SPI_PERIPHERAL, usartDisable); + CMU_ClockEnable(SPI_CLOCK(SL_MEMLCD_SPI_PERIPHERAL_NO), false); + GPIO->USARTROUTE[SL_MEMLCD_SPI_PERIPHERAL_NO].ROUTEEN = 0; + xSemaphoreGive(spi_sem_sync_hdl); +} + +#endif /* EFR32MG24 */ /***************************************************************************** *@brief @@ -214,16 +255,6 @@ static void spi_dmaTransfertComplete(SPIDRV_HandleData_t * pxHandle, Ecode_t tra portYIELD_FROM_ISR(xHigherPriorityTaskWoken); } -#if defined(EFR32MG24) -void rsi_update_spi(void) -{ - spi_switch(EXP_HDR); - // GPIO_PinModeSet(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN, gpioModePushPull, PINOUT_SET); - /* MG24 + rs9116 combination uses EUSART driver */ - tx_dma_channel = sl_spidrv_eusart_exp_handle->txDMACh; - rx_dma_channel = sl_spidrv_eusart_exp_handle->rxDMACh; -} -#endif /********************************************************************* * @fn int16_t rsi_spi_transfer(uint8_t *tx_buf, uint8_t *rx_buf, uint16_t xlen, uint8_t mode) * @brief @@ -238,19 +269,10 @@ void rsi_update_spi(void) int16_t rsi_spi_transfer(uint8_t * tx_buf, uint8_t * rx_buf, uint16_t xlen, uint8_t mode) { #if defined(EFR32MG24) - /* In case of MG24, take multiplex synchronization semaphore to ensure SPI is - * available and then set CS of Exp Hdr SPI to low/enable */ - if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) - { - return SL_STATUS_TIMEOUT; - } - if (pr_type != EXP_HDR) - { - rsi_update_spi(); - } - GPIO_PinOutClear(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN); -#endif - if (xlen <= MIN_XLEN || (tx_buf == NULL && rx_buf == NULL)) // at least one buffer needs to be provided + sl_wfx_host_spi_cs_assert(); +#endif /* EFR32MG24 */ + // at least one buffer needs to be provided + if (xlen <= MIN_XLEN || (tx_buf == NULL && rx_buf == NULL)) { return RSI_ERROR_INVALID_PARAM; } @@ -263,21 +285,22 @@ int16_t rsi_spi_transfer(uint8_t * tx_buf, uint8_t * rx_buf, uint16_t xlen, uint return RSI_ERROR_SPI_BUSY; } - configASSERT(spiInitiatorTaskHandle == NULL); // No other task should currently be waiting for the dma completion + // No other task should currently be waiting for the dma completion + configASSERT(spiInitiatorTaskHandle == NULL); spiInitiatorTaskHandle = xTaskGetCurrentTaskHandle(); Ecode_t spiError; if (tx_buf == NULL) // Rx operation only { - spiError = SPIDRV_MReceive(SPI_HANDLE, rx_buf, xlen, spi_dmaTransfertComplete); + spiError = SPIDRV_MReceive(SL_SPIDRV_HANDLE, rx_buf, xlen, spi_dmaTransfertComplete); } else if (rx_buf == NULL) // Tx operation only { - spiError = SPIDRV_MTransmit(SPI_HANDLE, tx_buf, xlen, spi_dmaTransfertComplete); + spiError = SPIDRV_MTransmit(SL_SPIDRV_HANDLE, tx_buf, xlen, spi_dmaTransfertComplete); } else // Tx and Rx operation { - spiError = SPIDRV_MTransfer(SPI_HANDLE, tx_buf, rx_buf, xlen, spi_dmaTransfertComplete); + spiError = SPIDRV_MTransfer(SL_SPIDRV_HANDLE, tx_buf, rx_buf, xlen, spi_dmaTransfertComplete); } if (spiError == ECODE_EMDRV_SPIDRV_OK) @@ -289,11 +312,11 @@ int16_t rsi_spi_transfer(uint8_t * tx_buf, uint8_t * rx_buf, uint16_t xlen, uint { int itemsTransferred = 0; int itemsRemaining = 0; - SPIDRV_GetTransferStatus(SPI_HANDLE, &itemsTransferred, &itemsRemaining); + SPIDRV_GetTransferStatus(SL_SPIDRV_HANDLE, &itemsTransferred, &itemsRemaining); SILABS_LOG("SPI transfert timed out %d/%d (rx%x rx%x)", itemsTransferred, itemsRemaining, (uint32_t) tx_buf, (uint32_t) rx_buf); - SPIDRV_AbortTransfer(SPI_HANDLE); + SPIDRV_AbortTransfer(SL_SPIDRV_HANDLE); rsiError = RSI_ERROR_SPI_TIMEOUT; } } @@ -306,9 +329,7 @@ int16_t rsi_spi_transfer(uint8_t * tx_buf, uint8_t * rx_buf, uint16_t xlen, uint xSemaphoreGive(spiTransferLock); #if defined(EFR32MG24) - /* In case of MG24, set CS of Exp Hdr SPI to high and release multiplex synchronization semaphore*/ - GPIO_PinOutSet(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN); - xSemaphoreGive(spi_sem_sync_hdl); -#endif + sl_wfx_host_spi_cs_deassert(); +#endif /* EFR32MG24 */ return rsiError; } diff --git a/examples/platform/silabs/efr32/spi_multiplex.c b/examples/platform/silabs/efr32/spi_multiplex.c index 405ff8452abdea..ce81265c6479a9 100644 --- a/examples/platform/silabs/efr32/spi_multiplex.c +++ b/examples/platform/silabs/efr32/spi_multiplex.c @@ -15,45 +15,15 @@ * limitations under the License. */ -#if (defined(EFR32MG24) && defined(WF200_WIFI)) -#include "sl_wfx.h" -#endif /* EFR32MG24 && WF200_WIFI */ - #include "dmadrv.h" #include "em_bus.h" #include "em_cmu.h" #include "em_gpio.h" #include "em_ldma.h" #include "em_usart.h" -#if SL_WIFI -#include "btl_interface.h" -#include "sl_memlcd.h" #include "spi_multiplex.h" -#endif /* SL_WIFI */ - -#define CONCAT(A, B) (A##B) -#define SPI_CLOCK(N) CONCAT(cmuClock_USART, N) -#ifdef WF200_WIFI -#define SL_SPIDRV_FRAME_LENGTH SL_SPIDRV_EXP_FRAME_LENGTH -#else -#define SL_SPIDRV_FRAME_LENGTH 8 // default value -#endif - -const uint32_t spiBitRates[] = { [EXP_HDR] = SL_BIT_RATE_EXP_HDR, [LCD] = SL_BIT_RATE_LCD, [EXT_SPIFLASH] = SL_BIT_RATE_SPI_FLASH }; - -extern void efr32Log(const char *, ...); -extern SPIDRV_Handle_t sl_spidrv_eusart_exp_handle; -extern SPIDRV_Init_t sl_spidrv_eusart_init_exp; - -/**************************************************************************** - * @fn void spi_drv_reinit() - * @brief - * Re-Intializes SPI driver to required baudrate - * @param[in] None - * @return returns void - *****************************************************************************/ -void spi_drv_reinit(uint32_t baudrate) +void SPIDRV_ReInit(uint32_t baudrate) { if (USART_BaudrateGet(USART0) == baudrate) { @@ -64,227 +34,10 @@ void spi_drv_reinit(uint32_t baudrate) USART_InitSync_TypeDef usartInit = USART_INITSYNC_DEFAULT; usartInit.msbf = true; usartInit.clockMode = usartClockMode0; -#ifdef WF200_WIFI - usartInit.baudrate = baudrate; -#elif RS911X_WIFI - usartInit.baudrate = spiBitRates[pr_type]; -#endif + usartInit.baudrate = baudrate; uint32_t databits = SL_SPIDRV_FRAME_LENGTH - 4U + _USART_FRAME_DATABITS_FOUR; usartInit.databits = (USART_Databits_TypeDef) databits; usartInit.autoCsEnable = true; USART_InitSync(USART0, &usartInit); } - -/**************************************************************************** - * @fn void spiflash_cs_assert() - * @brief - * Assert SPI flash chip select. - * @param[in] None - * @return returns void - *****************************************************************************/ -void spiflash_cs_assert(void) -{ - GPIO_PinOutClear(SL_MX25_FLASH_SHUTDOWN_CS_PORT, SL_MX25_FLASH_SHUTDOWN_CS_PIN); -} - -/**************************************************************************** - * @fn void spiflash_cs_deassert() - * @brief - * De-Assert SPI flash chip select. - * @param[in] None - * @return returns void - *****************************************************************************/ -void spiflash_cs_deassert(void) -{ - GPIO_PinOutSet(SL_MX25_FLASH_SHUTDOWN_CS_PORT, SL_MX25_FLASH_SHUTDOWN_CS_PIN); -} - -/**************************************************************************** - * @fn void pre_bootloader_spi_transfer() - * @brief - * Take a semaphore and controlling CS pin for EXP header and SPI flash - * @param[in] None - * @return returns void - *****************************************************************************/ -void pre_bootloader_spi_transfer(void) -{ - if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) - { - return; - } - /* - * Assert CS pin for EXT SPI Flash - */ -#ifdef WF200_WIFI - spi_drv_reinit(SL_BIT_RATE_SPI_FLASH); -#else - spi_switch(EXT_SPIFLASH); -#endif - spiflash_cs_assert(); -} - -/**************************************************************************** - * @fn void post_bootloader_spi_transfer() - * @brief - * De-Assert EXT SPI flash CS pin and release semaphore - * @param[in] None - * @return returns void - *****************************************************************************/ -void post_bootloader_spi_transfer(void) -{ - /* - * De-Assert CS pin for EXT SPI Flash - */ - spiflash_cs_deassert(); - xSemaphoreGive(spi_sem_sync_hdl); -} - -/**************************************************************************** - * @fn void pre_lcd_spi_transfer() - * @brief - * Take a semaphore and setting LCD baudrate - * @param[in] None - * @return returns void - *****************************************************************************/ -void pre_lcd_spi_transfer(void) -{ - if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) - { - return; - } -#ifdef WF200_WIFI - spi_drv_reinit(SL_BIT_RATE_LCD); -#else - spi_switch(LCD); -#endif - /*LCD CS is handled as part of LCD gsdk*/ -} - -/**************************************************************************** - * @fn void post_lcd_spi_transfer() - * @brief - * Release semaphore - * @param[in] None - * @return returns void - *****************************************************************************/ -void post_lcd_spi_transfer(void) -{ - xSemaphoreGive(spi_sem_sync_hdl); -} - -#ifdef RS911X_WIFI -/**************************************************************************** - * @fn void spi_switch(pr_type) - * @brief - * Handles switching between pheripherals spi - * @param[in] prType - enum indicating type of pheripheral to switch the SPI to - * @return returns void - *****************************************************************************/ -void spi_switch(peripheraltype_t prType) -{ - efr32Log("switching spi from %u to %u", pr_type, prType); - if (pr_type != EXP_HDR && prType == EXP_HDR) - { - if (pr_type == LCD) - { - /* deinit USART of LCD*/ - USART_Enable(SL_MEMLCD_SPI_PERIPHERAL, usartDisable); - CMU_ClockEnable(SPI_CLOCK(SL_MEMLCD_SPI_PERIPHERAL_NO), false); - // USART_Reset(SL_MEMLCD_SPI_PERIPHERAL); - GPIO->USARTROUTE[SL_MEMLCD_SPI_PERIPHERAL_NO].ROUTEEN = 0; - } - else if (pr_type == EXT_SPIFLASH) - { - bootloader_deinit(); - GPIO->USARTROUTE[0].ROUTEEN = 0; - } - pr_type = EXP_HDR; - /* init EUSART of RS911x*/ - SPIDRV_Init(sl_spidrv_eusart_exp_handle, &sl_spidrv_eusart_init_exp); - } - else if (pr_type != LCD && prType == LCD) - { - if (pr_type == EXT_SPIFLASH) - { - spi_drv_reinit(SL_BIT_RATE_LCD); - pr_type = prType; - efr32Log("spi switched to %u", pr_type); - return; - } - if (pr_type == EXP_HDR) - { - efr32Log("deinited eusart of exp hdr"); - SPIDRV_DeInit(sl_spidrv_eusart_exp_handle); - GPIO->EUSARTROUTE[SL_SPIDRV_EUSART_EXP_PERIPHERAL_NO].ROUTEEN = 0; - } - pr_type = LCD; - efr32Log("inited usart for lcd"); - sl_memlcd_refresh(sl_memlcd_get()); - } - else if (pr_type != EXT_SPIFLASH && prType == EXT_SPIFLASH) - { - if (pr_type == LCD) - { - spi_drv_reinit(SL_BIT_RATE_SPI_FLASH); - pr_type = prType; - efr32Log("spi switched to %u", pr_type); - return; - } - else if (pr_type == EXP_HDR) - { - SPIDRV_DeInit(sl_spidrv_eusart_exp_handle); - GPIO->EUSARTROUTE[SL_SPIDRV_EUSART_EXP_PERIPHERAL_NO].ROUTEEN = 0; - } - pr_type = EXT_SPIFLASH; - /* init EUSART of RS911x*/ - bootloader_init(); - } - efr32Log("spi switched to %u", pr_type); -} -#endif - -#if (defined(EFR32MG24) && defined(WF200_WIFI)) -/**************************************************************************** - * @fn void pre_uart_transfer() - * @brief - * Take a semaphore and setting GPIO, disable IRQ - * @param[in] None - * @return returns void - *****************************************************************************/ -void pre_uart_transfer(void) -{ - if (spi_sem_sync_hdl == NULL) - { - // UART is initialized before host SPI interface - // spi_sem_sync_hdl will not be initalized during execution - GPIO_PinModeSet(gpioPortA, 8, gpioModePushPull, 1); - return; - } - sl_wfx_disable_irq(); - sl_wfx_host_disable_platform_interrupt(); - if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) - { - return; - } - GPIO_PinModeSet(gpioPortA, 8, gpioModePushPull, 1); -} -/**************************************************************************** - * @fn void post_uart_transfer() - * @brief - * Reset GPIO, enabled IRQ, release semaphore - * @param[in] None - * @return returns void - *****************************************************************************/ -void post_uart_transfer(void) -{ - if (spi_sem_sync_hdl == NULL) - { - return; - } - GPIO_PinModeSet(gpioPortA, 8, gpioModeInputPull, 1); - xSemaphoreGive(spi_sem_sync_hdl); - sl_wfx_host_enable_platform_interrupt(); - sl_wfx_enable_irq(); -} -#endif /* EFR32MG24 && WF200_WIFI */ \ No newline at end of file diff --git a/examples/platform/silabs/efr32/spi_multiplex.h b/examples/platform/silabs/efr32/spi_multiplex.h index a4c3bf125a85bc..29e304afc61ae7 100644 --- a/examples/platform/silabs/efr32/spi_multiplex.h +++ b/examples/platform/silabs/efr32/spi_multiplex.h @@ -44,48 +44,119 @@ extern "C" { #define SL_BIT_RATE_SPI_FLASH 16000000 #define SL_BIT_RATE_UART_CONSOLE 16000000 -extern SemaphoreHandle_t spi_sem_sync_hdl; - #ifdef RS911X_WIFI +#define SL_SPIDRV_FRAME_LENGTH SL_SPIDRV_EUSART_EXP_FRAME_LENGTH extern SPIDRV_Handle_t sl_spidrv_eusart_exp_handle; #define SL_SPIDRV_HANDLE sl_spidrv_eusart_exp_handle - -typedef enum PERIPHERAL_TYPE -{ - EXP_HDR = 0, - LCD, - EXT_SPIFLASH, -} peripheraltype_t; - -extern peripheraltype_t pr_type; - -sl_status_t sl_wfx_host_spi_cs_deassert(void); -sl_status_t sl_wfx_host_spi_cs_assert(void); - -void spi_switch(peripheraltype_t); - -#endif - -#ifdef WF200_WIFI +extern SPIDRV_Init_t sl_spidrv_eusart_init_exp; +#elif WF200_WIFI +#define SL_SPIDRV_FRAME_LENGTH SL_SPIDRV_EXP_FRAME_LENGTH extern SPIDRV_Handle_t sl_spidrv_exp_handle; #define SL_SPIDRV_HANDLE sl_spidrv_exp_handle #endif -void spi_drv_reinit(uint32_t); - -void spiflash_cs_assert(void); -void spiflash_cs_deassert(void); - -void pre_bootloader_spi_transfer(void); -void post_bootloader_spi_transfer(void); - -void pre_lcd_spi_transfer(void); -void post_lcd_spi_transfer(void); +/**************************************************************************** + * @fn void SPIDRV_ReInit() + * @brief + * Re-Intializes SPI driver to required baudrate + * @param[in] None + * @return returns void + *****************************************************************************/ +void SPIDRV_ReInit(uint32_t); + +#if defined(RS911X_WIFI) +/**************************************************************************** + * @fn sl_status_t sl_wfx_host_spi_cs_assert() + * @brief + * Assert chip select. + * @param[in] None + * @return returns SL_STATUS_OK + *****************************************************************************/ +sl_status_t sl_wfx_host_spi_cs_assert(void); -#if (defined(EFR32MG24) && defined(WF200_WIFI)) -void pre_uart_transfer(void); -void post_uart_transfer(void); -#endif /* EFR32MG24 && WF200_WIFI */ +/**************************************************************************** + * @fn sl_status_t sl_wfx_host_spi_cs_deassert() + * @brief + * De-Assert chip select. + * @param[in] None + * @return returns SL_STATUS_OK + *****************************************************************************/ +sl_status_t sl_wfx_host_spi_cs_deassert(void); +#endif /* RS911X_WIFI */ + +/**************************************************************************** + * @fn void sl_wfx_host_spiflash_cs_assert() + * @brief + * Assert SPI flash chip select. + * @param[in] None + * @return returns void + *****************************************************************************/ +void sl_wfx_host_spiflash_cs_assert(void); + +/**************************************************************************** + * @fn void sl_wfx_host_spiflash_cs_deassert() + * @brief + * De-Assert SPI flash chip select. + * @param[in] None + * @return returns void + *****************************************************************************/ +void sl_wfx_host_spiflash_cs_deassert(void); + +/**************************************************************************** + * @fn void sl_wfx_host_pre_bootloader_spi_transfer() + * @brief + * Take a semaphore and controlling CS pin for EXP header and SPI flash + * @param[in] None + * @return returns void + *****************************************************************************/ +void sl_wfx_host_pre_bootloader_spi_transfer(void); + +/**************************************************************************** + * @fn void sl_wfx_host_post_bootloader_spi_transfer() + * @brief + * De-Assert EXT SPI flash CS pin and release semaphore + * @param[in] None + * @return returns void + *****************************************************************************/ +void sl_wfx_host_post_bootloader_spi_transfer(void); + +/**************************************************************************** + * @fn void sl_wfx_host_pre_lcd_spi_transfer() + * @brief + * Take a semaphore and setting LCD baudrate + * @param[in] None + * @return returns void + *****************************************************************************/ +void sl_wfx_host_pre_lcd_spi_transfer(void); + +/**************************************************************************** + * @fn void sl_wfx_host_post_lcd_spi_transfer() + * @brief + * Release semaphore + * @param[in] None + * @return returns void + *****************************************************************************/ +void sl_wfx_host_post_lcd_spi_transfer(void); + +#if defined(WF200_WIFI) +/**************************************************************************** + * @fn void sl_wfx_host_pre_uart_transfer() + * @brief + * Take a semaphore and setting GPIO, disable IRQ + * @param[in] None + * @return returns void + *****************************************************************************/ +void sl_wfx_host_pre_uart_transfer(void); + +/**************************************************************************** + * @fn void sl_wfx_host_post_uart_transfer() + * @brief + * Reset GPIO, enabled IRQ, release semaphore + * @param[in] None + * @return returns void + *****************************************************************************/ +void sl_wfx_host_post_uart_transfer(void); +#endif /* WF200_WIFI */ #ifdef __cplusplus } diff --git a/examples/platform/silabs/efr32/uart.cpp b/examples/platform/silabs/efr32/uart.cpp index 650f482bc65346..183417b3cc128f 100644 --- a/examples/platform/silabs/efr32/uart.cpp +++ b/examples/platform/silabs/efr32/uart.cpp @@ -474,9 +474,9 @@ void uartSendBytes(uint8_t * buffer, uint16_t nbOfBytes) #if (defined(EFR32MG24) && defined(WF200_WIFI)) // Blocking transmit for the MG24 + WF200 since UART TX is multiplexed with // WF200 SPI IRQ - pre_uart_transfer(); + sl_wfx_host_pre_uart_transfer(); UARTDRV_ForceTransmit(vcom_handle, (uint8_t *) buffer, nbOfBytes); - post_uart_transfer(); + sl_wfx_host_post_uart_transfer(); #else // Non Blocking Transmit UARTDRV_Transmit(vcom_handle, (uint8_t *) buffer, nbOfBytes, UART_tx_callback); diff --git a/examples/platform/silabs/efr32/wf200/efr_spi.c b/examples/platform/silabs/efr32/wf200/efr_spi.c index 5c97a294321648..9bbd85650aab7e 100644 --- a/examples/platform/silabs/efr32/wf200/efr_spi.c +++ b/examples/platform/silabs/efr32/wf200/efr_spi.c @@ -51,12 +51,13 @@ #if SL_WIFI #include "spi_multiplex.h" -StaticSemaphore_t spi_sem_peripharal; -SemaphoreHandle_t spi_sem_sync_hdl; #endif #define USART SL_WFX_HOST_PINOUT_SPI_PERIPHERAL +StaticSemaphore_t spi_sem_peripheral; +SemaphoreHandle_t spi_sem_sync_hdl; + StaticSemaphore_t xEfrSpiSemaBuffer; static SemaphoreHandle_t spi_sem; @@ -76,13 +77,6 @@ uint8_t wirq_irq_nb = SL_WFX_HOST_PINOUT_SPI_WIRQ_PIN; // SL_WFX_HOST_PINOUT_SPI #define PIN_OUT_SET 1 #define PIN_OUT_CLEAR 0 -/**************************************************************************** - * @fn sl_status_t sl_wfx_host_init_bus(void) - * @brief - * Initialize SPI peripheral - * @param[in] None - * @return returns SL_STATUS_OK - *****************************************************************************/ sl_status_t sl_wfx_host_init_bus(void) { spi_enabled = true; @@ -112,19 +106,12 @@ sl_status_t sl_wfx_host_init_bus(void) xSemaphoreGive(spi_sem); #if defined(EFR32MG24) - spi_sem_sync_hdl = xSemaphoreCreateBinaryStatic(&spi_sem_peripharal); + spi_sem_sync_hdl = xSemaphoreCreateBinaryStatic(&spi_sem_peripheral); xSemaphoreGive(spi_sem_sync_hdl); #endif /* EFR32MG24 */ return SL_STATUS_OK; } -/**************************************************************************** - * @fn sl_status_t sl_wfx_host_deinit_bus(void) - * @brief - * De-initialize SPI peripheral and DMAs - * @param[in] None - * @return returns SL_STATUS_OK - *****************************************************************************/ sl_status_t sl_wfx_host_deinit_bus(void) { vSemaphoreDelete(spi_sem); @@ -139,13 +126,6 @@ sl_status_t sl_wfx_host_deinit_bus(void) return SL_STATUS_OK; } -/**************************************************************************** - * @fn sl_status_t sl_wfx_host_spi_cs_assert() - * @brief - * Assert chip select. - * @param[in] None - * @return returns SL_STATUS_OK - *****************************************************************************/ sl_status_t sl_wfx_host_spi_cs_assert() { configASSERT(spi_sem_sync_hdl); @@ -153,18 +133,11 @@ sl_status_t sl_wfx_host_spi_cs_assert() { return SL_STATUS_TIMEOUT; } - spi_drv_reinit(SL_BIT_RATE_EXP_HDR); + SPIDRV_ReInit(SL_BIT_RATE_EXP_HDR); GPIO_PinOutClear(SL_SPIDRV_EXP_CS_PORT, SL_SPIDRV_EXP_CS_PIN); return SL_STATUS_OK; } -/**************************************************************************** - * @fn sl_status_t sl_wfx_host_spi_cs_deassert() - * @brief - * De-Assert chip select. - * @param[in] None - * @return returns SL_STATUS_OK - *****************************************************************************/ sl_status_t sl_wfx_host_spi_cs_deassert() { GPIO_PinOutSet(SL_SPIDRV_EXP_CS_PORT, SL_SPIDRV_EXP_CS_PIN); @@ -245,22 +218,6 @@ void transmitDMA(uint8_t * buffer, uint16_t buffer_length) dmadrvDataSize1, NULL, NULL); } -/**************************************************************************** - * @fn sl_status_t sl_wfx_host_spi_transfer_no_cs_assert(sl_wfx_host_bus_transfer_type_t type, - uint8_t *header, - uint16_t header_length, - uint8_t *buffer, - uint16_t buffer_length) - * @brief - * WFX SPI transfer implementation - * @param[in] type: - * @param[in] header: - * @param[in] header_length: - * @param[in] buffer: - * @param[in] buffer_length: - * @return returns SL_STATUS_OK if successful, - * SL_STATUS_FAIL otherwise - *****************************************************************************/ sl_status_t sl_wfx_host_spi_transfer_no_cs_assert(sl_wfx_host_bus_transfer_type_t type, uint8_t * header, uint16_t header_length, uint8_t * buffer, uint16_t buffer_length) { @@ -316,55 +273,24 @@ sl_status_t sl_wfx_host_spi_transfer_no_cs_assert(sl_wfx_host_bus_transfer_type_ return SL_STATUS_OK; } -/**************************************************************************** - * @fn void sl_wfx_host_start_platform_interrupt(void) - * @brief - * Enable WFX interrupt - * @param[in] none - * @return None - *****************************************************************************/ void sl_wfx_host_start_platform_interrupt(void) { // Enable (and clear) the bus interrupt GPIO_ExtIntConfig(SL_WFX_HOST_PINOUT_SPI_WIRQ_PORT, SL_WFX_HOST_PINOUT_SPI_WIRQ_PIN, wirq_irq_nb, true, false, true); } -/**************************************************************************** - * @fn sl_status_t sl_wfx_host_disable_platform_interrupt(void) - * @brief - * Disable WFX interrupt - * @param[in] None - * @return returns SL_STATUS_OK if successful, - * SL_STATUS_FAIL otherwise - *****************************************************************************/ sl_status_t sl_wfx_host_disable_platform_interrupt(void) { GPIO_IntDisable(1 << wirq_irq_nb); return SL_STATUS_OK; } -/**************************************************************************** - * @fn sl_status_t sl_wfx_host_enable_platform_interrupt(void) - * @brief - * enable the platform interrupt - * @param[in] None - * @return returns SL_STATUS_OK if successful, - * SL_STATUS_FAIL otherwise - *****************************************************************************/ sl_status_t sl_wfx_host_enable_platform_interrupt(void) { GPIO_IntEnable(1 << wirq_irq_nb); return SL_STATUS_OK; } -/**************************************************************************** - * @fn sl_status_t sl_wfx_host_enable_spi(void) - * @brief - * enable spi - * @param[in] None - * @return returns SL_STATUS_OK if successful, - * SL_STATUS_FAIL otherwise - *****************************************************************************/ sl_status_t sl_wfx_host_enable_spi(void) { if (spi_enabled == false) @@ -374,14 +300,6 @@ sl_status_t sl_wfx_host_enable_spi(void) return SL_STATUS_OK; } -/**************************************************************************** - * @fn sl_status_t sl_wfx_host_disable_spi(void) - * @brief - * disable spi - * @param[in] None - * @return returns SL_STATUS_OK if successful, - * SL_STATUS_FAIL otherwise - *****************************************************************************/ sl_status_t sl_wfx_host_disable_spi(void) { if (spi_enabled == true) @@ -445,3 +363,80 @@ void sl_wfx_host_gpio_init(void) NVIC_SetPriority(GPIO_EVEN_IRQn, 5); NVIC_SetPriority(GPIO_ODD_IRQn, 5); } + +void sl_wfx_host_spiflash_cs_assert(void) +{ + GPIO_PinOutClear(SL_MX25_FLASH_SHUTDOWN_CS_PORT, SL_MX25_FLASH_SHUTDOWN_CS_PIN); +} + +void sl_wfx_host_spiflash_cs_deassert(void) +{ + GPIO_PinOutSet(SL_MX25_FLASH_SHUTDOWN_CS_PORT, SL_MX25_FLASH_SHUTDOWN_CS_PIN); +} + +void sl_wfx_host_pre_bootloader_spi_transfer(void) +{ + if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) + { + return; + } + /* + * Assert CS pin for EXT SPI Flash + */ + SPIDRV_ReInit(SL_BIT_RATE_SPI_FLASH); + sl_wfx_host_spiflash_cs_assert(); +} + +void sl_wfx_host_post_bootloader_spi_transfer(void) +{ + /* + * De-Assert CS pin for EXT SPI Flash + */ + sl_wfx_host_spiflash_cs_deassert(); + xSemaphoreGive(spi_sem_sync_hdl); +} + +void sl_wfx_host_pre_lcd_spi_transfer(void) +{ + if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) + { + return; + } + SPIDRV_ReInit(SL_BIT_RATE_LCD); + /*LCD CS is handled as part of LCD gsdk*/ +} + +void sl_wfx_host_post_lcd_spi_transfer(void) +{ + xSemaphoreGive(spi_sem_sync_hdl); +} + +void sl_wfx_host_pre_uart_transfer(void) +{ + if (spi_sem_sync_hdl == NULL) + { + // UART is initialized before host SPI interface + // spi_sem_sync_hdl will not be initalized during execution + GPIO_PinModeSet(gpioPortA, 8, gpioModePushPull, 1); + return; + } + sl_wfx_disable_irq(); + sl_wfx_host_disable_platform_interrupt(); + if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) + { + return; + } + GPIO_PinModeSet(gpioPortA, 8, gpioModePushPull, 1); +} + +void sl_wfx_host_post_uart_transfer(void) +{ + if (spi_sem_sync_hdl == NULL) + { + return; + } + GPIO_PinModeSet(gpioPortA, 8, gpioModeInputPull, 1); + xSemaphoreGive(spi_sem_sync_hdl); + sl_wfx_host_enable_platform_interrupt(); + sl_wfx_enable_irq(); +} diff --git a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp index 0a4f2e3bf4acd2..fee2215cd68f9e 100644 --- a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp +++ b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp @@ -136,9 +136,6 @@ void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context) ChipLogProgress(SoftwareUpdate, "HandlePrepareDownload"); CORE_CRITICAL_SECTION(bootloader_init();) -#ifdef RS911X_WIFI - pr_type = EXT_SPIFLASH; -#endif mSlotId = 0; // Single slot until we support multiple images writeBufOffset = 0; mWriteOffset = 0; @@ -172,11 +169,11 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context) writeBufOffset++; } #if (defined(EFR32MG24) && defined(SL_WIFI)) - pre_bootloader_spi_transfer(); + sl_wfx_host_pre_bootloader_spi_transfer(); #endif CORE_CRITICAL_SECTION(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, kAlignmentBytes);) #if (defined(EFR32MG24) && defined(SL_WIFI)) - post_bootloader_spi_transfer(); + sl_wfx_host_post_bootloader_spi_transfer(); #endif if (err) { @@ -200,7 +197,7 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) // Force KVS to store pending keys such as data from StoreCurrentUpdateInfo() chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().ForceKeyMapSave(); #if (defined(EFR32MG24) && defined(SL_WIFI)) - pre_bootloader_spi_transfer(); + sl_wfx_host_pre_bootloader_spi_transfer(); #endif CORE_CRITICAL_SECTION(err = bootloader_verifyImage(mSlotId, NULL);) if (err != SL_BOOTLOADER_OK) @@ -225,7 +222,7 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) // This reboots the device CORE_CRITICAL_SECTION(bootloader_rebootAndInstall();) #if (defined(EFR32MG24) && defined(SL_WIFI)) - xSemaphoreGive(spi_sem_sync_hdl); + sl_wfx_host_post_bootloader_spi_transfer(); #endif } @@ -278,11 +275,11 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context) { writeBufOffset = 0; #if (defined(EFR32MG24) && defined(SL_WIFI)) - pre_bootloader_spi_transfer(); + sl_wfx_host_pre_bootloader_spi_transfer(); #endif CORE_CRITICAL_SECTION(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, kAlignmentBytes);) #if (defined(EFR32MG24) && defined(SL_WIFI)) - post_bootloader_spi_transfer(); + sl_wfx_host_post_bootloader_spi_transfer(); #endif if (err) { From 564b10545fa4e0e8770e36c5f1efd392b8ef330e Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Sun, 30 Apr 2023 12:14:19 +0530 Subject: [PATCH 03/50] Adds additional macro checks --- examples/platform/silabs/efr32/spi_multiplex.c | 4 ++++ examples/platform/silabs/efr32/spi_multiplex.h | 12 +++++++----- examples/platform/silabs/efr32/wf200/efr_spi.c | 13 +++++++++++-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/examples/platform/silabs/efr32/spi_multiplex.c b/examples/platform/silabs/efr32/spi_multiplex.c index ce81265c6479a9..26e36c4aab7166 100644 --- a/examples/platform/silabs/efr32/spi_multiplex.c +++ b/examples/platform/silabs/efr32/spi_multiplex.c @@ -15,6 +15,8 @@ * limitations under the License. */ +#if defined(EFR32MG24) + #include "dmadrv.h" #include "em_bus.h" #include "em_cmu.h" @@ -41,3 +43,5 @@ void SPIDRV_ReInit(uint32_t baudrate) USART_InitSync(USART0, &usartInit); } + +#endif /* EFR32MG24 */ \ No newline at end of file diff --git a/examples/platform/silabs/efr32/spi_multiplex.h b/examples/platform/silabs/efr32/spi_multiplex.h index 29e304afc61ae7..8a6a175c6db73b 100644 --- a/examples/platform/silabs/efr32/spi_multiplex.h +++ b/examples/platform/silabs/efr32/spi_multiplex.h @@ -17,21 +17,22 @@ #pragma once +#if defined(EFR32MG24) #ifdef __cplusplus extern "C" { #endif #include "FreeRTOS.h" #include "semphr.h" #include "sl_mx25_flash_shutdown_usart_config.h" -#ifdef WF200_WIFI +#if (defined(EFR32MG24) && defined(WF200_WIFI)) #include "sl_spidrv_exp_config.h" -#endif -#ifdef RS911X_WIFI +#endif /* EFR32MG24 && WF200_WIFI */ +#if (defined(EFR32MG24) && defined(RS911X_WIFI)) #include "sl_spidrv_eusart_exp_config.h" -#endif +#endif /* EFR32MG24 && RS911X_WIFI */ #if (defined(EFR32MG24) && defined(WF200_WIFI)) #include "sl_wfx_host_api.h" -#endif +#endif /* EFR32MG24 && WF200_WIFI */ #include "em_eusart.h" #include "spidrv.h" @@ -161,3 +162,4 @@ void sl_wfx_host_post_uart_transfer(void); #ifdef __cplusplus } #endif +#endif /* EFR32MG24 */ \ No newline at end of file diff --git a/examples/platform/silabs/efr32/wf200/efr_spi.c b/examples/platform/silabs/efr32/wf200/efr_spi.c index 9bbd85650aab7e..c9bfeb19a7abaa 100644 --- a/examples/platform/silabs/efr32/wf200/efr_spi.c +++ b/examples/platform/silabs/efr32/wf200/efr_spi.c @@ -39,7 +39,6 @@ #include "gpiointerrupt.h" -#include "sl_spidrv_exp_config.h" #include "sl_wfx_board.h" #include "sl_wfx_host.h" #include "sl_wfx_task.h" @@ -49,8 +48,14 @@ #include "sl_power_manager.h" #endif -#if SL_WIFI +#if defined(EFR32MG12) +#include "sl_spidrv_exp_config.h" +extern SPIDRV_Handle_t sl_spidrv_exp_handle; +#define SL_SPIDRV_HANDLE sl_spidrv_exp_handle +#elif defined(EFR32MG24) #include "spi_multiplex.h" +#else +#error "Unknown platform" #endif #define USART SL_WFX_HOST_PINOUT_SPI_PERIPHERAL @@ -133,7 +138,9 @@ sl_status_t sl_wfx_host_spi_cs_assert() { return SL_STATUS_TIMEOUT; } +#if defined(EFR32MG24) SPIDRV_ReInit(SL_BIT_RATE_EXP_HDR); +#endif /* EFR32MG24 */ GPIO_PinOutClear(SL_SPIDRV_EXP_CS_PORT, SL_SPIDRV_EXP_CS_PIN); return SL_STATUS_OK; } @@ -364,6 +371,7 @@ void sl_wfx_host_gpio_init(void) NVIC_SetPriority(GPIO_ODD_IRQn, 5); } +#if defined(EFR32MG24) void sl_wfx_host_spiflash_cs_assert(void) { GPIO_PinOutClear(SL_MX25_FLASH_SHUTDOWN_CS_PORT, SL_MX25_FLASH_SHUTDOWN_CS_PIN); @@ -440,3 +448,4 @@ void sl_wfx_host_post_uart_transfer(void) sl_wfx_host_enable_platform_interrupt(); sl_wfx_enable_irq(); } +#endif /* EFR32MG24 */ \ No newline at end of file From 897a9f072b43605efce5a4be0110e6487029728d Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Thu, 4 May 2023 17:06:05 +0530 Subject: [PATCH 04/50] Adds updated working logic for multiplexing expansion header and LCD --- .../silabs/efr32/rs911x/hal/efx_spi.c | 78 ++++++++++++++++--- 1 file changed, 66 insertions(+), 12 deletions(-) diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index 31071f92ccbabc..75b12183fe45d7 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -79,8 +79,11 @@ extern SPIDRV_Handle_t sl_spidrv_exp_handle; #error "Unknown platform" #endif +// variable to identify spi configured for expansion header +// EUSART configuration available on the SPIDRV +static bool spi_enabled = false; + extern void rsi_gpio_irq_cb(uint8_t irqnum); -// #define RS911X_USE_LDMA /******************************************************** * @fn sl_wfx_host_gpio_init(void) @@ -115,6 +118,8 @@ void sl_wfx_host_gpio_init(void) // Change GPIO interrupt priority (FreeRTOS asserts unless this is done here!) NVIC_SetPriority(GPIO_EVEN_IRQn, WFX_SPI_NVIC_PRIORITY); NVIC_SetPriority(GPIO_ODD_IRQn, WFX_SPI_NVIC_PRIORITY); + spi_enabled = true; + SILABS_LOG("%s completed.", __func__) } /***************************************************************** @@ -137,6 +142,7 @@ void sl_wfx_host_reset_chip(void) // Delay for 3ms vTaskDelay(pdMS_TO_TICKS(3)); + SILABS_LOG("%s completed.", __func__) } /***************************************************************** @@ -161,75 +167,118 @@ void rsi_hal_board_init(void) /* Reset of Wifi chip */ sl_wfx_host_reset_chip(); + SILABS_LOG("%s completed.", __func__) } #if defined(EFR32MG24) sl_status_t sl_wfx_host_spi_cs_assert() { + SILABS_LOG("%s started.", __func__) configASSERT(spi_sem_sync_hdl); if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) { + SILABS_LOG("%s errored.", __func__) return SL_STATUS_TIMEOUT; } - SPIDRV_DeInit(SL_SPIDRV_HANDLE); - SPIDRV_Init(SL_SPIDRV_HANDLE, &sl_spidrv_eusart_init_exp); + // if (spi_enabled) + // { + // SPIDRV_DeInit(SL_SPIDRV_HANDLE); + // SILABS_LOG("%s did deinit.", __func__) + // spi_enabled = false; + // } + if (!spi_enabled) // Reduce SPIDRV_Init + { + SPIDRV_Init(SL_SPIDRV_HANDLE, &sl_spidrv_eusart_init_exp); + spi_enabled = true; + } GPIO_PinOutClear(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN); + SILABS_LOG("%s completed.", __func__) return SL_STATUS_OK; } sl_status_t sl_wfx_host_spi_cs_deassert() { + SILABS_LOG("%s started.", __func__) + if (spi_enabled) + { + SPIDRV_DeInit(SL_SPIDRV_HANDLE); + spi_enabled = false; + } GPIO_PinOutSet(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN); - SPIDRV_DeInit(SL_SPIDRV_HANDLE); + // TODO: should be done by deinit, check once. GPIO->EUSARTROUTE[SL_SPIDRV_EUSART_EXP_PERIPHERAL_NO].ROUTEEN = 0; xSemaphoreGive(spi_sem_sync_hdl); + SILABS_LOG("%s completed.", __func__) return SL_STATUS_OK; } -void sl_wfx_host_spiflash_cs_assert(void) +void sl_wfx_host_spiflash_cs_assert() { + SILABS_LOG("%s started.", __func__) GPIO_PinOutClear(SL_MX25_FLASH_SHUTDOWN_CS_PORT, SL_MX25_FLASH_SHUTDOWN_CS_PIN); + SILABS_LOG("%s completed.", __func__) } -void sl_wfx_host_spiflash_cs_deassert(void) +void sl_wfx_host_spiflash_cs_deassert() { + SILABS_LOG("%s started.", __func__) GPIO_PinOutSet(SL_MX25_FLASH_SHUTDOWN_CS_PORT, SL_MX25_FLASH_SHUTDOWN_CS_PIN); + SILABS_LOG("%s completed.", __func__) } -void sl_wfx_host_pre_bootloader_spi_transfer(void) +void sl_wfx_host_pre_bootloader_spi_transfer() { + SILABS_LOG("%s started.", __func__) if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) { return; } + if (spi_enabled) + { + SPIDRV_DeInit(SL_SPIDRV_HANDLE); + spi_enabled = false; + } bootloader_init(); + // bootloader_init takes care of SPIDRV_Init() sl_wfx_host_spiflash_cs_assert(); + SILABS_LOG("%s completed.", __func__) } -void sl_wfx_host_post_bootloader_spi_transfer(void) +void sl_wfx_host_post_bootloader_spi_transfer() { + SILABS_LOG("%s started.", __func__) bootloader_deinit(); GPIO->USARTROUTE[0].ROUTEEN = 0; sl_wfx_host_spiflash_cs_deassert(); xSemaphoreGive(spi_sem_sync_hdl); + SILABS_LOG("%s completed.", __func__) } -void sl_wfx_host_pre_lcd_spi_transfer(void) +void sl_wfx_host_pre_lcd_spi_transfer() { + SILABS_LOG("%s started.", __func__) if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) { return; } - SPIDRV_ReInit(SL_BIT_RATE_LCD); + if (spi_enabled) + { + SPIDRV_DeInit(SL_SPIDRV_HANDLE); + spi_enabled = false; + } sl_memlcd_refresh(sl_memlcd_get()); + // sl_memlcd_refresh takes care of SPIDRV_Init() + SILABS_LOG("%s completed.", __func__) } -void sl_wfx_host_post_lcd_spi_transfer(void) +void sl_wfx_host_post_lcd_spi_transfer() { + SILABS_LOG("%s started.", __func__) USART_Enable(SL_MEMLCD_SPI_PERIPHERAL, usartDisable); CMU_ClockEnable(SPI_CLOCK(SL_MEMLCD_SPI_PERIPHERAL_NO), false); GPIO->USARTROUTE[SL_MEMLCD_SPI_PERIPHERAL_NO].ROUTEEN = 0; xSemaphoreGive(spi_sem_sync_hdl); + SILABS_LOG("%s completed.", __func__) } #endif /* EFR32MG24 */ @@ -268,12 +317,16 @@ static void spi_dmaTransfertComplete(SPIDRV_HandleData_t * pxHandle, Ecode_t tra **************************************************************************/ int16_t rsi_spi_transfer(uint8_t * tx_buf, uint8_t * rx_buf, uint16_t xlen, uint8_t mode) { + SILABS_LOG("%s started.", __func__) #if defined(EFR32MG24) sl_wfx_host_spi_cs_assert(); #endif /* EFR32MG24 */ - // at least one buffer needs to be provided + /* + TODO: tx_buf and rx_buf needs to be replaced with a dummy buffer of length xlen to align with SDK of WiFi + */ if (xlen <= MIN_XLEN || (tx_buf == NULL && rx_buf == NULL)) { + SILABS_LOG("%s error.", __func__) return RSI_ERROR_INVALID_PARAM; } @@ -331,5 +384,6 @@ int16_t rsi_spi_transfer(uint8_t * tx_buf, uint8_t * rx_buf, uint16_t xlen, uint #if defined(EFR32MG24) sl_wfx_host_spi_cs_deassert(); #endif /* EFR32MG24 */ + SILABS_LOG("%s completed.", __func__) return rsiError; } From eceb277b0dda8c5d722758247475fb12575c33bd Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Mon, 15 May 2023 17:01:17 +0530 Subject: [PATCH 05/50] Adds missing ; --- .../silabs/efr32/rs911x/hal/efx_spi.c | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index 75b12183fe45d7..5a89a933d7afdd 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -119,7 +119,7 @@ void sl_wfx_host_gpio_init(void) NVIC_SetPriority(GPIO_EVEN_IRQn, WFX_SPI_NVIC_PRIORITY); NVIC_SetPriority(GPIO_ODD_IRQn, WFX_SPI_NVIC_PRIORITY); spi_enabled = true; - SILABS_LOG("%s completed.", __func__) + SILABS_LOG("%s completed.", __func__); } /***************************************************************** @@ -142,7 +142,7 @@ void sl_wfx_host_reset_chip(void) // Delay for 3ms vTaskDelay(pdMS_TO_TICKS(3)); - SILABS_LOG("%s completed.", __func__) + SILABS_LOG("%s completed.", __func__); } /***************************************************************** @@ -167,23 +167,23 @@ void rsi_hal_board_init(void) /* Reset of Wifi chip */ sl_wfx_host_reset_chip(); - SILABS_LOG("%s completed.", __func__) + SILABS_LOG("%s completed.", __func__); } #if defined(EFR32MG24) sl_status_t sl_wfx_host_spi_cs_assert() { - SILABS_LOG("%s started.", __func__) + SILABS_LOG("%s started.", __func__); configASSERT(spi_sem_sync_hdl); if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) { - SILABS_LOG("%s errored.", __func__) + SILABS_LOG("%s errored.", __func__); return SL_STATUS_TIMEOUT; } // if (spi_enabled) // { // SPIDRV_DeInit(SL_SPIDRV_HANDLE); - // SILABS_LOG("%s did deinit.", __func__) + // SILABS_LOG("%s did deinit.", __func__); // spi_enabled = false; // } if (!spi_enabled) // Reduce SPIDRV_Init @@ -192,13 +192,13 @@ sl_status_t sl_wfx_host_spi_cs_assert() spi_enabled = true; } GPIO_PinOutClear(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN); - SILABS_LOG("%s completed.", __func__) + SILABS_LOG("%s completed.", __func__); return SL_STATUS_OK; } sl_status_t sl_wfx_host_spi_cs_deassert() { - SILABS_LOG("%s started.", __func__) + SILABS_LOG("%s started.", __func__); if (spi_enabled) { SPIDRV_DeInit(SL_SPIDRV_HANDLE); @@ -208,27 +208,27 @@ sl_status_t sl_wfx_host_spi_cs_deassert() // TODO: should be done by deinit, check once. GPIO->EUSARTROUTE[SL_SPIDRV_EUSART_EXP_PERIPHERAL_NO].ROUTEEN = 0; xSemaphoreGive(spi_sem_sync_hdl); - SILABS_LOG("%s completed.", __func__) + SILABS_LOG("%s completed.", __func__); return SL_STATUS_OK; } void sl_wfx_host_spiflash_cs_assert() { - SILABS_LOG("%s started.", __func__) + SILABS_LOG("%s started.", __func__); GPIO_PinOutClear(SL_MX25_FLASH_SHUTDOWN_CS_PORT, SL_MX25_FLASH_SHUTDOWN_CS_PIN); - SILABS_LOG("%s completed.", __func__) + SILABS_LOG("%s completed.", __func__); } void sl_wfx_host_spiflash_cs_deassert() { - SILABS_LOG("%s started.", __func__) + SILABS_LOG("%s started.", __func__); GPIO_PinOutSet(SL_MX25_FLASH_SHUTDOWN_CS_PORT, SL_MX25_FLASH_SHUTDOWN_CS_PIN); - SILABS_LOG("%s completed.", __func__) + SILABS_LOG("%s completed.", __func__); } void sl_wfx_host_pre_bootloader_spi_transfer() { - SILABS_LOG("%s started.", __func__) + SILABS_LOG("%s started.", __func__); if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) { return; @@ -241,22 +241,22 @@ void sl_wfx_host_pre_bootloader_spi_transfer() bootloader_init(); // bootloader_init takes care of SPIDRV_Init() sl_wfx_host_spiflash_cs_assert(); - SILABS_LOG("%s completed.", __func__) + SILABS_LOG("%s completed.", __func__); } void sl_wfx_host_post_bootloader_spi_transfer() { - SILABS_LOG("%s started.", __func__) + SILABS_LOG("%s started.", __func__); bootloader_deinit(); GPIO->USARTROUTE[0].ROUTEEN = 0; sl_wfx_host_spiflash_cs_deassert(); xSemaphoreGive(spi_sem_sync_hdl); - SILABS_LOG("%s completed.", __func__) + SILABS_LOG("%s completed.", __func__); } void sl_wfx_host_pre_lcd_spi_transfer() { - SILABS_LOG("%s started.", __func__) + SILABS_LOG("%s started.", __func__); if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) { return; @@ -268,17 +268,17 @@ void sl_wfx_host_pre_lcd_spi_transfer() } sl_memlcd_refresh(sl_memlcd_get()); // sl_memlcd_refresh takes care of SPIDRV_Init() - SILABS_LOG("%s completed.", __func__) + SILABS_LOG("%s completed.", __func__); } void sl_wfx_host_post_lcd_spi_transfer() { - SILABS_LOG("%s started.", __func__) + SILABS_LOG("%s started.", __func__); USART_Enable(SL_MEMLCD_SPI_PERIPHERAL, usartDisable); CMU_ClockEnable(SPI_CLOCK(SL_MEMLCD_SPI_PERIPHERAL_NO), false); GPIO->USARTROUTE[SL_MEMLCD_SPI_PERIPHERAL_NO].ROUTEEN = 0; xSemaphoreGive(spi_sem_sync_hdl); - SILABS_LOG("%s completed.", __func__) + SILABS_LOG("%s completed.", __func__); } #endif /* EFR32MG24 */ @@ -317,7 +317,7 @@ static void spi_dmaTransfertComplete(SPIDRV_HandleData_t * pxHandle, Ecode_t tra **************************************************************************/ int16_t rsi_spi_transfer(uint8_t * tx_buf, uint8_t * rx_buf, uint16_t xlen, uint8_t mode) { - SILABS_LOG("%s started.", __func__) + SILABS_LOG("%s started.", __func__); #if defined(EFR32MG24) sl_wfx_host_spi_cs_assert(); #endif /* EFR32MG24 */ @@ -326,7 +326,7 @@ int16_t rsi_spi_transfer(uint8_t * tx_buf, uint8_t * rx_buf, uint16_t xlen, uint */ if (xlen <= MIN_XLEN || (tx_buf == NULL && rx_buf == NULL)) { - SILABS_LOG("%s error.", __func__) + SILABS_LOG("%s error.", __func__); return RSI_ERROR_INVALID_PARAM; } @@ -384,6 +384,6 @@ int16_t rsi_spi_transfer(uint8_t * tx_buf, uint8_t * rx_buf, uint16_t xlen, uint #if defined(EFR32MG24) sl_wfx_host_spi_cs_deassert(); #endif /* EFR32MG24 */ - SILABS_LOG("%s completed.", __func__) + SILABS_LOG("%s completed.", __func__); return rsiError; } From 5308e5bc946739e19e4897ab8482fd516ff920cd Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Tue, 16 May 2023 10:31:23 +0530 Subject: [PATCH 06/50] Adds fix for WF200 baudrate on SPI --- examples/platform/silabs/efr32/spi_multiplex.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/platform/silabs/efr32/spi_multiplex.h b/examples/platform/silabs/efr32/spi_multiplex.h index 8a6a175c6db73b..dfae0c5e9d1cac 100644 --- a/examples/platform/silabs/efr32/spi_multiplex.h +++ b/examples/platform/silabs/efr32/spi_multiplex.h @@ -38,10 +38,10 @@ extern "C" { #define SL_BIT_RATE_LCD 1100000 #ifdef WF200_WIFI -#define SL_BIT_RATE_EXP_HDR 16000000 +#define SL_BIT_RATE_EXP_HDR 10000000 #else #define SL_BIT_RATE_EXP_HDR SL_SPIDRV_EUSART_EXP_BITRATE -#endif +#endif /* WF200_WIFI */ #define SL_BIT_RATE_SPI_FLASH 16000000 #define SL_BIT_RATE_UART_CONSOLE 16000000 From 5e6c9a4d1ca9edb8394d75e9707579d616f5edf0 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Tue, 16 May 2023 16:10:20 +0530 Subject: [PATCH 07/50] Adds fix for third_party --- third_party/open-iot-sdk/sdk | 2 +- third_party/silabs/matter_support | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/third_party/open-iot-sdk/sdk b/third_party/open-iot-sdk/sdk index f2ffb845311828..152061529ebeca 160000 --- a/third_party/open-iot-sdk/sdk +++ b/third_party/open-iot-sdk/sdk @@ -1 +1 @@ -Subproject commit f2ffb845311828af0c5a8ecdbacdc104cb03c703 +Subproject commit 152061529ebeca4488c81f2562a0db9c60b7b325 diff --git a/third_party/silabs/matter_support b/third_party/silabs/matter_support index 53c27ef4ed0cff..2bc3f28d778850 160000 --- a/third_party/silabs/matter_support +++ b/third_party/silabs/matter_support @@ -1 +1 @@ -Subproject commit 53c27ef4ed0cff01ad913b9e25d57ccb58cd49f4 +Subproject commit 2bc3f28d778850417f34c7201cbe78bd72e3ee78 From 25ed2967974606f77f50249fc4b08a0e591cd35f Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Wed, 17 May 2023 11:10:52 +0530 Subject: [PATCH 08/50] Adds updated log statements --- .../silabs/efr32/rs911x/hal/efx_spi.c | 16 ++++---- .../silabs/efr32/OTAImageProcessorImpl.cpp | 40 +++++++++++++------ 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index 5a89a933d7afdd..8643662b6dd1ff 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -173,7 +173,7 @@ void rsi_hal_board_init(void) #if defined(EFR32MG24) sl_status_t sl_wfx_host_spi_cs_assert() { - SILABS_LOG("%s started.", __func__); + // SILABS_LOG("%s started.", __func__); configASSERT(spi_sem_sync_hdl); if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) { @@ -192,13 +192,13 @@ sl_status_t sl_wfx_host_spi_cs_assert() spi_enabled = true; } GPIO_PinOutClear(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN); - SILABS_LOG("%s completed.", __func__); + // SILABS_LOG("%s completed.", __func__); return SL_STATUS_OK; } sl_status_t sl_wfx_host_spi_cs_deassert() { - SILABS_LOG("%s started.", __func__); + // SILABS_LOG("%s started.", __func__); if (spi_enabled) { SPIDRV_DeInit(SL_SPIDRV_HANDLE); @@ -208,7 +208,7 @@ sl_status_t sl_wfx_host_spi_cs_deassert() // TODO: should be done by deinit, check once. GPIO->EUSARTROUTE[SL_SPIDRV_EUSART_EXP_PERIPHERAL_NO].ROUTEEN = 0; xSemaphoreGive(spi_sem_sync_hdl); - SILABS_LOG("%s completed.", __func__); + // SILABS_LOG("%s completed.", __func__); return SL_STATUS_OK; } @@ -317,7 +317,7 @@ static void spi_dmaTransfertComplete(SPIDRV_HandleData_t * pxHandle, Ecode_t tra **************************************************************************/ int16_t rsi_spi_transfer(uint8_t * tx_buf, uint8_t * rx_buf, uint16_t xlen, uint8_t mode) { - SILABS_LOG("%s started.", __func__); + // SILABS_LOG("%s started.", __func__); #if defined(EFR32MG24) sl_wfx_host_spi_cs_assert(); #endif /* EFR32MG24 */ @@ -366,7 +366,7 @@ int16_t rsi_spi_transfer(uint8_t * tx_buf, uint8_t * rx_buf, uint16_t xlen, uint int itemsTransferred = 0; int itemsRemaining = 0; SPIDRV_GetTransferStatus(SL_SPIDRV_HANDLE, &itemsTransferred, &itemsRemaining); - SILABS_LOG("SPI transfert timed out %d/%d (rx%x rx%x)", itemsTransferred, itemsRemaining, (uint32_t) tx_buf, + SILABS_LOG("%s: timed out %d/%d (rx%x rx%x)", __func__, itemsTransferred, itemsRemaining, (uint32_t) tx_buf, (uint32_t) rx_buf); SPIDRV_AbortTransfer(SL_SPIDRV_HANDLE); @@ -375,7 +375,7 @@ int16_t rsi_spi_transfer(uint8_t * tx_buf, uint8_t * rx_buf, uint16_t xlen, uint } else { - SILABS_LOG("SPI transfert failed with err:%x (tx%x rx%x)", spiError, (uint32_t) tx_buf, (uint32_t) rx_buf); + SILABS_LOG("%s: failed with err:%x (tx%x rx%x)", __func__, spiError, (uint32_t) tx_buf, (uint32_t) rx_buf); rsiError = RSI_ERROR_SPI_FAIL; spiInitiatorTaskHandle = NULL; // SPI operation failed. No notification to received. } @@ -384,6 +384,6 @@ int16_t rsi_spi_transfer(uint8_t * tx_buf, uint8_t * rx_buf, uint16_t xlen, uint #if defined(EFR32MG24) sl_wfx_host_spi_cs_deassert(); #endif /* EFR32MG24 */ - SILABS_LOG("%s completed.", __func__); + // SILABS_LOG("%s completed.", __func__); return rsiError; } diff --git a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp index fee2215cd68f9e..4aa8d7464d4721 100644 --- a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp +++ b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp @@ -46,31 +46,37 @@ uint8_t OTAImageProcessorImpl::writeBuffer[kAlignmentBytes] __attribute__((align CHIP_ERROR OTAImageProcessorImpl::PrepareDownload() { + ChipLogProgress(SoftwareUpdate, "%s: started", __func__); DeviceLayer::PlatformMgr().ScheduleWork(HandlePrepareDownload, reinterpret_cast(this)); return CHIP_NO_ERROR; } CHIP_ERROR OTAImageProcessorImpl::Finalize() { + ChipLogProgress(SoftwareUpdate, "%s: started", __func__); DeviceLayer::PlatformMgr().ScheduleWork(HandleFinalize, reinterpret_cast(this)); return CHIP_NO_ERROR; } CHIP_ERROR OTAImageProcessorImpl::Apply() { + ChipLogProgress(SoftwareUpdate, "%s: started", __func__); DeviceLayer::PlatformMgr().ScheduleWork(HandleApply, reinterpret_cast(this)); return CHIP_NO_ERROR; } CHIP_ERROR OTAImageProcessorImpl::Abort() { + ChipLogProgress(SoftwareUpdate, "%s: started", __func__); DeviceLayer::PlatformMgr().ScheduleWork(HandleAbort, reinterpret_cast(this)); return CHIP_NO_ERROR; } CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & block) { + ChipLogProgress(SoftwareUpdate, "%s: started", __func__); if ((block.data() == nullptr) || block.empty()) { + ChipLogError(SoftwareUpdate, "%s: block is empty", __func__); return CHIP_ERROR_INVALID_ARGUMENT; } @@ -79,6 +85,7 @@ CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & block) if (err != CHIP_NO_ERROR) { ChipLogError(SoftwareUpdate, "Cannot set block data: %" CHIP_ERROR_FORMAT, err.Format()); + return err; } DeviceLayer::PlatformMgr().ScheduleWork(HandleProcessBlock, reinterpret_cast(this)); @@ -87,9 +94,11 @@ CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & block) bool OTAImageProcessorImpl::IsFirstImageRun() { + ChipLogProgress(SoftwareUpdate, "%s: started", __func__); OTARequestorInterface * requestor = chip::GetRequestorInstance(); if (requestor == nullptr) { + ChipLogError(SoftwareUpdate, "%s: requestor is null", __func__); return false; } @@ -98,9 +107,11 @@ bool OTAImageProcessorImpl::IsFirstImageRun() CHIP_ERROR OTAImageProcessorImpl::ConfirmCurrentImage() { + ChipLogProgress(SoftwareUpdate, "%s: started", __func__); OTARequestorInterface * requestor = chip::GetRequestorInstance(); if (requestor == nullptr) { + ChipLogError(SoftwareUpdate, "%s: requestor is null", __func__); return CHIP_ERROR_INTERNAL; } @@ -124,16 +135,16 @@ void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context) if (imageProcessor == nullptr) { - ChipLogError(SoftwareUpdate, "ImageProcessor context is null"); + ChipLogError(SoftwareUpdate, "%s: imageProcessor context is null", __func__); return; } else if (imageProcessor->mDownloader == nullptr) { - ChipLogError(SoftwareUpdate, "mDownloader is null"); + ChipLogError(SoftwareUpdate, "%s: mDownloader is null", __func__); return; } - ChipLogProgress(SoftwareUpdate, "HandlePrepareDownload"); + ChipLogProgress(SoftwareUpdate, "%s: started", __func__); CORE_CRITICAL_SECTION(bootloader_init();) mSlotId = 0; // Single slot until we support multiple images @@ -154,9 +165,12 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context) auto * imageProcessor = reinterpret_cast(context); if (imageProcessor == nullptr) { + ChipLogError(SoftwareUpdate, "%s: imageProcessor context is null", __func__); return; } + ChipLogProgress(SoftwareUpdate, "%s: started", __func__); + // Pad the remainder of the write buffer with zeros and write it to bootloader storage if (writeBufOffset != 0) { @@ -177,7 +191,7 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context) #endif if (err) { - ChipLogError(SoftwareUpdate, "ERROR: In HandleFinalize bootloader_eraseWriteStorage() error %ld", err); + ChipLogError(SoftwareUpdate, "%s: bootloader_eraseWriteStorage() error %ld", __func__, err); imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); return; } @@ -192,7 +206,7 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) { uint32_t err = SL_BOOTLOADER_OK; - ChipLogProgress(SoftwareUpdate, "OTAImageProcessorImpl::HandleApply()"); + ChipLogProgress(SoftwareUpdate, "%s: started"); // Force KVS to store pending keys such as data from StoreCurrentUpdateInfo() chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().ForceKeyMapSave(); @@ -202,20 +216,18 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) CORE_CRITICAL_SECTION(err = bootloader_verifyImage(mSlotId, NULL);) if (err != SL_BOOTLOADER_OK) { - ChipLogError(SoftwareUpdate, "ERROR: bootloader_verifyImage() error %ld", err); + ChipLogError(SoftwareUpdate, "%s: bootloader_verifyImage() error %ld", __func__, err); // Call the OTARequestor API to reset the state GetRequestorInstance()->CancelImageUpdate(); - return; } CORE_CRITICAL_SECTION(err = bootloader_setImageToBootload(mSlotId);) if (err != SL_BOOTLOADER_OK) { - ChipLogError(SoftwareUpdate, "ERROR: bootloader_setImageToBootload() error %ld", err); + ChipLogError(SoftwareUpdate, "%s: bootloader_setImageToBootload() error %ld", __func__, err); // Call the OTARequestor API to reset the state GetRequestorInstance()->CancelImageUpdate(); - return; } @@ -231,8 +243,10 @@ void OTAImageProcessorImpl::HandleAbort(intptr_t context) auto * imageProcessor = reinterpret_cast(context); if (imageProcessor == nullptr) { + ChipLogError(SoftwareUpdate, "%s: imageProcessor context is null", __func__); return; } + ChipLogProgress(SoftwareUpdate, "%s: started", __func__); // Not clearing the image storage area as it is done during each write imageProcessor->ReleaseBlock(); @@ -244,12 +258,12 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context) auto * imageProcessor = reinterpret_cast(context); if (imageProcessor == nullptr) { - ChipLogError(SoftwareUpdate, "ImageProcessor context is null"); + ChipLogError(SoftwareUpdate, "%s: imageProcessor context is null", __func__); return; } else if (imageProcessor->mDownloader == nullptr) { - ChipLogError(SoftwareUpdate, "mDownloader is null"); + ChipLogError(SoftwareUpdate, "%s: mDownloader is null", __func__); return; } @@ -283,7 +297,7 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context) #endif if (err) { - ChipLogError(SoftwareUpdate, "ERROR: In HandleProcessBlock bootloader_eraseWriteStorage() error %ld", err); + ChipLogError(SoftwareUpdate, "%s: bootloader_eraseWriteStorage() error %ld", __func__, err); imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); return; } @@ -320,6 +334,7 @@ CHIP_ERROR OTAImageProcessorImpl::SetBlock(ByteSpan & block) { if ((block.data() == nullptr) || block.empty()) { + ChipLogError(SoftwareUpdate, "%s: block is empty", __func__); return CHIP_NO_ERROR; } @@ -331,6 +346,7 @@ CHIP_ERROR OTAImageProcessorImpl::SetBlock(ByteSpan & block) mBlock = MutableByteSpan(static_cast(chip::Platform::MemoryAlloc(block.size())), block.size()); if (mBlock.data() == nullptr) { + ChipLogError(SoftwareUpdate, "%s: mBlock is null", __func__); return CHIP_ERROR_NO_MEMORY; } } From 68710c3ed1542f1621283c7c7edf124e16799d6e Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Wed, 17 May 2023 11:38:21 +0530 Subject: [PATCH 09/50] Adds fix for log statement --- src/platform/silabs/efr32/OTAImageProcessorImpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp index 4aa8d7464d4721..0034cc423c538a 100644 --- a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp +++ b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp @@ -206,7 +206,7 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) { uint32_t err = SL_BOOTLOADER_OK; - ChipLogProgress(SoftwareUpdate, "%s: started"); + ChipLogProgress(SoftwareUpdate, "%s: started", __func__); // Force KVS to store pending keys such as data from StoreCurrentUpdateInfo() chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().ForceKeyMapSave(); From 62e7aaeaf1461410c00a39c7c7db9f52c930c680 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Thu, 18 May 2023 22:50:45 +0530 Subject: [PATCH 10/50] Adds conditional use of semaphore --- examples/platform/silabs/efr32/wf200/efr_spi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/platform/silabs/efr32/wf200/efr_spi.c b/examples/platform/silabs/efr32/wf200/efr_spi.c index c9bfeb19a7abaa..d2f4b192395e8c 100644 --- a/examples/platform/silabs/efr32/wf200/efr_spi.c +++ b/examples/platform/silabs/efr32/wf200/efr_spi.c @@ -120,7 +120,9 @@ sl_status_t sl_wfx_host_init_bus(void) sl_status_t sl_wfx_host_deinit_bus(void) { vSemaphoreDelete(spi_sem); + #if defined(EFR32MG24) vSemaphoreDelete(spi_sem_sync_hdl); + #endif /* EFR32MG24 */ // Stop DMAs. DMADRV_StopTransfer(rx_dma_channel); DMADRV_StopTransfer(tx_dma_channel); @@ -133,12 +135,12 @@ sl_status_t sl_wfx_host_deinit_bus(void) sl_status_t sl_wfx_host_spi_cs_assert() { +#if defined(EFR32MG24) configASSERT(spi_sem_sync_hdl); if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) { return SL_STATUS_TIMEOUT; } -#if defined(EFR32MG24) SPIDRV_ReInit(SL_BIT_RATE_EXP_HDR); #endif /* EFR32MG24 */ GPIO_PinOutClear(SL_SPIDRV_EXP_CS_PORT, SL_SPIDRV_EXP_CS_PIN); From 830f1f2c96f37f61b0a8ba051c8151ee16f8d4db Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Thu, 18 May 2023 23:33:44 +0530 Subject: [PATCH 11/50] Adds conditional EFR32MG24 semaphore logic --- examples/platform/silabs/efr32/rs911x/hal/efx_spi.c | 2 ++ examples/platform/silabs/efr32/wf200/efr_spi.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index 8643662b6dd1ff..02f44f8a5c5aa3 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -62,8 +62,10 @@ #define CONCAT(A, B) (A##B) #define SPI_CLOCK(N) CONCAT(cmuClock_USART, N) +#if defined(EFR32MG24) StaticSemaphore_t spi_sem_peripheral; SemaphoreHandle_t spi_sem_sync_hdl; +#endif /* EFR32MG24 */ StaticSemaphore_t xEfxSpiIntfSemaBuffer; static SemaphoreHandle_t spiTransferLock; diff --git a/examples/platform/silabs/efr32/wf200/efr_spi.c b/examples/platform/silabs/efr32/wf200/efr_spi.c index d2f4b192395e8c..37b52d1bebc8ca 100644 --- a/examples/platform/silabs/efr32/wf200/efr_spi.c +++ b/examples/platform/silabs/efr32/wf200/efr_spi.c @@ -60,8 +60,10 @@ extern SPIDRV_Handle_t sl_spidrv_exp_handle; #define USART SL_WFX_HOST_PINOUT_SPI_PERIPHERAL +#if defined(EFR32MG24) StaticSemaphore_t spi_sem_peripheral; SemaphoreHandle_t spi_sem_sync_hdl; +#endif /* EFR32MG24 */ StaticSemaphore_t xEfrSpiSemaBuffer; static SemaphoreHandle_t spi_sem; @@ -150,7 +152,9 @@ sl_status_t sl_wfx_host_spi_cs_assert() sl_status_t sl_wfx_host_spi_cs_deassert() { GPIO_PinOutSet(SL_SPIDRV_EXP_CS_PORT, SL_SPIDRV_EXP_CS_PIN); +#if defined(EFR32MG24) xSemaphoreGive(spi_sem_sync_hdl); +#endif /* EFR32MG24 */ return SL_STATUS_OK; } From 3c82fbac415d0346090352379a43ff9d9046cd80 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Thu, 18 May 2023 23:33:55 +0530 Subject: [PATCH 12/50] Adds fix for err usage --- src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp b/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp index 215cfddb6d37cb..66283c1d511fe3 100644 --- a/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp +++ b/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp @@ -260,6 +260,7 @@ void ConnectivityManagerImpl::DriveStationState() // Ensure that the WFX is started. if ((serr = wfx_wifi_start()) != SL_STATUS_OK) { + err = CHIP_ERROR_INTERNAL; ChipLogError(DeviceLayer, "wfx_wifi_start() failed: %s", chip::ErrorStr(err)); return; } From 471a3c8bf949e85f452c0bee33dd3f5505717935 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Tue, 23 May 2023 13:09:28 +0530 Subject: [PATCH 13/50] Refactor SPIDRV_ReInit --- .../platform/silabs/efr32/spi_multiplex.c | 19 ----------------- .../platform/silabs/efr32/wf200/efr_spi.c | 21 +++++++++++++++++++ 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/examples/platform/silabs/efr32/spi_multiplex.c b/examples/platform/silabs/efr32/spi_multiplex.c index 26e36c4aab7166..5fda2f395acded 100644 --- a/examples/platform/silabs/efr32/spi_multiplex.c +++ b/examples/platform/silabs/efr32/spi_multiplex.c @@ -25,23 +25,4 @@ #include "em_usart.h" #include "spi_multiplex.h" -void SPIDRV_ReInit(uint32_t baudrate) -{ - if (USART_BaudrateGet(USART0) == baudrate) - { - // USART synced to baudrate already - return; - } - // USART is used in MG24 + WF200 combination - USART_InitSync_TypeDef usartInit = USART_INITSYNC_DEFAULT; - usartInit.msbf = true; - usartInit.clockMode = usartClockMode0; - usartInit.baudrate = baudrate; - uint32_t databits = SL_SPIDRV_FRAME_LENGTH - 4U + _USART_FRAME_DATABITS_FOUR; - usartInit.databits = (USART_Databits_TypeDef) databits; - usartInit.autoCsEnable = true; - - USART_InitSync(USART0, &usartInit); -} - #endif /* EFR32MG24 */ \ No newline at end of file diff --git a/examples/platform/silabs/efr32/wf200/efr_spi.c b/examples/platform/silabs/efr32/wf200/efr_spi.c index 37b52d1bebc8ca..d8cc30442d5078 100644 --- a/examples/platform/silabs/efr32/wf200/efr_spi.c +++ b/examples/platform/silabs/efr32/wf200/efr_spi.c @@ -53,6 +53,7 @@ extern SPIDRV_Handle_t sl_spidrv_exp_handle; #define SL_SPIDRV_HANDLE sl_spidrv_exp_handle #elif defined(EFR32MG24) +#include "sl_spidrv_eusart_exp_config.h" #include "spi_multiplex.h" #else #error "Unknown platform" @@ -378,6 +379,26 @@ void sl_wfx_host_gpio_init(void) } #if defined(EFR32MG24) + +void SPIDRV_ReInit(uint32_t baudrate) +{ + if (USART_BaudrateGet(MY_USART) == baudrate) + { + // USART synced to baudrate already + return; + } + // USART is used in MG24 + WF200 combination + USART_InitSync_TypeDef usartInit = USART_INITSYNC_DEFAULT; + usartInit.msbf = true; + usartInit.clockMode = usartClockMode0; + usartInit.baudrate = baudrate; + uint32_t databits = SL_SPIDRV_FRAME_LENGTH - 4U + _USART_FRAME_DATABITS_FOUR; + usartInit.databits = (USART_Databits_TypeDef) databits; + usartInit.autoCsEnable = true; + + USART_InitSync(MY_USART, &usartInit); +} + void sl_wfx_host_spiflash_cs_assert(void) { GPIO_PinOutClear(SL_MX25_FLASH_SHUTDOWN_CS_PORT, SL_MX25_FLASH_SHUTDOWN_CS_PIN); From d0ed067559f38b084271805843fbe637a70f3be1 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Tue, 23 May 2023 14:19:12 +0530 Subject: [PATCH 14/50] Adds SPIDRV_ReInit for EUSART --- .../platform/silabs/efr32/rs911x/hal/efx_spi.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index 02f44f8a5c5aa3..b3471bb405eac2 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -173,6 +173,17 @@ void rsi_hal_board_init(void) } #if defined(EFR32MG24) + +void SPIDRV_ReInit(uint32_t baudrate) +{ + if (EUSART_BaudrateGet(MY_USART) == baudrate) + { + // EUSART synced to baudrate already + return; + } + EUSART_BaudrateSet(MY_USART, 0, baudrate); +} + sl_status_t sl_wfx_host_spi_cs_assert() { // SILABS_LOG("%s started.", __func__); @@ -182,12 +193,7 @@ sl_status_t sl_wfx_host_spi_cs_assert() SILABS_LOG("%s errored.", __func__); return SL_STATUS_TIMEOUT; } - // if (spi_enabled) - // { - // SPIDRV_DeInit(SL_SPIDRV_HANDLE); - // SILABS_LOG("%s did deinit.", __func__); - // spi_enabled = false; - // } + if (!spi_enabled) // Reduce SPIDRV_Init { SPIDRV_Init(SL_SPIDRV_HANDLE, &sl_spidrv_eusart_init_exp); From d0cbb77c3e03c9892d76bfd4c57d1855fc59a4d5 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Tue, 23 May 2023 14:53:52 +0530 Subject: [PATCH 15/50] Added error logs --- .../platform/silabs/efr32/rs911x/hal/efx_spi.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index b3471bb405eac2..183e468b5befed 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -246,8 +246,13 @@ void sl_wfx_host_pre_bootloader_spi_transfer() SPIDRV_DeInit(SL_SPIDRV_HANDLE); spi_enabled = false; } - bootloader_init(); + int32_t status = bootloader_init(); // bootloader_init takes care of SPIDRV_Init() + if (status != BOOTLOADER_OK) + { + SILABS_LOG("%s: bootloader_init failed with error code: %d", __func__, status); + return; + } sl_wfx_host_spiflash_cs_assert(); SILABS_LOG("%s completed.", __func__); } @@ -255,8 +260,14 @@ void sl_wfx_host_pre_bootloader_spi_transfer() void sl_wfx_host_post_bootloader_spi_transfer() { SILABS_LOG("%s started.", __func__); - bootloader_deinit(); - GPIO->USARTROUTE[0].ROUTEEN = 0; + int32_t status = bootloader_deinit(); + // bootloader_deinit will do USART disable + if (status != BOOTLOADER_OK) + { + SILABS_LOG("%s: bootloader_deinit failed with error code: %d", __func__, status); + return; + } + GPIO->USARTROUTE[SL_MX25_FLASH_SHUTDOWN_PERIPHERAL_NO].ROUTEEN = 0; sl_wfx_host_spiflash_cs_deassert(); xSemaphoreGive(spi_sem_sync_hdl); SILABS_LOG("%s completed.", __func__); From 7e2f516edba1a1412f46453549a70bb67fe1eb47 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Tue, 23 May 2023 15:05:57 +0530 Subject: [PATCH 16/50] Added logs --- examples/platform/silabs/efr32/rs911x/hal/efx_spi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index 183e468b5befed..9b7ec6b3f39c36 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -47,6 +47,7 @@ #include "event_groups.h" #include "task.h" +#include "silabs_utils.h" #include "wfx_host_events.h" #include "wfx_rsi.h" From 2764df6ab2cb1cfba982063430ebea82152af6e3 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Tue, 23 May 2023 16:54:42 +0530 Subject: [PATCH 17/50] Revert submodule update --- examples/platform/silabs/efr32/rs911x/hal/efx_spi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index 9b7ec6b3f39c36..e3d5896560b56f 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -36,7 +36,7 @@ #endif #include "spidrv.h" -#include "btl_interface.h" +#include "silabs_utils.h" #include "gpiointerrupt.h" #include "sl_device_init_clocks.h" @@ -47,7 +47,7 @@ #include "event_groups.h" #include "task.h" -#include "silabs_utils.h" +#include "btl_interface.h" #include "wfx_host_events.h" #include "wfx_rsi.h" From f46cbf2cd0589312eff5afb05e8d4a14c4278423 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Wed, 24 May 2023 10:40:19 +0530 Subject: [PATCH 18/50] Aligned the macros --- examples/platform/silabs/efr32/spi_multiplex.h | 10 +++++----- examples/platform/silabs/efr32/wf200/efr_spi.c | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/platform/silabs/efr32/spi_multiplex.h b/examples/platform/silabs/efr32/spi_multiplex.h index dfae0c5e9d1cac..9e8760b36e6a89 100644 --- a/examples/platform/silabs/efr32/spi_multiplex.h +++ b/examples/platform/silabs/efr32/spi_multiplex.h @@ -36,14 +36,14 @@ extern "C" { #include "em_eusart.h" #include "spidrv.h" -#define SL_BIT_RATE_LCD 1100000 +#define SL_SPIDRV_LCD_BITRATE 1100000 #ifdef WF200_WIFI -#define SL_BIT_RATE_EXP_HDR 10000000 +#define SL_SPIDRV_EXP_BITRATE 10000000 #else -#define SL_BIT_RATE_EXP_HDR SL_SPIDRV_EUSART_EXP_BITRATE +#define SL_SPIDRV_EXP_BITRATE SL_SPIDRV_EUSART_EXP_BITRATE #endif /* WF200_WIFI */ -#define SL_BIT_RATE_SPI_FLASH 16000000 -#define SL_BIT_RATE_UART_CONSOLE 16000000 +#define SL_SPIDRV_MX25_FLASH_BITRATE 16000000 +#define SL_SPIDRV_UART_CONSOLE_BITRATE 16000000 #ifdef RS911X_WIFI #define SL_SPIDRV_FRAME_LENGTH SL_SPIDRV_EUSART_EXP_FRAME_LENGTH diff --git a/examples/platform/silabs/efr32/wf200/efr_spi.c b/examples/platform/silabs/efr32/wf200/efr_spi.c index d8cc30442d5078..a9fd3ff6560400 100644 --- a/examples/platform/silabs/efr32/wf200/efr_spi.c +++ b/examples/platform/silabs/efr32/wf200/efr_spi.c @@ -144,7 +144,7 @@ sl_status_t sl_wfx_host_spi_cs_assert() { return SL_STATUS_TIMEOUT; } - SPIDRV_ReInit(SL_BIT_RATE_EXP_HDR); + SPIDRV_ReInit(SL_SPIDRV_EXP_BITRATE); #endif /* EFR32MG24 */ GPIO_PinOutClear(SL_SPIDRV_EXP_CS_PORT, SL_SPIDRV_EXP_CS_PIN); return SL_STATUS_OK; @@ -418,7 +418,7 @@ void sl_wfx_host_pre_bootloader_spi_transfer(void) /* * Assert CS pin for EXT SPI Flash */ - SPIDRV_ReInit(SL_BIT_RATE_SPI_FLASH); + SPIDRV_ReInit(SL_SPIDRV_MX25_FLASH_BITRATE); sl_wfx_host_spiflash_cs_assert(); } @@ -437,7 +437,7 @@ void sl_wfx_host_pre_lcd_spi_transfer(void) { return; } - SPIDRV_ReInit(SL_BIT_RATE_LCD); + SPIDRV_ReInit(SL_SPIDRV_LCD_BITRATE); /*LCD CS is handled as part of LCD gsdk*/ } From 3a617a764fdc57584adeabfffe0420d7cd2aca29 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Wed, 24 May 2023 22:46:43 +0530 Subject: [PATCH 19/50] Restyled --- examples/platform/silabs/efr32/spi_multiplex.c | 4 ++-- examples/platform/silabs/efr32/spi_multiplex.h | 2 +- examples/platform/silabs/efr32/wf200/efr_spi.c | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/platform/silabs/efr32/spi_multiplex.c b/examples/platform/silabs/efr32/spi_multiplex.c index 5fda2f395acded..bb2d7e7f626f1c 100644 --- a/examples/platform/silabs/efr32/spi_multiplex.c +++ b/examples/platform/silabs/efr32/spi_multiplex.c @@ -17,12 +17,12 @@ #if defined(EFR32MG24) +#include "spi_multiplex.h" #include "dmadrv.h" #include "em_bus.h" #include "em_cmu.h" #include "em_gpio.h" #include "em_ldma.h" #include "em_usart.h" -#include "spi_multiplex.h" -#endif /* EFR32MG24 */ \ No newline at end of file +#endif /* EFR32MG24 */ diff --git a/examples/platform/silabs/efr32/spi_multiplex.h b/examples/platform/silabs/efr32/spi_multiplex.h index 9e8760b36e6a89..dcbd87daca0d3a 100644 --- a/examples/platform/silabs/efr32/spi_multiplex.h +++ b/examples/platform/silabs/efr32/spi_multiplex.h @@ -162,4 +162,4 @@ void sl_wfx_host_post_uart_transfer(void); #ifdef __cplusplus } #endif -#endif /* EFR32MG24 */ \ No newline at end of file +#endif /* EFR32MG24 */ diff --git a/examples/platform/silabs/efr32/wf200/efr_spi.c b/examples/platform/silabs/efr32/wf200/efr_spi.c index a9fd3ff6560400..3310a9482baa6c 100644 --- a/examples/platform/silabs/efr32/wf200/efr_spi.c +++ b/examples/platform/silabs/efr32/wf200/efr_spi.c @@ -123,9 +123,9 @@ sl_status_t sl_wfx_host_init_bus(void) sl_status_t sl_wfx_host_deinit_bus(void) { vSemaphoreDelete(spi_sem); - #if defined(EFR32MG24) +#if defined(EFR32MG24) vSemaphoreDelete(spi_sem_sync_hdl); - #endif /* EFR32MG24 */ +#endif /* EFR32MG24 */ // Stop DMAs. DMADRV_StopTransfer(rx_dma_channel); DMADRV_StopTransfer(tx_dma_channel); @@ -475,4 +475,4 @@ void sl_wfx_host_post_uart_transfer(void) sl_wfx_host_enable_platform_interrupt(); sl_wfx_enable_irq(); } -#endif /* EFR32MG24 */ \ No newline at end of file +#endif /* EFR32MG24 */ From ddd86b0c44bff29eb7c9e1aaf902ef8575fe03fb Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Thu, 25 May 2023 17:36:29 +0530 Subject: [PATCH 20/50] Aligned the MACRO --- examples/platform/silabs/efr32/spi_multiplex.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/platform/silabs/efr32/spi_multiplex.h b/examples/platform/silabs/efr32/spi_multiplex.h index dcbd87daca0d3a..cb1368eee1451a 100644 --- a/examples/platform/silabs/efr32/spi_multiplex.h +++ b/examples/platform/silabs/efr32/spi_multiplex.h @@ -36,12 +36,13 @@ extern "C" { #include "em_eusart.h" #include "spidrv.h" -#define SL_SPIDRV_LCD_BITRATE 1100000 #ifdef WF200_WIFI #define SL_SPIDRV_EXP_BITRATE 10000000 #else #define SL_SPIDRV_EXP_BITRATE SL_SPIDRV_EUSART_EXP_BITRATE #endif /* WF200_WIFI */ + +#define SL_SPIDRV_LCD_BITRATE 1100000 #define SL_SPIDRV_MX25_FLASH_BITRATE 16000000 #define SL_SPIDRV_UART_CONSOLE_BITRATE 16000000 From 9a23e6b87ea1791f2e2d697305842eb33051a985 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Fri, 26 May 2023 10:35:40 +0530 Subject: [PATCH 21/50] Adds cosmetic changes --- .../silabs/efr32/rs911x/hal/efx_spi.c | 35 +++++-------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index e3d5896560b56f..32764953b0b2c7 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -185,9 +185,8 @@ void SPIDRV_ReInit(uint32_t baudrate) EUSART_BaudrateSet(MY_USART, 0, baudrate); } -sl_status_t sl_wfx_host_spi_cs_assert() +sl_status_t sl_wfx_host_spi_cs_assert(void) { - // SILABS_LOG("%s started.", __func__); configASSERT(spi_sem_sync_hdl); if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) { @@ -201,43 +200,34 @@ sl_status_t sl_wfx_host_spi_cs_assert() spi_enabled = true; } GPIO_PinOutClear(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN); - // SILABS_LOG("%s completed.", __func__); return SL_STATUS_OK; } -sl_status_t sl_wfx_host_spi_cs_deassert() +sl_status_t sl_wfx_host_spi_cs_deassert(void) { - // SILABS_LOG("%s started.", __func__); if (spi_enabled) { SPIDRV_DeInit(SL_SPIDRV_HANDLE); spi_enabled = false; } GPIO_PinOutSet(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN); - // TODO: should be done by deinit, check once. GPIO->EUSARTROUTE[SL_SPIDRV_EUSART_EXP_PERIPHERAL_NO].ROUTEEN = 0; xSemaphoreGive(spi_sem_sync_hdl); - // SILABS_LOG("%s completed.", __func__); return SL_STATUS_OK; } -void sl_wfx_host_spiflash_cs_assert() +void sl_wfx_host_spiflash_cs_assert(void) { - SILABS_LOG("%s started.", __func__); GPIO_PinOutClear(SL_MX25_FLASH_SHUTDOWN_CS_PORT, SL_MX25_FLASH_SHUTDOWN_CS_PIN); - SILABS_LOG("%s completed.", __func__); } -void sl_wfx_host_spiflash_cs_deassert() +void sl_wfx_host_spiflash_cs_deassert(void) { - SILABS_LOG("%s started.", __func__); GPIO_PinOutSet(SL_MX25_FLASH_SHUTDOWN_CS_PORT, SL_MX25_FLASH_SHUTDOWN_CS_PIN); - SILABS_LOG("%s completed.", __func__); } -void sl_wfx_host_pre_bootloader_spi_transfer() +void sl_wfx_host_pre_bootloader_spi_transfer(void) { - SILABS_LOG("%s started.", __func__); if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) { return; @@ -255,12 +245,10 @@ void sl_wfx_host_pre_bootloader_spi_transfer() return; } sl_wfx_host_spiflash_cs_assert(); - SILABS_LOG("%s completed.", __func__); } -void sl_wfx_host_post_bootloader_spi_transfer() +void sl_wfx_host_post_bootloader_spi_transfer(void) { - SILABS_LOG("%s started.", __func__); int32_t status = bootloader_deinit(); // bootloader_deinit will do USART disable if (status != BOOTLOADER_OK) @@ -271,12 +259,10 @@ void sl_wfx_host_post_bootloader_spi_transfer() GPIO->USARTROUTE[SL_MX25_FLASH_SHUTDOWN_PERIPHERAL_NO].ROUTEEN = 0; sl_wfx_host_spiflash_cs_deassert(); xSemaphoreGive(spi_sem_sync_hdl); - SILABS_LOG("%s completed.", __func__); } -void sl_wfx_host_pre_lcd_spi_transfer() +void sl_wfx_host_pre_lcd_spi_transfer(void) { - SILABS_LOG("%s started.", __func__); if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) { return; @@ -288,17 +274,14 @@ void sl_wfx_host_pre_lcd_spi_transfer() } sl_memlcd_refresh(sl_memlcd_get()); // sl_memlcd_refresh takes care of SPIDRV_Init() - SILABS_LOG("%s completed.", __func__); } -void sl_wfx_host_post_lcd_spi_transfer() +void sl_wfx_host_post_lcd_spi_transfer(void) { - SILABS_LOG("%s started.", __func__); USART_Enable(SL_MEMLCD_SPI_PERIPHERAL, usartDisable); CMU_ClockEnable(SPI_CLOCK(SL_MEMLCD_SPI_PERIPHERAL_NO), false); GPIO->USARTROUTE[SL_MEMLCD_SPI_PERIPHERAL_NO].ROUTEEN = 0; xSemaphoreGive(spi_sem_sync_hdl); - SILABS_LOG("%s completed.", __func__); } #endif /* EFR32MG24 */ @@ -337,7 +320,6 @@ static void spi_dmaTransfertComplete(SPIDRV_HandleData_t * pxHandle, Ecode_t tra **************************************************************************/ int16_t rsi_spi_transfer(uint8_t * tx_buf, uint8_t * rx_buf, uint16_t xlen, uint8_t mode) { - // SILABS_LOG("%s started.", __func__); #if defined(EFR32MG24) sl_wfx_host_spi_cs_assert(); #endif /* EFR32MG24 */ @@ -404,6 +386,5 @@ int16_t rsi_spi_transfer(uint8_t * tx_buf, uint8_t * rx_buf, uint16_t xlen, uint #if defined(EFR32MG24) sl_wfx_host_spi_cs_deassert(); #endif /* EFR32MG24 */ - // SILABS_LOG("%s completed.", __func__); return rsiError; } From e55962ad48e5880f0a6e6b8c7d59884f1ec03812 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Fri, 26 May 2023 10:41:55 +0530 Subject: [PATCH 22/50] Removes debug log --- src/platform/silabs/efr32/OTAImageProcessorImpl.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp index 0034cc423c538a..bc336ad6ef55f9 100644 --- a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp +++ b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp @@ -46,34 +46,29 @@ uint8_t OTAImageProcessorImpl::writeBuffer[kAlignmentBytes] __attribute__((align CHIP_ERROR OTAImageProcessorImpl::PrepareDownload() { - ChipLogProgress(SoftwareUpdate, "%s: started", __func__); DeviceLayer::PlatformMgr().ScheduleWork(HandlePrepareDownload, reinterpret_cast(this)); return CHIP_NO_ERROR; } CHIP_ERROR OTAImageProcessorImpl::Finalize() { - ChipLogProgress(SoftwareUpdate, "%s: started", __func__); DeviceLayer::PlatformMgr().ScheduleWork(HandleFinalize, reinterpret_cast(this)); return CHIP_NO_ERROR; } CHIP_ERROR OTAImageProcessorImpl::Apply() { - ChipLogProgress(SoftwareUpdate, "%s: started", __func__); DeviceLayer::PlatformMgr().ScheduleWork(HandleApply, reinterpret_cast(this)); return CHIP_NO_ERROR; } CHIP_ERROR OTAImageProcessorImpl::Abort() { - ChipLogProgress(SoftwareUpdate, "%s: started", __func__); DeviceLayer::PlatformMgr().ScheduleWork(HandleAbort, reinterpret_cast(this)); return CHIP_NO_ERROR; } CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & block) { - ChipLogProgress(SoftwareUpdate, "%s: started", __func__); if ((block.data() == nullptr) || block.empty()) { ChipLogError(SoftwareUpdate, "%s: block is empty", __func__); @@ -94,7 +89,6 @@ CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & block) bool OTAImageProcessorImpl::IsFirstImageRun() { - ChipLogProgress(SoftwareUpdate, "%s: started", __func__); OTARequestorInterface * requestor = chip::GetRequestorInstance(); if (requestor == nullptr) { @@ -107,7 +101,6 @@ bool OTAImageProcessorImpl::IsFirstImageRun() CHIP_ERROR OTAImageProcessorImpl::ConfirmCurrentImage() { - ChipLogProgress(SoftwareUpdate, "%s: started", __func__); OTARequestorInterface * requestor = chip::GetRequestorInstance(); if (requestor == nullptr) { From 161b508ccc2d4a5a52818abde3c678ef9ff73484 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Fri, 26 May 2023 10:47:47 +0530 Subject: [PATCH 23/50] Adds sl_wfx_host_post_bootloader_spi_transfer in relevant failure outcomes --- src/platform/silabs/efr32/OTAImageProcessorImpl.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp index bc336ad6ef55f9..750baa7a7aeeb2 100644 --- a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp +++ b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp @@ -212,6 +212,9 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) ChipLogError(SoftwareUpdate, "%s: bootloader_verifyImage() error %ld", __func__, err); // Call the OTARequestor API to reset the state GetRequestorInstance()->CancelImageUpdate(); +#if (defined(EFR32MG24) && defined(SL_WIFI)) + sl_wfx_host_post_bootloader_spi_transfer(); +#endif return; } @@ -221,14 +224,17 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) ChipLogError(SoftwareUpdate, "%s: bootloader_setImageToBootload() error %ld", __func__, err); // Call the OTARequestor API to reset the state GetRequestorInstance()->CancelImageUpdate(); +#if (defined(EFR32MG24) && defined(SL_WIFI)) + sl_wfx_host_post_bootloader_spi_transfer(); +#endif return; } - // This reboots the device - CORE_CRITICAL_SECTION(bootloader_rebootAndInstall();) #if (defined(EFR32MG24) && defined(SL_WIFI)) sl_wfx_host_post_bootloader_spi_transfer(); #endif + // This reboots the device + CORE_CRITICAL_SECTION(bootloader_rebootAndInstall();) } void OTAImageProcessorImpl::HandleAbort(intptr_t context) From 3df8e4abbc832318b74b76ac206779ed2bd0e5a3 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Mon, 29 May 2023 11:25:56 +0530 Subject: [PATCH 24/50] Adds re factored local function updateDisplay(void) --- examples/platform/silabs/display/demo-ui.c | 37 ++--- examples/platform/silabs/display/demo-ui.h | 171 +++++++++++---------- examples/platform/silabs/display/lcd.cpp | 20 +-- 3 files changed, 111 insertions(+), 117 deletions(-) diff --git a/examples/platform/silabs/display/demo-ui.c b/examples/platform/silabs/display/demo-ui.c index fff63ead654351..a394bffe644cd4 100644 --- a/examples/platform/silabs/display/demo-ui.c +++ b/examples/platform/silabs/display/demo-ui.c @@ -92,7 +92,6 @@ static void demoUIDisplayLogo(void) GLIB_drawBitmap(&glibContext, SILICONLABS_X_POSITION, SILICONLABS_Y_POSITION, SILICONLABS_BITMAP_WIDTH, SILICONLABS_BITMAP_HEIGHT, siliconlabsBitmap); } - /******************************************************************************* ************************** GLOBAL FUNCTIONS ******************************* ******************************************************************************/ @@ -101,33 +100,33 @@ void demoUIInit(GLIB_Context_t * context) memcpy(&glibContext, context, sizeof(GLIB_Context_t)); } -void demoUIDisplayHeader(char * name) +EMSTATUS updateDisplay(void) { - demoUIDisplayLogo(); - if (APP_NAME_MAX_LENGTH >= strlen(name)) - { - GLIB_drawStringOnLine(&glibContext, name, 5, GLIB_ALIGN_CENTER, 0, 0, true); - } #if (defined(EFR32MG24) && defined(SL_WIFI)) sl_wfx_host_pre_lcd_spi_transfer(); #endif - DMD_updateDisplay(); + EMSTATUS status = DMD_updateDisplay(); #if (defined(EFR32MG24) && defined(SL_WIFI)) sl_wfx_host_post_lcd_spi_transfer(); #endif + return status; +} + +void demoUIDisplayHeader(char * name) +{ + demoUIDisplayLogo(); + if (APP_NAME_MAX_LENGTH >= strlen(name)) + { + GLIB_drawStringOnLine(&glibContext, name, 5, GLIB_ALIGN_CENTER, 0, 0, true); + } + updateDisplay(); } void demoUIDisplayApp(bool on) { GLIB_drawBitmap(&glibContext, APP_X_POSITION, APP_Y_POSITION, APP_BITMAP_WIDTH, APP_BITMAP_HEIGHT, (on ? OnStateBitMap : OffStateBitMap)); -#if (defined(EFR32MG24) && defined(SL_WIFI)) - sl_wfx_host_pre_lcd_spi_transfer(); -#endif - DMD_updateDisplay(); -#if (defined(EFR32MG24) && defined(SL_WIFI)) - sl_wfx_host_post_lcd_spi_transfer(); -#endif + updateDisplay(); } void demoUIDisplayProtocol(demoUIProtocol protocol, bool isConnected) @@ -138,13 +137,7 @@ void demoUIDisplayProtocol(demoUIProtocol protocol, bool isConnected) (protocol == DEMO_UI_PROTOCOL1 ? PROT1_BITMAP_HEIGHT : PROT2_BITMAP_HEIGHT), (protocol == DEMO_UI_PROTOCOL1 ? (isConnected ? PROT1_BITMAP_CONN : PROT1_BITMAP) : (isConnected ? PROT2_BITMAP_CONN : PROT2_BITMAP))); -#if (defined(EFR32MG24) && defined(SL_WIFI)) - sl_wfx_host_pre_lcd_spi_transfer(); -#endif - DMD_updateDisplay(); -#if (defined(EFR32MG24) && defined(SL_WIFI)) - sl_wfx_host_post_lcd_spi_transfer(); -#endif + updateDisplay(); } void demoUIClearMainScreen(uint8_t * name) diff --git a/examples/platform/silabs/display/demo-ui.h b/examples/platform/silabs/display/demo-ui.h index 6197a4e73c71ef..744db6a90b8e94 100644 --- a/examples/platform/silabs/display/demo-ui.h +++ b/examples/platform/silabs/display/demo-ui.h @@ -1,22 +1,23 @@ -/***************************************************************************/ /** - * @file - * @brief User Interface for demo. - ******************************************************************************* - * # License - * Copyright 2020 Silicon Laboratories Inc. - *www.silabs.com - ******************************************************************************* - * - * The licensor of this software is Silicon - *Laboratories Inc. Your use of this software is - *governed by the terms of Silicon Labs Master - *Software License Agreement (MSLA) available at - * www.silabs.com/about-us/legal/master-software-license-agreement. - *This software is distributed to you in Source Code - *format and is governed by the sections of the MSLA - *applicable to Source Code. - * - ******************************************************************************/ +/***************************************************************************/ +/** + * @file + * @brief User Interface for demo. + ******************************************************************************* + * # License + * Copyright 2020 Silicon Laboratories Inc. + *www.silabs.com + ******************************************************************************* + * + * The licensor of this software is Silicon + *Laboratories Inc. Your use of this software is + *governed by the terms of Silicon Labs Master + *Software License Agreement (MSLA) available at + * www.silabs.com/about-us/legal/master-software-license-agreement. + *This software is distributed to you in Source Code + *format and is governed by the sections of the MSLA + *applicable to Source Code. + * + ******************************************************************************/ #pragma once @@ -25,13 +26,14 @@ extern "C" { #endif #include "glib.h" -/**************************************************************************/ /** - * DEMO UI uses the underlying DMD interface and the - *GLIB and exposes several wrapper functions to - *application. These functions are used to display - * different bitmaps for the demo. - * - ******************************************************************************/ +/**************************************************************************/ +/** + * DEMO UI uses the underlying DMD interface and the + *GLIB and exposes several wrapper functions to + *application. These functions are used to display + * different bitmaps for the demo. + * + ******************************************************************************/ #define APP_NAME_MAX_LENGTH 20 @@ -73,67 +75,82 @@ typedef enum ****************************** PROTOTYPES ********************************* ******************************************************************************/ -/**************************************************************************/ /** - * @brief - * Initilize the GLIB and DMD interfaces. - * - * @param[in] void - * - * @return - * void - *****************************************************************************/ +/**************************************************************************/ +/** + * @brief + * Initilize the GLIB and DMD interfaces. + * + * @param[in] void + * + * @return + * void + *****************************************************************************/ void demoUIInit(GLIB_Context_t * context); -/**************************************************************************/ /** - * @brief - * Update the display with Silicon Labs logo and - *application name. - * - * @param[in] name name of the current application. - * - * @return - * void - *****************************************************************************/ +/**************************************************************************/ +/** + * @brief + * Update the display with Silicon Labs logo and + *application name. + * + * @param[in] name name of the current application. + * + * @return + * void + *****************************************************************************/ void demoUIDisplayHeader(char * name); -/**************************************************************************/ /** - * @brief - * Update the display with App image. Bool state only - *for now. - * - * @param[in] on status of App - * - * @return - * void - *****************************************************************************/ +/**************************************************************************/ +/** + * @brief + * Update the display with App image. Bool state only + *for now. + * + * @param[in] on status of App + * + * @return + * void + *****************************************************************************/ void demoUIDisplayApp(bool on); -/**************************************************************************/ /** - * @brief - * Update the display to show if the bluetooth is - *connected to the mobile device. - * - * @param[in] bool, true if the Light is connected to - *mobile device, false otherwise. - * - * @return - * void - *****************************************************************************/ +/**************************************************************************/ +/** + * @brief + * Update the display to show if the bluetooth is + *connected to the mobile device. + * + * @param[in] bool, true if the Light is connected to + *mobile device, false otherwise. + * + * @return + * void + *****************************************************************************/ void demoUIDisplayProtocol(demoUIProtocol protocol, bool isConnected); -/**************************************************************************/ /** - * @brief - * Clear the Lcd screen and display the main screen. - * - * @param[in] name - application name - * @param[in] showPROT1 - show protocol 1 related icon. - * @param[in] showPROT2 - show protocol 2 related icon. - * - * @return - * void - *****************************************************************************/ +/**************************************************************************/ +/** + * @brief + * Clear the Lcd screen and display the main screen. + * + * @param[in] name - application name + * @param[in] showPROT1 - show protocol 1 related icon. + * @param[in] showPROT2 - show protocol 2 related icon. + * + * @return + * void + *****************************************************************************/ void demoUIClearMainScreen(uint8_t * name); +/**************************************************************************/ +/** + * @brief + * Clear the Lcd screen and display the main screen. + * + * @return + * Returns DMD_OK if successful, error otherwise. + *****************************************************************************/ +EMSTATUS updateDisplay(void); + #ifdef __cplusplus } #endif diff --git a/examples/platform/silabs/display/lcd.cpp b/examples/platform/silabs/display/lcd.cpp index fcd495d4c4aedb..355b86c9b804b9 100644 --- a/examples/platform/silabs/display/lcd.cpp +++ b/examples/platform/silabs/display/lcd.cpp @@ -121,16 +121,7 @@ int SilabsLCD::DrawPixel(void * pContext, int32_t x, int32_t y) int SilabsLCD::Update(void) { int status; -#if (defined(EFR32MG24) && defined(SL_WIFI)) - sl_wfx_host_pre_lcd_spi_transfer(); -#endif - status = DMD_updateDisplay(); -#if (defined(EFR32MG24) && defined(SL_WIFI)) - sl_wfx_host_post_lcd_spi_transfer(); -#endif - /* - * TO-DO; Above logic can be optimised by writing a common API - */ + status = static_cast(updateDisplay()); return status; } @@ -194,14 +185,7 @@ void SilabsLCD::WriteQRCode() } } } -#if (defined(EFR32MG24) && defined(SL_WIFI)) - sl_wfx_host_pre_lcd_spi_transfer(); -#endif - - DMD_updateDisplay(); -#if (defined(EFR32MG24) && defined(SL_WIFI)) - sl_wfx_host_post_lcd_spi_transfer(); -#endif + SilabsLCD::Update(); } void SilabsLCD::SetQRCode(uint8_t * str, uint32_t size) From e0d011fdd8269aeaf16033d1334912dc526b1142 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Mon, 29 May 2023 11:51:51 +0530 Subject: [PATCH 25/50] Removes spi_multiplex.c --- .../platform/silabs/efr32/rs911x/rs911x.gni | 1 - .../platform/silabs/efr32/spi_multiplex.c | 28 ------------------- .../platform/silabs/efr32/wf200/wf200.gni | 1 - 3 files changed, 30 deletions(-) delete mode 100644 examples/platform/silabs/efr32/spi_multiplex.c diff --git a/examples/platform/silabs/efr32/rs911x/rs911x.gni b/examples/platform/silabs/efr32/rs911x/rs911x.gni index fb725f2d395724..0c305ce810abd1 100644 --- a/examples/platform/silabs/efr32/rs911x/rs911x.gni +++ b/examples/platform/silabs/efr32/rs911x/rs911x.gni @@ -12,7 +12,6 @@ rs911x_src_plat = [ "${examples_plat_dir}/rs911x/hal/rsi_hal_mcu_timer.c", "${examples_plat_dir}/rs911x/hal/efx_spi.c", "${wifi_sdk_dir}/wfx_notify.cpp", - "${examples_plat_dir}/spi_multiplex.c", ] # diff --git a/examples/platform/silabs/efr32/spi_multiplex.c b/examples/platform/silabs/efr32/spi_multiplex.c deleted file mode 100644 index bb2d7e7f626f1c..00000000000000 --- a/examples/platform/silabs/efr32/spi_multiplex.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * - * Copyright (c) 2022 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#if defined(EFR32MG24) - -#include "spi_multiplex.h" -#include "dmadrv.h" -#include "em_bus.h" -#include "em_cmu.h" -#include "em_gpio.h" -#include "em_ldma.h" -#include "em_usart.h" - -#endif /* EFR32MG24 */ diff --git a/examples/platform/silabs/efr32/wf200/wf200.gni b/examples/platform/silabs/efr32/wf200/wf200.gni index 372b1d0c8f3b31..4cd2943b12f8fb 100644 --- a/examples/platform/silabs/efr32/wf200/wf200.gni +++ b/examples/platform/silabs/efr32/wf200/wf200.gni @@ -10,5 +10,4 @@ wf200_plat_src = [ "${examples_plat_dir}/wf200/wf200_init.c", "${examples_plat_dir}/wf200/efr_spi.c", "${examples_plat_dir}/wf200/host_if.cpp", - "${examples_plat_dir}/spi_multiplex.c", ] From 23857202d80d9f3fd378626a4d734231d8765602 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Mon, 29 May 2023 11:52:23 +0530 Subject: [PATCH 26/50] Removes development debug trace and log --- examples/platform/silabs/efr32/rs911x/hal/efx_spi.c | 3 --- src/platform/silabs/efr32/OTAImageProcessorImpl.cpp | 5 ----- 2 files changed, 8 deletions(-) diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index 32764953b0b2c7..d42cd554860321 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -122,7 +122,6 @@ void sl_wfx_host_gpio_init(void) NVIC_SetPriority(GPIO_EVEN_IRQn, WFX_SPI_NVIC_PRIORITY); NVIC_SetPriority(GPIO_ODD_IRQn, WFX_SPI_NVIC_PRIORITY); spi_enabled = true; - SILABS_LOG("%s completed.", __func__); } /***************************************************************** @@ -145,7 +144,6 @@ void sl_wfx_host_reset_chip(void) // Delay for 3ms vTaskDelay(pdMS_TO_TICKS(3)); - SILABS_LOG("%s completed.", __func__); } /***************************************************************** @@ -190,7 +188,6 @@ sl_status_t sl_wfx_host_spi_cs_assert(void) configASSERT(spi_sem_sync_hdl); if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) { - SILABS_LOG("%s errored.", __func__); return SL_STATUS_TIMEOUT; } diff --git a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp index 750baa7a7aeeb2..1c990572fe91f7 100644 --- a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp +++ b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp @@ -162,8 +162,6 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context) return; } - ChipLogProgress(SoftwareUpdate, "%s: started", __func__); - // Pad the remainder of the write buffer with zeros and write it to bootloader storage if (writeBufOffset != 0) { @@ -245,8 +243,6 @@ void OTAImageProcessorImpl::HandleAbort(intptr_t context) ChipLogError(SoftwareUpdate, "%s: imageProcessor context is null", __func__); return; } - ChipLogProgress(SoftwareUpdate, "%s: started", __func__); - // Not clearing the image storage area as it is done during each write imageProcessor->ReleaseBlock(); } @@ -333,7 +329,6 @@ CHIP_ERROR OTAImageProcessorImpl::SetBlock(ByteSpan & block) { if ((block.data() == nullptr) || block.empty()) { - ChipLogError(SoftwareUpdate, "%s: block is empty", __func__); return CHIP_NO_ERROR; } From 89ae0e9a61fa661ceab7419d9fecbde4f234485e Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Mon, 29 May 2023 14:03:33 +0530 Subject: [PATCH 27/50] Renamed conflicting variable --- examples/platform/silabs/efr32/spi_multiplex.h | 4 ++-- examples/platform/silabs/efr32/wf200/efr_spi.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/platform/silabs/efr32/spi_multiplex.h b/examples/platform/silabs/efr32/spi_multiplex.h index cb1368eee1451a..d6829091697723 100644 --- a/examples/platform/silabs/efr32/spi_multiplex.h +++ b/examples/platform/silabs/efr32/spi_multiplex.h @@ -37,9 +37,9 @@ extern "C" { #include "spidrv.h" #ifdef WF200_WIFI -#define SL_SPIDRV_EXP_BITRATE 10000000 +#define SL_SPIDRV_EXP_BITRATE_MULTIPLEXED 10000000 #else -#define SL_SPIDRV_EXP_BITRATE SL_SPIDRV_EUSART_EXP_BITRATE +#define SL_SPIDRV_EXP_BITRATE_MULTIPLEXED SL_SPIDRV_EUSART_EXP_BITRATE #endif /* WF200_WIFI */ #define SL_SPIDRV_LCD_BITRATE 1100000 diff --git a/examples/platform/silabs/efr32/wf200/efr_spi.c b/examples/platform/silabs/efr32/wf200/efr_spi.c index 3310a9482baa6c..a0ccbfffcc1f65 100644 --- a/examples/platform/silabs/efr32/wf200/efr_spi.c +++ b/examples/platform/silabs/efr32/wf200/efr_spi.c @@ -144,7 +144,7 @@ sl_status_t sl_wfx_host_spi_cs_assert() { return SL_STATUS_TIMEOUT; } - SPIDRV_ReInit(SL_SPIDRV_EXP_BITRATE); + SPIDRV_ReInit(SL_SPIDRV_EXP_BITRATE_MULTIPLEXED); #endif /* EFR32MG24 */ GPIO_PinOutClear(SL_SPIDRV_EXP_CS_PORT, SL_SPIDRV_EXP_CS_PIN); return SL_STATUS_OK; From ca0319449ad84b2bb9a16f261d51f5a3592849d7 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Mon, 29 May 2023 14:17:24 +0530 Subject: [PATCH 28/50] Adds comment for technical debt and understanding --- examples/platform/silabs/efr32/spi_multiplex.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/platform/silabs/efr32/spi_multiplex.h b/examples/platform/silabs/efr32/spi_multiplex.h index d6829091697723..9b15912da7cfc7 100644 --- a/examples/platform/silabs/efr32/spi_multiplex.h +++ b/examples/platform/silabs/efr32/spi_multiplex.h @@ -37,6 +37,8 @@ extern "C" { #include "spidrv.h" #ifdef WF200_WIFI +// TODO: Investigate why using SL_SPIDRV_EXP_BITRATE is causing WF200 init failure +// REF: sl_spidrv_exp_config.h #define SL_SPIDRV_EXP_BITRATE_MULTIPLEXED 10000000 #else #define SL_SPIDRV_EXP_BITRATE_MULTIPLEXED SL_SPIDRV_EUSART_EXP_BITRATE From ab9621f3a631ee71ac16aa12c0cb9995e81e2505 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Thu, 1 Jun 2023 09:37:51 +0530 Subject: [PATCH 29/50] Adds changes for updateDisplay function --- examples/platform/silabs/display/demo-ui.c | 8 +++++--- examples/platform/silabs/display/demo-ui.h | 5 +++-- examples/platform/silabs/display/lcd.cpp | 4 +--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/examples/platform/silabs/display/demo-ui.c b/examples/platform/silabs/display/demo-ui.c index a394bffe644cd4..e430e01ddb82dd 100644 --- a/examples/platform/silabs/display/demo-ui.c +++ b/examples/platform/silabs/display/demo-ui.c @@ -100,16 +100,18 @@ void demoUIInit(GLIB_Context_t * context) memcpy(&glibContext, context, sizeof(GLIB_Context_t)); } -EMSTATUS updateDisplay(void) +sl_status_t updateDisplay(void) { #if (defined(EFR32MG24) && defined(SL_WIFI)) sl_wfx_host_pre_lcd_spi_transfer(); #endif - EMSTATUS status = DMD_updateDisplay(); + sl_status_t status = DMD_updateDisplay(); #if (defined(EFR32MG24) && defined(SL_WIFI)) sl_wfx_host_post_lcd_spi_transfer(); #endif - return status; + if (status != DMD_OK) + return SL_STATUS_FAIL; + return SL_STATUS_OK; } void demoUIDisplayHeader(char * name) diff --git a/examples/platform/silabs/display/demo-ui.h b/examples/platform/silabs/display/demo-ui.h index 744db6a90b8e94..baf4902ef6184b 100644 --- a/examples/platform/silabs/display/demo-ui.h +++ b/examples/platform/silabs/display/demo-ui.h @@ -26,6 +26,7 @@ extern "C" { #endif #include "glib.h" +#include "sl_status.h" /**************************************************************************/ /** * DEMO UI uses the underlying DMD interface and the @@ -147,9 +148,9 @@ void demoUIClearMainScreen(uint8_t * name); * Clear the Lcd screen and display the main screen. * * @return - * Returns DMD_OK if successful, error otherwise. + * Returns SL_STATUS_OK if successful, error otherwise. *****************************************************************************/ -EMSTATUS updateDisplay(void); +sl_status_t updateDisplay(void); #ifdef __cplusplus } diff --git a/examples/platform/silabs/display/lcd.cpp b/examples/platform/silabs/display/lcd.cpp index 355b86c9b804b9..6a06be1c28f6c8 100644 --- a/examples/platform/silabs/display/lcd.cpp +++ b/examples/platform/silabs/display/lcd.cpp @@ -120,9 +120,7 @@ int SilabsLCD::DrawPixel(void * pContext, int32_t x, int32_t y) int SilabsLCD::Update(void) { - int status; - status = static_cast(updateDisplay()); - return status; + return updateDisplay(); } void SilabsLCD::WriteDemoUI(bool state) From 81a77329e83a9211eb7b74762345d5132929b5ee Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Thu, 1 Jun 2023 10:55:55 +0530 Subject: [PATCH 30/50] Adds checks for semaphore used for sync peripherals --- examples/platform/silabs/efr32/rs911x/hal/efx_spi.c | 7 +++++-- examples/platform/silabs/efr32/wf200/efr_spi.c | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index d42cd554860321..8153b1deacfab3 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -159,7 +159,11 @@ void rsi_hal_board_init(void) xSemaphoreGive(spiTransferLock); #if defined(EFR32MG24) - spi_sem_sync_hdl = xSemaphoreCreateBinaryStatic(&spi_sem_peripheral); + if (spi_sem_sync_hdl == NULL) + { + spi_sem_sync_hdl = xSemaphoreCreateBinaryStatic(&spi_sem_peripheral); + } + configASSERT(spi_sem_sync_hdl); xSemaphoreGive(spi_sem_sync_hdl); #endif /* EFR32MG24 */ @@ -185,7 +189,6 @@ void SPIDRV_ReInit(uint32_t baudrate) sl_status_t sl_wfx_host_spi_cs_assert(void) { - configASSERT(spi_sem_sync_hdl); if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) { return SL_STATUS_TIMEOUT; diff --git a/examples/platform/silabs/efr32/wf200/efr_spi.c b/examples/platform/silabs/efr32/wf200/efr_spi.c index a0ccbfffcc1f65..7293fcca3d19bf 100644 --- a/examples/platform/silabs/efr32/wf200/efr_spi.c +++ b/examples/platform/silabs/efr32/wf200/efr_spi.c @@ -114,7 +114,11 @@ sl_status_t sl_wfx_host_init_bus(void) xSemaphoreGive(spi_sem); #if defined(EFR32MG24) - spi_sem_sync_hdl = xSemaphoreCreateBinaryStatic(&spi_sem_peripheral); + if (spi_sem_sync_hdl == NULL) + { + spi_sem_sync_hdl = xSemaphoreCreateBinaryStatic(&spi_sem_peripheral); + } + configASSERT(spi_sem_sync_hdl); xSemaphoreGive(spi_sem_sync_hdl); #endif /* EFR32MG24 */ return SL_STATUS_OK; @@ -139,7 +143,6 @@ sl_status_t sl_wfx_host_deinit_bus(void) sl_status_t sl_wfx_host_spi_cs_assert() { #if defined(EFR32MG24) - configASSERT(spi_sem_sync_hdl); if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) { return SL_STATUS_TIMEOUT; From d041967377536dc2ab69884ee7af6db107aa526d Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Thu, 1 Jun 2023 10:56:30 +0530 Subject: [PATCH 31/50] Clean up of unreachable code due to portMAX_DELAY --- .../silabs/efr32/rs911x/hal/efx_spi.c | 20 +++--------- .../platform/silabs/efr32/wf200/efr_spi.c | 31 ++++--------------- 2 files changed, 10 insertions(+), 41 deletions(-) diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index 8153b1deacfab3..b5ec0a2527e4cc 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -189,10 +189,7 @@ void SPIDRV_ReInit(uint32_t baudrate) sl_status_t sl_wfx_host_spi_cs_assert(void) { - if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) - { - return SL_STATUS_TIMEOUT; - } + xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY); if (!spi_enabled) // Reduce SPIDRV_Init { @@ -228,10 +225,7 @@ void sl_wfx_host_spiflash_cs_deassert(void) void sl_wfx_host_pre_bootloader_spi_transfer(void) { - if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) - { - return; - } + xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY); if (spi_enabled) { SPIDRV_DeInit(SL_SPIDRV_HANDLE); @@ -263,10 +257,7 @@ void sl_wfx_host_post_bootloader_spi_transfer(void) void sl_wfx_host_pre_lcd_spi_transfer(void) { - if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) - { - return; - } + xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY); if (spi_enabled) { SPIDRV_DeInit(SL_SPIDRV_HANDLE); @@ -335,10 +326,7 @@ int16_t rsi_spi_transfer(uint8_t * tx_buf, uint8_t * rx_buf, uint16_t xlen, uint (void) mode; // currently not used; rsi_error_t rsiError = RSI_ERROR_NONE; - if (xSemaphoreTake(spiTransferLock, portMAX_DELAY) != pdTRUE) - { - return RSI_ERROR_SPI_BUSY; - } + xSemaphoreTake(spiTransferLock, portMAX_DELAY); // No other task should currently be waiting for the dma completion configASSERT(spiInitiatorTaskHandle == NULL); diff --git a/examples/platform/silabs/efr32/wf200/efr_spi.c b/examples/platform/silabs/efr32/wf200/efr_spi.c index 7293fcca3d19bf..889de8e289b4d8 100644 --- a/examples/platform/silabs/efr32/wf200/efr_spi.c +++ b/examples/platform/silabs/efr32/wf200/efr_spi.c @@ -143,10 +143,7 @@ sl_status_t sl_wfx_host_deinit_bus(void) sl_status_t sl_wfx_host_spi_cs_assert() { #if defined(EFR32MG24) - if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) - { - return SL_STATUS_TIMEOUT; - } + xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY); SPIDRV_ReInit(SL_SPIDRV_EXP_BITRATE_MULTIPLEXED); #endif /* EFR32MG24 */ GPIO_PinOutClear(SL_SPIDRV_EXP_CS_PORT, SL_SPIDRV_EXP_CS_PIN); @@ -267,11 +264,7 @@ sl_status_t sl_wfx_host_spi_transfer_no_cs_assert(sl_wfx_host_bus_transfer_type_ MY_USART->CMD = USART_CMD_CLEARRX | USART_CMD_CLEARTX; // Reset the semaphore configASSERT(spi_sem); - if (xSemaphoreTake(spi_sem, portMAX_DELAY) != pdTRUE) - { - return SL_STATUS_TIMEOUT; - } - + xSemaphoreTake(spi_sem, portMAX_DELAY); if (is_read) { receiveDMA(buffer, buffer_length); @@ -281,10 +274,7 @@ sl_status_t sl_wfx_host_spi_transfer_no_cs_assert(sl_wfx_host_bus_transfer_type_ transmitDMA(buffer, buffer_length); } // wait for dma_complete by using the same spi_semaphore - if (xSemaphoreTake(spi_sem, portMAX_DELAY) != pdTRUE) - { - return SL_STATUS_TIMEOUT; - } + xSemaphoreTake(spi_sem, portMAX_DELAY); xSemaphoreGive(spi_sem); } return SL_STATUS_OK; @@ -414,10 +404,7 @@ void sl_wfx_host_spiflash_cs_deassert(void) void sl_wfx_host_pre_bootloader_spi_transfer(void) { - if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) - { - return; - } + xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY); /* * Assert CS pin for EXT SPI Flash */ @@ -436,10 +423,7 @@ void sl_wfx_host_post_bootloader_spi_transfer(void) void sl_wfx_host_pre_lcd_spi_transfer(void) { - if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) - { - return; - } + xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY); SPIDRV_ReInit(SL_SPIDRV_LCD_BITRATE); /*LCD CS is handled as part of LCD gsdk*/ } @@ -460,10 +444,7 @@ void sl_wfx_host_pre_uart_transfer(void) } sl_wfx_disable_irq(); sl_wfx_host_disable_platform_interrupt(); - if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) - { - return; - } + xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY); GPIO_PinModeSet(gpioPortA, 8, gpioModePushPull, 1); } From 0396629c2a2816a7d08eaa8caf360824df8bc901 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Thu, 1 Jun 2023 10:57:43 +0530 Subject: [PATCH 32/50] Adds fix for comment alignment --- examples/platform/silabs/efr32/rs911x/hal/efx_spi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index b5ec0a2527e4cc..e492327e57c652 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -231,8 +231,8 @@ void sl_wfx_host_pre_bootloader_spi_transfer(void) SPIDRV_DeInit(SL_SPIDRV_HANDLE); spi_enabled = false; } - int32_t status = bootloader_init(); // bootloader_init takes care of SPIDRV_Init() + int32_t status = bootloader_init(); if (status != BOOTLOADER_OK) { SILABS_LOG("%s: bootloader_init failed with error code: %d", __func__, status); @@ -243,8 +243,8 @@ void sl_wfx_host_pre_bootloader_spi_transfer(void) void sl_wfx_host_post_bootloader_spi_transfer(void) { - int32_t status = bootloader_deinit(); // bootloader_deinit will do USART disable + int32_t status = bootloader_deinit(); if (status != BOOTLOADER_OK) { SILABS_LOG("%s: bootloader_deinit failed with error code: %d", __func__, status); @@ -263,8 +263,8 @@ void sl_wfx_host_pre_lcd_spi_transfer(void) SPIDRV_DeInit(SL_SPIDRV_HANDLE); spi_enabled = false; } - sl_memlcd_refresh(sl_memlcd_get()); // sl_memlcd_refresh takes care of SPIDRV_Init() + sl_memlcd_refresh(sl_memlcd_get()); } void sl_wfx_host_post_lcd_spi_transfer(void) From dcf6f028bfd8670f2dca00d96fc19d528e8c2b46 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Thu, 1 Jun 2023 11:03:54 +0530 Subject: [PATCH 33/50] Changes SPIDRV_ReInit to SPIDRV_SetBaudrate --- examples/platform/silabs/efr32/rs911x/hal/efx_spi.c | 2 +- examples/platform/silabs/efr32/spi_multiplex.h | 6 +++--- examples/platform/silabs/efr32/wf200/efr_spi.c | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index e492327e57c652..6590fe89bd4f83 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -177,7 +177,7 @@ void rsi_hal_board_init(void) #if defined(EFR32MG24) -void SPIDRV_ReInit(uint32_t baudrate) +void SPIDRV_SetBaudrate(uint32_t baudrate) { if (EUSART_BaudrateGet(MY_USART) == baudrate) { diff --git a/examples/platform/silabs/efr32/spi_multiplex.h b/examples/platform/silabs/efr32/spi_multiplex.h index 9b15912da7cfc7..ce67364f7b0e6b 100644 --- a/examples/platform/silabs/efr32/spi_multiplex.h +++ b/examples/platform/silabs/efr32/spi_multiplex.h @@ -60,13 +60,13 @@ extern SPIDRV_Handle_t sl_spidrv_exp_handle; #endif /**************************************************************************** - * @fn void SPIDRV_ReInit() + * @fn void SPIDRV_SetBaudrate() * @brief - * Re-Intializes SPI driver to required baudrate + * Sets the SPI driver to required baudrate * @param[in] None * @return returns void *****************************************************************************/ -void SPIDRV_ReInit(uint32_t); +void SPIDRV_SetBaudrate(uint32_t); #if defined(RS911X_WIFI) /**************************************************************************** diff --git a/examples/platform/silabs/efr32/wf200/efr_spi.c b/examples/platform/silabs/efr32/wf200/efr_spi.c index 889de8e289b4d8..f488125b30d076 100644 --- a/examples/platform/silabs/efr32/wf200/efr_spi.c +++ b/examples/platform/silabs/efr32/wf200/efr_spi.c @@ -144,7 +144,7 @@ sl_status_t sl_wfx_host_spi_cs_assert() { #if defined(EFR32MG24) xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY); - SPIDRV_ReInit(SL_SPIDRV_EXP_BITRATE_MULTIPLEXED); + SPIDRV_SetBaudrate(SL_SPIDRV_EXP_BITRATE_MULTIPLEXED); #endif /* EFR32MG24 */ GPIO_PinOutClear(SL_SPIDRV_EXP_CS_PORT, SL_SPIDRV_EXP_CS_PIN); return SL_STATUS_OK; @@ -373,7 +373,7 @@ void sl_wfx_host_gpio_init(void) #if defined(EFR32MG24) -void SPIDRV_ReInit(uint32_t baudrate) +void SPIDRV_SetBaudrate(uint32_t baudrate) { if (USART_BaudrateGet(MY_USART) == baudrate) { @@ -408,7 +408,7 @@ void sl_wfx_host_pre_bootloader_spi_transfer(void) /* * Assert CS pin for EXT SPI Flash */ - SPIDRV_ReInit(SL_SPIDRV_MX25_FLASH_BITRATE); + SPIDRV_SetBaudrate(SL_SPIDRV_MX25_FLASH_BITRATE); sl_wfx_host_spiflash_cs_assert(); } @@ -424,7 +424,7 @@ void sl_wfx_host_post_bootloader_spi_transfer(void) void sl_wfx_host_pre_lcd_spi_transfer(void) { xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY); - SPIDRV_ReInit(SL_SPIDRV_LCD_BITRATE); + SPIDRV_SetBaudrate(SL_SPIDRV_LCD_BITRATE); /*LCD CS is handled as part of LCD gsdk*/ } From 81cfce5e627a72f90de3211d645e971f7e48f96e Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Thu, 1 Jun 2023 11:06:04 +0530 Subject: [PATCH 34/50] Removes unused error variable --- src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp b/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp index 66283c1d511fe3..cfdc66c0e7450d 100644 --- a/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp +++ b/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp @@ -247,7 +247,6 @@ CHIP_ERROR ConnectivityManagerImpl::_RequestSEDActiveMode(bool onOff, bool delay void ConnectivityManagerImpl::DriveStationState() { - CHIP_ERROR err = CHIP_NO_ERROR; sl_status_t serr; bool stationConnected; @@ -260,8 +259,7 @@ void ConnectivityManagerImpl::DriveStationState() // Ensure that the WFX is started. if ((serr = wfx_wifi_start()) != SL_STATUS_OK) { - err = CHIP_ERROR_INTERNAL; - ChipLogError(DeviceLayer, "wfx_wifi_start() failed: %s", chip::ErrorStr(err)); + ChipLogError(DeviceLayer, "wfx_wifi_start() failed: %x", serr); return; } // Ensure that station mode is enabled in the WFX WiFi layer. From 16550a757ede4a81af80fbfb7c09595e603cb7c9 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Thu, 1 Jun 2023 11:26:28 +0530 Subject: [PATCH 35/50] Clean up logs --- .../silabs/efr32/OTAImageProcessorImpl.cpp | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp index 1c990572fe91f7..9361e7ef617aab 100644 --- a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp +++ b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp @@ -71,7 +71,7 @@ CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & block) { if ((block.data() == nullptr) || block.empty()) { - ChipLogError(SoftwareUpdate, "%s: block is empty", __func__); + ChipLogError(SoftwareUpdate, "block is empty"); return CHIP_ERROR_INVALID_ARGUMENT; } @@ -92,7 +92,6 @@ bool OTAImageProcessorImpl::IsFirstImageRun() OTARequestorInterface * requestor = chip::GetRequestorInstance(); if (requestor == nullptr) { - ChipLogError(SoftwareUpdate, "%s: requestor is null", __func__); return false; } @@ -104,7 +103,7 @@ CHIP_ERROR OTAImageProcessorImpl::ConfirmCurrentImage() OTARequestorInterface * requestor = chip::GetRequestorInstance(); if (requestor == nullptr) { - ChipLogError(SoftwareUpdate, "%s: requestor is null", __func__); + ChipLogError(SoftwareUpdate, "requestor is null"); return CHIP_ERROR_INTERNAL; } @@ -128,16 +127,16 @@ void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context) if (imageProcessor == nullptr) { - ChipLogError(SoftwareUpdate, "%s: imageProcessor context is null", __func__); + ChipLogError(SoftwareUpdate, "imageProcessor context is null"); return; } else if (imageProcessor->mDownloader == nullptr) { - ChipLogError(SoftwareUpdate, "%s: mDownloader is null", __func__); + ChipLogError(SoftwareUpdate, "mDownloader is null"); return; } - ChipLogProgress(SoftwareUpdate, "%s: started", __func__); + ChipLogProgress(SoftwareUpdate, "HandlePrepareDownload: started"); CORE_CRITICAL_SECTION(bootloader_init();) mSlotId = 0; // Single slot until we support multiple images @@ -158,7 +157,7 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context) auto * imageProcessor = reinterpret_cast(context); if (imageProcessor == nullptr) { - ChipLogError(SoftwareUpdate, "%s: imageProcessor context is null", __func__); + ChipLogError(SoftwareUpdate, "imageProcessor context is null"); return; } @@ -182,7 +181,7 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context) #endif if (err) { - ChipLogError(SoftwareUpdate, "%s: bootloader_eraseWriteStorage() error %ld", __func__, err); + ChipLogError(SoftwareUpdate, "bootloader_eraseWriteStorage() error: %ld", err); imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); return; } @@ -197,7 +196,7 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) { uint32_t err = SL_BOOTLOADER_OK; - ChipLogProgress(SoftwareUpdate, "%s: started", __func__); + ChipLogProgress(SoftwareUpdate, "HandleApply: started"); // Force KVS to store pending keys such as data from StoreCurrentUpdateInfo() chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().ForceKeyMapSave(); @@ -207,7 +206,7 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) CORE_CRITICAL_SECTION(err = bootloader_verifyImage(mSlotId, NULL);) if (err != SL_BOOTLOADER_OK) { - ChipLogError(SoftwareUpdate, "%s: bootloader_verifyImage() error %ld", __func__, err); + ChipLogError(SoftwareUpdate, "bootloader_verifyImage() error: %ld", err); // Call the OTARequestor API to reset the state GetRequestorInstance()->CancelImageUpdate(); #if (defined(EFR32MG24) && defined(SL_WIFI)) @@ -219,7 +218,7 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) CORE_CRITICAL_SECTION(err = bootloader_setImageToBootload(mSlotId);) if (err != SL_BOOTLOADER_OK) { - ChipLogError(SoftwareUpdate, "%s: bootloader_setImageToBootload() error %ld", __func__, err); + ChipLogError(SoftwareUpdate, "bootloader_setImageToBootload() error: %ld", err); // Call the OTARequestor API to reset the state GetRequestorInstance()->CancelImageUpdate(); #if (defined(EFR32MG24) && defined(SL_WIFI)) @@ -240,7 +239,7 @@ void OTAImageProcessorImpl::HandleAbort(intptr_t context) auto * imageProcessor = reinterpret_cast(context); if (imageProcessor == nullptr) { - ChipLogError(SoftwareUpdate, "%s: imageProcessor context is null", __func__); + ChipLogError(SoftwareUpdate, "imageProcessor context is null"); return; } // Not clearing the image storage area as it is done during each write @@ -253,12 +252,12 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context) auto * imageProcessor = reinterpret_cast(context); if (imageProcessor == nullptr) { - ChipLogError(SoftwareUpdate, "%s: imageProcessor context is null", __func__); + ChipLogError(SoftwareUpdate, "imageProcessor context is null"); return; } else if (imageProcessor->mDownloader == nullptr) { - ChipLogError(SoftwareUpdate, "%s: mDownloader is null", __func__); + ChipLogError(SoftwareUpdate, "mDownloader is null"); return; } @@ -267,7 +266,7 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context) if (chip_error != CHIP_NO_ERROR) { - ChipLogError(SoftwareUpdate, "Matter image header parser error %s", chip::ErrorStr(chip_error)); + ChipLogError(SoftwareUpdate, "Matter image header parser error: %s", chip::ErrorStr(chip_error)); imageProcessor->mDownloader->EndDownload(CHIP_ERROR_INVALID_FILE_IDENTIFIER); return; } @@ -292,7 +291,7 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context) #endif if (err) { - ChipLogError(SoftwareUpdate, "%s: bootloader_eraseWriteStorage() error %ld", __func__, err); + ChipLogError(SoftwareUpdate, "bootloader_eraseWriteStorage() error: %ld", err); imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); return; } @@ -340,7 +339,7 @@ CHIP_ERROR OTAImageProcessorImpl::SetBlock(ByteSpan & block) mBlock = MutableByteSpan(static_cast(chip::Platform::MemoryAlloc(block.size())), block.size()); if (mBlock.data() == nullptr) { - ChipLogError(SoftwareUpdate, "%s: mBlock is null", __func__); + ChipLogError(SoftwareUpdate, "mBlock is null"); return CHIP_ERROR_NO_MEMORY; } } From 79ad0c91ba6578420ad8aaa6c54f7f7a6a70c96f Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Thu, 1 Jun 2023 11:37:31 +0530 Subject: [PATCH 36/50] Clean up of logs --- examples/platform/silabs/efr32/rs911x/hal/efx_spi.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index 6590fe89bd4f83..a0210b3087fc3b 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -235,7 +235,7 @@ void sl_wfx_host_pre_bootloader_spi_transfer(void) int32_t status = bootloader_init(); if (status != BOOTLOADER_OK) { - SILABS_LOG("%s: bootloader_init failed with error code: %d", __func__, status); + SILABS_LOG("bootloader_init error: %x", status); return; } sl_wfx_host_spiflash_cs_assert(); @@ -247,7 +247,7 @@ void sl_wfx_host_post_bootloader_spi_transfer(void) int32_t status = bootloader_deinit(); if (status != BOOTLOADER_OK) { - SILABS_LOG("%s: bootloader_deinit failed with error code: %d", __func__, status); + SILABS_LOG("bootloader_deinit error: %x", status); return; } GPIO->USARTROUTE[SL_MX25_FLASH_SHUTDOWN_PERIPHERAL_NO].ROUTEEN = 0; @@ -319,7 +319,6 @@ int16_t rsi_spi_transfer(uint8_t * tx_buf, uint8_t * rx_buf, uint16_t xlen, uint */ if (xlen <= MIN_XLEN || (tx_buf == NULL && rx_buf == NULL)) { - SILABS_LOG("%s error.", __func__); return RSI_ERROR_INVALID_PARAM; } @@ -356,7 +355,7 @@ int16_t rsi_spi_transfer(uint8_t * tx_buf, uint8_t * rx_buf, uint16_t xlen, uint int itemsTransferred = 0; int itemsRemaining = 0; SPIDRV_GetTransferStatus(SL_SPIDRV_HANDLE, &itemsTransferred, &itemsRemaining); - SILABS_LOG("%s: timed out %d/%d (rx%x rx%x)", __func__, itemsTransferred, itemsRemaining, (uint32_t) tx_buf, + SILABS_LOG("ERR: SPI timed out %d/%d (rx%x rx%x)", itemsTransferred, itemsRemaining, (uint32_t) tx_buf, (uint32_t) rx_buf); SPIDRV_AbortTransfer(SL_SPIDRV_HANDLE); @@ -365,7 +364,7 @@ int16_t rsi_spi_transfer(uint8_t * tx_buf, uint8_t * rx_buf, uint16_t xlen, uint } else { - SILABS_LOG("%s: failed with err:%x (tx%x rx%x)", __func__, spiError, (uint32_t) tx_buf, (uint32_t) rx_buf); + SILABS_LOG("ERR: SPI failed with error:%x (tx%x rx%x)", spiError, (uint32_t) tx_buf, (uint32_t) rx_buf); rsiError = RSI_ERROR_SPI_FAIL; spiInitiatorTaskHandle = NULL; // SPI operation failed. No notification to received. } From 4157d56c653c70aa4076669507e63b0a344fe3e9 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Thu, 1 Jun 2023 11:39:59 +0530 Subject: [PATCH 37/50] Replace magic number --- examples/platform/silabs/efr32/rs911x/hal/efx_spi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index a0210b3087fc3b..b5eac7c83ab9c4 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -208,7 +208,7 @@ sl_status_t sl_wfx_host_spi_cs_deassert(void) spi_enabled = false; } GPIO_PinOutSet(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN); - GPIO->EUSARTROUTE[SL_SPIDRV_EUSART_EXP_PERIPHERAL_NO].ROUTEEN = 0; + GPIO->EUSARTROUTE[SL_SPIDRV_EUSART_EXP_PERIPHERAL_NO].ROUTEEN = PIN_OUT_CLEAR; xSemaphoreGive(spi_sem_sync_hdl); return SL_STATUS_OK; } @@ -250,7 +250,7 @@ void sl_wfx_host_post_bootloader_spi_transfer(void) SILABS_LOG("bootloader_deinit error: %x", status); return; } - GPIO->USARTROUTE[SL_MX25_FLASH_SHUTDOWN_PERIPHERAL_NO].ROUTEEN = 0; + GPIO->USARTROUTE[SL_MX25_FLASH_SHUTDOWN_PERIPHERAL_NO].ROUTEEN = PIN_OUT_CLEAR; sl_wfx_host_spiflash_cs_deassert(); xSemaphoreGive(spi_sem_sync_hdl); } @@ -271,7 +271,7 @@ void sl_wfx_host_post_lcd_spi_transfer(void) { USART_Enable(SL_MEMLCD_SPI_PERIPHERAL, usartDisable); CMU_ClockEnable(SPI_CLOCK(SL_MEMLCD_SPI_PERIPHERAL_NO), false); - GPIO->USARTROUTE[SL_MEMLCD_SPI_PERIPHERAL_NO].ROUTEEN = 0; + GPIO->USARTROUTE[SL_MEMLCD_SPI_PERIPHERAL_NO].ROUTEEN = PIN_OUT_CLEAR; xSemaphoreGive(spi_sem_sync_hdl); } From f41a3290832485bf37a6ab298aabedf810f6a2a0 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Mon, 5 Jun 2023 11:30:06 +0530 Subject: [PATCH 38/50] Added tickets for tracking additional rework --- examples/platform/silabs/efr32/rs911x/hal/efx_spi.c | 1 + examples/platform/silabs/efr32/spi_multiplex.h | 6 ++++-- src/platform/silabs/efr32/OTAImageProcessorImpl.cpp | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index b5eac7c83ab9c4..3225724b2dc89a 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -223,6 +223,7 @@ void sl_wfx_host_spiflash_cs_deassert(void) GPIO_PinOutSet(SL_MX25_FLASH_SHUTDOWN_CS_PORT, SL_MX25_FLASH_SHUTDOWN_CS_PIN); } +// TODO: (MATTER-1904) Add logic to return from function and implement error checking void sl_wfx_host_pre_bootloader_spi_transfer(void) { xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY); diff --git a/examples/platform/silabs/efr32/spi_multiplex.h b/examples/platform/silabs/efr32/spi_multiplex.h index ce67364f7b0e6b..b3d739e5862755 100644 --- a/examples/platform/silabs/efr32/spi_multiplex.h +++ b/examples/platform/silabs/efr32/spi_multiplex.h @@ -24,7 +24,7 @@ extern "C" { #include "FreeRTOS.h" #include "semphr.h" #include "sl_mx25_flash_shutdown_usart_config.h" -#if (defined(EFR32MG24) && defined(WF200_WIFI)) +#if (defined(EFR32MG24) && defined(WF200_WIFI)) // TODO: (MATTER-1905) clean up of MACROs #include "sl_spidrv_exp_config.h" #endif /* EFR32MG24 && WF200_WIFI */ #if (defined(EFR32MG24) && defined(RS911X_WIFI)) @@ -37,13 +37,14 @@ extern "C" { #include "spidrv.h" #ifdef WF200_WIFI -// TODO: Investigate why using SL_SPIDRV_EXP_BITRATE is causing WF200 init failure +// TODO: (MATTER-1906) Investigate why using SL_SPIDRV_EXP_BITRATE is causing WF200 init failure // REF: sl_spidrv_exp_config.h #define SL_SPIDRV_EXP_BITRATE_MULTIPLEXED 10000000 #else #define SL_SPIDRV_EXP_BITRATE_MULTIPLEXED SL_SPIDRV_EUSART_EXP_BITRATE #endif /* WF200_WIFI */ +// TODO: (MATTER-1907) Replace with GSDK MACROs #define SL_SPIDRV_LCD_BITRATE 1100000 #define SL_SPIDRV_MX25_FLASH_BITRATE 16000000 #define SL_SPIDRV_UART_CONSOLE_BITRATE 16000000 @@ -52,6 +53,7 @@ extern "C" { #define SL_SPIDRV_FRAME_LENGTH SL_SPIDRV_EUSART_EXP_FRAME_LENGTH extern SPIDRV_Handle_t sl_spidrv_eusart_exp_handle; #define SL_SPIDRV_HANDLE sl_spidrv_eusart_exp_handle +// TODO: (MATTER-1907) Replace use of extern variable extern SPIDRV_Init_t sl_spidrv_eusart_init_exp; #elif WF200_WIFI #define SL_SPIDRV_FRAME_LENGTH SL_SPIDRV_EXP_FRAME_LENGTH diff --git a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp index 9361e7ef617aab..1da4316de103e1 100644 --- a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp +++ b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp @@ -25,7 +25,7 @@ extern "C" { #include "em_bus.h" // For CORE_CRITICAL_SECTION #if (defined(EFR32MG24) && defined(SL_WIFI)) #include "spi_multiplex.h" -#ifdef WF200_WIFI +#ifdef WF200_WIFI // TODO: (MATTER-1905) clean up of MACROs #include "sl_wfx_host_api.h" #endif #endif From e35ebfe483cdef166dbbbc40324b0ff8edd7a43c Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Mon, 5 Jun 2023 12:21:30 +0530 Subject: [PATCH 39/50] Clean up additional logs --- src/platform/silabs/efr32/OTAImageProcessorImpl.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp index 1da4316de103e1..8ba00c364ab204 100644 --- a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp +++ b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp @@ -71,7 +71,6 @@ CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & block) { if ((block.data() == nullptr) || block.empty()) { - ChipLogError(SoftwareUpdate, "block is empty"); return CHIP_ERROR_INVALID_ARGUMENT; } @@ -103,7 +102,6 @@ CHIP_ERROR OTAImageProcessorImpl::ConfirmCurrentImage() OTARequestorInterface * requestor = chip::GetRequestorInstance(); if (requestor == nullptr) { - ChipLogError(SoftwareUpdate, "requestor is null"); return CHIP_ERROR_INTERNAL; } @@ -339,7 +337,6 @@ CHIP_ERROR OTAImageProcessorImpl::SetBlock(ByteSpan & block) mBlock = MutableByteSpan(static_cast(chip::Platform::MemoryAlloc(block.size())), block.size()); if (mBlock.data() == nullptr) { - ChipLogError(SoftwareUpdate, "mBlock is null"); return CHIP_ERROR_NO_MEMORY; } } From 6fa303b319b7178c523c86961df352d5e8fea879 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Thu, 8 Jun 2023 19:37:21 +0530 Subject: [PATCH 40/50] Adds fix for print statements --- src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp b/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp index cfdc66c0e7450d..ae3bb69ea4d2b7 100644 --- a/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp +++ b/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp @@ -259,7 +259,7 @@ void ConnectivityManagerImpl::DriveStationState() // Ensure that the WFX is started. if ((serr = wfx_wifi_start()) != SL_STATUS_OK) { - ChipLogError(DeviceLayer, "wfx_wifi_start() failed: %x", serr); + ChipLogError(DeviceLayer, "wfx_wifi_start() failed: %lx", serr); return; } // Ensure that station mode is enabled in the WFX WiFi layer. @@ -294,7 +294,7 @@ void ConnectivityManagerImpl::DriveStationState() serr = wfx_sta_discon(); if (serr != SL_STATUS_OK) { - ChipLogError(DeviceLayer, "wfx_wifi_disconnect() failed: %s", chip::ErrorStr(err)); + ChipLogError(DeviceLayer, "wfx_wifi_disconnect() failed: %lx", serr); } SuccessOrExit(serr); From d015a24640e301311036734f8225adaf40fde21b Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Thu, 8 Jun 2023 19:44:54 +0530 Subject: [PATCH 41/50] Adds fix for MACRO --- examples/platform/silabs/efr32/rs911x/hal/efx_spi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index 3225724b2dc89a..b69b663341f40e 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -208,7 +208,7 @@ sl_status_t sl_wfx_host_spi_cs_deassert(void) spi_enabled = false; } GPIO_PinOutSet(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN); - GPIO->EUSARTROUTE[SL_SPIDRV_EUSART_EXP_PERIPHERAL_NO].ROUTEEN = PIN_OUT_CLEAR; + GPIO->EUSARTROUTE[SL_SPIDRV_EUSART_EXP_PERIPHERAL_NO].ROUTEEN = PINOUT_CLEAR; xSemaphoreGive(spi_sem_sync_hdl); return SL_STATUS_OK; } @@ -251,7 +251,7 @@ void sl_wfx_host_post_bootloader_spi_transfer(void) SILABS_LOG("bootloader_deinit error: %x", status); return; } - GPIO->USARTROUTE[SL_MX25_FLASH_SHUTDOWN_PERIPHERAL_NO].ROUTEEN = PIN_OUT_CLEAR; + GPIO->USARTROUTE[SL_MX25_FLASH_SHUTDOWN_PERIPHERAL_NO].ROUTEEN = PINOUT_CLEAR; sl_wfx_host_spiflash_cs_deassert(); xSemaphoreGive(spi_sem_sync_hdl); } @@ -272,7 +272,7 @@ void sl_wfx_host_post_lcd_spi_transfer(void) { USART_Enable(SL_MEMLCD_SPI_PERIPHERAL, usartDisable); CMU_ClockEnable(SPI_CLOCK(SL_MEMLCD_SPI_PERIPHERAL_NO), false); - GPIO->USARTROUTE[SL_MEMLCD_SPI_PERIPHERAL_NO].ROUTEEN = PIN_OUT_CLEAR; + GPIO->USARTROUTE[SL_MEMLCD_SPI_PERIPHERAL_NO].ROUTEEN = PINOUT_CLEAR; xSemaphoreGive(spi_sem_sync_hdl); } From 8740a886727cbdcec03334ca62814c98e152665c Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Mon, 19 Jun 2023 18:35:20 +0530 Subject: [PATCH 42/50] Adds fix for MATTER-1904 --- .../silabs/efr32/rs911x/hal/efx_spi.c | 53 +++++++++++++----- .../platform/silabs/efr32/spi_multiplex.h | 48 ++++++++-------- .../platform/silabs/efr32/wf200/efr_spi.c | 28 ++++++---- .../silabs/efr32/OTAImageProcessorImpl.cpp | 56 ++++++++++++++++--- 4 files changed, 129 insertions(+), 56 deletions(-) diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index b69b663341f40e..07bd01a65bea54 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -193,7 +193,11 @@ sl_status_t sl_wfx_host_spi_cs_assert(void) if (!spi_enabled) // Reduce SPIDRV_Init { - SPIDRV_Init(SL_SPIDRV_HANDLE, &sl_spidrv_eusart_init_exp); + if (ECODE_OK != SPIDRV_Init(SL_SPIDRV_HANDLE, &sl_spidrv_eusart_init_exp)) + { + xSemaphoreGive(spi_sem_sync_hdl); + return SL_STATUS_FAIL; + } spi_enabled = true; } GPIO_PinOutClear(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN); @@ -204,7 +208,11 @@ sl_status_t sl_wfx_host_spi_cs_deassert(void) { if (spi_enabled) { - SPIDRV_DeInit(SL_SPIDRV_HANDLE); + if (ECODE_OK != SPIDRV_DeInit(SL_SPIDRV_HANDLE)) + { + xSemaphoreGive(spi_sem_sync_hdl); + return SL_STATUS_FAIL; + } spi_enabled = false; } GPIO_PinOutSet(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN); @@ -213,23 +221,28 @@ sl_status_t sl_wfx_host_spi_cs_deassert(void) return SL_STATUS_OK; } -void sl_wfx_host_spiflash_cs_assert(void) +sl_status_t sl_wfx_host_spiflash_cs_assert(void) { GPIO_PinOutClear(SL_MX25_FLASH_SHUTDOWN_CS_PORT, SL_MX25_FLASH_SHUTDOWN_CS_PIN); + return SL_STATUS_OK; } -void sl_wfx_host_spiflash_cs_deassert(void) +sl_status_t sl_wfx_host_spiflash_cs_deassert(void) { GPIO_PinOutSet(SL_MX25_FLASH_SHUTDOWN_CS_PORT, SL_MX25_FLASH_SHUTDOWN_CS_PIN); + return SL_STATUS_OK; } -// TODO: (MATTER-1904) Add logic to return from function and implement error checking -void sl_wfx_host_pre_bootloader_spi_transfer(void) +sl_status_t sl_wfx_host_pre_bootloader_spi_transfer(void) { xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY); if (spi_enabled) { - SPIDRV_DeInit(SL_SPIDRV_HANDLE); + if (ECODE_OK != SPIDRV_DeInit(SL_SPIDRV_HANDLE)) + { + xSemaphoreGive(spi_sem_sync_hdl); + return SL_STATUS_FAIL; + } spi_enabled = false; } // bootloader_init takes care of SPIDRV_Init() @@ -237,38 +250,50 @@ void sl_wfx_host_pre_bootloader_spi_transfer(void) if (status != BOOTLOADER_OK) { SILABS_LOG("bootloader_init error: %x", status); - return; + xSemaphoreGive(spi_sem_sync_hdl); + return SL_STATUS_FAIL; } sl_wfx_host_spiflash_cs_assert(); + return SL_STATUS_OK; } -void sl_wfx_host_post_bootloader_spi_transfer(void) +sl_status_t sl_wfx_host_post_bootloader_spi_transfer(void) { // bootloader_deinit will do USART disable int32_t status = bootloader_deinit(); if (status != BOOTLOADER_OK) { SILABS_LOG("bootloader_deinit error: %x", status); - return; + xSemaphoreGive(spi_sem_sync_hdl); + return SL_STATUS_FAIL; } GPIO->USARTROUTE[SL_MX25_FLASH_SHUTDOWN_PERIPHERAL_NO].ROUTEEN = PINOUT_CLEAR; sl_wfx_host_spiflash_cs_deassert(); xSemaphoreGive(spi_sem_sync_hdl); } -void sl_wfx_host_pre_lcd_spi_transfer(void) +sl_status_t sl_wfx_host_pre_lcd_spi_transfer(void) { xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY); if (spi_enabled) { - SPIDRV_DeInit(SL_SPIDRV_HANDLE); + if (ECODE_OK != SPIDRV_DeInit(SL_SPIDRV_HANDLE)) + { + xSemaphoreGive(spi_sem_sync_hdl); + return SL_STATUS_FAIL; + } spi_enabled = false; } // sl_memlcd_refresh takes care of SPIDRV_Init() - sl_memlcd_refresh(sl_memlcd_get()); + if(SL_STATUS_OK != sl_memlcd_refresh(sl_memlcd_get()) + { + xSemaphoreGive(spi_sem_sync_hdl); + return SL_STATUS_FAIL; + } + return SL_STATUS_OK; } -void sl_wfx_host_post_lcd_spi_transfer(void) +sl_status_t sl_wfx_host_post_lcd_spi_transfer(void) { USART_Enable(SL_MEMLCD_SPI_PERIPHERAL, usartDisable); CMU_ClockEnable(SPI_CLOCK(SL_MEMLCD_SPI_PERIPHERAL_NO), false); diff --git a/examples/platform/silabs/efr32/spi_multiplex.h b/examples/platform/silabs/efr32/spi_multiplex.h index b3d739e5862755..630eb4b2535423 100644 --- a/examples/platform/silabs/efr32/spi_multiplex.h +++ b/examples/platform/silabs/efr32/spi_multiplex.h @@ -91,77 +91,77 @@ sl_status_t sl_wfx_host_spi_cs_deassert(void); #endif /* RS911X_WIFI */ /**************************************************************************** - * @fn void sl_wfx_host_spiflash_cs_assert() + * @fn sl_status_t sl_wfx_host_spiflash_cs_assert() * @brief * Assert SPI flash chip select. * @param[in] None - * @return returns void + * @return returns SL_STATUS_OK *****************************************************************************/ -void sl_wfx_host_spiflash_cs_assert(void); +sl_status_t sl_wfx_host_spiflash_cs_assert(void); /**************************************************************************** - * @fn void sl_wfx_host_spiflash_cs_deassert() + * @fn sl_status_t sl_wfx_host_spiflash_cs_deassert() * @brief * De-Assert SPI flash chip select. * @param[in] None - * @return returns void + * @return returns SL_STATUS_OK *****************************************************************************/ -void sl_wfx_host_spiflash_cs_deassert(void); +sl_status_t sl_wfx_host_spiflash_cs_deassert(void); /**************************************************************************** - * @fn void sl_wfx_host_pre_bootloader_spi_transfer() + * @fn sl_status_t sl_wfx_host_pre_bootloader_spi_transfer() * @brief * Take a semaphore and controlling CS pin for EXP header and SPI flash * @param[in] None - * @return returns void + * @return SL_STATUS_OK *****************************************************************************/ -void sl_wfx_host_pre_bootloader_spi_transfer(void); +sl_status_t sl_wfx_host_pre_bootloader_spi_transfer(void); /**************************************************************************** - * @fn void sl_wfx_host_post_bootloader_spi_transfer() + * @fn sl_status_t sl_wfx_host_post_bootloader_spi_transfer() * @brief * De-Assert EXT SPI flash CS pin and release semaphore * @param[in] None - * @return returns void + * @return SL_STATUS_OK *****************************************************************************/ -void sl_wfx_host_post_bootloader_spi_transfer(void); +sl_status_t sl_wfx_host_post_bootloader_spi_transfer(void); /**************************************************************************** - * @fn void sl_wfx_host_pre_lcd_spi_transfer() + * @fn sl_status_t sl_wfx_host_pre_lcd_spi_transfer() * @brief * Take a semaphore and setting LCD baudrate * @param[in] None - * @return returns void + * @return SL_STATUS_OK *****************************************************************************/ -void sl_wfx_host_pre_lcd_spi_transfer(void); +sl_status_t sl_wfx_host_pre_lcd_spi_transfer(void); /**************************************************************************** - * @fn void sl_wfx_host_post_lcd_spi_transfer() + * @fn sl_status_t sl_wfx_host_post_lcd_spi_transfer() * @brief * Release semaphore * @param[in] None - * @return returns void + * @return SL_STATUS_OK *****************************************************************************/ -void sl_wfx_host_post_lcd_spi_transfer(void); +sl_status_t sl_wfx_host_post_lcd_spi_transfer(void); #if defined(WF200_WIFI) /**************************************************************************** - * @fn void sl_wfx_host_pre_uart_transfer() + * @fn sl_status_t sl_wfx_host_pre_uart_transfer() * @brief * Take a semaphore and setting GPIO, disable IRQ * @param[in] None - * @return returns void + * @return SL_STATUS_OK *****************************************************************************/ -void sl_wfx_host_pre_uart_transfer(void); +sl_status_t sl_wfx_host_pre_uart_transfer(void); /**************************************************************************** - * @fn void sl_wfx_host_post_uart_transfer() + * @fn sl_status_t sl_wfx_host_post_uart_transfer() * @brief * Reset GPIO, enabled IRQ, release semaphore * @param[in] None - * @return returns void + * @return SL_STATUS_OK *****************************************************************************/ -void sl_wfx_host_post_uart_transfer(void); +sl_status_t sl_wfx_host_post_uart_transfer(void); #endif /* WF200_WIFI */ #ifdef __cplusplus diff --git a/examples/platform/silabs/efr32/wf200/efr_spi.c b/examples/platform/silabs/efr32/wf200/efr_spi.c index f488125b30d076..f01069f80d6f28 100644 --- a/examples/platform/silabs/efr32/wf200/efr_spi.c +++ b/examples/platform/silabs/efr32/wf200/efr_spi.c @@ -392,17 +392,19 @@ void SPIDRV_SetBaudrate(uint32_t baudrate) USART_InitSync(MY_USART, &usartInit); } -void sl_wfx_host_spiflash_cs_assert(void) +sl_status_t sl_wfx_host_spiflash_cs_assert(void) { GPIO_PinOutClear(SL_MX25_FLASH_SHUTDOWN_CS_PORT, SL_MX25_FLASH_SHUTDOWN_CS_PIN); + return SL_STATUS_OK; } -void sl_wfx_host_spiflash_cs_deassert(void) +sl_status_t sl_wfx_host_spiflash_cs_deassert(void) { GPIO_PinOutSet(SL_MX25_FLASH_SHUTDOWN_CS_PORT, SL_MX25_FLASH_SHUTDOWN_CS_PIN); + return SL_STATUS_OK; } -void sl_wfx_host_pre_bootloader_spi_transfer(void) +sl_status_t sl_wfx_host_pre_bootloader_spi_transfer(void) { xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY); /* @@ -410,53 +412,59 @@ void sl_wfx_host_pre_bootloader_spi_transfer(void) */ SPIDRV_SetBaudrate(SL_SPIDRV_MX25_FLASH_BITRATE); sl_wfx_host_spiflash_cs_assert(); + return SL_STATUS_OK; } -void sl_wfx_host_post_bootloader_spi_transfer(void) +sl_status_t sl_wfx_host_post_bootloader_spi_transfer(void) { /* * De-Assert CS pin for EXT SPI Flash */ sl_wfx_host_spiflash_cs_deassert(); xSemaphoreGive(spi_sem_sync_hdl); + return SL_STATUS_OK; } -void sl_wfx_host_pre_lcd_spi_transfer(void) +sl_status_t sl_wfx_host_pre_lcd_spi_transfer(void) { xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY); SPIDRV_SetBaudrate(SL_SPIDRV_LCD_BITRATE); /*LCD CS is handled as part of LCD gsdk*/ + return SL_STATUS_OK; } -void sl_wfx_host_post_lcd_spi_transfer(void) +sl_status_t sl_wfx_host_post_lcd_spi_transfer(void) { xSemaphoreGive(spi_sem_sync_hdl); + return SL_STATUS_OK; } -void sl_wfx_host_pre_uart_transfer(void) +sl_status_t sl_wfx_host_pre_uart_transfer(void) { if (spi_sem_sync_hdl == NULL) { // UART is initialized before host SPI interface // spi_sem_sync_hdl will not be initalized during execution GPIO_PinModeSet(gpioPortA, 8, gpioModePushPull, 1); - return; + return SL_STATUS_OK; } sl_wfx_disable_irq(); sl_wfx_host_disable_platform_interrupt(); xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY); GPIO_PinModeSet(gpioPortA, 8, gpioModePushPull, 1); + return SL_STATUS_OK; } -void sl_wfx_host_post_uart_transfer(void) +sl_status_t sl_wfx_host_post_uart_transfer(void) { if (spi_sem_sync_hdl == NULL) { - return; + return SL_STATUS_OK; } GPIO_PinModeSet(gpioPortA, 8, gpioModeInputPull, 1); xSemaphoreGive(spi_sem_sync_hdl); sl_wfx_host_enable_platform_interrupt(); sl_wfx_enable_irq(); + return SL_STATUS_OK; } #endif /* EFR32MG24 */ diff --git a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp index 8ba00c364ab204..85118f9559ac1c 100644 --- a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp +++ b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp @@ -171,11 +171,21 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context) writeBufOffset++; } #if (defined(EFR32MG24) && defined(SL_WIFI)) - sl_wfx_host_pre_bootloader_spi_transfer(); + err = sl_wfx_host_pre_bootloader_spi_transfer(); + if (err != SL_STATUS_OK) + { + ChipLogError(SoftwareUpdate, "sl_wfx_host_pre_bootloader_spi_transfer() error: %ld", err); + return; + } #endif CORE_CRITICAL_SECTION(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, kAlignmentBytes);) #if (defined(EFR32MG24) && defined(SL_WIFI)) - sl_wfx_host_post_bootloader_spi_transfer(); + err = sl_wfx_host_post_bootloader_spi_transfer(); + if (err != SL_STATUS_OK) + { + ChipLogError(SoftwareUpdate, "sl_wfx_host_post_bootloader_spi_transfer() error: %ld", err); + return; + } #endif if (err) { @@ -199,7 +209,12 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) // Force KVS to store pending keys such as data from StoreCurrentUpdateInfo() chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().ForceKeyMapSave(); #if (defined(EFR32MG24) && defined(SL_WIFI)) - sl_wfx_host_pre_bootloader_spi_transfer(); + err = sl_wfx_host_pre_bootloader_spi_transfer(); + if (err != SL_STATUS_OK) + { + ChipLogError(SoftwareUpdate, "sl_wfx_host_pre_bootloader_spi_transfer() error: %ld", err); + return; + } #endif CORE_CRITICAL_SECTION(err = bootloader_verifyImage(mSlotId, NULL);) if (err != SL_BOOTLOADER_OK) @@ -208,7 +223,12 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) // Call the OTARequestor API to reset the state GetRequestorInstance()->CancelImageUpdate(); #if (defined(EFR32MG24) && defined(SL_WIFI)) - sl_wfx_host_post_bootloader_spi_transfer(); + err = sl_wfx_host_post_bootloader_spi_transfer(); + if (err != SL_STATUS_OK) + { + ChipLogError(SoftwareUpdate, "sl_wfx_host_post_bootloader_spi_transfer() error: %ld", err); + return; + } #endif return; } @@ -220,13 +240,23 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) // Call the OTARequestor API to reset the state GetRequestorInstance()->CancelImageUpdate(); #if (defined(EFR32MG24) && defined(SL_WIFI)) - sl_wfx_host_post_bootloader_spi_transfer(); + err = sl_wfx_host_post_bootloader_spi_transfer(); + if (err != SL_STATUS_OK) + { + ChipLogError(SoftwareUpdate, "sl_wfx_host_post_bootloader_spi_transfer() error: %ld", err); + return; + } #endif return; } #if (defined(EFR32MG24) && defined(SL_WIFI)) - sl_wfx_host_post_bootloader_spi_transfer(); + err = sl_wfx_host_post_bootloader_spi_transfer(); + if (err != SL_STATUS_OK) + { + ChipLogError(SoftwareUpdate, "sl_wfx_host_post_bootloader_spi_transfer() error: %ld", err); + return; + } #endif // This reboots the device CORE_CRITICAL_SECTION(bootloader_rebootAndInstall();) @@ -281,11 +311,21 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context) { writeBufOffset = 0; #if (defined(EFR32MG24) && defined(SL_WIFI)) - sl_wfx_host_pre_bootloader_spi_transfer(); + err = sl_wfx_host_pre_bootloader_spi_transfer(); + if (err != SL_STATUS_OK) + { + ChipLogError(SoftwareUpdate, "sl_wfx_host_pre_bootloader_spi_transfer() error: %ld", err); + return; + } #endif CORE_CRITICAL_SECTION(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, kAlignmentBytes);) #if (defined(EFR32MG24) && defined(SL_WIFI)) - sl_wfx_host_post_bootloader_spi_transfer(); + err = sl_wfx_host_post_bootloader_spi_transfer(); + if (err != SL_STATUS_OK) + { + ChipLogError(SoftwareUpdate, "sl_wfx_host_post_bootloader_spi_transfer() error: %ld", err); + return; + } #endif if (err) { From 89bba240ddc87bcc150de04837375dca9ab7d079 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Tue, 20 Jun 2023 11:52:16 +0530 Subject: [PATCH 43/50] Adds partial fix for MATTER-1907 --- examples/platform/silabs/efr32/spi_multiplex.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/platform/silabs/efr32/spi_multiplex.h b/examples/platform/silabs/efr32/spi_multiplex.h index 630eb4b2535423..96b240ffaa206f 100644 --- a/examples/platform/silabs/efr32/spi_multiplex.h +++ b/examples/platform/silabs/efr32/spi_multiplex.h @@ -40,14 +40,14 @@ extern "C" { // TODO: (MATTER-1906) Investigate why using SL_SPIDRV_EXP_BITRATE is causing WF200 init failure // REF: sl_spidrv_exp_config.h #define SL_SPIDRV_EXP_BITRATE_MULTIPLEXED 10000000 +#define SL_SPIDRV_UART_CONSOLE_BITRATE SL_UARTDRV_USART_VCOM_BAUDRATE #else #define SL_SPIDRV_EXP_BITRATE_MULTIPLEXED SL_SPIDRV_EUSART_EXP_BITRATE +#define SL_SPIDRV_UART_CONSOLE_BITRATE SL_UARTDRV_EUSART_VCOM_BAUDRATE #endif /* WF200_WIFI */ -// TODO: (MATTER-1907) Replace with GSDK MACROs -#define SL_SPIDRV_LCD_BITRATE 1100000 +#define SL_SPIDRV_LCD_BITRATE SL_MEMLCD_SCLK_FREQ #define SL_SPIDRV_MX25_FLASH_BITRATE 16000000 -#define SL_SPIDRV_UART_CONSOLE_BITRATE 16000000 #ifdef RS911X_WIFI #define SL_SPIDRV_FRAME_LENGTH SL_SPIDRV_EUSART_EXP_FRAME_LENGTH From 12f958d0af1941f73c7f4dbee73fe3885fcd1603 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Tue, 20 Jun 2023 13:51:47 +0530 Subject: [PATCH 44/50] Adds for fix code compilation --- examples/platform/silabs/efr32/rs911x/hal/efx_spi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index 07bd01a65bea54..bc3560f99c19df 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -270,6 +270,7 @@ sl_status_t sl_wfx_host_post_bootloader_spi_transfer(void) GPIO->USARTROUTE[SL_MX25_FLASH_SHUTDOWN_PERIPHERAL_NO].ROUTEEN = PINOUT_CLEAR; sl_wfx_host_spiflash_cs_deassert(); xSemaphoreGive(spi_sem_sync_hdl); + return SL_STATUS_OK; } sl_status_t sl_wfx_host_pre_lcd_spi_transfer(void) @@ -285,7 +286,7 @@ sl_status_t sl_wfx_host_pre_lcd_spi_transfer(void) spi_enabled = false; } // sl_memlcd_refresh takes care of SPIDRV_Init() - if(SL_STATUS_OK != sl_memlcd_refresh(sl_memlcd_get()) + if(SL_STATUS_OK != sl_memlcd_refresh(sl_memlcd_get())) { xSemaphoreGive(spi_sem_sync_hdl); return SL_STATUS_FAIL; @@ -299,6 +300,7 @@ sl_status_t sl_wfx_host_post_lcd_spi_transfer(void) CMU_ClockEnable(SPI_CLOCK(SL_MEMLCD_SPI_PERIPHERAL_NO), false); GPIO->USARTROUTE[SL_MEMLCD_SPI_PERIPHERAL_NO].ROUTEEN = PINOUT_CLEAR; xSemaphoreGive(spi_sem_sync_hdl); + return SL_STATUS_OK; } #endif /* EFR32MG24 */ From 1ba09ffe9ecf5b1cf400f2046585d42f0a696428 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Tue, 20 Jun 2023 22:18:47 +0530 Subject: [PATCH 45/50] Adds code to clean up MACROs --- .../platform/silabs/efr32/spi_multiplex.h | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/examples/platform/silabs/efr32/spi_multiplex.h b/examples/platform/silabs/efr32/spi_multiplex.h index 96b240ffaa206f..8de4715e086cff 100644 --- a/examples/platform/silabs/efr32/spi_multiplex.h +++ b/examples/platform/silabs/efr32/spi_multiplex.h @@ -22,40 +22,33 @@ extern "C" { #endif #include "FreeRTOS.h" +#include "em_eusart.h" #include "semphr.h" +#include "sl_memlcd_display.h" #include "sl_mx25_flash_shutdown_usart_config.h" -#if (defined(EFR32MG24) && defined(WF200_WIFI)) // TODO: (MATTER-1905) clean up of MACROs -#include "sl_spidrv_exp_config.h" -#endif /* EFR32MG24 && WF200_WIFI */ -#if (defined(EFR32MG24) && defined(RS911X_WIFI)) -#include "sl_spidrv_eusart_exp_config.h" -#endif /* EFR32MG24 && RS911X_WIFI */ -#if (defined(EFR32MG24) && defined(WF200_WIFI)) -#include "sl_wfx_host_api.h" -#endif /* EFR32MG24 && WF200_WIFI */ -#include "em_eusart.h" #include "spidrv.h" -#ifdef WF200_WIFI -// TODO: (MATTER-1906) Investigate why using SL_SPIDRV_EXP_BITRATE is causing WF200 init failure -// REF: sl_spidrv_exp_config.h -#define SL_SPIDRV_EXP_BITRATE_MULTIPLEXED 10000000 -#define SL_SPIDRV_UART_CONSOLE_BITRATE SL_UARTDRV_USART_VCOM_BAUDRATE -#else -#define SL_SPIDRV_EXP_BITRATE_MULTIPLEXED SL_SPIDRV_EUSART_EXP_BITRATE -#define SL_SPIDRV_UART_CONSOLE_BITRATE SL_UARTDRV_EUSART_VCOM_BAUDRATE -#endif /* WF200_WIFI */ - #define SL_SPIDRV_LCD_BITRATE SL_MEMLCD_SCLK_FREQ #define SL_SPIDRV_MX25_FLASH_BITRATE 16000000 #ifdef RS911X_WIFI +#include "sl_spidrv_eusart_exp_config.h" + +#define SL_SPIDRV_EXP_BITRATE_MULTIPLEXED SL_SPIDRV_EUSART_EXP_BITRATE +#define SL_SPIDRV_UART_CONSOLE_BITRATE SL_UARTDRV_EUSART_VCOM_BAUDRATE #define SL_SPIDRV_FRAME_LENGTH SL_SPIDRV_EUSART_EXP_FRAME_LENGTH extern SPIDRV_Handle_t sl_spidrv_eusart_exp_handle; #define SL_SPIDRV_HANDLE sl_spidrv_eusart_exp_handle // TODO: (MATTER-1907) Replace use of extern variable extern SPIDRV_Init_t sl_spidrv_eusart_init_exp; #elif WF200_WIFI +#include "sl_spidrv_exp_config.h" +#include "sl_wfx_host_api.h" + +// TODO: (MATTER-1906) Investigate why using SL_SPIDRV_EXP_BITRATE is causing WF200 init failure +// REF: sl_spidrv_exp_config.h +#define SL_SPIDRV_EXP_BITRATE_MULTIPLEXED 10000000 +#define SL_SPIDRV_UART_CONSOLE_BITRATE SL_UARTDRV_USART_VCOM_BAUDRATE #define SL_SPIDRV_FRAME_LENGTH SL_SPIDRV_EXP_FRAME_LENGTH extern SPIDRV_Handle_t sl_spidrv_exp_handle; #define SL_SPIDRV_HANDLE sl_spidrv_exp_handle From 6cdf6341f74f7d22a6f1fe34feaabe6b88e4a6c2 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 20 Jun 2023 17:13:52 +0000 Subject: [PATCH 46/50] Restyled by clang-format --- examples/platform/silabs/efr32/rs911x/hal/efx_spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index bc3560f99c19df..472cea618f3036 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -286,7 +286,7 @@ sl_status_t sl_wfx_host_pre_lcd_spi_transfer(void) spi_enabled = false; } // sl_memlcd_refresh takes care of SPIDRV_Init() - if(SL_STATUS_OK != sl_memlcd_refresh(sl_memlcd_get())) + if (SL_STATUS_OK != sl_memlcd_refresh(sl_memlcd_get())) { xSemaphoreGive(spi_sem_sync_hdl); return SL_STATUS_FAIL; From 3326a401071419059a9087295d040b586db4cff9 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Wed, 21 Jun 2023 10:56:27 +0530 Subject: [PATCH 47/50] Removes debug log --- examples/platform/silabs/efr32/rs911x/hal/efx_spi.c | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index 472cea618f3036..d3d4f5e4002973 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -172,7 +172,6 @@ void rsi_hal_board_init(void) /* Reset of Wifi chip */ sl_wfx_host_reset_chip(); - SILABS_LOG("%s completed.", __func__); } #if defined(EFR32MG24) From ae9f3af10ebc1c64a2d525b10a893fade64ca327 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Wed, 21 Jun 2023 11:01:29 +0530 Subject: [PATCH 48/50] Adds fix for MATTER-1907 --- examples/platform/silabs/efr32/rs911x/hal/efx_spi.c | 8 ++------ examples/platform/silabs/efr32/spi_multiplex.h | 8 +++----- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index d3d4f5e4002973..addf05d9c66c65 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -190,13 +190,9 @@ sl_status_t sl_wfx_host_spi_cs_assert(void) { xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY); - if (!spi_enabled) // Reduce SPIDRV_Init + if (!spi_enabled) // Reduce sl_spidrv_init_instances { - if (ECODE_OK != SPIDRV_Init(SL_SPIDRV_HANDLE, &sl_spidrv_eusart_init_exp)) - { - xSemaphoreGive(spi_sem_sync_hdl); - return SL_STATUS_FAIL; - } + sl_spidrv_init_instances(); spi_enabled = true; } GPIO_PinOutClear(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN); diff --git a/examples/platform/silabs/efr32/spi_multiplex.h b/examples/platform/silabs/efr32/spi_multiplex.h index 8de4715e086cff..a5151f328d86c0 100644 --- a/examples/platform/silabs/efr32/spi_multiplex.h +++ b/examples/platform/silabs/efr32/spi_multiplex.h @@ -26,6 +26,7 @@ extern "C" { #include "semphr.h" #include "sl_memlcd_display.h" #include "sl_mx25_flash_shutdown_usart_config.h" +#include "sl_spidrv_instances.h" #include "spidrv.h" #define SL_SPIDRV_LCD_BITRATE SL_MEMLCD_SCLK_FREQ @@ -37,10 +38,8 @@ extern "C" { #define SL_SPIDRV_EXP_BITRATE_MULTIPLEXED SL_SPIDRV_EUSART_EXP_BITRATE #define SL_SPIDRV_UART_CONSOLE_BITRATE SL_UARTDRV_EUSART_VCOM_BAUDRATE #define SL_SPIDRV_FRAME_LENGTH SL_SPIDRV_EUSART_EXP_FRAME_LENGTH -extern SPIDRV_Handle_t sl_spidrv_eusart_exp_handle; #define SL_SPIDRV_HANDLE sl_spidrv_eusart_exp_handle -// TODO: (MATTER-1907) Replace use of extern variable -extern SPIDRV_Init_t sl_spidrv_eusart_init_exp; + #elif WF200_WIFI #include "sl_spidrv_exp_config.h" #include "sl_wfx_host_api.h" @@ -50,9 +49,8 @@ extern SPIDRV_Init_t sl_spidrv_eusart_init_exp; #define SL_SPIDRV_EXP_BITRATE_MULTIPLEXED 10000000 #define SL_SPIDRV_UART_CONSOLE_BITRATE SL_UARTDRV_USART_VCOM_BAUDRATE #define SL_SPIDRV_FRAME_LENGTH SL_SPIDRV_EXP_FRAME_LENGTH -extern SPIDRV_Handle_t sl_spidrv_exp_handle; #define SL_SPIDRV_HANDLE sl_spidrv_exp_handle -#endif +#endif /* RS911X_WIFI || WF200_WIFI */ /**************************************************************************** * @fn void SPIDRV_SetBaudrate() From d72078846f7d94f2ff7718402ec278c13686c0db Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Wed, 21 Jun 2023 11:02:13 +0530 Subject: [PATCH 49/50] Adds use of the ECODE_EMDRV_SPIDRV status instead of generic ECODE --- examples/platform/silabs/efr32/rs911x/hal/efx_spi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c index addf05d9c66c65..62b14e0bd34b51 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c +++ b/examples/platform/silabs/efr32/rs911x/hal/efx_spi.c @@ -203,7 +203,7 @@ sl_status_t sl_wfx_host_spi_cs_deassert(void) { if (spi_enabled) { - if (ECODE_OK != SPIDRV_DeInit(SL_SPIDRV_HANDLE)) + if (ECODE_EMDRV_SPIDRV_OK != SPIDRV_DeInit(SL_SPIDRV_HANDLE)) { xSemaphoreGive(spi_sem_sync_hdl); return SL_STATUS_FAIL; @@ -233,7 +233,7 @@ sl_status_t sl_wfx_host_pre_bootloader_spi_transfer(void) xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY); if (spi_enabled) { - if (ECODE_OK != SPIDRV_DeInit(SL_SPIDRV_HANDLE)) + if (ECODE_EMDRV_SPIDRV_OK != SPIDRV_DeInit(SL_SPIDRV_HANDLE)) { xSemaphoreGive(spi_sem_sync_hdl); return SL_STATUS_FAIL; @@ -273,7 +273,7 @@ sl_status_t sl_wfx_host_pre_lcd_spi_transfer(void) xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY); if (spi_enabled) { - if (ECODE_OK != SPIDRV_DeInit(SL_SPIDRV_HANDLE)) + if (ECODE_EMDRV_SPIDRV_OK != SPIDRV_DeInit(SL_SPIDRV_HANDLE)) { xSemaphoreGive(spi_sem_sync_hdl); return SL_STATUS_FAIL; From c9472c11569deeaf1d786ed783e5b7a279855250 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Wed, 21 Jun 2023 11:11:25 +0530 Subject: [PATCH 50/50] Adds comment for declaring the current supported family. --- examples/platform/silabs/efr32/spi_multiplex.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/platform/silabs/efr32/spi_multiplex.h b/examples/platform/silabs/efr32/spi_multiplex.h index a5151f328d86c0..0c926b809fab1a 100644 --- a/examples/platform/silabs/efr32/spi_multiplex.h +++ b/examples/platform/silabs/efr32/spi_multiplex.h @@ -15,6 +15,13 @@ * limitations under the License. */ +/* + * This file contains all the functions specific to the MG24 family for + * multiplexing the SPI port with WiFi NCP and other WSTK + * devices such as External Flash and LCD. + * That can be extended to other families as well. + */ + #pragma once #if defined(EFR32MG24)