Skip to content

Commit 69551a1

Browse files
jczhang777restyled-commitswy-hh
authored
[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 <[email protected]> Co-authored-by: wyhong <[email protected]>
1 parent a736e56 commit 69551a1

File tree

11 files changed

+78
-19
lines changed

11 files changed

+78
-19
lines changed

examples/lighting-app/bouffalolab/bl602/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ The steps in this document were validated on Ubuntu 18.04 and 20.04.
6666
```
6767
cd third_party/bouffalolab/repo/tools/flash_tool
6868
69-
./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
69+
./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
7070
```
7171
7272
```

examples/lighting-app/bouffalolab/bl602/src/AppTask.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
#define FACTORY_RESET_TRIGGER_TIMEOUT 3000
5656
#define FACTORY_RESET_CANCEL_WINDOW_TIMEOUT 3000
5757
#define APP_EVENT_QUEUE_SIZE 10
58-
#define APP_TASK_STACK_SIZE (8192)
58+
#define APP_TASK_STACK_SIZE (4096)
5959
#define APP_TASK_PRIORITY 2
6060
#define STATUS_LED_GPIO_NUM GPIO_NUM_2 // Use LED1 (blue LED) as status LED on DevKitC
6161

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ __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);
14+
__RAM_TCM_LEN = (16K + 16K + 48K + 64K + 64K - 16K - 16K);
1515
__RAM_WIFI_LEN = (__RAM_END - __RAM_START - __RAM_TCM_LEN);
1616

1717
MEMORY

src/platform/bouffalolab/BL602/CHIPPlatformConfig.h

+4
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@
109109
#define CHIP_CONFIG_MAX_LOCAL_ADDR_UDP_ENDPOINTS 4
110110
#endif // CHIP_CONFIG_MAX_LOCAL_ADDR_UDP_ENDPOINTS
111111

112+
#ifndef CHIP_CONFIG_MAX_FABRICS
113+
#define CHIP_CONFIG_MAX_FABRICS 6 // 5 fabrics + 1 for rotation slack
114+
#endif
115+
112116
// ==================== Security Configuration Overrides ====================
113117

114118
#ifndef CHIP_CONFIG_DEBUG_CERT_VALIDATION

src/platform/bouffalolab/BL602/ConfigurationManagerImpl.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
216216
CHIP_ERROR err;
217217

218218
ChipLogProgress(DeviceLayer, "Performing factory reset");
219+
ef_env_set_default();
219220
ChipLogProgress(DeviceLayer, "System restarting");
220221
hal_reboot();
221222
}

src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp

+40-5
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,29 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetBootReason(BootReasonType & bootReason
163163
return CHIP_NO_ERROR;
164164
}
165165

166+
static int bl_netif_get_all_ip6(struct netif * netif, ip6_addr_t if_ip6[])
167+
{
168+
if (netif == NULL || if_ip6 == NULL)
169+
{
170+
return 0;
171+
}
172+
173+
int addr_count = 0;
174+
for (int i = 0; (i < LWIP_IPV6_NUM_ADDRESSES) && (i < kMaxIPv6AddrCount); i++)
175+
{
176+
if (!ip_addr_cmp(&netif->ip6_addr[i], IP6_ADDR_ANY))
177+
{
178+
memcpy(&if_ip6[addr_count++], &netif->ip6_addr[i], sizeof(ip6_addr_t));
179+
}
180+
}
181+
182+
return addr_count;
183+
}
184+
166185
CHIP_ERROR DiagnosticDataProviderImpl::GetNetworkInterfaces(NetworkInterface ** netifpp)
167186
{
168187
NetworkInterface * ifp = new NetworkInterface();
169188
struct netif * netif;
170-
uint8_t mac_addr[6];
171189

172190
netif = wifi_mgmr_sta_netif_get();
173191
if (netif)
@@ -179,10 +197,28 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetNetworkInterfaces(NetworkInterface **
179197
ifp->type = EMBER_ZCL_INTERFACE_TYPE_WI_FI;
180198
ifp->offPremiseServicesReachableIPv4.SetNull();
181199
ifp->offPremiseServicesReachableIPv6.SetNull();
182-
bl_efuse_read_mac(mac_addr);
183-
memcpy(ifp->MacAddress, mac_addr, sizeof(mac_addr));
200+
bl_efuse_read_mac(ifp->MacAddress);
201+
ifp->hardwareAddress = ByteSpan(ifp->MacAddress, 6);
202+
203+
uint32_t ip, gw, mask;
204+
wifi_mgmr_sta_ip_get(&ip, &gw, &mask);
205+
memcpy(ifp->Ipv4AddressesBuffer[0], &ip, kMaxIPv4AddrSize);
206+
ifp->Ipv4AddressSpans[0] = ByteSpan(ifp->Ipv4AddressesBuffer[0], kMaxIPv4AddrSize);
207+
ifp->IPv4Addresses = chip::app::DataModel::List<chip::ByteSpan>(ifp->Ipv4AddressSpans, 1);
208+
209+
uint8_t ipv6_addr_count = 0;
210+
ip6_addr_t ip6_addr[kMaxIPv6AddrCount];
211+
ipv6_addr_count = bl_netif_get_all_ip6(netif, ip6_addr);
212+
for (uint8_t idx = 0; idx < ipv6_addr_count; ++idx)
213+
{
214+
memcpy(ifp->Ipv6AddressesBuffer[idx], ip6_addr[idx].addr, kMaxIPv6AddrSize);
215+
ifp->Ipv6AddressSpans[idx] = ByteSpan(ifp->Ipv6AddressesBuffer[idx], kMaxIPv6AddrSize);
216+
}
217+
ifp->IPv6Addresses = chip::app::DataModel::List<chip::ByteSpan>(ifp->Ipv6AddressSpans, ipv6_addr_count);
184218
}
185219

220+
*netifpp = ifp;
221+
186222
return CHIP_NO_ERROR;
187223
}
188224

@@ -256,8 +292,7 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiBeaconLostCount(uint32_t & beaconL
256292

257293
CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiCurrentMaxRate(uint64_t & currentMaxRate)
258294
{
259-
currentMaxRate = 0;
260-
return CHIP_NO_ERROR;
295+
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
261296
}
262297

263298
CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiPacketMulticastRxCount(uint32_t & packetMulticastRxCount)

src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp

+25-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include <string>
3333
#include <utils_log.h>
3434

35+
#define WIFI_STA_DISCONNECT_DELAY (pdMS_TO_TICKS(200))
36+
3537
using namespace ::chip;
3638
//#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
3739
namespace chip {
@@ -121,6 +123,9 @@ bool BLWiFiDriver::NetworkMatch(const WiFiNetwork & network, ByteSpan networkId)
121123
Status BLWiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, MutableCharSpan & outDebugText,
122124
uint8_t & outNetworkIndex)
123125
{
126+
outDebugText.reduce_size(0);
127+
outNetworkIndex = 0;
128+
124129
VerifyOrReturnError(mStagingNetwork.ssidLen == 0 || NetworkMatch(mStagingNetwork, ssid), Status::kBoundsExceeded);
125130
VerifyOrReturnError(credentials.size() <= sizeof(mStagingNetwork.credentials), Status::kOutOfRange);
126131
VerifyOrReturnError(ssid.size() <= sizeof(mStagingNetwork.ssid), Status::kOutOfRange);
@@ -136,6 +141,9 @@ Status BLWiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, Mut
136141

137142
Status BLWiFiDriver::RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex)
138143
{
144+
outDebugText.reduce_size(0);
145+
outNetworkIndex = 0;
146+
139147
VerifyOrReturnError(NetworkMatch(mStagingNetwork, networkId), Status::kNetworkIDNotFound);
140148

141149
// Use empty ssid for representing invalid network
@@ -145,6 +153,8 @@ Status BLWiFiDriver::RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebu
145153

146154
Status BLWiFiDriver::ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText)
147155
{
156+
outDebugText.reduce_size(0);
157+
148158
// Only one network is supported now
149159
VerifyOrReturnError(index == 0, Status::kOutOfRange);
150160
VerifyOrReturnError(NetworkMatch(mStagingNetwork, networkId), Status::kNetworkIDNotFound);
@@ -157,12 +167,24 @@ CHIP_ERROR BLWiFiDriver::ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen,
157167

158168
char wifi_ssid[64] = { 0 };
159169
char passwd[64] = { 0 };
160-
// Set the wifi configuration
170+
int state = 0;
171+
172+
wifi_mgmr_sta_disconnect();
173+
vTaskDelay(WIFI_STA_DISCONNECT_DELAY);
174+
175+
wifi_mgmr_sta_disable(NULL);
176+
wifi_mgmr_state_get(&state);
177+
while (state != WIFI_STATE_IDLE)
178+
{
179+
wifi_mgmr_state_get(&state);
180+
vTaskDelay(100);
181+
}
182+
161183
memcpy(wifi_ssid, ssid, ssidLen);
162184
memcpy(passwd, key, keyLen);
163185
wifi_interface_t wifi_interface;
164186
wifi_interface = wifi_mgmr_sta_enable();
165-
wifi_mgmr_sta_connect(wifi_interface, ssid, passwd, NULL, NULL, 0, 0);
187+
wifi_mgmr_sta_connect(wifi_interface, wifi_ssid, passwd, NULL, NULL, 0, 0);
166188

167189
ReturnErrorOnFailure(ConnectivityMgr().SetWiFiStationMode(ConnectivityManager::kWiFiStationMode_Disabled));
168190

@@ -280,6 +302,7 @@ void BLWiFiDriver::OnScanWiFiNetworkDone()
280302
}
281303
}))
282304
{
305+
vPortFree(ScanResult);
283306
ChipLogProgress(DeviceLayer, "ScheduleLambda OK");
284307
}
285308
}

src/platform/bouffalolab/BL602/OTAImageProcessorImpl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
158158
}
159159

160160
DeviceLayer::SystemLayer().StartTimer(
161-
System::Clock::Seconds32(2),
161+
System::Clock::Seconds32(4),
162162
[](Layer *, void *) {
163163
ChipLogProgress(SoftwareUpdate, "Rebooting...");
164164
hal_reboot();

src/platform/bouffalolab/BL602/PlatformManagerImpl.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ static int app_entropy_source(void * data, unsigned char * output, size_t len, s
6767

6868
static void WifiStaDisconect(void)
6969
{
70+
NetworkCommissioning::BLWiFiDriver::GetInstance().SetLastDisconnectReason(NULL);
71+
7072
uint16_t reason = NetworkCommissioning::BLWiFiDriver::GetInstance().GetLastDisconnectReason();
7173
uint8_t associationFailureCause =
7274
chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::AssociationFailureCause::kUnknown);
@@ -138,7 +140,6 @@ static void WifiStaDisconect(void)
138140
chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::WiFiConnectionStatus::kNotConnected));
139141
}
140142

141-
NetworkCommissioning::BLWiFiDriver::GetInstance().SetLastDisconnectReason(NULL);
142143
ConnectivityMgrImpl().ChangeWiFiStationState(ConnectivityManagerImpl::kWiFiStationState_Disconnecting);
143144
}
144145

third_party/bouffalolab/bl602/bl602_sdk.gni

+1-6
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ template("bl602_sdk") {
189189
"SYS_AOS_LOOP_ENABLE=1",
190190
"BL602_USE_HAL_DRIVER=1",
191191
"BL602=BL602",
192-
"SYS_LOOPRT_ENABLE=1",
192+
193193
"CFG_TXDESC=2",
194194
"CFG_STA_MAX=1",
195195
"CFG_CHIP_BL602",
@@ -295,11 +295,6 @@ template("bl602_sdk") {
295295
cflags_cc += [ "-std=c++17" ]
296296
cflags_cc += [ "-D _GNU_SOURCE" ]
297297

298-
#cflags_cc += [ "-fcommon" ]
299-
#cflags_cc += [ "-fno-rtti" ]
300-
#cflags_cc += [ "-Wnon-virtual-dtor" ]
301-
#cflags_cc += [ "-frtti" ]
302-
303298
foreach(include_dir, _include_dirs) {
304299
cflags += [ "-isystem" + rebase_path(include_dir, root_build_dir) ]
305300
}

0 commit comments

Comments
 (0)