Skip to content

Commit 818183c

Browse files
committed
[bouffalo lab] fix wifi scan issues and update some platform changes
1 parent 1348a8a commit 818183c

File tree

24 files changed

+138
-41
lines changed

24 files changed

+138
-41
lines changed

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ bouffalolab_executable("lighting_app") {
9797
output_name = "chip-bl602-lighting-example.out"
9898

9999
defines = [
100-
"APP_TASK_STACK_SIZE=2044",
100+
"APP_TASK_STACK_SIZE=4096",
101101
"CHIP_UART_BAUDRATE=${baudrate}",
102102
"START_ENTRY=bfl_main",
103103
"SYS_AOS_LOOP_ENABLE",
@@ -110,6 +110,10 @@ bouffalolab_executable("lighting_app") {
110110
defines +=
111111
[ "CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE=${chip_enable_factory_data}" ]
112112

113+
if (enable_lwip_pbuf_ram) {
114+
defines += [ "CHIP_SYSTEM_CONFIG_PACKETBUFFER_LWIP_PBUF_RAM=1" ]
115+
}
116+
113117
bl_plat_name = "bl602"
114118
sources = [
115119
"${examples_plat_dir}/common/route_hook/bl_route_hook.c",
@@ -228,6 +232,11 @@ bouffalolab_executable("lighting_app") {
228232
inputs = [ ldscript ]
229233

230234
if (chip_print_memory_usage) {
235+
236+
if (enable_lwip_pbuf_ram) {
237+
ldflags += [ "-Wl,--defsym=__RAM_PBUF_POOL=0" ]
238+
}
239+
231240
ldflags += [
232241
"-Wl,--print-memory-usage",
233242
"-fstack-usage",

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

+6
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ bouffalo_sdk("sdk") {
7272
"OTA_PERIODIC_TIMEOUT=${ota_periodic_query_timeout_seconds}",
7373
"OTA_AUTO_REBOOT_DELAY=${ota_auto_reboot_delay_seconds}",
7474
"CHIP_UART_BAUDRATE=${baudrate}",
75+
"CHIP_SYSTEM_CRYPTO_HEADER_RESERVE_SIZE=388",
7576
]
7677

7778
defines += [ "PW_RPC_ENABLED=${chip_enable_pw_rpc}" ]
@@ -108,6 +109,7 @@ bouffalolab_executable("lighting_app") {
108109
"CHIP_UART_BAUDRATE=${baudrate}",
109110
"BL616_ENABLE",
110111
"START_ENTRY=main",
112+
"CHIP_SYSTEM_CRYPTO_HEADER_RESERVE_SIZE=388",
111113
]
112114

113115
defines +=
@@ -121,6 +123,10 @@ bouffalolab_executable("lighting_app") {
121123
defines += [ "BOOT_PIN_RESET=2" ]
122124
}
123125

126+
if (enable_lwip_pbuf_ram) {
127+
defines += [ "CHIP_SYSTEM_CONFIG_PACKETBUFFER_LWIP_PBUF_RAM=1" ]
128+
}
129+
124130
defines += [ "BL616DK" ]
125131

126132
sources = [

examples/lighting-app/bouffalolab/bl616/args.gni

+1-10
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,7 @@ import("${chip_root}/src/platform/bouffalolab/BL616/args.gni")
1919

2020
bouffalo_sdk_target = get_label_info(":sdk", "label_no_toolchain")
2121

22-
pw_log_BACKEND = "${chip_root}/src/pw_backends/log"
23-
pw_assert_BACKEND = "${chip_root}/src/pw_backends/assert"
24-
pw_rpc_CONFIG = "$dir_pw_rpc:disable_global_mutex"
25-
26-
chip_detail_logging = true
22+
chip_detail_logging = false
2723

2824
# use -Os instead of -Og
2925
is_debug = false
30-
31-
pw_build_LINK_DEPS = [
32-
"$dir_pw_assert:impl",
33-
"$dir_pw_log:impl",
34-
]

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ bouffalolab_executable("lighting_app") {
129129
bl_plat_name = "bl702"
130130

131131
defines = [
132-
"APP_TASK_STACK_SIZE=2048",
132+
"APP_TASK_STACK_SIZE=4096",
133133
"CHIP_UART_BAUDRATE=${baudrate}",
134134
"START_ENTRY=bl702_main",
135135
]

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ bouffalolab_executable("lighting_app") {
106106
bl_plat_name = "bl702l"
107107

108108
defines = [
109-
"APP_TASK_STACK_SIZE=2048",
109+
"APP_TASK_STACK_SIZE=4096",
110110
"CHIP_UART_BAUDRATE=${baudrate}",
111111
"START_ENTRY=bl702_main",
112112
]

examples/platform/bouffalolab/bl602/ldscripts/flash_rom.ld

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ __RFTLV_HEAD1_L = (0x41524150); /* PAPA */
1111
__RAM_START = 0x4200C000;
1212
__RAM_END = 0x4200C000 + 256K - __EM_SIZE; /* leave 8K left for BLE */
1313

14-
__RAM_TCM_LEN = (16K + 16K + 48K + 64K + 64K - 16K - 16K);
14+
__RAM_PBUF_POOL = DEFINED(__RAM_PBUF_POOL) ? __RAM_PBUF_POOL : 30K;
15+
16+
__RAM_TCM_LEN = (16K + 16K + 48K + 64K + 64K - 16K - 16K + 30K - 12K - __RAM_PBUF_POOL);
1517
__RAM_WIFI_LEN = (__RAM_END - __RAM_START - __RAM_TCM_LEN);
1618

1719
MEMORY
@@ -173,6 +175,9 @@ SECTIONS
173175
*libwifi_drv.a:bl_utils.o(.bss*)
174176
*(.wifi_ram*)
175177
. = ALIGN(16);
178+
179+
KEEP(*libCHIP.a:*(.bss.*PlatformManagerImp*))
180+
. = ALIGN(16);
176181
} > ram_wifi
177182

178183
PROVIDE( _heap_wifi_start = . );

examples/platform/bouffalolab/bl602/lwipopts/lwipopts.h

+23-7
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ a lot of data that needs to be copied, this should be set high. */
7878

7979
#define MEMP_NUM_NETCONN (MEMP_NUM_TCP_PCB + MEMP_NUM_UDP_PCB + MEMP_NUM_TCP_PCB_LISTEN)
8080

81-
/* ---------- Pbuf options ---------- */
82-
/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */
83-
#define PBUF_POOL_SIZE 20
84-
8581
/* ---------- TCP options ---------- */
8682
#define LWIP_TCP 1
8783
#define IP_DEFAULT_TTL 64
@@ -269,17 +265,37 @@ a lot of data that needs to be copied, this should be set high. */
269265

270266
#define LWIP_NETIF_EXT_STATUS_CALLBACK 1
271267

272-
/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */
273268
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS + 40 + PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN)
274269

275-
#define LWIP_PBUF_FROM_CUSTOM_POOLS (0)
276-
277270
/*
278271
---------------------------------
279272
---------- MISC. options ----------
280273
---------------------------------
281274
*/
282275

276+
#if defined(CHIP_SYSTEM_CONFIG_PACKETBUFFER_LWIP_PBUF_RAM) && CHIP_SYSTEM_CONFIG_PACKETBUFFER_LWIP_PBUF_RAM
277+
#define PBUF_POOL_SIZE 0
278+
#define MEM_LIBC_MALLOC 0
279+
#define MEM_USE_POOLS 0
280+
#define MEMP_USE_CUSTOM_POOLS 0
281+
282+
#include <lwip/arch.h>
283+
#include <lwip/mem.h>
284+
#define LWIP_PBUF_CUSTOM_DATA mem_size_t pool;
285+
286+
#if defined(__cplusplus)
287+
extern "C" const mem_size_t * memp_sizes;
288+
extern "C" struct pbuf *pbuf_rightsize(struct pbuf *p, s16_t offset);
289+
#else
290+
extern const mem_size_t * memp_sizes;
291+
extern struct pbuf *pbuf_rightsize(struct pbuf *p, s16_t offset);
292+
#endif
293+
#else
294+
295+
#define PBUF_POOL_SIZE 20
296+
#define LWIP_PBUF_FROM_CUSTOM_POOLS (0)
297+
#endif
298+
283299
#if defined(__cplusplus)
284300
extern "C" int bl_rand(void);
285301
extern "C" int * __errno(void);

examples/platform/bouffalolab/bl616/lwipopts.h

+19-2
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,9 @@ extern const int fhost_tcpip_priority;
120120
#define MEMP_NUM_UDP_PCB 16
121121
#define MEMP_NUM_REASSDATA LWIP_MIN((IP_REASS_MAX_PBUFS), 5)
122122

123-
#define PBUF_POOL_SIZE 0
124123
#define MEM_ALIGNMENT 4
125124
#define MEM_SIZE 30720
126-
#define PBUF_POOL_BUFSIZE (PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + 1280)
125+
#define PBUF_POOL_BUFSIZE (1280 + 462 + 26)
127126
#define MEMP_MEM_MALLOC 1
128127

129128
// #define LWIP_HOOK_FILENAME "lwiphooks.h"
@@ -177,4 +176,22 @@ extern const int fhost_tcpip_priority;
177176
#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) \
178177
u8_t variable_name[size] __attribute__((aligned(4))) __attribute__((section("SHAREDRAM")))
179178

179+
#if defined(CHIP_SYSTEM_CONFIG_PACKETBUFFER_LWIP_PBUF_RAM) && CHIP_SYSTEM_CONFIG_PACKETBUFFER_LWIP_PBUF_RAM
180+
#define PBUF_POOL_SIZE 0
181+
182+
#include <lwip/arch.h>
183+
#include <lwip/mem.h>
184+
#define LWIP_PBUF_CUSTOM_DATA mem_size_t pool;
185+
186+
#if defined(__cplusplus)
187+
extern "C" const mem_size_t * memp_sizes;
188+
extern "C" struct pbuf *pbuf_rightsize(struct pbuf *p, s16_t offset);
189+
#else
190+
extern const mem_size_t * memp_sizes;
191+
extern struct pbuf *pbuf_rightsize(struct pbuf *p, s16_t offset);
192+
#endif
193+
#else
194+
#define PBUF_POOL_SIZE 20
195+
#endif
196+
180197
#endif /* LWIP_HDR_LWIPOPTS_H__ */

examples/platform/bouffalolab/bl702/ldscripts/psram_flash.ld

+3
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ SECTIONS
208208
_bt_l2cap_fixed_chan_list_start = .;
209209
KEEP(*(SORT_BY_NAME("._bt_l2cap_fixed_chan.static.*")))
210210
_bt_l2cap_fixed_chan_list_end = .;
211+
212+
. = ALIGN(8);
213+
KEEP(*libCHIP.a:*(.bss.*PlatformManagerImp*))
211214
} >tcm_ocram AT >flash
212215

213216
.boot2 (NOLOAD) :

examples/platform/bouffalolab/bl702l/ldscripts/psram_flash.ld

+3
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ SECTIONS
170170
_bt_l2cap_fixed_chan_list_start = .;
171171
KEEP(*(SORT_BY_NAME("._bt_l2cap_fixed_chan.static.*")))
172172
_bt_l2cap_fixed_chan_list_end = .;
173+
174+
. = ALIGN(8);
175+
KEEP(*libCHIP.a:*(.bss.*PlatformManagerImp*))
173176
} >tcm_ocram AT >flash
174177

175178
.boot2 (NOLOAD) :

examples/platform/bouffalolab/common/bouffalo_sdk/platform_port.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ extern "C" void vAssertCalled(void)
5656
printf("vAssertCalled, ra = %p in task %s\r\n", (void *) ra, pcTaskGetName(NULL));
5757
}
5858

59-
while (true)
60-
;
59+
abort();
60+
61+
while (true) ;
6162
}
6263

6364
extern "C" void bflb_assert(void) __attribute__((weak, alias("vAssertCalled")));

examples/platform/bouffalolab/common/iot_sdk/platform_port.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ extern "C" void vAssertCalled(void)
178178

179179
portABORT();
180180

181-
while (true)
182-
;
181+
while (true) ;
183182
}
184183

185184
extern "C" void user_vAssertCalled(void) __attribute__((weak, alias("vAssertCalled")));

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ CHIP_ERROR PlatformManagerImpl::PlatformInit(void)
235235
}
236236
else
237237
{
238-
ChipLogError(NotSpecified, "sFactoryDataProvider.Init() failed");
238+
ChipLogError(NotSpecified, "factory data provider is failed to initialize, use example DAC provider.");
239+
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
239240
}
240241
#else
241242
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());

scripts/build/builders/bouffalolab.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -285,16 +285,14 @@ def PreBuildCommand(self):
285285

286286
def PostBuildCommand(self):
287287

288-
bouffalo_sdk_chips = ["bl616"]
289-
abs_path_fw = os.path.join(self.output_dir, self.app.AppNamePrefix(self.chip_name) + ".bin")
290-
291-
if self.chip_name not in bouffalo_sdk_chips:
292-
abs_path_fw_raw = os.path.join(self.output_dir, self.app.AppNamePrefix(self.chip_name) + ".raw")
288+
if self.chip_name in ["bl616"]:
289+
abs_path_fw = os.path.join(self.output_dir, self.app.AppNamePrefix(self.chip_name) + ".raw")
290+
else:
291+
abs_path_fw = os.path.join(self.output_dir, self.app.AppNamePrefix(self.chip_name) + ".bin")
293292

294293
if os.path.isfile(abs_path_fw):
295294
target_dir = self.output_dir.replace(self.chip_dir, "").strip("/")
296295

297-
abs_path_fw_bin = os.path.join(self.output_dir, self.app.AppNamePrefix(self.chip_name) + ".bin")
298296
path_fw = os.path.join(target_dir, self.app.AppNamePrefix(self.chip_name) + ".bin")
299297
path_flash_script = os.path.join(target_dir, self.app.AppNamePrefix(self.chip_name) + ".flash.py")
300298

src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ void BLWiFiDriver::OnScanWiFiNetworkDone()
268268
}
269269

270270
wifi_mgmr_ap_item_t * ScanResult = (wifi_mgmr_ap_item_t *) pvPortMalloc(ap_num * sizeof(wifi_mgmr_ap_item_t));
271-
wifi_mgmr_get_scan_result(ScanResult, &ap_num, 0, mScanSSID);
271+
wifi_mgmr_get_scan_result(ScanResult, &ap_num, mScanType, mScanSSID);
272272

273273
if (ScanResult)
274274
{

src/platform/bouffalolab/common/CHIPDevicePlatformConfig.h

+2
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,6 @@
5858
#define CHIP_CONFIG_FREERTOS_USE_STATIC_QUEUE 1
5959
#elif CHIP_DEVICE_LAYER_TARGET_BL702
6060
#define CHIP_CONFIG_FREERTOS_USE_STATIC_TASK 1
61+
#elif CHIP_DEVICE_LAYER_TARGET_BL702L
62+
#define CHIP_CONFIG_FREERTOS_USE_STATIC_TASK 1
6163
#endif

src/platform/bouffalolab/common/DiagnosticDataProviderImpl.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,20 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapUsed(uint64_t & currentHeap
7878
CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapHighWatermark(uint64_t & currentHeapHighWatermark)
7979
{
8080
#if CHIP_DEVICE_LAYER_TARGET_BL616
81-
return CHIP_ERROR_NOT_IMPLEMENTED;
81+
struct meminfo info;
82+
bflb_mem_usage(KMEM_HEAP, &info);
83+
currentHeapHighWatermark = info.total_size - info.max_free_size;
84+
8285
#else
8386
#ifdef CFG_USE_PSRAM
8487
currentHeapHighWatermark =
8588
get_heap_size() + get_heap3_size() - xPortGetMinimumEverFreeHeapSize() - xPortGetMinimumEverFreeHeapSizePsram();
8689
#else
8790
currentHeapHighWatermark = get_heap_size() - xPortGetMinimumEverFreeHeapSize();
8891
#endif
89-
return CHIP_NO_ERROR;
9092
#endif
93+
94+
return CHIP_NO_ERROR;
9195
}
9296

9397
CHIP_ERROR DiagnosticDataProviderImpl::GetThreadMetrics(ThreadMetrics ** threadMetricsOut)

src/platform/bouffalolab/common/DiagnosticDataProviderImpl.h

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class DiagnosticDataProviderImpl : public DiagnosticDataProvider
3232
static DiagnosticDataProviderImpl & GetDefaultInstance();
3333

3434
// ===== Methods that implement the PlatformManager abstract interface.
35+
bool SupportsWatermarks() override { return true; }
3536

3637
CHIP_ERROR GetCurrentHeapFree(uint64_t & currentHeapFree) override;
3738
CHIP_ERROR GetCurrentHeapUsed(uint64_t & currentHeapUsed) override;

src/platform/bouffalolab/common/SystemPlatformConfig.h

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ struct ChipDeviceEvent;
3838
// #define CHIP_CONFIG_SHA256_CONTEXT_SIZE sizeof(mbedtls_sha256_context) in hw_acc/sha256_alt.h
3939
#define CHIP_CONFIG_SHA256_CONTEXT_SIZE (32 + 64 + 64 + 19 * 32)
4040
#define CHIP_CONFIG_SHA256_CONTEXT_ALIGN 32
41-
#define CHIP_SYSTEM_CRYPTO_HEADER_RESERVE_SIZE (388)
4241
#else
4342

4443
// #define CHIP_CONFIG_SHA256_CONTEXT_SIZE sizeof(bl_sha_ctx_t)

third_party/bouffalolab/bl602/bl_iot_sdk.gni

+19-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import("${chip_root}/src/lib/lib.gni")
2020
declare_args() {
2121
bl_iot_sdk_root = "${chip_root}/third_party/bouffalolab/repo"
2222

23+
enable_lwip_pbuf_ram = false
2324
enable_debug_coredump = false
2425
coredump_binary_id = 0
2526
}
@@ -63,6 +64,11 @@ template("bl_iot_sdk") {
6364
"-include",
6465
rebase_path("${invoker.freertos_config}", root_build_dir),
6566
]
67+
68+
if (defined(invoker.enable_lwip_pbuf_ram) &&
69+
invoker.enable_lwip_pbuf_ram) {
70+
defines += [ "CHIP_SYSTEM_CONFIG_PACKETBUFFER_LWIP_PBUF_RAM=1" ]
71+
}
6672
}
6773

6874
source_set("${sdk_target_name}_soc") {
@@ -906,6 +912,11 @@ template("bl_iot_sdk") {
906912
"${bl_iot_sdk_root}/components/network/lwip_dhcpd",
907913
]
908914

915+
if (defined(invoker.enable_lwip_pbuf_ram) &&
916+
invoker.enable_lwip_pbuf_ram) {
917+
include_dirs += [ "${bouffalolab_iot_sdk_build_root}/patches/lwip" ]
918+
}
919+
909920
defines = [ "LWIP_IPV6=1" ]
910921
}
911922

@@ -927,7 +938,6 @@ template("bl_iot_sdk") {
927938
"${bl_iot_sdk_root}/components/network/lwip/src/core/inet_chksum.c",
928939
"${bl_iot_sdk_root}/components/network/lwip/src/core/init.c",
929940
"${bl_iot_sdk_root}/components/network/lwip/src/core/ip.c",
930-
"${bl_iot_sdk_root}/components/network/lwip/src/core/mem.c",
931941
"${bl_iot_sdk_root}/components/network/lwip/src/core/memp.c",
932942
"${bl_iot_sdk_root}/components/network/lwip/src/core/netif.c",
933943
"${bl_iot_sdk_root}/components/network/lwip/src/core/pbuf.c",
@@ -941,6 +951,14 @@ template("bl_iot_sdk") {
941951
"${bl_iot_sdk_root}/components/network/lwip/src/core/udp.c",
942952
]
943953

954+
if (defined(invoker.enable_lwip_pbuf_ram) &&
955+
invoker.enable_lwip_pbuf_ram) {
956+
sources += [ "${bouffalolab_iot_sdk_build_root}/patches/lwip/mem.c" ]
957+
}
958+
else {
959+
sources += [ "${bl_iot_sdk_root}/components/network/lwip/src/core/mem.c" ]
960+
}
961+
944962
sources += [
945963
"${bl_iot_sdk_root}/components/network/lwip/src/core/ipv4/autoip.c",
946964
"${bl_iot_sdk_root}/components/network/lwip/src/core/ipv4/dhcp.c",

0 commit comments

Comments
 (0)