Skip to content

Commit

Permalink
Pull request #11: Provisioning series 3 (project-chip#35733)
Browse files Browse the repository at this point in the history
Merge in WMN_TOOLS/matter_sdk from feature/provisioning_api_series3 to feature/rainier-ifc2

Squashed commit of the following:

commit 0f219b792349f77756e33fe820fdb549376bb146
Author: lpbeliveau-silabs <[email protected]>
Date:   Tue Sep 10 14:14:52 2024 -0400

    Added series 3 API to replace MSC and updated to support series3 flash api
  • Loading branch information
lpbeliveau-silabs authored Sep 23, 2024
1 parent 8bc3888 commit b6daecb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
49 changes: 47 additions & 2 deletions examples/platform/silabs/provision/ProvisionStorageDefault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "AttestationKey.h"
#include "ProvisionStorage.h"
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <em_device.h>
#include <lib/support/BytesToHex.h>
#include <lib/support/CHIPMemString.h>
#include <lib/support/CodeUtils.h>
Expand All @@ -34,7 +35,13 @@
#ifdef SLI_SI91X_MCU_INTERFACE
#include <sl_si91x_common_flash_intf.h>
#else
#ifdef _SILICON_LABS_32B_SERIES_2
#include <em_msc.h>
#elif defined(_SILICON_LABS_32B_SERIES_3)
#include "sl_se_manager.h"
#include "sl_se_manager_types.h"
#include <sl_se_manager_extmem.h>
#endif // _SILICON_LABS_32B_SERIES_2
#include <psa/crypto.h>
#endif

Expand All @@ -44,6 +51,16 @@ extern void setNvm3End(uint32_t addr);
#include <sl_matter_provision_config.h>
#endif

#if defined(_SILICON_LABS_32B_SERIES_3)
// To remove any ambiguities regarding the Flash aliases, use the below macro to ignore the 8 MSB.
#define FLASH_GENERIC_MASK 0x00FFFFFF
#define GENERIC_ADDRESS(addr) ((addr) &FLASH_GENERIC_MASK)

// Transforms any address into an address using the same alias as FLASH_BASE from the CMSIS.
#define CMSIS_CONVERTED_ADDRESS(addr) (GENERIC_ADDRESS(addr) | FLASH_BASE)
sl_se_command_context_t cmd_ctx;
#endif // _SILICON_LABS_32B_SERIES_3

extern uint8_t linker_nvm_end[];

using namespace chip::Credentials;
Expand All @@ -66,8 +83,18 @@ CHIP_ERROR ErasePage(uint32_t addr)
{
#ifdef SLI_SI91X_MCU_INTERFACE
rsi_flash_erase_sector((uint32_t *) addr);
#else
#elif defined(_SILICON_LABS_32B_SERIES_2)
MSC_ErasePage((uint32_t *) addr);
#elif defined(_SILICON_LABS_32B_SERIES_3)
sl_status_t status;
uint32_t * data_start = NULL;
size_t data_size;

status = sl_se_data_region_get_location(&cmd_ctx, (void **) &data_start, &data_size);
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR(status));
VerifyOrReturnError(GENERIC_ADDRESS(addr) > GENERIC_ADDRESS((uint32_t) data_start), CHIP_ERROR_INVALID_ADDRESS);
status = sl_se_data_region_erase(&cmd_ctx, (void *) addr, 1); // Erase one page
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR(status));
#endif
return CHIP_NO_ERROR;
}
Expand All @@ -76,8 +103,18 @@ CHIP_ERROR WritePage(uint32_t addr, const uint8_t * data, size_t size)
{
#ifdef SLI_SI91X_MCU_INTERFACE
rsi_flash_write((uint32_t *) addr, (unsigned char *) data, size);
#else
#elif defined(_SILICON_LABS_32B_SERIES_2)
MSC_WriteWord((uint32_t *) addr, data, size);
#elif defined(_SILICON_LABS_32B_SERIES_3)
sl_status_t status;
uint32_t * data_start = NULL;
size_t data_size;

status = sl_se_data_region_get_location(&cmd_ctx, (void **) &data_start, &data_size);
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR(status));
VerifyOrReturnError(GENERIC_ADDRESS(addr) > GENERIC_ADDRESS((uint32_t) data_start), CHIP_ERROR_INVALID_ADDRESS);
status = sl_se_data_region_write(&cmd_ctx, (void *) addr, data, size);
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR(status));
#endif
return CHIP_NO_ERROR;
}
Expand Down Expand Up @@ -161,7 +198,15 @@ CHIP_ERROR Storage::Initialize(uint32_t flash_addr, uint32_t flash_size)
{
#ifndef SLI_SI91X_MCU_INTERFACE
base_addr = (flash_addr + flash_size - FLASH_PAGE_SIZE);

#ifdef _SILICON_LABS_32B_SERIES_2
MSC_Init();
#elif defined(_SILICON_LABS_32B_SERIES_3)
sl_status_t status;
status = sl_se_init();
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR_INTERNAL);
status = sl_se_init_command_context(&cmd_ctx);
#endif // _SILICON_LABS_32B_SERIES
#endif // SLI_SI91X_MCU_INTERFACE
#ifdef SL_PROVISION_GENERATOR
setNvm3End(base_addr);
Expand Down
2 changes: 1 addition & 1 deletion src/platform/silabs/platformAbstraction/GsdkSpam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "em_rmu.h"
#else
#include "sl_hal_emu.h"
#endif
#endif // _SILICON_LABS_32B_SERIES_2
#include "sl_system_kernel.h"

#ifdef ENABLE_WSTK_LEDS
Expand Down

0 comments on commit b6daecb

Please sign in to comment.