Skip to content

Commit e30b0dc

Browse files
wy-hhrestyled-commits
authored andcommitted
[bouffalo lab] fix wifi scan issues and update some platform changes (project-chip#37455)
* [bouffalo lab] fix wifi scan issues and update some platform changes * Restyled by clang-format * Restyled by gn * Restyled by clang-format * fix wifi scan on bl706 + bl602 platform * Restyled by whitespace * Restyled by clang-format * use strncpy to copy ssid * Restyled by whitespace * Restyled by clang-format --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent f76019b commit e30b0dc

File tree

26 files changed

+210
-105
lines changed

26 files changed

+210
-105
lines changed

examples/contact-sensor-app/bouffalolab/bl702l/app_pds.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,9 @@ extern "C" void vApplicationSleep(TickType_t xExpectedIdleTime)
5959
extern BaseType_t TrapNetCounter, *pTrapNetCounter;
6060
if (app_pds_wakeup_source == PDS_WAKEUP_BY_RTC)
6161
{
62-
extern void * pxCurrentTCB;
63-
64-
ChipLogProgress(NotSpecified, "wakeup source: rtc. %lu vs %lu ms @ %lu\r\n", xExpectedIdleTime,
65-
(uint32_t) (bl_rtc_get_timestamp_ms() - sleep_before), (uint32_t) bl_rtc_get_timestamp_ms());
66-
67-
ChipLogProgress(NotSpecified, "application_sleep; %lu, %lu, %lu\r\n", (uint32_t) sleep_calling_time, (uint32_t) sleep_time,
68-
(uint32_t) wakeup_time);
6962
}
7063
else if (app_pds_wakeup_source == PDS_WAKEUP_BY_GPIO)
7164
{
72-
7365
if (((1 << CHIP_RESET_PIN) & app_pds_wakeup_pin) && app_pds_irq_handler)
7466
{
7567
app_pds_irq_handler(&gpio_key);
@@ -79,10 +71,6 @@ extern "C" void vApplicationSleep(TickType_t xExpectedIdleTime)
7971
{
8072
app_pds_irq_handler(&gpio_contact);
8173
}
82-
83-
ChipLogProgress(NotSpecified, "wakeup source: gpio -> 0x%08lX. %lu vs %lu ms @ %lu\r\n", app_pds_wakeup_pin,
84-
xExpectedIdleTime, (uint32_t) (bl_rtc_get_timestamp_ms() - sleep_before),
85-
(uint32_t) bl_rtc_get_timestamp_ms());
8674
}
8775

8876
app_pds_wakeup_source = -1;

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

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

9898
defines = [
99-
"APP_TASK_STACK_SIZE=2044",
99+
"APP_TASK_STACK_SIZE=4096",
100100
"CHIP_UART_BAUDRATE=${baudrate}",
101101
"START_ENTRY=bfl_main",
102102
"SYS_AOS_LOOP_ENABLE",
@@ -109,6 +109,10 @@ bouffalolab_executable("lighting_app") {
109109
defines +=
110110
[ "CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE=${chip_enable_factory_data}" ]
111111

112+
if (enable_lwip_pbuf_ram) {
113+
defines += [ "CHIP_SYSTEM_CONFIG_PACKETBUFFER_LWIP_PBUF_RAM=1" ]
114+
}
115+
112116
bl_plat_name = "bl602"
113117
sources = [
114118
"${examples_plat_dir}/common/route_hook/bl_route_hook.c",
@@ -227,6 +231,10 @@ bouffalolab_executable("lighting_app") {
227231
inputs = [ ldscript ]
228232

229233
if (chip_print_memory_usage) {
234+
if (enable_lwip_pbuf_ram) {
235+
ldflags += [ "-Wl,--defsym=__RAM_PBUF_POOL=0" ]
236+
}
237+
230238
ldflags += [
231239
"-Wl,--print-memory-usage",
232240
"-fstack-usage",

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

+4
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ bouffalolab_executable("lighting_app") {
121121
defines += [ "BOOT_PIN_RESET=2" ]
122122
}
123123

124+
if (enable_lwip_pbuf_ram) {
125+
defines += [ "CHIP_SYSTEM_CONFIG_PACKETBUFFER_LWIP_PBUF_RAM=1" ]
126+
}
127+
124128
defines += [ "BL616DK" ]
125129

126130
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
@@ -126,7 +126,7 @@ bouffalolab_executable("lighting_app") {
126126
bl_plat_name = "bl702"
127127

128128
defines = [
129-
"APP_TASK_STACK_SIZE=2048",
129+
"APP_TASK_STACK_SIZE=4096",
130130
"CHIP_UART_BAUDRATE=${baudrate}",
131131
"START_ENTRY=bl702_main",
132132
]

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

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

59+
abort();
60+
5961
while (true)
6062
;
6163
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ CHIP_ERROR PlatformManagerImpl::PlatformInit(void)
264264
}
265265
else
266266
{
267-
ChipLogError(NotSpecified, "sFactoryDataProvider.Init() failed");
267+
ChipLogError(NotSpecified, "factory data provider is failed to initialize, use example DAC provider.");
268+
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
268269
}
269270
#else
270271
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/BL702/ConnectivityManagerImpl.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,15 @@ extern "C" void wifiInterface_eventGotIP(struct netif * interface)
106106

107107
extern "C" void wifiInterface_eventScanDone(struct netif * interface, netbus_fs_scan_ind_cmd_msg_t * pmsg)
108108
{
109+
ChipDeviceEvent event;
110+
109111
ChipLogProgress(DeviceLayer, "wifiInterface_eventScanDone");
112+
113+
memset(&event, 0, sizeof(ChipDeviceEvent));
110114
NetworkCommissioning::BLWiFiDriver::GetInstance().OnScanWiFiNetworkDone(pmsg);
115+
116+
event.Type = kWiFiOnScanDone;
117+
PlatformMgr().PostEventOrDie(&event);
111118
}
112119
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI
113120

0 commit comments

Comments
 (0)