Skip to content

Commit

Permalink
[Silabs] Added fixes for hardfault issue with rs9116 when LCD enabled…
Browse files Browse the repository at this point in the history
… and 917 NCP-LCD enablement (project-chip#32209)

* Added fixes for hardfault issue with rs9116 when LCD enabled

* resolved build errors with mg12

* Pull request project-chip#1552: [MATTER-2763]wifi-917NCP_enabling LCD

Merge in WMN_TOOLS/matter from feature/wifi_917ncp_lcd to RC_2.3.0-1.3

Squashed commit of the following:

commit 136a77e165aefb649a8187c5177319e13af0f21a
Author: bhmanda-silabs <[email protected]>
Date:   Fri Feb 9 22:50:30 2024 +0530

    Resolved review comments

commit 4c2f020a346c3e6e3c12fb72fc4d8691ed12aaec
Author: bhmanda-silabs <[email protected]>
Date:   Thu Feb 8 19:36:25 2024 +0530

    removed commented code

commit a67ada4d9d56dea11e627887e6ee4d431bae22ad
Author: bhmanda-silabs <[email protected]>
Date:   Thu Feb 8 19:29:54 2024 +0530

    Removed special characters

... and 3 more commits

* resolved review comments

* Resolved review comments

* Resolved comments and removed ununsed macros

* removed semaphore in header file as it is not being used in this file

* resolved the comments

* Restyled
  • Loading branch information
bhmanda-silabs authored and huangxuyong committed Mar 19, 2024
1 parent 7afa990 commit ac76f45
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 161 deletions.
16 changes: 11 additions & 5 deletions examples/platform/silabs/display/demo-ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,24 @@ void demoUIInit(GLIB_Context_t * context)

sl_status_t updateDisplay(void)
{
sl_status_t status = SL_STATUS_OK;
#if SIWX_917 && SL_ICD_ENABLED && DISPLAY_ENABLED
sl_memlcd_post_wakeup_init();
#endif // SIWX_917 && SL_ICD_ENABLED && DISPLAY_ENABLED
#if SL_LCDCTRL_MUX
sl_wfx_host_pre_lcd_spi_transfer();
#endif // SL_LCDCTRL_MUX
sl_status_t status = DMD_updateDisplay();
#if SL_LCDCTRL_MUX
sl_wfx_host_post_lcd_spi_transfer();
status = sl_wfx_host_pre_lcd_spi_transfer();
if (status != SL_STATUS_OK)
return status;
#endif // SL_LCDCTRL_MUX
status = DMD_updateDisplay();
if (status != DMD_OK)
return SL_STATUS_FAIL;
#if SL_LCDCTRL_MUX
status = sl_wfx_host_post_lcd_spi_transfer();
if (status != SL_STATUS_OK)
return status;
#endif // SL_LCDCTRL_MUX

return SL_STATUS_OK;
}

Expand Down
26 changes: 18 additions & 8 deletions examples/platform/silabs/efr32/rs911x/hal/efx32_ncp_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@
#include "sl_power_manager.h"
#endif

#define USART_INITSYNC_BAUDRATE 12500000
#include "sl_board_control.h"
#include "sl_si91x_ncp_utility.h"
#include "spi_multiplex.h"

static bool dma_callback(unsigned int channel, unsigned int sequenceNo, void * userParam);

unsigned int rx_ldma_channel;
unsigned int tx_ldma_channel;
uint32_t rx_ldma_channel;
uint32_t tx_ldma_channel;
osMutexId_t ncp_transfer_mutex = 0;

static uint32_t dummy_buffer;
Expand Down Expand Up @@ -81,7 +83,7 @@ static void efx32_spi_init(void)
USART_InitSync_TypeDef init = USART_INITSYNC_DEFAULT;

init.msbf = true; // MSB first transmission for SPI compatibility
init.autoCsEnable = true; // Allow the USART to assert CS
init.autoCsEnable = false;
init.baudrate = USART_INITSYNC_BAUDRATE;

// Configure SPI bus pins
Expand Down Expand Up @@ -109,15 +111,15 @@ static void efx32_spi_init(void)
// Enable USART interface pins
GPIO->USARTROUTE[SPI_USART_ROUTE_INDEX].ROUTEEN = GPIO_USART_ROUTEEN_RXPEN | // MISO
GPIO_USART_ROUTEEN_TXPEN | // MOSI
GPIO_USART_ROUTEEN_CLKPEN | GPIO_USART_ROUTEEN_CSPEN;
GPIO_USART_ROUTEEN_CLKPEN;

// Set slew rate for alternate usage pins
GPIO_SlewrateSet(SPI_CLOCK_PIN.port, 7, 7);

// Configure and enable USART
USART_InitSync(SPI_USART, &init);

SPI_USART->TIMING |= /*USART_TIMING_TXDELAY_ONE | USART_TIMING_CSSETUP_ONE |*/ USART_TIMING_CSHOLD_ONE;
SPI_USART->TIMING |= USART_TIMING_TXDELAY_ONE | USART_TIMING_CSSETUP_ONE | USART_TIMING_CSHOLD_ONE;

// SPI_USART->CTRL_SET |= USART_CTRL_SMSDELAY;

Expand Down Expand Up @@ -145,6 +147,14 @@ uint32_t sl_si91x_host_get_wake_indicator(void)

sl_status_t sl_si91x_host_init(sl_si91x_host_init_configuration * config)
{
#if SL_SPICTRL_MUX
sl_status_t status = sl_board_disable_display();
if (SL_STATUS_OK != status)
{
SILABS_LOG("sl_board_disable_display failed with error: %x", status);
return status;
}
#endif // SL_SPICTRL_MUX
init_config.rx_irq = config->rx_irq;
init_config.rx_done = config->rx_done;

Expand Down Expand Up @@ -175,8 +185,8 @@ sl_status_t sl_si91x_host_init(sl_si91x_host_init_configuration * config)
GPIO_PinModeSet(WAKE_INDICATOR_PIN.port, WAKE_INDICATOR_PIN.pin, gpioModeWiredOrPullDown, 0);

DMADRV_Init();
DMADRV_AllocateChannel(&rx_ldma_channel, NULL);
DMADRV_AllocateChannel(&tx_ldma_channel, NULL);
DMADRV_AllocateChannel((unsigned int *) &rx_ldma_channel, NULL);
DMADRV_AllocateChannel((unsigned int *) &tx_ldma_channel, NULL);

return SL_STATUS_OK;
}
Expand Down
95 changes: 34 additions & 61 deletions examples/platform/silabs/efr32/rs911x/hal/efx_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,18 @@
#include "em_gpio.h"
#include "em_ldma.h"
#include "gpiointerrupt.h"
#include "spidrv.h"

#include "sl_board_control.h"
#include "sl_device_init_clocks.h"
#include "sl_device_init_hfxo.h"
#include "sl_spidrv_instances.h"
#include "sl_status.h"
#include "spidrv.h"

#include "silabs_utils.h"
#include "spi_multiplex.h"
#include "wfx_host_events.h"
#include "wfx_rsi.h"

#define DEFAULT_SPI_TRASFER_MODE 0
// Macro to drive semaphore block minimun timer in milli seconds
#define RSI_SEM_BLOCK_MIN_TIMER_VALUE_MS (50)
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
#include "sl_power_manager.h"
#endif
Expand All @@ -62,29 +59,33 @@
#endif // SL_BTLCTRL_MUX
#if SL_LCDCTRL_MUX
#include "sl_memlcd.h"
#include "sl_memlcd_display.h"
#endif // SL_LCDCTRL_MUX
#if SL_MX25CTRL_MUX
#include "sl_mx25_flash_shutdown_usart_config.h"
#endif // SL_MX25CTRL_MUX

#if defined(EFR32MG12)
#include "em_usart.h"

#include "sl_spidrv_exp_config.h"
#define SL_SPIDRV_HANDLE sl_spidrv_exp_handle

#elif defined(EFR32MG24)
#include "em_eusart.h"
#include "sl_spidrv_eusart_exp_config.h"
#include "spi_multiplex.h"
#else
#error "Unknown platform"
#endif

#if defined(EFR32MG24)
#define SL_SPIDRV_HANDLE sl_spidrv_eusart_exp_handle
#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

#endif // EFR32MG12 || EFR32MG24
#endif

#define CONCAT(A, B) (A##B)
#define SPI_CLOCK(N) CONCAT(cmuClock_USART, N)
// Macro to drive semaphore block minimun timer in milli seconds
#define RSI_SEM_BLOCK_MIN_TIMER_VALUE_MS (50)

#if SL_SPICTRL_MUX
StaticSemaphore_t spi_sem_peripheral;
Expand All @@ -97,16 +98,6 @@ static TaskHandle_t spiInitiatorTaskHandle = NULL;

static uint32_t dummy_buffer; /* Used for DMA - when results don't matter */

#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

// variable to identify spi configured for expansion header
// EUSART configuration available on the SPIDRV
static bool spi_enabled = false;
Expand All @@ -129,7 +120,7 @@ void sl_wfx_host_gpio_init(void)
#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
#endif // EFR32MG24

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);
Expand Down Expand Up @@ -171,8 +162,6 @@ void sl_wfx_host_reset_chip(void)
vTaskDelay(pdMS_TO_TICKS(3));
}

void gpio_interrupt([[maybe_unused]] uint8_t interrupt_number) {}

/*****************************************************************
* @fn void rsi_hal_board_init(void)
* @brief
Expand Down Expand Up @@ -201,26 +190,12 @@ void rsi_hal_board_init(void)
sl_wfx_host_reset_chip();
}

void sl_si91x_host_enable_high_speed_bus()
{
// dummy function for wifi-sdk
}

#if SL_SPICTRL_MUX
void SPIDRV_SetBaudrate(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(void)
{
#if SL_SPICTRL_MUX
xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY);

#endif // SL_SPICTRL_MUX
if (!spi_enabled) // Reduce sl_spidrv_init_instances
{
sl_spidrv_init_instances();
Expand All @@ -234,22 +209,23 @@ sl_status_t sl_wfx_host_spi_cs_assert(void)

sl_status_t sl_wfx_host_spi_cs_deassert(void)
{
sl_status_t status = SL_STATUS_OK;
if (spi_enabled)
{
if (ECODE_EMDRV_SPIDRV_OK != SPIDRV_DeInit(SL_SPIDRV_HANDLE))
status = SPIDRV_DeInit(SL_SPIDRV_HANDLE);
if (SL_STATUS_OK == status)
{
xSemaphoreGive(spi_sem_sync_hdl);
SILABS_LOG("%s error.", __func__);
return SL_STATUS_FAIL;
}
#if defined(EFR32MG24)
GPIO_PinOutSet(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN);
GPIO->EUSARTROUTE[SL_SPIDRV_EUSART_EXP_PERIPHERAL_NO].ROUTEEN = PINOUT_CLEAR;
GPIO_PinOutSet(SL_SPIDRV_EUSART_EXP_CS_PORT, SL_SPIDRV_EUSART_EXP_CS_PIN);
GPIO->EUSARTROUTE[SL_SPIDRV_EUSART_EXP_PERIPHERAL_NO].ROUTEEN = PINOUT_CLEAR;
#endif // EFR32MG24
spi_enabled = false;
spi_enabled = false;
}
}
#if SL_SPICTRL_MUX
xSemaphoreGive(spi_sem_sync_hdl);
return SL_STATUS_OK;
#endif // SL_SPICTRL_MUX
return status;
}
#endif // SL_SPICTRL_MUX

Expand Down Expand Up @@ -320,33 +296,30 @@ sl_status_t sl_wfx_host_post_bootloader_spi_transfer(void)
sl_status_t sl_wfx_host_pre_lcd_spi_transfer(void)
{
#if SL_SPICTRL_MUX
if (sl_wfx_host_spi_cs_deassert() != SL_STATUS_OK)
{
return SL_STATUS_FAIL;
}
xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY);
#endif // SL_SPICTRL_MUX
// sl_memlcd_refresh takes care of SPIDRV_Init()
if (SL_STATUS_OK != sl_memlcd_refresh(sl_memlcd_get()))
sl_status_t status = sl_board_enable_display();
if (SL_STATUS_OK == status)
{
// sl_memlcd_refresh takes care of SPIDRV_Init()
status = sl_memlcd_refresh(sl_memlcd_get());
}
#if SL_SPICTRL_MUX
xSemaphoreGive(spi_sem_sync_hdl);
xSemaphoreGive(spi_sem_sync_hdl);
#endif // SL_SPICTRL_MUX
SILABS_LOG("%s error.", __func__);
return SL_STATUS_FAIL;
}
return SL_STATUS_OK;
return status;
}

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);
GPIO->USARTROUTE[SL_MEMLCD_SPI_PERIPHERAL_NO].ROUTEEN = PINOUT_CLEAR;
sl_status_t status = sl_board_disable_display();
#if SL_SPICTRL_MUX
xSemaphoreGive(spi_sem_sync_hdl);
#endif // SL_SPICTRL_MUX
return SL_STATUS_OK;
return status;
}
#endif // SL_LCDCTRL_MUX

Expand Down
Loading

0 comments on commit ac76f45

Please sign in to comment.