Skip to content

Commit

Permalink
[BL602] Fix sve2 problems (#22582)
Browse files Browse the repository at this point in the history
* [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]>
  • Loading branch information
3 people authored and pull[bot] committed Jul 19, 2023
1 parent ca93783 commit b407518
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 19 deletions.
2 changes: 1 addition & 1 deletion examples/lighting-app/bouffalolab/bl602/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
```
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/bouffalolab/bl602/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 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,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
Expand Down
4 changes: 4 additions & 0 deletions src/platform/bouffalolab/BL602/CHIPPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
45 changes: 40 additions & 5 deletions src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<chip::ByteSpan>(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<chip::ByteSpan>(ifp->Ipv6AddressSpans, ipv6_addr_count);
}

*netifpp = ifp;

return CHIP_NO_ERROR;
}

Expand Down Expand Up @@ -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)
Expand Down
27 changes: 25 additions & 2 deletions src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include <string>
#include <utils_log.h>

#define WIFI_STA_DISCONNECT_DELAY (pdMS_TO_TICKS(200))

using namespace ::chip;
//#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
namespace chip {
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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));

Expand Down Expand Up @@ -280,6 +302,7 @@ void BLWiFiDriver::OnScanWiFiNetworkDone()
}
}))
{
vPortFree(ScanResult);
ChipLogProgress(DeviceLayer, "ScheduleLambda OK");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform/bouffalolab/BL602/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/platform/bouffalolab/BL602/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down
7 changes: 1 addition & 6 deletions third_party/bouffalolab/bl602/bl602_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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) ]
}
Expand Down
2 changes: 1 addition & 1 deletion third_party/bouffalolab/repo

0 comments on commit b407518

Please sign in to comment.