Skip to content

Commit

Permalink
[EFR32] Support external flash on EFRMG24 boards (project-chip#18095)
Browse files Browse the repository at this point in the history
* Changes to support external flash on EFRMG24 boards

Point third_party/efr32_sdk/ repo to the latest commit that introduces external flash support on EFRMG24 boards (change LCD to use USART, change VCOM to use EUSART, change the external flash to use USART). Update Matter EFR32 platform files to sync with this change.
  • Loading branch information
selissia authored May 5, 2022
1 parent c438b89 commit 89eceb5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
39 changes: 29 additions & 10 deletions examples/platform/efr32/uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ extern "C" {
#include "em_usart.h"
#include "sl_board_control.h"
#include "sl_uartdrv_instances.h"
#ifdef EFR32MG24
#include "sl_uartdrv_eusart_vcom_config.h"
#else
#include "sl_uartdrv_usart_vcom_config.h"
#endif // EFR32MG24
#include "uart.h"
#include "uartdrv.h"
#include <stddef.h>
Expand All @@ -42,11 +46,21 @@ extern "C" {

#define HELPER1(x) USART##x##_RX_IRQn
#define HELPER2(x) HELPER1(x)
#define USART_IRQ HELPER2(SL_UARTDRV_USART_VCOM_PERIPHERAL_NO)

#define HELPER3(x) USART##x##_RX_IRQHandler
#define HELPER4(x) HELPER3(x)

// On MG24 boards VCOM runs on the EUSART device, MG12 uses the UART device
#ifdef EFR32MG24
#define USART_IRQ HELPER2(SL_UARTDRV_EUSART_VCOM_PERIPHERAL_NO)
#define USART_IRQHandler HELPER4(SL_UARTDRV_EUSART_VCOM_PERIPHERAL_NO)
#define vcom_handle sl_uartdrv_eusart_vcom_handle

#else
#define USART_IRQ HELPER2(SL_UARTDRV_USART_VCOM_PERIPHERAL_NO)
#define USART_IRQHandler HELPER4(SL_UARTDRV_USART_VCOM_PERIPHERAL_NO)
#define vcom_handle sl_uartdrv_usart_vcom_handle
#endif // EFR32MG24

typedef struct
{
Expand Down Expand Up @@ -190,13 +204,19 @@ void uartConsoleInit(void)
InitFifo(&sReceiveFifo, sRxFifoBuffer, MAX_BUFFER_SIZE);

// Activate 2 dma queues to always have one active
UARTDRV_Receive(sl_uartdrv_usart_vcom_handle, sRxDmaBuffer, MAX_DMA_BUFFER_SIZE, UART_rx_callback);
UARTDRV_Receive(sl_uartdrv_usart_vcom_handle, sRxDmaBuffer2, MAX_DMA_BUFFER_SIZE, UART_rx_callback);

UARTDRV_Receive(vcom_handle, sRxDmaBuffer, MAX_DMA_BUFFER_SIZE, UART_rx_callback);
UARTDRV_Receive(vcom_handle, sRxDmaBuffer2, MAX_DMA_BUFFER_SIZE, UART_rx_callback);

// Enable USART0 interrupt to wake OT task when data arrives
NVIC_ClearPendingIRQ(USART_IRQ);
NVIC_EnableIRQ(USART_IRQ);

#ifdef EFR32MG24
EUSART_IntEnable(SL_UARTDRV_EUSART_VCOM_PERIPHERAL, USART_IF_RXDATAV);
#else
USART_IntEnable(SL_UARTDRV_USART_VCOM_PERIPHERAL, USART_IF_RXDATAV);
#endif // EFR32MG24
}

void USART_IRQHandler(void)
Expand Down Expand Up @@ -225,7 +245,7 @@ static void UART_rx_callback(UARTDRV_Handle_t handle, Ecode_t transferStatus, ui
lastCount = 0;
}

UARTDRV_Receive(sl_uartdrv_usart_vcom_handle, data, transferCount, UART_rx_callback);
UARTDRV_Receive(vcom_handle, data, transferCount, UART_rx_callback);

#ifdef ENABLE_CHIP_SHELL
chip::NotifyShellProcessFromISR();
Expand Down Expand Up @@ -255,7 +275,7 @@ int16_t uartConsoleWrite(const char * Buf, uint16_t BufLength)

// 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(sl_uartdrv_usart_vcom_handle, (uint8_t *) Buf, BufLength) == ECODE_EMDRV_UARTDRV_OK)
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);
Expand Down Expand Up @@ -289,11 +309,10 @@ int16_t uartConsoleRead(char * Buf, uint16_t NbBytesToRead)
{
// Not enough data available in the fifo for the read size request
// If there is data available in dma buffer, get it now.
CORE_ATOMIC_SECTION(UARTDRV_GetReceiveStatus(sl_uartdrv_usart_vcom_handle, &data, &count, &remaining);
if (count > lastCount) {
WriteToFifo(&sReceiveFifo, data + lastCount, count - lastCount);
lastCount = count;
})
CORE_ATOMIC_SECTION(UARTDRV_GetReceiveStatus(vcom_handle, &data, &count, &remaining); if (count > lastCount) {
WriteToFifo(&sReceiveFifo, data + lastCount, count - lastCount);
lastCount = count;
})
}

return (int16_t) RetrieveFromFifo(&sReceiveFifo, (uint8_t *) Buf, NbBytesToRead);
Expand Down
11 changes: 6 additions & 5 deletions third_party/efr32_sdk/efr32_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ template("efr32_sdk") {
"${efr32_sdk_root}/hardware/driver/memlcd/inc",
"${efr32_sdk_root}/hardware/driver/memlcd/src/ls013b7dh03",
"${efr32_sdk_root}/matter/efr32",
"${efr32_sdk_root}/matter/efr32/${efr32_family}/",
"${efr32_sdk_root}/matter/efr32/${efr32_family}/${efr32_board}",
"${efr32_sdk_root}/platform/bootloader",
"${efr32_sdk_root}/platform/CMSIS/Include",
Expand Down Expand Up @@ -198,8 +199,8 @@ template("efr32_sdk") {
]
} else if (efr32_family == "efr32mg24") {
_include_dirs += [
"${efr32_sdk_root}/hardware/driver/memlcd/inc/memlcd_eusart",
"${efr32_sdk_root}/hardware/driver/mx25_flash_shutdown/inc/sl_mx25_flash_shutdown_eusart",
"${efr32_sdk_root}/hardware/driver/memlcd/inc/memlcd_usart",
"${efr32_sdk_root}/hardware/driver/mx25_flash_shutdown/inc/sl_mx25_flash_shutdown_usart",
]
}
}
Expand Down Expand Up @@ -485,7 +486,7 @@ template("efr32_sdk") {
chip_build_libshell || enable_openthread_cli ||
(defined(invoker.show_qr_code) && invoker.show_qr_code)) {
sources += [
"${efr32_sdk_root}/matter/efr32/sl_uartdrv_init.c",
"${efr32_sdk_root}/matter/efr32/${efr32_family}/sl_uartdrv_init.c",
"${efr32_sdk_root}/platform/emdrv/uartdrv/src/uartdrv.c",
"${efr32_sdk_root}/platform/emlib/src/em_eusart.c",
"${efr32_sdk_root}/platform/emlib/src/em_leuart.c",
Expand All @@ -504,8 +505,8 @@ template("efr32_sdk") {
]
} else if (efr32_family == "efr32mg24") {
sources += [
"${efr32_sdk_root}/hardware/driver/memlcd/src/memlcd_eusart/sl_memlcd_spi.c",
"${efr32_sdk_root}/hardware/driver/mx25_flash_shutdown/src/sl_mx25_flash_shutdown_eusart/sl_mx25_flash_shutdown.c",
"${efr32_sdk_root}/hardware/driver/memlcd/src/memlcd_usart/sl_memlcd_spi.c",
"${efr32_sdk_root}/hardware/driver/mx25_flash_shutdown/src/sl_mx25_flash_shutdown_usart/sl_mx25_flash_shutdown.c",
]
}
}
Expand Down

0 comments on commit 89eceb5

Please sign in to comment.