diff --git a/examples/platform/silabs/efr32/spi_multiplex.c b/examples/platform/silabs/efr32/spi_multiplex.c index 30e29f62d76b2c..137c3973aa846e 100644 --- a/examples/platform/silabs/efr32/spi_multiplex.c +++ b/examples/platform/silabs/efr32/spi_multiplex.c @@ -15,13 +15,19 @@ * limitations under the License. */ -#include "spi_multiplex.h" +#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 "spi_multiplex.h" +#endif /* SL_WIFI */ /**************************************************************************** * @fn void spi_drv_reinit() @@ -163,3 +169,48 @@ void post_lcd_spi_transfer(void) { xSemaphoreGive(spi_sem_sync_hdl); } +#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); + set_spi_baudrate(EXP_HDR); + xSemaphoreGive(spi_sem_sync_hdl); + sl_wfx_host_enable_platform_interrupt(); + sl_wfx_enable_irq(); +} +#endif /* EFR32MG24 && WF200_WIFI */ diff --git a/examples/platform/silabs/efr32/spi_multiplex.h b/examples/platform/silabs/efr32/spi_multiplex.h index 21f337abbcfc99..865e93ff4d8b36 100644 --- a/examples/platform/silabs/efr32/spi_multiplex.h +++ b/examples/platform/silabs/efr32/spi_multiplex.h @@ -52,6 +52,11 @@ void post_bootloader_spi_transfer(void); void pre_lcd_spi_transfer(void); void post_lcd_spi_transfer(void); +#if (defined(EFR32MG24) && defined(WF200_WIFI)) +void pre_uart_transfer(void); +void post_uart_transfer(void); +#endif /* EFR32MG24 && WF200_WIFI */ + #ifdef __cplusplus } #endif diff --git a/examples/platform/silabs/efr32/uart.cpp b/examples/platform/silabs/efr32/uart.cpp index 5481eab4c3e061..85509482622b9c 100644 --- a/examples/platform/silabs/efr32/uart.cpp +++ b/examples/platform/silabs/efr32/uart.cpp @@ -28,6 +28,9 @@ extern "C" { #include "sl_uartdrv_instances.h" #ifdef SL_CATALOG_UARTDRV_EUSART_PRESENT #include "sl_uartdrv_eusart_vcom_config.h" +#if (defined(EFR32MG24) && defined(WF200_WIFI)) +#include "spi_multiplex.h" +#endif /* EFR32MG24 && WF200_WIFI */ #endif #ifdef SL_CATALOG_UARTDRV_USART_PRESENT #include "sl_uartdrv_usart_vcom_config.h" @@ -294,20 +297,26 @@ int16_t uartConsoleWrite(const char * Buf, uint16_t BufLength) sl_power_manager_add_em_requirement(SL_POWER_MANAGER_EM1); #endif +#if (defined(EFR32MG24) && defined(WF200_WIFI)) + pre_uart_transfer(); +#endif /* EFR32MG24 && WF200_WIFI */ + // Use of ForceTransmit here. Transmit with DMA was causing errors with PW_RPC - // TODO Use DMA and find/fix what causes the issue with PW - if (UARTDRV_ForceTransmit(vcom_handle, (uint8_t *) Buf, BufLength) == ECODE_EMDRV_UARTDRV_OK) - { -#if defined(SL_CATALOG_POWER_MANAGER_PRESENT) - sl_power_manager_remove_em_requirement(SL_POWER_MANAGER_EM1); -#endif - return BufLength; - } + // TODO: Use DMA and find/fix what causes the issue with PW + Ecode_t ecode_status = UARTDRV_ForceTransmit(vcom_handle, (uint8_t *) Buf, BufLength); + +#if (defined(EFR32MG24) && defined(WF200_WIFI)) + post_uart_transfer(); +#endif /* EFR32MG24 && WF200_WIFI */ #if defined(SL_CATALOG_POWER_MANAGER_PRESENT) sl_power_manager_remove_em_requirement(SL_POWER_MANAGER_EM1); #endif + if (ECODE_EMDRV_UARTDRV_OK == ecode_status) + { + return BufLength; + } return UART_CONSOLE_ERR; }