Skip to content

Commit

Permalink
[bouffalo lab] fix wifi scan issues and update some platform changes (p…
Browse files Browse the repository at this point in the history
…roject-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>
  • Loading branch information
wy-hh and restyled-commits committed Feb 12, 2025
1 parent cdbd77f commit 517d968
Show file tree
Hide file tree
Showing 26 changed files with 210 additions and 105 deletions.
12 changes: 0 additions & 12 deletions examples/contact-sensor-app/bouffalolab/bl702l/app_pds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,9 @@ extern "C" void vApplicationSleep(TickType_t xExpectedIdleTime)
extern BaseType_t TrapNetCounter, *pTrapNetCounter;
if (app_pds_wakeup_source == PDS_WAKEUP_BY_RTC)
{
extern void * pxCurrentTCB;

ChipLogProgress(NotSpecified, "wakeup source: rtc. %lu vs %lu ms @ %lu\r\n", xExpectedIdleTime,
(uint32_t) (bl_rtc_get_timestamp_ms() - sleep_before), (uint32_t) bl_rtc_get_timestamp_ms());

ChipLogProgress(NotSpecified, "application_sleep; %lu, %lu, %lu\r\n", (uint32_t) sleep_calling_time, (uint32_t) sleep_time,
(uint32_t) wakeup_time);
}
else if (app_pds_wakeup_source == PDS_WAKEUP_BY_GPIO)
{

if (((1 << CHIP_RESET_PIN) & app_pds_wakeup_pin) && app_pds_irq_handler)
{
app_pds_irq_handler(&gpio_key);
Expand All @@ -79,10 +71,6 @@ extern "C" void vApplicationSleep(TickType_t xExpectedIdleTime)
{
app_pds_irq_handler(&gpio_contact);
}

ChipLogProgress(NotSpecified, "wakeup source: gpio -> 0x%08lX. %lu vs %lu ms @ %lu\r\n", app_pds_wakeup_pin,
xExpectedIdleTime, (uint32_t) (bl_rtc_get_timestamp_ms() - sleep_before),
(uint32_t) bl_rtc_get_timestamp_ms());
}

app_pds_wakeup_source = -1;
Expand Down
10 changes: 9 additions & 1 deletion examples/lighting-app/bouffalolab/bl602/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ bouffalolab_executable("lighting_app") {
output_name = "chip-bl602-lighting-example.out"

defines = [
"APP_TASK_STACK_SIZE=2044",
"APP_TASK_STACK_SIZE=4096",
"CHIP_UART_BAUDRATE=${baudrate}",
"START_ENTRY=bfl_main",
"SYS_AOS_LOOP_ENABLE",
Expand All @@ -109,6 +109,10 @@ bouffalolab_executable("lighting_app") {
defines +=
[ "CONFIG_BOUFFALOLAB_FACTORY_DATA_ENABLE=${chip_enable_factory_data}" ]

if (enable_lwip_pbuf_ram) {
defines += [ "CHIP_SYSTEM_CONFIG_PACKETBUFFER_LWIP_PBUF_RAM=1" ]
}

bl_plat_name = "bl602"
sources = [
"${examples_plat_dir}/common/route_hook/bl_route_hook.c",
Expand Down Expand Up @@ -227,6 +231,10 @@ bouffalolab_executable("lighting_app") {
inputs = [ ldscript ]

if (chip_print_memory_usage) {
if (enable_lwip_pbuf_ram) {
ldflags += [ "-Wl,--defsym=__RAM_PBUF_POOL=0" ]
}

ldflags += [
"-Wl,--print-memory-usage",
"-fstack-usage",
Expand Down
4 changes: 4 additions & 0 deletions examples/lighting-app/bouffalolab/bl616/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ bouffalolab_executable("lighting_app") {
defines += [ "BOOT_PIN_RESET=2" ]
}

if (enable_lwip_pbuf_ram) {
defines += [ "CHIP_SYSTEM_CONFIG_PACKETBUFFER_LWIP_PBUF_RAM=1" ]
}

defines += [ "BL616DK" ]

sources = [
Expand Down
11 changes: 1 addition & 10 deletions examples/lighting-app/bouffalolab/bl616/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,7 @@ import("${chip_root}/src/platform/bouffalolab/BL616/args.gni")

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

pw_log_BACKEND = "${chip_root}/src/pw_backends/log"
pw_assert_BACKEND = "${chip_root}/src/pw_backends/assert"
pw_rpc_CONFIG = "$dir_pw_rpc:disable_global_mutex"

chip_detail_logging = true
chip_detail_logging = false

# use -Os instead of -Og
is_debug = false

pw_build_LINK_DEPS = [
"$dir_pw_assert:impl",
"$dir_pw_log:impl",
]
2 changes: 1 addition & 1 deletion examples/lighting-app/bouffalolab/bl702/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ bouffalolab_executable("lighting_app") {
bl_plat_name = "bl702"

defines = [
"APP_TASK_STACK_SIZE=2048",
"APP_TASK_STACK_SIZE=4096",
"CHIP_UART_BAUDRATE=${baudrate}",
"START_ENTRY=bl702_main",
]
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/bouffalolab/bl702l/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ bouffalolab_executable("lighting_app") {
bl_plat_name = "bl702l"

defines = [
"APP_TASK_STACK_SIZE=2048",
"APP_TASK_STACK_SIZE=4096",
"CHIP_UART_BAUDRATE=${baudrate}",
"START_ENTRY=bl702_main",
]
Expand Down
7 changes: 6 additions & 1 deletion examples/platform/bouffalolab/bl602/ldscripts/flash_rom.ld
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ __RFTLV_HEAD1_L = (0x41524150); /* PAPA */
__RAM_START = 0x4200C000;
__RAM_END = 0x4200C000 + 256K - __EM_SIZE; /* leave 8K left for BLE */

__RAM_TCM_LEN = (16K + 16K + 48K + 64K + 64K - 16K - 16K);
__RAM_PBUF_POOL = DEFINED(__RAM_PBUF_POOL) ? __RAM_PBUF_POOL : 30K;

__RAM_TCM_LEN = (16K + 16K + 48K + 64K + 64K - 16K - 16K + 30K - 12K - __RAM_PBUF_POOL);
__RAM_WIFI_LEN = (__RAM_END - __RAM_START - __RAM_TCM_LEN);

MEMORY
Expand Down Expand Up @@ -173,6 +175,9 @@ SECTIONS
*libwifi_drv.a:bl_utils.o(.bss*)
*(.wifi_ram*)
. = ALIGN(16);

KEEP(*libCHIP.a:*(.bss.*PlatformManagerImp*))
. = ALIGN(16);
} > ram_wifi

PROVIDE( _heap_wifi_start = . );
Expand Down
30 changes: 23 additions & 7 deletions examples/platform/bouffalolab/bl602/lwipopts/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ a lot of data that needs to be copied, this should be set high. */

#define MEMP_NUM_NETCONN (MEMP_NUM_TCP_PCB + MEMP_NUM_UDP_PCB + MEMP_NUM_TCP_PCB_LISTEN)

/* ---------- Pbuf options ---------- */
/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */
#define PBUF_POOL_SIZE 20

/* ---------- TCP options ---------- */
#define LWIP_TCP 1
#define IP_DEFAULT_TTL 64
Expand Down Expand Up @@ -269,17 +265,37 @@ a lot of data that needs to be copied, this should be set high. */

#define LWIP_NETIF_EXT_STATUS_CALLBACK 1

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

#define LWIP_PBUF_FROM_CUSTOM_POOLS (0)

/*
---------------------------------
---------- MISC. options ----------
---------------------------------
*/

#if defined(CHIP_SYSTEM_CONFIG_PACKETBUFFER_LWIP_PBUF_RAM) && CHIP_SYSTEM_CONFIG_PACKETBUFFER_LWIP_PBUF_RAM
#define PBUF_POOL_SIZE 0
#define MEM_LIBC_MALLOC 0
#define MEM_USE_POOLS 0
#define MEMP_USE_CUSTOM_POOLS 0

#include <lwip/arch.h>
#include <lwip/mem.h>
#define LWIP_PBUF_CUSTOM_DATA mem_size_t pool;

#if defined(__cplusplus)
extern "C" const mem_size_t * memp_sizes;
extern "C" struct pbuf * pbuf_rightsize(struct pbuf * p, s16_t offset);
#else
extern const mem_size_t * memp_sizes;
extern struct pbuf * pbuf_rightsize(struct pbuf * p, s16_t offset);
#endif
#else

#define PBUF_POOL_SIZE 20
#define LWIP_PBUF_FROM_CUSTOM_POOLS (0)
#endif

#if defined(__cplusplus)
extern "C" int bl_rand(void);
extern "C" int * __errno(void);
Expand Down
21 changes: 19 additions & 2 deletions examples/platform/bouffalolab/bl616/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,9 @@ extern const int fhost_tcpip_priority;
#define MEMP_NUM_UDP_PCB 16
#define MEMP_NUM_REASSDATA LWIP_MIN((IP_REASS_MAX_PBUFS), 5)

#define PBUF_POOL_SIZE 0
#define MEM_ALIGNMENT 4
#define MEM_SIZE 30720
#define PBUF_POOL_BUFSIZE (PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + 1280)
#define PBUF_POOL_BUFSIZE (1280 + 462 + 26)
#define MEMP_MEM_MALLOC 1

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

#if defined(CHIP_SYSTEM_CONFIG_PACKETBUFFER_LWIP_PBUF_RAM) && CHIP_SYSTEM_CONFIG_PACKETBUFFER_LWIP_PBUF_RAM
#define PBUF_POOL_SIZE 0

#include <lwip/arch.h>
#include <lwip/mem.h>
#define LWIP_PBUF_CUSTOM_DATA mem_size_t pool;

#if defined(__cplusplus)
extern "C" const mem_size_t * memp_sizes;
extern "C" struct pbuf * pbuf_rightsize(struct pbuf * p, s16_t offset);
#else
extern const mem_size_t * memp_sizes;
extern struct pbuf * pbuf_rightsize(struct pbuf * p, s16_t offset);
#endif
#else
#define PBUF_POOL_SIZE 20
#endif

#endif /* LWIP_HDR_LWIPOPTS_H__ */
3 changes: 3 additions & 0 deletions examples/platform/bouffalolab/bl702/ldscripts/psram_flash.ld
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ SECTIONS
_bt_l2cap_fixed_chan_list_start = .;
KEEP(*(SORT_BY_NAME("._bt_l2cap_fixed_chan.static.*")))
_bt_l2cap_fixed_chan_list_end = .;

. = ALIGN(8);
KEEP(*libCHIP.a:*(.bss.*PlatformManagerImp*))
} >tcm_ocram AT >flash

.boot2 (NOLOAD) :
Expand Down
3 changes: 3 additions & 0 deletions examples/platform/bouffalolab/bl702l/ldscripts/psram_flash.ld
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ SECTIONS
_bt_l2cap_fixed_chan_list_start = .;
KEEP(*(SORT_BY_NAME("._bt_l2cap_fixed_chan.static.*")))
_bt_l2cap_fixed_chan_list_end = .;

. = ALIGN(8);
KEEP(*libCHIP.a:*(.bss.*PlatformManagerImp*))
} >tcm_ocram AT >flash

.boot2 (NOLOAD) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ extern "C" void vAssertCalled(void)
printf("vAssertCalled, ra = %p in task %s\r\n", (void *) ra, pcTaskGetName(NULL));
}

abort();

while (true)
;
}
Expand Down
3 changes: 2 additions & 1 deletion examples/platform/bouffalolab/common/plat/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ CHIP_ERROR PlatformManagerImpl::PlatformInit(void)
}
else
{
ChipLogError(NotSpecified, "sFactoryDataProvider.Init() failed");
ChipLogError(NotSpecified, "factory data provider is failed to initialize, use example DAC provider.");
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
}
#else
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
Expand Down
10 changes: 4 additions & 6 deletions scripts/build/builders/bouffalolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,16 +285,14 @@ def PreBuildCommand(self):

def PostBuildCommand(self):

bouffalo_sdk_chips = ["bl616"]
abs_path_fw = os.path.join(self.output_dir, self.app.AppNamePrefix(self.chip_name) + ".bin")

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ void BLWiFiDriver::OnScanWiFiNetworkDone()
}

wifi_mgmr_ap_item_t * ScanResult = (wifi_mgmr_ap_item_t *) pvPortMalloc(ap_num * sizeof(wifi_mgmr_ap_item_t));
wifi_mgmr_get_scan_result(ScanResult, &ap_num, 0, mScanSSID);
wifi_mgmr_get_scan_result(ScanResult, &ap_num, mScanType, mScanSSID);

if (ScanResult)
{
Expand Down
7 changes: 7 additions & 0 deletions src/platform/bouffalolab/BL702/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,15 @@ extern "C" void wifiInterface_eventGotIP(struct netif * interface)

extern "C" void wifiInterface_eventScanDone(struct netif * interface, netbus_fs_scan_ind_cmd_msg_t * pmsg)
{
ChipDeviceEvent event;

ChipLogProgress(DeviceLayer, "wifiInterface_eventScanDone");

memset(&event, 0, sizeof(ChipDeviceEvent));
NetworkCommissioning::BLWiFiDriver::GetInstance().OnScanWiFiNetworkDone(pmsg);

event.Type = kWiFiOnScanDone;
PlatformMgr().PostEventOrDie(&event);
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI

Expand Down
Loading

0 comments on commit 517d968

Please sign in to comment.