Skip to content

Commit 1673916

Browse files
wy-hhpull[bot]
authored andcommitted
[Bouffalolab] Remove lwip in BL70X Thread Application (#30020)
* remove lwip depency from thread application * fix init * Adjust packet buffer pool size * remove lwip dependency from bl702 thread application * Fix lint code * fix compile error on bl706 when usb cdc enabled
1 parent 8f826e6 commit 1673916

File tree

15 files changed

+74
-20
lines changed

15 files changed

+74
-20
lines changed

examples/lighting-app/bouffalolab/bl702l/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ bl_iot_sdk("sdk") {
9898
}
9999

100100
chip_data_model("bouffalolab-lighting") {
101-
zap_file = "${example_dir}/data_model/lighting-app-wifi.zap"
101+
zap_file = "${example_dir}/data_model/lighting-app-thread.zap"
102102

103103
zap_pregenerated_dir = "${chip_root}/zzz_generated/lighting-app/zap-generated"
104104
is_server = true

examples/platform/bouffalolab/common/plat/platform.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,18 @@ void ChipEventHandler(const ChipDeviceEvent * event, intptr_t arg)
165165
}
166166
}
167167

168+
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
169+
void LockOpenThreadTask(void)
170+
{
171+
chip::DeviceLayer::ThreadStackMgr().LockThreadStack();
172+
}
173+
174+
void UnlockOpenThreadTask(void)
175+
{
176+
chip::DeviceLayer::ThreadStackMgr().UnlockThreadStack();
177+
}
178+
#endif
179+
168180
CHIP_ERROR PlatformManagerImpl::PlatformInit(void)
169181
{
170182
chip::RendezvousInformationFlags rendezvousMode(chip::RendezvousInformationFlag::kOnNetwork);
@@ -235,6 +247,14 @@ CHIP_ERROR PlatformManagerImpl::PlatformInit(void)
235247
static CommonCaseDeviceServerInitParams initParams;
236248
(void) initParams.InitializeStaticResourcesBeforeServerInit();
237249

250+
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
251+
chip::Inet::EndPointStateOpenThread::OpenThreadEndpointInitParam nativeParams;
252+
nativeParams.lockCb = LockOpenThreadTask;
253+
nativeParams.unlockCb = UnlockOpenThreadTask;
254+
nativeParams.openThreadInstancePtr = chip::DeviceLayer::ThreadStackMgrImpl().OTInstance();
255+
initParams.endpointNativeParams = static_cast<void *>(&nativeParams);
256+
#endif
257+
238258
ReturnLogErrorOnFailure(chip::Server::GetInstance().Init(initParams));
239259

240260
gExampleDeviceInfoProvider.SetStorageDelegate(&chip::Server::GetInstance().GetPersistentStorage());

scripts/build/builders/bouffalolab.py

+2
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ def __init__(self,
166166
self.argsOpt.append(f'chip_inet_config_enable_ipv4={str(enable_ethernet or enable_wifi).lower()}')
167167

168168
if enable_thread:
169+
self.argsOpt.append('chip_system_config_use_open_thread_inet_endpoints=true')
170+
self.argsOpt.append('chip_with_lwip=false')
169171
self.argsOpt.append(f'openthread_project_core_config_file="{bouffalo_chip}-openthread-core-bl-config.h"')
170172
if not use_matter_openthread:
171173
self.argsOpt.append(

src/platform/bouffalolab/BL702/BUILD.gn

+3
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,7 @@ static_library("BL702") {
115115

116116
deps += [ "${chip_root}/src/credentials:credentials_header" ]
117117
public_deps = [ "${chip_root}/src/platform:platform_base" ]
118+
119+
public_configs =
120+
[ "${chip_root}/src/lib/address_resolve:default_address_resolve_config" ]
118121
}

src/platform/bouffalolab/BL702/PlatformManagerImpl.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
#include <platform/bouffalolab/common/DiagnosticDataProviderImpl.h>
2424
#include <platform/internal/GenericPlatformManagerImpl_FreeRTOS.ipp>
2525

26+
#if CHIP_SYSTEM_CONFIG_USE_LWIP
2627
#include <lwip/tcpip.h>
28+
#endif
29+
2730
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
2831
#include <platform/bouffalolab/BL702/wifi_mgmr_portable.h>
2932
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI
@@ -62,8 +65,10 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
6265
CHIP_ERROR err;
6366
TaskHandle_t backup_eventLoopTask;
6467

68+
#if CHIP_SYSTEM_CONFIG_USE_LWIP
6569
// Initialize LwIP.
6670
tcpip_init(NULL, NULL);
71+
#endif
6772

6873
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
6974
otRadio_opt_t opt;

src/platform/bouffalolab/BL702/ThreadStackManagerImpl.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717

1818
#include <platform/internal/CHIPDeviceLayerInternal.h>
1919

20-
#include <platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.hpp>
21-
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.cpp>
22-
2320
#include <platform/OpenThread/OpenThreadUtils.h>
2421
#include <platform/ThreadStackManager.h>
2522

26-
#include <openthread/platform/entropy.h>
23+
#include <platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.hpp>
24+
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp>
2725

2826
#include <lib/support/CHIPPlatformMemory.h>
2927

28+
#include <openthread/platform/entropy.h>
29+
3030
#include <mbedtls/platform.h>
3131

3232
#include <openthread_port.h>
@@ -51,7 +51,7 @@ CHIP_ERROR ThreadStackManagerImpl::InitThreadStack(otInstance * otInst)
5151
// Initialize the generic implementation base classes.
5252
err = GenericThreadStackManagerImpl_FreeRTOS<ThreadStackManagerImpl>::DoInit();
5353
SuccessOrExit(err);
54-
err = GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>::DoInit(otInstanceInitSingle());
54+
err = GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>::DoInit(otInst);
5555
SuccessOrExit(err);
5656

5757
mbedtls_platform_set_calloc_free(pvPortCalloc, vPortFree);

src/platform/bouffalolab/BL702L/BUILD.gn

+3
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,7 @@ static_library("BL702L") {
9292

9393
deps += [ "${chip_root}/src/credentials:credentials_header" ]
9494
public_deps = [ "${chip_root}/src/platform:platform_base" ]
95+
96+
public_configs =
97+
[ "${chip_root}/src/lib/address_resolve:default_address_resolve_config" ]
9598
}

src/platform/bouffalolab/BL702L/DiagnosticDataProviderImpl.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
#include <platform/DiagnosticDataProvider.h>
2222
#include <platform/bouffalolab/common/DiagnosticDataProviderImpl.h>
2323

24-
#include "FreeRTOS.h"
25-
#include <lwip/tcpip.h>
24+
#include <FreeRTOS.h>
2625

2726
extern "C" {
2827
#include <bl_sys.h>

src/platform/bouffalolab/BL702L/PlatformManagerImpl.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
#include <platform/bouffalolab/common/DiagnosticDataProviderImpl.h>
2525
#include <platform/internal/GenericPlatformManagerImpl_FreeRTOS.ipp>
2626

27+
#if CHIP_SYSTEM_CONFIG_USE_LWIP
2728
#include <lwip/tcpip.h>
29+
#endif
2830

2931
extern "C" {
3032
#include <bl_sec.h>
@@ -68,8 +70,10 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
6870

6971
ReturnErrorOnFailure(System::Clock::InitClock_RealTime());
7072

73+
#if CHIP_SYSTEM_CONFIG_USE_LWIP
7174
// Initialize LwIP.
7275
tcpip_init(NULL, NULL);
76+
#endif
7377

7478
err = chip::Crypto::add_entropy_source(app_entropy_source, NULL, 16);
7579
SuccessOrExit(err);

src/platform/bouffalolab/BL702L/ThreadStackManagerImpl.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717

1818
#include <platform/internal/CHIPDeviceLayerInternal.h>
1919

20-
#include <platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.hpp>
21-
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.cpp>
22-
2320
#include <platform/OpenThread/OpenThreadUtils.h>
2421
#include <platform/ThreadStackManager.h>
2522

23+
#include <platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.hpp>
24+
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp>
25+
26+
#include <lib/support/CHIPPlatformMemory.h>
27+
2628
#include <openthread/platform/entropy.h>
2729

2830
#include <mbedtls/platform.h>
@@ -54,7 +56,7 @@ CHIP_ERROR ThreadStackManagerImpl::InitThreadStack(otInstance * otInst)
5456
// Initialize the generic implementation base classes.
5557
err = GenericThreadStackManagerImpl_FreeRTOS<ThreadStackManagerImpl>::DoInit();
5658
SuccessOrExit(err);
57-
err = GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>::DoInit(otInst);
59+
err = GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>::DoInit(otInst);
5860
SuccessOrExit(err);
5961

6062
mbedtls_platform_set_calloc_free(pvPortCalloc, vPortFree);

src/platform/bouffalolab/common/BLConfig.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ namespace Internal {
2626

2727
void BLConfig::Init(void)
2828
{
29+
env_node_obj node;
30+
2931
easyflash_init();
3032
ef_load_env_cache();
3133

32-
if (ef_get_env(kBLKey_factoryResetFlag))
34+
if (ef_get_env_obj(kBLKey_factoryResetFlag, &node))
3335
{
34-
3536
ef_print_env_cb([](env_node_obj_t env, void * arg1, void * arg2) {
3637
if (ENV_WRITE == env->status)
3738
{

src/platform/bouffalolab/common/SystemPlatformConfig.h

+4
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,9 @@ struct ChipDeviceEvent;
3030
#define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME 1
3131
#define CHIP_SYSTEM_CONFIG_EVENT_OBJECT_TYPE const struct ::chip::DeviceLayer::ChipDeviceEvent *
3232

33+
#if CHIP_ENABLE_OPENTHREAD
34+
#define CHIP_SYSTEM_CONFIG_PACKETBUFFER_POOL_SIZE 8
35+
#endif
36+
3337
// #define CHIP_CONFIG_SHA256_CONTEXT_SIZE sizeof(bl_sha_ctx_t)
3438
#define CHIP_CONFIG_SHA256_CONTEXT_SIZE ((7 + 1 + 5 + 18 + 16 + 16 + 7) * sizeof(unsigned int))

src/platform/bouffalolab/common/ThreadStackManagerImpl.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@
1717

1818
#pragma once
1919

20-
#include <platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.h>
21-
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.h>
22-
2320
#include <openthread/tasklet.h>
2421
#include <openthread/thread.h>
25-
26-
#include <queue.h>
22+
#include <platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.h>
23+
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h>
2724

2825
extern "C" void otSysEventSignalPending(void);
2926
extern "C" void otrLock(void);
@@ -41,7 +38,7 @@ class ThreadStackManagerImpl;
4138
* using the Bouffalolab SDK and the OpenThread stack.
4239
*/
4340
class ThreadStackManagerImpl final : public ThreadStackManager,
44-
public Internal::GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>,
41+
public Internal::GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>,
4542
public Internal::GenericThreadStackManagerImpl_FreeRTOS<ThreadStackManagerImpl>
4643
{
4744
// Allow the ThreadStackManager interface class to delegate method calls to

src/system/BUILD.gn

+10
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ if (chip_device_platform == "cc13x2_26x2") {
6868
import("//build_overrides/mt793x_sdk.gni")
6969
} else if (chip_device_platform == "stm32") {
7070
import("//build_overrides/stm32_sdk.gni")
71+
} else if (chip_device_platform == "bl702") {
72+
import("//build_overrides/bouffalolab_iot_sdk.gni")
73+
} else if (chip_device_platform == "bl702l") {
74+
import("//build_overrides/bouffalolab_iot_sdk.gni")
7175
}
7276

7377
buildconfig_header("system_buildconfig") {
@@ -192,6 +196,12 @@ source_set("system_config_header") {
192196
if (chip_device_platform == "stm32") {
193197
public_deps += [ "${stm32_sdk_build_root}:stm32_sdk" ]
194198
}
199+
if (chip_device_platform == "bl702") {
200+
public_deps += [ "${bouffalolab_iot_sdk_build_root}/bl702:bl_iot_sdk" ]
201+
}
202+
if (chip_device_platform == "bl702l") {
203+
public_deps += [ "${bouffalolab_iot_sdk_build_root}/bl702l:bl_iot_sdk" ]
204+
}
195205

196206
# Add platform here as needed.
197207
}

third_party/bouffalolab/bl702/bl_iot_sdk.gni

+4
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,10 @@ template("bl_iot_sdk") {
403403
"${bl_iot_sdk_root}/components/stage/blfdt/inc",
404404
"${bl_iot_sdk_root}/components/stage/cli/cli/include",
405405
]
406+
407+
if (defined(invoker.enable_cdc_module) && invoker.enable_cdc_module) {
408+
cflags_cc = [ "-Wno-shadow" ]
409+
}
406410
}
407411

408412
source_set("${sdk_target_name}_stage") {

0 commit comments

Comments
 (0)