From 9e01d927f5d297d1a6e5ee7feaa1728a2297881b Mon Sep 17 00:00:00 2001 From: keeramis Date: Thu, 11 Aug 2022 15:09:21 -0500 Subject: [PATCH] Enable HAL_PLATFORM_WIFI for trackerm and other minor --- hal/inc/hal_platform.h | 6 ++++++ hal/src/argon/hal_platform_config.h | 1 + hal/src/rtl872x/deviceid_hal.cpp | 4 ++-- hal/src/tracker/hal_platform_config.h | 1 + hal/src/trackerm/hal_platform_config.h | 4 ++-- hal/src/trackerm/network/network.cpp | 2 +- hal/src/trackerm/platform_ncp_quectel.cpp | 11 ++++++++--- hal/src/tron/network/network.cpp | 2 ++ 8 files changed, 23 insertions(+), 8 deletions(-) diff --git a/hal/inc/hal_platform.h b/hal/inc/hal_platform.h index 5f07a48476..821e2dd9c0 100644 --- a/hal/inc/hal_platform.h +++ b/hal/inc/hal_platform.h @@ -36,11 +36,17 @@ #define HAL_PLATFORM_WIFI_NCP_SDIO (0) #endif // HAL_PLATFORM_WIFI_NCP_SDIO +#ifndef HAL_PLATFORM_ESP32_NCP +#define HAL_PLATFORM_ESP32_NCP (0) +#endif // HAL_PLATFORM_ESP32_NCP + +#if HAL_PLATFORM_ESP32_NCP #if HAL_PLATFORM_WIFI && HAL_PLATFORM_NCP_AT && !HAL_PLATFORM_WIFI_NCP_SDIO # ifndef HAL_PLATFORM_WIFI_SERIAL # error "HAL_PLATFORM_WIFI_SERIAL is not defined" # endif /* HAL_PLATFORM_WIFI_SERIAL */ #endif /* HAL_PLATFORM_WIFI */ +#endif /* HAL_PLATFORM_ESP32_NCP */ #ifndef HAL_PLATFORM_CELLULAR #define HAL_PLATFORM_CELLULAR 0 diff --git a/hal/src/argon/hal_platform_config.h b/hal/src/argon/hal_platform_config.h index 51827a15e6..2216fda854 100644 --- a/hal/src/argon/hal_platform_config.h +++ b/hal/src/argon/hal_platform_config.h @@ -14,6 +14,7 @@ #define HAL_PLATFORM_WIFI_COMPAT (1) #define HAL_PLATFORM_NCP_COUNT (1) #define HAL_PLATFORM_MAX_CLOUD_CONNECT_TIME (1*60*1000) +#define HAL_PLATFORM_ESP32_NCP (1) #define PRODUCT_SERIES "argon" diff --git a/hal/src/rtl872x/deviceid_hal.cpp b/hal/src/rtl872x/deviceid_hal.cpp index 413d6cf8b1..3904e2c628 100644 --- a/hal/src/rtl872x/deviceid_hal.cpp +++ b/hal/src/rtl872x/deviceid_hal.cpp @@ -135,8 +135,8 @@ int hal_get_device_serial_number(char* str, size_t size, void* reserved) int hal_get_device_hw_version(uint32_t* revision, void* reserved) { - // HW Data format: | NCP_ID | HW_VERSION | HW Feature Flags | - // | byte 0 | byte 1 | byte 2/3 | + // HW Data format: | NCP_ID (LSB) | HW_VERSION | HW Feature Flags | + // | byte 0 | byte 1 | byte 2/3 | uint8_t hw_data[4] = {}; CHECK(readLogicalEfuse(HARDWARE_DATA_OFFSET, (uint8_t*)hw_data, HARDWARE_DATA_SIZE)); if (hw_data[1] == 0xFF) { diff --git a/hal/src/tracker/hal_platform_config.h b/hal/src/tracker/hal_platform_config.h index a40cd2eef3..8b02a5c525 100644 --- a/hal/src/tracker/hal_platform_config.h +++ b/hal/src/tracker/hal_platform_config.h @@ -12,6 +12,7 @@ #define HAL_PLATFORM_I2C_NUM (3) #define HAL_PLATFORM_USART_NUM (2) #define HAL_PLATFORM_NCP_UPDATABLE (1) +#define HAL_PLATFORM_ESP32_NCP (1) #define HAL_PLATFORM_PMIC_BQ24195 (1) #define HAL_PLATFORM_PMIC_BQ24195_I2C (HAL_I2C_INTERFACE2) diff --git a/hal/src/trackerm/hal_platform_config.h b/hal/src/trackerm/hal_platform_config.h index 80e7f3b211..24b87cdb19 100644 --- a/hal/src/trackerm/hal_platform_config.h +++ b/hal/src/trackerm/hal_platform_config.h @@ -13,8 +13,8 @@ #define HAL_PLATFORM_I2C_NUM (2) #define HAL_PLATFORM_USART_NUM (3) #define HAL_PLATFORM_NCP_COUNT (1) -#define HAL_PLATFORM_WIFI (0) -// #define HAL_PLATFORM_WIFI_COMPAT (1) +#define HAL_PLATFORM_WIFI (1) +#define HAL_PLATFORM_WIFI_COMPAT (0) // #define HAL_PLATFORM_WIFI_NCP_SDIO (1) #define HAL_PLATFORM_WIFI_SCAN_ONLY (1) diff --git a/hal/src/trackerm/network/network.cpp b/hal/src/trackerm/network/network.cpp index a81876e3df..ea5057b7bb 100644 --- a/hal/src/trackerm/network/network.cpp +++ b/hal/src/trackerm/network/network.cpp @@ -171,6 +171,7 @@ int if_init_platform(void*) { reserve_netif_index(); } + // Order of initialization is important! /* pp3 - Cellular */ pp3 = new PppNcpNetif(); if (pp3) { @@ -196,7 +197,6 @@ int if_init_platform(void*) { return 0; } - extern "C" { struct netif* lwip_hook_ip4_route_src(const ip4_addr_t* src, const ip4_addr_t* dst) { diff --git a/hal/src/trackerm/platform_ncp_quectel.cpp b/hal/src/trackerm/platform_ncp_quectel.cpp index bcb69aea43..009a57764e 100644 --- a/hal/src/trackerm/platform_ncp_quectel.cpp +++ b/hal/src/trackerm/platform_ncp_quectel.cpp @@ -20,10 +20,12 @@ #include "dct.h" #include "check.h" #include "system_error.h" +#include "deviceid_hal.h" namespace { -const uintptr_t NCP_ID_OTP_ADDRESS = 0x00000020; +// Undefine hardware version +const auto HW_VERSION_UNDEFINED = 0xFF; bool isValidNcpId(uint8_t id) { switch (id) { @@ -47,8 +49,11 @@ PlatformNCPIdentifier platform_primary_ncp_identifier() { uint8_t ncpId = 0; int r = dct_read_app_data_copy(DCT_NCP_ID_OFFSET, &ncpId, 1); if (r < 0 || !isValidNcpId(ncpId)) { - // Check the OTP flash - r = hal_exflash_read_special(HAL_EXFLASH_SPECIAL_SECTOR_OTP, NCP_ID_OTP_ADDRESS, &ncpId, 1); + // Check the logical eFuse + uint32_t hwVersion = HW_VERSION_UNDEFINED; + r = hal_get_device_hw_version(&hwVersion, nullptr); + // get the first byte for NCP ID + ncpId = (hwVersion & 0xFF); if (r < 0 || !isValidNcpId(ncpId)) { ncpId = PlatformNCPIdentifier::PLATFORM_NCP_UNKNOWN; } diff --git a/hal/src/tron/network/network.cpp b/hal/src/tron/network/network.cpp index 08c120f167..75c9020f88 100644 --- a/hal/src/tron/network/network.cpp +++ b/hal/src/tron/network/network.cpp @@ -30,6 +30,8 @@ #include "realtek/rtlncpnetif.h" #include "lwip_util.h" #include "core_hal.h" +#include "deviceid_hal.h" + using namespace particle; using namespace particle::net;