Skip to content

Commit f2bf70d

Browse files
Merge branch 'release_2.5-1.4' into update/matter_sdk_changes_with_wifi_sdk_3.4.0
2 parents 71a447a + 736240f commit f2bf70d

12 files changed

+196
-82
lines changed

examples/platform/silabs/BaseApplication.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ void BaseApplication::OnPlatformEvent(const ChipDeviceEvent * event, intptr_t)
936936
#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER && RS911X_WIFI */
937937
// SL-Only
938938
#ifdef SL_CATALOG_ZIGBEE_STACK_COMMON_PRESENT
939-
#if defined(SL_MATTER_ZIGBEE_CMP)
939+
#if defined(SL_MATTER_ZIGBEE_CMP) && defined(_SILICON_LABS_32B_SERIES_3)
940940
uint8_t channel = otLinkGetChannel(DeviceLayer::ThreadStackMgrImpl().OTInstance());
941941
Zigbee::RequestStart(channel); // leave handle internally
942942
#elif defined(SL_MATTER_ZIGBEE_SEQUENTIAL) // Matter Zigbee sequential

examples/platform/silabs/SoftwareFaultReports.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
#include "SoftwareFaultReports.h"
20-
#include "FreeRTOS.h"
20+
#include "FreeRTOSConfig.h"
2121
#include "silabs_utils.h"
2222
#include <app/clusters/software-diagnostics-server/software-diagnostics-server.h>
2323
#include <app/util/attribute-storage.h>

examples/platform/silabs/provision/ProvisionStorageDefault.cpp

+5-62
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "AttestationKey.h"
1818
#include "ProvisionStorage.h"
1919
#include <credentials/examples/DeviceAttestationCredsExample.h>
20-
#include <em_device.h>
2120
#include <lib/support/BytesToHex.h>
2221
#include <lib/support/CHIPMemString.h>
2322
#include <lib/support/CodeUtils.h>
@@ -28,6 +27,7 @@
2827
#include <platform/CHIPDeviceConfig.h>
2928
#include <platform/silabs/MigrationManager.h>
3029
#include <platform/silabs/SilabsConfig.h>
30+
#include <platform/silabs/platformAbstraction/SilabsPlatform.h>
3131
#include <silabs_creds.h>
3232
#ifndef NDEBUG
3333
#if defined(SL_MATTER_TEST_EVENT_TRIGGER_ENABLED) && (SL_MATTER_GN_BUILD == 0)
@@ -37,16 +37,7 @@
3737
#ifdef OTA_ENCRYPTION_ENABLE
3838
#include <platform/silabs/multi-ota/OtaTlvEncryptionKey.h>
3939
#endif // OTA_ENCRYPTION_ENABLE
40-
#ifdef SLI_SI91X_MCU_INTERFACE
41-
#include <sl_si91x_common_flash_intf.h>
42-
#else
43-
#ifdef _SILICON_LABS_32B_SERIES_2
44-
#include <em_msc.h>
45-
#elif defined(_SILICON_LABS_32B_SERIES_3)
46-
#include "sl_se_manager.h"
47-
#include "sl_se_manager_types.h"
48-
#include <sl_se_manager_extmem.h>
49-
#endif // _SILICON_LABS_32B_SERIES_2
40+
#ifndef SLI_SI91X_MCU_INTERFACE
5041
#include <psa/crypto.h>
5142
#endif
5243

@@ -56,16 +47,6 @@ extern void setNvm3End(uint32_t addr);
5647
#include <sl_matter_provision_config.h>
5748
#endif
5849

59-
#if defined(_SILICON_LABS_32B_SERIES_3)
60-
// To remove any ambiguities regarding the Flash aliases, use the below macro to ignore the 8 MSB.
61-
#define FLASH_GENERIC_MASK 0x00FFFFFF
62-
#define GENERIC_ADDRESS(addr) ((addr) &FLASH_GENERIC_MASK)
63-
64-
// Transforms any address into an address using the same alias as FLASH_BASE from the CMSIS.
65-
#define CMSIS_CONVERTED_ADDRESS(addr) (GENERIC_ADDRESS(addr) | FLASH_BASE)
66-
sl_se_command_context_t cmd_ctx;
67-
#endif // _SILICON_LABS_32B_SERIES_3
68-
6950
extern uint8_t linker_nvm_end[];
7051

7152
using namespace chip::Credentials;
@@ -86,42 +67,12 @@ size_t sCredentialsOffset = 0;
8667

8768
CHIP_ERROR ErasePage(uint32_t addr)
8869
{
89-
#ifdef SLI_SI91X_MCU_INTERFACE
90-
rsi_flash_erase_sector((uint32_t *) addr);
91-
#elif defined(_SILICON_LABS_32B_SERIES_2)
92-
MSC_ErasePage((uint32_t *) addr);
93-
#elif defined(_SILICON_LABS_32B_SERIES_3)
94-
sl_status_t status;
95-
uint32_t * data_start = NULL;
96-
size_t data_size;
97-
98-
status = sl_se_data_region_get_location(&cmd_ctx, (void **) &data_start, &data_size);
99-
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR(status));
100-
VerifyOrReturnError(GENERIC_ADDRESS(addr) > GENERIC_ADDRESS((uint32_t) data_start), CHIP_ERROR_INVALID_ADDRESS);
101-
status = sl_se_data_region_erase(&cmd_ctx, (void *) addr, 1); // Erase one page
102-
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR(status));
103-
#endif
104-
return CHIP_NO_ERROR;
70+
return chip::DeviceLayer::Silabs::GetPlatform().FlashErasePage(addr);
10571
}
10672

10773
CHIP_ERROR WritePage(uint32_t addr, const uint8_t * data, size_t size)
10874
{
109-
#ifdef SLI_SI91X_MCU_INTERFACE
110-
rsi_flash_write((uint32_t *) addr, (unsigned char *) data, size);
111-
#elif defined(_SILICON_LABS_32B_SERIES_2)
112-
MSC_WriteWord((uint32_t *) addr, data, size);
113-
#elif defined(_SILICON_LABS_32B_SERIES_3)
114-
sl_status_t status;
115-
uint32_t * data_start = NULL;
116-
size_t data_size;
117-
118-
status = sl_se_data_region_get_location(&cmd_ctx, (void **) &data_start, &data_size);
119-
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR(status));
120-
VerifyOrReturnError(GENERIC_ADDRESS(addr) > GENERIC_ADDRESS((uint32_t) data_start), CHIP_ERROR_INVALID_ADDRESS);
121-
status = sl_se_data_region_write(&cmd_ctx, (void *) addr, data, size);
122-
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR(status));
123-
#endif
124-
return CHIP_NO_ERROR;
75+
return chip::DeviceLayer::Silabs::GetPlatform().FlashWritePage(addr, data, size);
12576
}
12677

12778
size_t RoundNearest(size_t n, size_t multiple)
@@ -203,16 +154,8 @@ CHIP_ERROR Storage::Initialize(uint32_t flash_addr, uint32_t flash_size)
203154
{
204155
#ifndef SLI_SI91X_MCU_INTERFACE
205156
base_addr = (flash_addr + flash_size - FLASH_PAGE_SIZE);
206-
207-
#ifdef _SILICON_LABS_32B_SERIES_2
208-
MSC_Init();
209-
#elif defined(_SILICON_LABS_32B_SERIES_3)
210-
sl_status_t status;
211-
status = sl_se_init();
212-
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR_INTERNAL);
213-
status = sl_se_init_command_context(&cmd_ctx);
214-
#endif // _SILICON_LABS_32B_SERIES
215157
#endif // SLI_SI91X_MCU_INTERFACE
158+
chip::DeviceLayer::Silabs::GetPlatform().FlashInit();
216159
#ifdef SL_PROVISION_GENERATOR
217160
setNvm3End(base_addr);
218161
#endif

src/platform/silabs/BLEManagerImpl.h

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
6868
int32_t SendBLEAdvertisementCommand(void);
6969
#else
7070
void HandleConnectEvent(volatile sl_bt_msg_t * evt);
71+
void HandleConnectParams(volatile sl_bt_msg_t * evt);
7172
void HandleConnectionCloseEvent(volatile sl_bt_msg_t * evt);
7273
void HandleWriteEvent(volatile sl_bt_msg_t * evt);
7374
void UpdateMtu(volatile sl_bt_msg_t * evt);

src/platform/silabs/CHIPDevicePlatformConfig.h

-4
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,7 @@
138138
#endif // CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE
139139

140140
#ifndef CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE
141-
#if defined(EFR32MG21)
142-
#define CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE (2 * 1024)
143-
#else
144141
#define CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE (8 * 1024)
145-
#endif
146142
#endif // CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE
147143

148144
#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_TELEMETRY 0

src/platform/silabs/OTAImageProcessorImpl.h

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class OTAImageProcessorImpl : public OTAImageProcessorInterface
5050
static void HandleApply(intptr_t context);
5151
static void HandleAbort(intptr_t context);
5252
static void HandleProcessBlock(intptr_t context);
53+
static void LockRadioProcessing();
54+
static void UnlockRadioProcessing();
5355
CHIP_ERROR ProcessHeader(ByteSpan & block);
5456

5557
/**

src/platform/silabs/efr32/BLEManagerImpl.cpp

+26-2
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,21 @@ void BLEManagerImpl::HandleConnectEvent(volatile sl_bt_msg_t * evt)
674674
PlatformMgr().ScheduleWork(DriveBLEState, 0);
675675
}
676676

677+
void BLEManagerImpl::HandleConnectParams(volatile sl_bt_msg_t * evt)
678+
{
679+
sl_bt_evt_connection_parameters_t * con_param_evt = (sl_bt_evt_connection_parameters_t *) &(evt->data);
680+
681+
if (con_param_evt->timeout < BLE_CONFIG_TIMEOUT)
682+
{
683+
ChipLogProgress(DeviceLayer, "Request to increase the connection timeout from %d to %d", con_param_evt->timeout,
684+
BLE_CONFIG_TIMEOUT);
685+
sl_bt_connection_set_parameters(con_param_evt->connection, BLE_CONFIG_MIN_INTERVAL, BLE_CONFIG_MAX_INTERVAL,
686+
BLE_CONFIG_LATENCY, BLE_CONFIG_TIMEOUT, BLE_CONFIG_MIN_CE_LENGTH, BLE_CONFIG_MAX_CE_LENGTH);
687+
}
688+
689+
PlatformMgr().ScheduleWork(DriveBLEState, 0);
690+
}
691+
677692
void BLEManagerImpl::HandleConnectionCloseEvent(volatile sl_bt_msg_t * evt)
678693
{
679694
sl_bt_evt_connection_closed_t * conn_evt = (sl_bt_evt_connection_closed_t *) &(evt->data);
@@ -1061,11 +1076,20 @@ extern "C" void sl_bt_on_event(sl_bt_msg_t * evt)
10611076
}
10621077
break;
10631078
case sl_bt_evt_connection_parameters_id: {
1064-
// ChipLogProgress(DeviceLayer, "Connection parameter ID received");
1079+
ChipLogProgress(DeviceLayer, "Connection parameter ID received - i:%d, l:%d, t:%d, sm:%d",
1080+
evt->data.evt_connection_parameters.interval, evt->data.evt_connection_parameters.latency,
1081+
evt->data.evt_connection_parameters.timeout, evt->data.evt_connection_parameters.security_mode);
1082+
chip::DeviceLayer::Internal::BLEMgrImpl().HandleConnectParams(evt);
10651083
}
10661084
break;
10671085
case sl_bt_evt_connection_phy_status_id: {
1068-
// ChipLogProgress(DeviceLayer, "PHY update procedure is completed");
1086+
ChipLogProgress(DeviceLayer, "Connection phy status ID received - phy:%d", evt->data.evt_connection_phy_status.phy);
1087+
}
1088+
break;
1089+
case sl_bt_evt_connection_data_length_id: {
1090+
ChipLogProgress(DeviceLayer, "Connection data length ID received - txL:%d, txT:%d, rxL:%d, rxL:%d",
1091+
evt->data.evt_connection_data_length.tx_data_len, evt->data.evt_connection_data_length.tx_time_us,
1092+
evt->data.evt_connection_data_length.rx_data_len, evt->data.evt_connection_data_length.rx_time_us);
10691093
}
10701094
break;
10711095
case sl_bt_evt_connection_closed_id: {

src/platform/silabs/efr32/OTAImageProcessorImpl.cpp

+63-10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ extern "C" {
3030

3131
#include <platform/silabs/SilabsConfig.h>
3232

33+
#ifdef _SILICON_LABS_32B_SERIES_2
34+
// Series 2 bootloader_ api calls must be called from a critical section context for thread safeness
35+
#define WRAP_BL_DFU_CALL(code) \
36+
{ \
37+
CORE_CRITICAL_SECTION(code;) \
38+
}
39+
#else
40+
// series 3 bootloader_ calls uses rtos mutex for thread safety. Cannot be called within a critical section
41+
#define WRAP_BL_DFU_CALL(code) \
42+
{ \
43+
code; \
44+
}
45+
#endif
46+
3347
/// No error, operation OK
3448
#define SL_BOOTLOADER_OK 0L
3549

@@ -144,7 +158,15 @@ void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context)
144158

145159
ChipLogProgress(SoftwareUpdate, "HandlePrepareDownload: started");
146160

147-
CORE_CRITICAL_SECTION(bootloader_init();)
161+
#ifdef _SILICON_LABS_32B_SERIES_2
162+
// TODO sl-temp: bootloader_init is called previously sl_platform_init(). Recalling it for series3 causes a crash.
163+
WRAP_BL_DFU_CALL(err = bootloader_init())
164+
if (err != SL_BOOTLOADER_OK)
165+
{
166+
ChipLogProgress(SoftwareUpdate, "bootloader_init Failed error: %ld", err);
167+
}
168+
#endif
169+
148170
mSlotId = 0; // Single slot until we support multiple images
149171
writeBufOffset = 0;
150172
mWriteOffset = 0;
@@ -186,7 +208,8 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context)
186208
return;
187209
}
188210
#endif // SL_BTLCTRL_MUX
189-
CORE_CRITICAL_SECTION(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, kAlignmentBytes);)
211+
WRAP_BL_DFU_CALL(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, kAlignmentBytes))
212+
190213
#if SL_BTLCTRL_MUX
191214
err = sl_wfx_host_post_bootloader_spi_transfer();
192215
if (err != SL_STATUS_OK)
@@ -208,11 +231,27 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context)
208231
ChipLogProgress(SoftwareUpdate, "OTA image downloaded successfully");
209232
}
210233

234+
// TODO: SE access is not thread safe. It assert if other tasks accesses it during bootloader_verifyImage or
235+
// bootloader_setImageToBootload steps - MATTER-4155 - PLATFORM_HYD-3235
236+
void OTAImageProcessorImpl::LockRadioProcessing()
237+
{
238+
#if !SL_WIFI
239+
DeviceLayer::ThreadStackMgr().LockThreadStack();
240+
#endif // SL_WIFI
241+
}
242+
243+
void OTAImageProcessorImpl::UnlockRadioProcessing()
244+
{
245+
#if !SL_WIFI
246+
DeviceLayer::ThreadStackMgr().UnlockThreadStack();
247+
#endif // SL_WIFI
248+
}
249+
211250
void OTAImageProcessorImpl::HandleApply(intptr_t context)
212251
{
213252
uint32_t err = SL_BOOTLOADER_OK;
214253

215-
ChipLogProgress(SoftwareUpdate, "HandleApply: started");
254+
ChipLogProgress(SoftwareUpdate, "HandleApply: verifying image");
216255

217256
// Force KVS to store pending keys such as data from StoreCurrentUpdateInfo()
218257
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().ForceKeyMapSave();
@@ -224,7 +263,13 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
224263
return;
225264
}
226265
#endif // SL_BTLCTRL_MUX
227-
CORE_CRITICAL_SECTION(err = bootloader_verifyImage(mSlotId, NULL);)
266+
267+
#if defined(_SILICON_LABS_32B_SERIES_3) && CHIP_PROGRESS_LOGGING
268+
osDelay(100); // sl-temp: delay for uart print before verifyImage
269+
#endif // _SILICON_LABS_32B_SERIES_3 && CHIP_PROGRESS_LOGGING
270+
LockRadioProcessing();
271+
WRAP_BL_DFU_CALL(err = bootloader_verifyImage(mSlotId, NULL))
272+
UnlockRadioProcessing();
228273
if (err != SL_BOOTLOADER_OK)
229274
{
230275
ChipLogError(SoftwareUpdate, "bootloader_verifyImage() error: %ld", err);
@@ -235,13 +280,14 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
235280
if (err != SL_STATUS_OK)
236281
{
237282
ChipLogError(SoftwareUpdate, "sl_wfx_host_post_bootloader_spi_transfer() error: %ld", err);
238-
return;
239283
}
240284
#endif // SL_BTLCTRL_MUX
241285
return;
242286
}
243-
244-
CORE_CRITICAL_SECTION(err = bootloader_setImageToBootload(mSlotId);)
287+
ChipLogProgress(SoftwareUpdate, "Image verified, Set image to bootload");
288+
LockRadioProcessing();
289+
WRAP_BL_DFU_CALL(err = bootloader_setImageToBootload(mSlotId))
290+
UnlockRadioProcessing();
245291
if (err != SL_BOOTLOADER_OK)
246292
{
247293
ChipLogError(SoftwareUpdate, "bootloader_setImageToBootload() error: %ld", err);
@@ -252,7 +298,6 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
252298
if (err != SL_STATUS_OK)
253299
{
254300
ChipLogError(SoftwareUpdate, "sl_wfx_host_post_bootloader_spi_transfer() error: %ld", err);
255-
return;
256301
}
257302
#endif // SL_BTLCTRL_MUX
258303
return;
@@ -266,8 +311,15 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
266311
return;
267312
}
268313
#endif // SL_BTLCTRL_MUX
314+
315+
ChipLogProgress(SoftwareUpdate, "Reboot and install new image...");
316+
#if defined(_SILICON_LABS_32B_SERIES_3) && CHIP_PROGRESS_LOGGING
317+
osDelay(100); // sl-temp: delay for uart print before reboot
318+
#endif // _SILICON_LABS_32B_SERIES_3 && CHIP_PROGRESS_LOGGING
319+
LockRadioProcessing();
269320
// This reboots the device
270-
CORE_CRITICAL_SECTION(bootloader_rebootAndInstall();)
321+
WRAP_BL_DFU_CALL(bootloader_rebootAndInstall())
322+
UnlockRadioProcessing(); // Unneccessay but for good measure
271323
}
272324

273325
void OTAImageProcessorImpl::HandleAbort(intptr_t context)
@@ -326,7 +378,8 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context)
326378
return;
327379
}
328380
#endif // SL_BTLCTRL_MUX
329-
CORE_CRITICAL_SECTION(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, kAlignmentBytes);)
381+
WRAP_BL_DFU_CALL(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, kAlignmentBytes))
382+
330383
#if SL_BTLCTRL_MUX
331384
err = sl_wfx_host_post_bootloader_spi_transfer();
332385
if (err != SL_STATUS_OK)

0 commit comments

Comments
 (0)