From de70583838bc7c243ef9202da21ba30b7ca7ea36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Sat, 28 May 2022 20:09:10 +0200 Subject: [PATCH] [core] Put full UF2 Family ID in ChipFamily --- arduino/libretuya/core/ChipType.h | 32 +++++++++---------- arduino/libretuya/core/LibreTuyaAPI.cpp | 14 ++++++++ arduino/libretuya/core/LibreTuyaAPI.h | 2 ++ .../cores/arduino/LibreTuyaAPI.cpp | 2 +- boards/_base/realtek-ambz.json | 1 + boards/wr3.json | 1 - builder/frameworks/realtek-ambz-arduino.py | 1 - builder/utils.py | 3 +- 8 files changed, 36 insertions(+), 20 deletions(-) diff --git a/arduino/libretuya/core/ChipType.h b/arduino/libretuya/core/ChipType.h index 849685e..29f3e4d 100644 --- a/arduino/libretuya/core/ChipType.h +++ b/arduino/libretuya/core/ChipType.h @@ -1,23 +1,23 @@ /* Copyright (c) Kuba SzczodrzyƄski 2022-05-28. */ enum ChipFamily { - // copied from UF2 families (first nibble) - RTL8710A = 0x9F, // Realtek Ameba1 - RTL8710B = 0x22, // Realtek AmebaZ (realtek-ambz) - RTL8720C = 0xE0, // Realtek AmebaZ2 - RTL8720D = 0x33, // Realtek AmebaD - BK7231T = 0x67, // Beken 7231T - BK7231N = 0x7B, // Beken 7231N - BL602 = 0xDE, // Boufallo 602 - XR809 = 0x51, // Xradiotech 809 + // used in UF2 Family ID + RTL8710A = 0x9FFFD543, // Realtek Ameba1 + RTL8710B = 0x22E0D6FC, // Realtek AmebaZ (realtek-ambz) + RTL8720C = 0xE08F7564, // Realtek AmebaZ2 + RTL8720D = 0x3379CFE2, // Realtek AmebaD + BK7231T = 0x675A40B0, // Beken 7231T + BK7231N = 0x7B3EF230, // Beken 7231N + BL602 = 0xDE1270B7, // Boufallo 602 + XR809 = 0x51E903A8, // Xradiotech 809 }; enum ChipType { - // copied from rtl8710b_efuse.h - RTL8710BL = (RTL8710B << 8) | 0xE0, // ??? - RTL8710BN = (RTL8710B << 8) | 0xFF, // CHIPID_8710BN / QFN32 - RTL8710BU = (RTL8710B << 8) | 0xFE, // CHIPID_8710BU / QFN48 - RTL8710BX = (RTL8710B << 8) | 0xFB, // CHIPID_8710BN_L0 / QFN32 - RTL8711BN = (RTL8710B << 8) | 0xFD, // CHIPID_8711BN / QFN48 - RTL8711BU = (RTL8710B << 8) | 0xFC, // CHIPID_8711BG / QFN68 + // IDs copied from rtl8710b_efuse.h + RTL8710BL = ((RTL8710B >> 24) << 8) | 0xE0, // ??? + RTL8710BN = ((RTL8710B >> 24) << 8) | 0xFF, // CHIPID_8710BN / QFN32 + RTL8710BU = ((RTL8710B >> 24) << 8) | 0xFE, // CHIPID_8710BU / QFN48 + RTL8710BX = ((RTL8710B >> 24) << 8) | 0xFB, // CHIPID_8710BN_L0 / QFN32 + RTL8711BN = ((RTL8710B >> 24) << 8) | 0xFD, // CHIPID_8711BN / QFN48 + RTL8711BU = ((RTL8710B >> 24) << 8) | 0xFC, // CHIPID_8711BG / QFN68 }; diff --git a/arduino/libretuya/core/LibreTuyaAPI.cpp b/arduino/libretuya/core/LibreTuyaAPI.cpp index 1a0657c..9e0abcd 100644 --- a/arduino/libretuya/core/LibreTuyaAPI.cpp +++ b/arduino/libretuya/core/LibreTuyaAPI.cpp @@ -74,6 +74,20 @@ const char *LibreTuya::getBoard() { return LT_BOARD_STR; } +/** + * @brief Get CPU family ID. + */ +ChipFamily LibreTuya::getChipFamily() { + return FAMILY; +} + +/** + * @brief Get CPU family name as string. + */ +const char *LibreTuya::getChipFamilyName() { + return STRINGIFY_MACRO(FAMILY); +} + static char *deviceName = NULL; /** diff --git a/arduino/libretuya/core/LibreTuyaAPI.h b/arduino/libretuya/core/LibreTuyaAPI.h index 75c6fb8..2307b3e 100644 --- a/arduino/libretuya/core/LibreTuyaAPI.h +++ b/arduino/libretuya/core/LibreTuyaAPI.h @@ -71,6 +71,8 @@ class LibreTuya { const char *getVersion(); const char *getBoard(); const char *getDeviceName(); + ChipFamily getChipFamily(); + const char *getChipFamilyName(); public: /* Inline methods */ inline uint32_t getFlashChipSize() { diff --git a/arduino/realtek-ambz/cores/arduino/LibreTuyaAPI.cpp b/arduino/realtek-ambz/cores/arduino/LibreTuyaAPI.cpp index 0b16814..714f72f 100644 --- a/arduino/realtek-ambz/cores/arduino/LibreTuyaAPI.cpp +++ b/arduino/realtek-ambz/cores/arduino/LibreTuyaAPI.cpp @@ -14,7 +14,7 @@ void LibreTuya::restart() { ChipType LibreTuya::getChipType() { uint8_t chipId; EFUSE_OneByteReadROM(9902, 0xF8, &chipId, L25EOUTVOLTAGE); - return (ChipType)((RTL8710B << 8) | chipId); + return (ChipType)(((RTL8710B >> 24) << 8) | chipId); } const char *LibreTuya::getChipModel() { diff --git a/boards/_base/realtek-ambz.json b/boards/_base/realtek-ambz.json index a0124dc..19bcc61 100644 --- a/boards/_base/realtek-ambz.json +++ b/boards/_base/realtek-ambz.json @@ -1,5 +1,6 @@ { "build": { + "family": "RTL8710B", "f_cpu": "125000000L", "amb_flash_addr": "0x08000000" }, diff --git a/boards/wr3.json b/boards/wr3.json index 96101e6..ddde584 100644 --- a/boards/wr3.json +++ b/boards/wr3.json @@ -6,7 +6,6 @@ ], "build": { "mcu": "rtl8710bn", - "family": "rtl8710", "variant": "wr3" }, "name": "WR3 Wi-Fi Module", diff --git a/builder/frameworks/realtek-ambz-arduino.py b/builder/frameworks/realtek-ambz-arduino.py index 937ab8f..139a34e 100644 --- a/builder/frameworks/realtek-ambz-arduino.py +++ b/builder/frameworks/realtek-ambz-arduino.py @@ -45,7 +45,6 @@ env.Append( "ARDUINO_AMEBA", "ARDUINO_SDK", "ARDUINO_ARCH_AMBZ", - "BOARD_${FAMILY}", # the SDK declares bool if not defined before # which conflicts with C++ built-in bool # so it's either -fpermissive or this: diff --git a/builder/utils.py b/builder/utils.py index 311cc8f..535e833 100644 --- a/builder/utils.py +++ b/builder/utils.py @@ -28,7 +28,7 @@ def env_add_defaults(env, platform_name: str, sdk_name: str): OPENOCD_DIR=join("${PLATFORM_DIR}", "openocd"), # Board config variables MCU=board.get("build.mcu").upper(), - FAMILY=board.get("build.family").upper(), + FAMILY=board.get("build.family"), VARIANT=board.get("build.variant"), LDSCRIPT_SDK=board.get("build.ldscript_sdk"), LDSCRIPT_ARDUINO=board.get("build.ldscript_arduino"), @@ -51,6 +51,7 @@ def env_add_defaults(env, platform_name: str, sdk_name: str): ("LT_BOARD", board.get("build.variant")), ("F_CPU", board.get("build.f_cpu")), ("MCU", board.get("build.mcu").upper()), + ("FAMILY", board.get("build.family")), ], )