diff --git a/boards/_base/realtek-ambz2-2mb-900k.json b/boards/_base/realtek-ambz2-2mb-900k.json new file mode 100644 index 0000000..b1f9ed8 --- /dev/null +++ b/boards/_base/realtek-ambz2-2mb-900k.json @@ -0,0 +1,12 @@ +{ + "flash": { + "ota1": "0x010000+0xE0000", + "ota2": "0x0F0000+0xE0000", + "kvs": "0x1D0000+0x8000", + "userdata": "0x1D8000+0x28000" + }, + "upload": { + "flash_size": 2097152, + "maximum_size": 917504 + } +} diff --git a/boards/_base/realtek-ambz2-image.json b/boards/_base/realtek-ambz2-image.json new file mode 100644 index 0000000..1ac54e3 --- /dev/null +++ b/boards/_base/realtek-ambz2-image.json @@ -0,0 +1,96 @@ +{ + "image": { + "keys": { + "decryption": "a0d6dae7e062ca94cbb294bf896b9f68cf8438774256ac7403ca4fd9a1c9564f", + "keyblock": { + "part_table": "882aa16c8c44a7760aa8c9ab22e3568c6fa16c2afa4f0cea29a10abcdf60e44f", + "boot": "882aa16c8c44a7760aa8c9ab22e3568c6fa16c2afa4f0cea29a10abcdf60e44f" + }, + "hash_keys": { + "part_table": "47e5661335a4c5e0a94d69f3c737d54f2383791332939753ef24279608f6d72b", + "boot": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "ota1": "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e5f", + "ota2": "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e5f" + }, + "user_keys": { + "boot": "aa0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", + "ota1": "bb0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", + "ota2": "bb0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" + }, + "xip_sce_key": "a0d6dae7e062ca94cbb294bf896b9f68", + "xip_sce_iv": "94879487948794879487948794879487" + }, + "ptable": { + "boot": "BOOT", + "ota1": "FW1", + "ota2": "FW2" + }, + "boot": { + "name": "boot.sram", + "type": "SRAM", + "entry": "__ram_start_table_start__", + "elf": [ + ".ram.func.table", + ".data", + ".ram.code_text", + ".ram.code_rodata" + ], + "is_boot": true + }, + "fw": [ + { + "type": "FWHS_S", + "sections": [ + { + "name": "fwhs.sram", + "type": "SRAM", + "entry": "__ram_start_table_start__", + "elf": [ + ".ram.img.signature", + ".ram.func.table", + ".data", + ".ram.code_text", + ".ram.code_rodata" + ] + }, + { + "name": "fwhs.psram", + "type": "PSRAM", + "entry": "__psram_start__", + "elf": [ + ".psram.data", + ".psram.code_text", + ".psram.code_rodata" + ] + } + ] + }, + { + "type": "XIP", + "sections": [ + { + "name": "fwhs.xip_c", + "entry": "XIP_RamImgSignature_s", + "type": "XIP", + "elf": [ + ".xip.code_c" + ] + } + ] + }, + { + "type": "XIP", + "sections": [ + { + "name": "fwhs.xip_p", + "entry": "__xip_code_rodata_start__", + "type": "XIP", + "elf": [ + ".xip.code_p" + ] + } + ] + } + ] + } +} diff --git a/boards/_base/realtek-ambz2.json b/boards/_base/realtek-ambz2.json index be1f316..0bdd708 100644 --- a/boards/_base/realtek-ambz2.json +++ b/boards/_base/realtek-ambz2.json @@ -16,7 +16,11 @@ "protocols": [] }, "upload": { - "maximum_ram_size": 262144 + "maximum_ram_size": 262144, + "protocol": "uart", + "protocols": [ + "uart" + ] }, "doc": { "params": { diff --git a/boards/bw15.json b/boards/bw15.json new file mode 100644 index 0000000..e2b972e --- /dev/null +++ b/boards/bw15.json @@ -0,0 +1,26 @@ +{ + "_base": [ + "realtek-ambz2", + "realtek-ambz2-8720", + "realtek-ambz2-image", + "realtek-ambz2-2mb-992k", + "ic/rtl8720cf", + "pcb/bw15" + ], + "build": { + "mcu": "rtl8720cf", + "variant": "bw15" + }, + "name": "BW15", + "url": "https://docs.ai-thinker.com/_media/rtl8710/docs/bw15_datasheet_en.pdf", + "vendor": "Ai-Thinker Co., Ltd.", + "pcb": { + "symbol": "BW15" + }, + "doc": { + "fccid": "2AXVG-BW15", + "links": { + "Vendor datasheet": "https://docs.ai-thinker.com/_media/rtl8710/docs/bw15_datasheet_en.pdf" + } + } +} diff --git a/boards/generic-rtl8720cf-2mb-992k.json b/boards/generic-rtl8720cf-2mb-992k.json new file mode 100644 index 0000000..906f297 --- /dev/null +++ b/boards/generic-rtl8720cf-2mb-992k.json @@ -0,0 +1,102 @@ +{ + "_base": [ + "generic", + "realtek-ambz2", + "realtek-ambz2-8720", + "realtek-ambz2-image", + "realtek-ambz2-2mb-992k", + "ic/rtl8720cf" + ], + "build": { + "mcu": "rtl8720cf", + "variant": "generic-rtl8720cf-2mb-992k" + }, + "name": "Generic - RTL8720CF (2M/992k)", + "symbol": "RTL8720CF (2M/992k)", + "url": "https://docs.libretiny.eu/boards/generic-rtl8720cf-2mb-992k/", + "vendor": "Generic", + "pcb": { + "pinout": { + "1": { + "IC": 15, + "ARD": "D0" + }, + "2": { + "IC": 16, + "ARD": "D1" + }, + "3": { + "IC": 18, + "ARD": "D2" + }, + "4": { + "IC": 19, + "ARD": "D3" + }, + "5": { + "IC": 20, + "ARD": "D4" + }, + "6": { + "IC": 21, + "ARD": "D5" + }, + "7": { + "IC": 22, + "ARD": "D6" + }, + "8": { + "IC": 23, + "ARD": "D7" + }, + "9": { + "IC": 24, + "ARD": "D8" + }, + "10": { + "IC": 25, + "ARD": "D9" + }, + "11": { + "IC": 26, + "ARD": "D10" + }, + "12": { + "IC": 33, + "ARD": "D11" + }, + "13": { + "IC": 34, + "ARD": "D12" + }, + "14": { + "IC": 36, + "ARD": "D13" + }, + "15": { + "IC": 37, + "ARD": "D14" + }, + "16": { + "IC": 38, + "ARD": "D15" + }, + "17": { + "IC": 39, + "ARD": "D16" + }, + "18": { + "IC": 40, + "ARD": "D17" + }, + "19": { + "IC": 1, + "ARD": "D18" + }, + "20": { + "IC": 3, + "ARD": "D19" + } + } + } +} diff --git a/builder/family/realtek-ambz2.py b/builder/family/realtek-ambz2.py index 2cab2fe..51a0db7 100644 --- a/builder/family/realtek-ambz2.py +++ b/builder/family/realtek-ambz2.py @@ -1,6 +1,7 @@ # Copyright (c) Kuba Szczodrzyński 2022-07-20. -from os.path import join +from os.path import isfile, join +from shutil import copyfile from platformio.platform.base import PlatformBase from platformio.platform.board import PlatformBoardConfig @@ -436,10 +437,25 @@ env.Replace( SIZEPRINTCMD="$SIZETOOL -B -d $SOURCES", ) +# Bootloader - copy for linking +# fmt: off +bootloader_src = env.subst("${SDK_DIR}/component/soc/realtek/8710c/misc/bsp/image/bootloader.axf") +bootloader_dst = env.subst("${BUILD_DIR}/bootloader.axf") +# fmt: on +if not isfile(bootloader_dst): + copyfile(bootloader_src, bootloader_dst) + # Build all libraries queue.BuildLibraries() # Main firmware outputs and actions +image_firmware_is = "${BUILD_DIR}/image_firmware_is.${FLASH_OTA1_OFFSET}.bin" env.Replace( - # TODO + # linker command (dual .bin outputs) + LINK="${LTCHIPTOOL} link2bin ${BOARD_JSON} '' ''", + # UF2OTA input list + UF2OTA=[ + # same OTA images for flasher and device + f"{image_firmware_is},{image_firmware_is}=device:ota1,ota2;flasher:ota1,ota2", + ], ) diff --git a/cores/common/base/lt_types.h b/cores/common/base/lt_types.h index eab0f69..1f280f1 100644 --- a/cores/common/base/lt_types.h +++ b/cores/common/base/lt_types.h @@ -40,6 +40,8 @@ typedef enum { RTL8711BU = CPU_MODEL(F_RTL8710B, 0xFC), // CHIPID_8711BG / QFN68 MX1290 = RTL8710BN, MX1290V2 = RTL8710BX, + // Realtek AmebaZ2 + RTL8720CF = CPU_MODEL(F_RTL8720C, 0x00), // TODO // Beken 72XX BK7231T = CPU_MODEL(F_BK7231U, 0x1A), // *SCTRL_CHIP_ID = 0x7231a BK7231N = CPU_MODEL(F_BK7231N, 0x1C), // *SCTRL_CHIP_ID = 0x7231c diff --git a/cores/realtek-amb/base/sdk_private.h b/cores/realtek-amb/base/sdk_private.h index 4b89051..ffda530 100644 --- a/cores/realtek-amb/base/sdk_private.h +++ b/cores/realtek-amb/base/sdk_private.h @@ -20,6 +20,7 @@ extern "C" { #include #endif #if LT_RTL8720C +#include #include #endif diff --git a/cores/realtek-amb/base/lt_api.c b/cores/realtek-ambz/base/lt_api.c similarity index 100% rename from cores/realtek-amb/base/lt_api.c rename to cores/realtek-ambz/base/lt_api.c diff --git a/cores/realtek-amb/base/port/printf.c b/cores/realtek-ambz/base/port/printf.c similarity index 100% rename from cores/realtek-amb/base/port/printf.c rename to cores/realtek-ambz/base/port/printf.c diff --git a/cores/realtek-amb/base/port/printf_port.h b/cores/realtek-ambz/base/port/printf_port.h similarity index 100% rename from cores/realtek-amb/base/port/printf_port.h rename to cores/realtek-ambz/base/port/printf_port.h diff --git a/cores/realtek-ambz2/base/fixups/cmd_shell.c b/cores/realtek-ambz2/base/fixups/cmd_shell.c new file mode 100644 index 0000000..d90ccab --- /dev/null +++ b/cores/realtek-ambz2/base/fixups/cmd_shell.c @@ -0,0 +1,3 @@ +/* Copyright (c) Kuba Szczodrzyński 2023-04-12. */ + +void shell_cmd_init() {} diff --git a/cores/realtek-ambz2/base/port/printf.c b/cores/realtek-ambz2/base/port/printf.c new file mode 100644 index 0000000..74b5200 --- /dev/null +++ b/cores/realtek-ambz2/base/port/printf.c @@ -0,0 +1,38 @@ +/* Copyright (c) Kuba Szczodrzyński 2023-04-12. */ + +#include +#include + +#include + +static UART0_Type *uart_dev[4] = { + UART0, + UART1, + UART2, + UART3, +}; + +uint8_t lt_uart_port = 2; + +void putchar_(char c) { + putchar_p(c, lt_uart_port); +} + +void putchar_p(char c, unsigned long port) { + // while (UART_Writable(uart_dev[port]) == 0) {} + uart_dev[port]->thr = c; +} + +WRAP_PRINTF(rtl_printf); +WRAP_SPRINTF(rtl_sprintf); +WRAP_SNPRINTF(rtl_snprintf); +WRAP_VSNPRINTF(rtl_vsnprintf); +WRAP_VSNPRINTF(rtl_vsnprintf_r); +WRAP_VPRINTF(rtl_vprintf); +WRAP_PRINTF(DiagPrintf); +WRAP_SPRINTF(DiagSPrintf); +WRAP_SNPRINTF(DiagSnPrintf); +WRAP_PRINTF(prvDiagPrintf); +WRAP_SPRINTF(prvDiagSPrintf); +WRAP_VSPRINTF(VSprintf); +WRAP_PRINTF(LOG_PRINTF); diff --git a/cores/realtek-ambz2/base/port/printf_port.h b/cores/realtek-ambz2/base/port/printf_port.h new file mode 100644 index 0000000..74d770e --- /dev/null +++ b/cores/realtek-ambz2/base/port/printf_port.h @@ -0,0 +1,18 @@ +/* Copyright (c) Kuba Szczodrzyński 2022-06-20. */ + +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +WRAP_DISABLE_DEF(rtl_printf); +WRAP_DISABLE_DEF(DiagPrintf); +WRAP_DISABLE_DEF(prvDiagPrintf); +WRAP_DISABLE_DEF(LOG_PRINTF); + +#ifdef __cplusplus +} // extern "C" +#endif