From b4075188b4a8206b0af4fdeaf220fbd072fe914a Mon Sep 17 00:00:00 2001 From: jczhang777 <101778393+jczhang777@users.noreply.github.com> Date: Fri, 16 Sep 2022 22:36:06 +0800 Subject: [PATCH] [BL602] Fix sve2 problems (#22582) * [BL602] Fix sve2 problems * Restyled by whitespace * Restyled by clang-format * Restyled by gn * [BL602] Update readme * call ef_env_set_default to do factory reset * [BL602] Fix code review issues * Restyled by clang-format * [BL602] Delete not use code Co-authored-by: Restyled.io Co-authored-by: wyhong --- .../lighting-app/bouffalolab/bl602/README.md | 2 +- .../bouffalolab/bl602/src/AppTask.cpp | 2 +- .../bouffalolab/bl602/ldscripts/flash_rom.ld | 2 +- .../bouffalolab/BL602/CHIPPlatformConfig.h | 4 ++ .../BL602/ConfigurationManagerImpl.cpp | 1 + .../BL602/DiagnosticDataProviderImpl.cpp | 45 ++++++++++++++++--- .../BL602/NetworkCommissioningDriver.cpp | 27 ++++++++++- .../BL602/OTAImageProcessorImpl.cpp | 2 +- .../bouffalolab/BL602/PlatformManagerImpl.cpp | 3 +- third_party/bouffalolab/bl602/bl602_sdk.gni | 7 +-- third_party/bouffalolab/repo | 2 +- 11 files changed, 78 insertions(+), 19 deletions(-) diff --git a/examples/lighting-app/bouffalolab/bl602/README.md b/examples/lighting-app/bouffalolab/bl602/README.md index 7a42f8f17abbe4..d82959afd7a19d 100644 --- a/examples/lighting-app/bouffalolab/bl602/README.md +++ b/examples/lighting-app/bouffalolab/bl602/README.md @@ -66,7 +66,7 @@ The steps in this document were validated on Ubuntu 18.04 and 20.04. ``` cd third_party/bouffalolab/repo/tools/flash_tool - ./bflb_iot_tool-ubuntu18 --chipname=BL602 --baudrate=115200 --port=/dev/ttyACM0 --pt=chips/bl602/partition/partition_cfg_4M.toml --dts=chips/bl602/device_tree/bl_factory_params_IoTKitA_40M.dts --firmware=../../../../../../out/bl602-light/chip-bl602-lighting-example.bin + ./bflb_iot_tool --chipname=BL602 --baudrate=115200 --port=/dev/ttyACM0 --pt=chips/bl602/partition/partition_cfg_4M.toml --dts=chips/bl602/device_tree/bl_factory_params_IoTKitA_40M.dts --firmware=../../../../../out/bl602-light/chip-bl602-lighting-example.bin ``` ``` diff --git a/examples/lighting-app/bouffalolab/bl602/src/AppTask.cpp b/examples/lighting-app/bouffalolab/bl602/src/AppTask.cpp index 8774b47b123c4a..62bb09cb5b928b 100644 --- a/examples/lighting-app/bouffalolab/bl602/src/AppTask.cpp +++ b/examples/lighting-app/bouffalolab/bl602/src/AppTask.cpp @@ -55,7 +55,7 @@ #define FACTORY_RESET_TRIGGER_TIMEOUT 3000 #define FACTORY_RESET_CANCEL_WINDOW_TIMEOUT 3000 #define APP_EVENT_QUEUE_SIZE 10 -#define APP_TASK_STACK_SIZE (8192) +#define APP_TASK_STACK_SIZE (4096) #define APP_TASK_PRIORITY 2 #define STATUS_LED_GPIO_NUM GPIO_NUM_2 // Use LED1 (blue LED) as status LED on DevKitC diff --git a/examples/platform/bouffalolab/bl602/ldscripts/flash_rom.ld b/examples/platform/bouffalolab/bl602/ldscripts/flash_rom.ld index 1741f6fb671568..0ed6b74099b710 100644 --- a/examples/platform/bouffalolab/bl602/ldscripts/flash_rom.ld +++ b/examples/platform/bouffalolab/bl602/ldscripts/flash_rom.ld @@ -11,7 +11,7 @@ __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); +__RAM_TCM_LEN = (16K + 16K + 48K + 64K + 64K - 16K - 16K); __RAM_WIFI_LEN = (__RAM_END - __RAM_START - __RAM_TCM_LEN); MEMORY diff --git a/src/platform/bouffalolab/BL602/CHIPPlatformConfig.h b/src/platform/bouffalolab/BL602/CHIPPlatformConfig.h index 2a5cfebda28e17..4117d3a1245ca3 100644 --- a/src/platform/bouffalolab/BL602/CHIPPlatformConfig.h +++ b/src/platform/bouffalolab/BL602/CHIPPlatformConfig.h @@ -109,6 +109,10 @@ #define CHIP_CONFIG_MAX_LOCAL_ADDR_UDP_ENDPOINTS 4 #endif // CHIP_CONFIG_MAX_LOCAL_ADDR_UDP_ENDPOINTS +#ifndef CHIP_CONFIG_MAX_FABRICS +#define CHIP_CONFIG_MAX_FABRICS 6 // 5 fabrics + 1 for rotation slack +#endif + // ==================== Security Configuration Overrides ==================== #ifndef CHIP_CONFIG_DEBUG_CERT_VALIDATION diff --git a/src/platform/bouffalolab/BL602/ConfigurationManagerImpl.cpp b/src/platform/bouffalolab/BL602/ConfigurationManagerImpl.cpp index 463997cf0b29d7..f207e295ca882f 100644 --- a/src/platform/bouffalolab/BL602/ConfigurationManagerImpl.cpp +++ b/src/platform/bouffalolab/BL602/ConfigurationManagerImpl.cpp @@ -216,6 +216,7 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) CHIP_ERROR err; ChipLogProgress(DeviceLayer, "Performing factory reset"); + ef_env_set_default(); ChipLogProgress(DeviceLayer, "System restarting"); hal_reboot(); } diff --git a/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp b/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp index eedf4eebf056a5..f116522a12b0c2 100644 --- a/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp +++ b/src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp @@ -163,11 +163,29 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetBootReason(BootReasonType & bootReason return CHIP_NO_ERROR; } +static int bl_netif_get_all_ip6(struct netif * netif, ip6_addr_t if_ip6[]) +{ + if (netif == NULL || if_ip6 == NULL) + { + return 0; + } + + int addr_count = 0; + for (int i = 0; (i < LWIP_IPV6_NUM_ADDRESSES) && (i < kMaxIPv6AddrCount); i++) + { + if (!ip_addr_cmp(&netif->ip6_addr[i], IP6_ADDR_ANY)) + { + memcpy(&if_ip6[addr_count++], &netif->ip6_addr[i], sizeof(ip6_addr_t)); + } + } + + return addr_count; +} + CHIP_ERROR DiagnosticDataProviderImpl::GetNetworkInterfaces(NetworkInterface ** netifpp) { NetworkInterface * ifp = new NetworkInterface(); struct netif * netif; - uint8_t mac_addr[6]; netif = wifi_mgmr_sta_netif_get(); if (netif) @@ -179,10 +197,28 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetNetworkInterfaces(NetworkInterface ** ifp->type = EMBER_ZCL_INTERFACE_TYPE_WI_FI; ifp->offPremiseServicesReachableIPv4.SetNull(); ifp->offPremiseServicesReachableIPv6.SetNull(); - bl_efuse_read_mac(mac_addr); - memcpy(ifp->MacAddress, mac_addr, sizeof(mac_addr)); + bl_efuse_read_mac(ifp->MacAddress); + ifp->hardwareAddress = ByteSpan(ifp->MacAddress, 6); + + uint32_t ip, gw, mask; + wifi_mgmr_sta_ip_get(&ip, &gw, &mask); + memcpy(ifp->Ipv4AddressesBuffer[0], &ip, kMaxIPv4AddrSize); + ifp->Ipv4AddressSpans[0] = ByteSpan(ifp->Ipv4AddressesBuffer[0], kMaxIPv4AddrSize); + ifp->IPv4Addresses = chip::app::DataModel::List(ifp->Ipv4AddressSpans, 1); + + uint8_t ipv6_addr_count = 0; + ip6_addr_t ip6_addr[kMaxIPv6AddrCount]; + ipv6_addr_count = bl_netif_get_all_ip6(netif, ip6_addr); + for (uint8_t idx = 0; idx < ipv6_addr_count; ++idx) + { + memcpy(ifp->Ipv6AddressesBuffer[idx], ip6_addr[idx].addr, kMaxIPv6AddrSize); + ifp->Ipv6AddressSpans[idx] = ByteSpan(ifp->Ipv6AddressesBuffer[idx], kMaxIPv6AddrSize); + } + ifp->IPv6Addresses = chip::app::DataModel::List(ifp->Ipv6AddressSpans, ipv6_addr_count); } + *netifpp = ifp; + return CHIP_NO_ERROR; } @@ -256,8 +292,7 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiBeaconLostCount(uint32_t & beaconL CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiCurrentMaxRate(uint64_t & currentMaxRate) { - currentMaxRate = 0; - return CHIP_NO_ERROR; + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiPacketMulticastRxCount(uint32_t & packetMulticastRxCount) diff --git a/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp b/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp index 1a99e17b6b4dd9..b99b4d212ae739 100644 --- a/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp +++ b/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp @@ -32,6 +32,8 @@ #include #include +#define WIFI_STA_DISCONNECT_DELAY (pdMS_TO_TICKS(200)) + using namespace ::chip; //#if CHIP_DEVICE_CONFIG_ENABLE_WIFI namespace chip { @@ -121,6 +123,9 @@ bool BLWiFiDriver::NetworkMatch(const WiFiNetwork & network, ByteSpan networkId) Status BLWiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) { + outDebugText.reduce_size(0); + outNetworkIndex = 0; + VerifyOrReturnError(mStagingNetwork.ssidLen == 0 || NetworkMatch(mStagingNetwork, ssid), Status::kBoundsExceeded); VerifyOrReturnError(credentials.size() <= sizeof(mStagingNetwork.credentials), Status::kOutOfRange); VerifyOrReturnError(ssid.size() <= sizeof(mStagingNetwork.ssid), Status::kOutOfRange); @@ -136,6 +141,9 @@ Status BLWiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, Mut Status BLWiFiDriver::RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) { + outDebugText.reduce_size(0); + outNetworkIndex = 0; + VerifyOrReturnError(NetworkMatch(mStagingNetwork, networkId), Status::kNetworkIDNotFound); // Use empty ssid for representing invalid network @@ -145,6 +153,8 @@ Status BLWiFiDriver::RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebu Status BLWiFiDriver::ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText) { + outDebugText.reduce_size(0); + // Only one network is supported now VerifyOrReturnError(index == 0, Status::kOutOfRange); VerifyOrReturnError(NetworkMatch(mStagingNetwork, networkId), Status::kNetworkIDNotFound); @@ -157,12 +167,24 @@ CHIP_ERROR BLWiFiDriver::ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, char wifi_ssid[64] = { 0 }; char passwd[64] = { 0 }; - // Set the wifi configuration + int state = 0; + + wifi_mgmr_sta_disconnect(); + vTaskDelay(WIFI_STA_DISCONNECT_DELAY); + + wifi_mgmr_sta_disable(NULL); + wifi_mgmr_state_get(&state); + while (state != WIFI_STATE_IDLE) + { + wifi_mgmr_state_get(&state); + vTaskDelay(100); + } + memcpy(wifi_ssid, ssid, ssidLen); memcpy(passwd, key, keyLen); wifi_interface_t wifi_interface; wifi_interface = wifi_mgmr_sta_enable(); - wifi_mgmr_sta_connect(wifi_interface, ssid, passwd, NULL, NULL, 0, 0); + wifi_mgmr_sta_connect(wifi_interface, wifi_ssid, passwd, NULL, NULL, 0, 0); ReturnErrorOnFailure(ConnectivityMgr().SetWiFiStationMode(ConnectivityManager::kWiFiStationMode_Disabled)); @@ -280,6 +302,7 @@ void BLWiFiDriver::OnScanWiFiNetworkDone() } })) { + vPortFree(ScanResult); ChipLogProgress(DeviceLayer, "ScheduleLambda OK"); } } diff --git a/src/platform/bouffalolab/BL602/OTAImageProcessorImpl.cpp b/src/platform/bouffalolab/BL602/OTAImageProcessorImpl.cpp index 6a94570ac2abb5..a24d9316f6d5f7 100644 --- a/src/platform/bouffalolab/BL602/OTAImageProcessorImpl.cpp +++ b/src/platform/bouffalolab/BL602/OTAImageProcessorImpl.cpp @@ -158,7 +158,7 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) } DeviceLayer::SystemLayer().StartTimer( - System::Clock::Seconds32(2), + System::Clock::Seconds32(4), [](Layer *, void *) { ChipLogProgress(SoftwareUpdate, "Rebooting..."); hal_reboot(); diff --git a/src/platform/bouffalolab/BL602/PlatformManagerImpl.cpp b/src/platform/bouffalolab/BL602/PlatformManagerImpl.cpp index 7e0ad568cdbe78..930ff9cd292bdf 100644 --- a/src/platform/bouffalolab/BL602/PlatformManagerImpl.cpp +++ b/src/platform/bouffalolab/BL602/PlatformManagerImpl.cpp @@ -67,6 +67,8 @@ static int app_entropy_source(void * data, unsigned char * output, size_t len, s static void WifiStaDisconect(void) { + NetworkCommissioning::BLWiFiDriver::GetInstance().SetLastDisconnectReason(NULL); + uint16_t reason = NetworkCommissioning::BLWiFiDriver::GetInstance().GetLastDisconnectReason(); uint8_t associationFailureCause = chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::AssociationFailureCause::kUnknown); @@ -138,7 +140,6 @@ static void WifiStaDisconect(void) chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::WiFiConnectionStatus::kNotConnected)); } - NetworkCommissioning::BLWiFiDriver::GetInstance().SetLastDisconnectReason(NULL); ConnectivityMgrImpl().ChangeWiFiStationState(ConnectivityManagerImpl::kWiFiStationState_Disconnecting); } diff --git a/third_party/bouffalolab/bl602/bl602_sdk.gni b/third_party/bouffalolab/bl602/bl602_sdk.gni index b2c14a30cafb01..ce3ca73a90a7c7 100644 --- a/third_party/bouffalolab/bl602/bl602_sdk.gni +++ b/third_party/bouffalolab/bl602/bl602_sdk.gni @@ -189,7 +189,7 @@ template("bl602_sdk") { "SYS_AOS_LOOP_ENABLE=1", "BL602_USE_HAL_DRIVER=1", "BL602=BL602", - "SYS_LOOPRT_ENABLE=1", + "CFG_TXDESC=2", "CFG_STA_MAX=1", "CFG_CHIP_BL602", @@ -295,11 +295,6 @@ template("bl602_sdk") { cflags_cc += [ "-std=c++17" ] cflags_cc += [ "-D _GNU_SOURCE" ] - #cflags_cc += [ "-fcommon" ] - #cflags_cc += [ "-fno-rtti" ] - #cflags_cc += [ "-Wnon-virtual-dtor" ] - #cflags_cc += [ "-frtti" ] - foreach(include_dir, _include_dirs) { cflags += [ "-isystem" + rebase_path(include_dir, root_build_dir) ] } diff --git a/third_party/bouffalolab/repo b/third_party/bouffalolab/repo index 78561b2b5f72c3..880fc351904db2 160000 --- a/third_party/bouffalolab/repo +++ b/third_party/bouffalolab/repo @@ -1 +1 @@ -Subproject commit 78561b2b5f72c340afa94eb2be56fca7e6cab636 +Subproject commit 880fc351904db2825d3a2c767d60fe1ae8cc5722