[realtek-ambz] Add basic debugger support
This commit is contained in:
@@ -9,6 +9,19 @@
|
||||
"amb_flash_addr": "0x08000000",
|
||||
"amb_boot_all": "boot_all_77F7.bin"
|
||||
},
|
||||
"connectivity": [
|
||||
"wifi"
|
||||
],
|
||||
"debug": {
|
||||
"protocol": "openocd",
|
||||
"protocols": [
|
||||
"openocd"
|
||||
],
|
||||
"openocd_config": "amebaz.cfg",
|
||||
"gdb_init": [
|
||||
"mem 0x8000000 0x8010000 ro"
|
||||
]
|
||||
},
|
||||
"flash": {
|
||||
"boot_xip": "0x000000+0x4000",
|
||||
"boot_ram": "0x004000+0x4000",
|
||||
|
||||
@@ -14,6 +14,7 @@ env.Replace(
|
||||
AS="arm-none-eabi-gcc",
|
||||
CC="arm-none-eabi-gcc",
|
||||
CXX="arm-none-eabi-g++",
|
||||
GDB="arm-none-eabi-gdb",
|
||||
NM="arm-none-eabi-gcc-nm",
|
||||
LINK="arm-none-eabi-gcc",
|
||||
LD="arm-none-eabi-gcc",
|
||||
|
||||
@@ -44,6 +44,12 @@
|
||||
"~1.90301.0",
|
||||
"~1.100301.0"
|
||||
]
|
||||
},
|
||||
"tool-openocd": {
|
||||
"type": "uploader",
|
||||
"optional": true,
|
||||
"owner": "platformio",
|
||||
"version": "~2.1100.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
94
platform.py
94
platform.py
@@ -1,7 +1,12 @@
|
||||
from os.path import dirname
|
||||
|
||||
from platformio.debug.config.base import DebugConfigBase
|
||||
from platformio.debug.exception import DebugInvalidOptionsError
|
||||
from platformio.managers.platform import PlatformBase
|
||||
from platformio.package.exception import MissingPackageManifestError
|
||||
from platformio.package.manager.base import BasePackageManager
|
||||
from platformio.package.meta import PackageItem, PackageSpec
|
||||
from platformio.platform.board import PlatformBoardConfig
|
||||
|
||||
libretuya_packages = None
|
||||
manifest_default = {"version": "0.0.0", "description": "", "keywords": []}
|
||||
@@ -63,11 +68,13 @@ class LibretuyaPlatform(PlatformBase):
|
||||
def configure_default_packages(self, options, targets):
|
||||
framework = options.get("pioframework")[0]
|
||||
# patch find_pkg root to ignore missing manifests and save PackageSpec
|
||||
BasePackageManager._find_pkg_root = BasePackageManager.find_pkg_root
|
||||
BasePackageManager.find_pkg_root = find_pkg_root
|
||||
if not hasattr(BasePackageManager, "_find_pkg_root"):
|
||||
BasePackageManager._find_pkg_root = BasePackageManager.find_pkg_root
|
||||
BasePackageManager.find_pkg_root = find_pkg_root
|
||||
# patch load_manifest to generate manifests from PackageSpec
|
||||
BasePackageManager._load_manifest = BasePackageManager.load_manifest
|
||||
BasePackageManager.load_manifest = load_manifest
|
||||
if not hasattr(BasePackageManager, "_load_manifest"):
|
||||
BasePackageManager._load_manifest = BasePackageManager.load_manifest
|
||||
BasePackageManager.load_manifest = load_manifest
|
||||
|
||||
# set specific compiler versions
|
||||
if framework.startswith("realtek-ambz"):
|
||||
@@ -82,3 +89,82 @@ class LibretuyaPlatform(PlatformBase):
|
||||
libretuya_packages = self.packages
|
||||
|
||||
return super().configure_default_packages(options, targets)
|
||||
|
||||
def get_boards(self, id_=None):
|
||||
result = PlatformBase.get_boards(self, id_)
|
||||
if not result:
|
||||
return result
|
||||
if id_:
|
||||
return self._add_default_debug_tools(result)
|
||||
else:
|
||||
for key, value in result.items():
|
||||
result[key] = self._add_default_debug_tools(value)
|
||||
return result
|
||||
|
||||
def _add_default_debug_tools(self, board: PlatformBoardConfig):
|
||||
# inspired by platform-ststm32/platform.py
|
||||
debug = board.manifest.get("debug", {})
|
||||
if not debug:
|
||||
return board
|
||||
protocols = debug.get("protocols", [])
|
||||
if "tools" not in debug:
|
||||
debug["tools"] = {}
|
||||
if "custom" not in debug["tools"]:
|
||||
debug["tools"]["custom"] = {}
|
||||
init = debug.get("gdb_init", [])
|
||||
|
||||
for link in protocols:
|
||||
if link == "openocd":
|
||||
args = ["-s", "$PACKAGE_DIR/scripts"]
|
||||
if debug.get("openocd_config"):
|
||||
args.extend(
|
||||
[
|
||||
"-f",
|
||||
"$LTPATH/platform/$LTPLATFORM/openocd/%s"
|
||||
% debug.get("openocd_config"),
|
||||
]
|
||||
)
|
||||
debug["tools"][link] = {
|
||||
"server": {
|
||||
"package": "tool-openocd",
|
||||
"executable": "bin/openocd",
|
||||
"arguments": args,
|
||||
},
|
||||
"extra_cmds": init,
|
||||
}
|
||||
else:
|
||||
continue
|
||||
debug["tools"][link]["default"] = link == debug.get("protocol", "")
|
||||
|
||||
debug["tools"]["custom"]["extra_cmds"] = init
|
||||
|
||||
board.manifest["debug"] = debug
|
||||
return board
|
||||
|
||||
def configure_debug_session(self, debug_config: DebugConfigBase):
|
||||
opts = debug_config.env_options
|
||||
server = debug_config.server
|
||||
lt_path = dirname(__file__)
|
||||
lt_platform = opts["framework"][0].rpartition("-")[0]
|
||||
if not server:
|
||||
debug_tool = opts.get("debug_tool", "custom")
|
||||
board = opts.get("board", "<unknown>")
|
||||
if debug_tool == "custom":
|
||||
return
|
||||
exc = DebugInvalidOptionsError(
|
||||
f"[LibreTuya] Debug tool {debug_tool} is not supported by board {board}."
|
||||
)
|
||||
exc.MESSAGE = ""
|
||||
raise exc
|
||||
if "arguments" in server:
|
||||
# allow setting interface via platformio.ini
|
||||
if opts.get("openocd_interface"):
|
||||
server["arguments"] = [
|
||||
"-f",
|
||||
"interface/%s.cfg" % opts.get("openocd_interface"),
|
||||
] + server["arguments"]
|
||||
# replace $LTPLATFORM with actual name
|
||||
server["arguments"] = [
|
||||
arg.replace("$LTPLATFORM", lt_platform).replace("$LTPATH", lt_path)
|
||||
for arg in server["arguments"]
|
||||
]
|
||||
|
||||
59
platform/realtek-ambz/openocd/amebaz.cfg
Normal file
59
platform/realtek-ambz/openocd/amebaz.cfg
Normal file
@@ -0,0 +1,59 @@
|
||||
# Main file for AmebaZ series Cortex-M3 parts
|
||||
#
|
||||
# !!!!!!
|
||||
#
|
||||
|
||||
set CHIPNAME rtl8711b
|
||||
set CHIPSERIES amebaz
|
||||
|
||||
transport select swd
|
||||
|
||||
# Adapt based on what transport is active.
|
||||
source [find target/swj-dp.tcl]
|
||||
|
||||
if { [info exists CHIPNAME] } {
|
||||
set _CHIPNAME $CHIPNAME
|
||||
} else {
|
||||
error "CHIPNAME not set. Please do not include amebaz.cfg directly."
|
||||
}
|
||||
|
||||
if { [info exists CHIPSERIES] } {
|
||||
# Validate chip series is supported
|
||||
if { $CHIPSERIES != "amebaz" } {
|
||||
error "Unsupported chip series specified."
|
||||
}
|
||||
set _CHIPSERIES $CHIPSERIES
|
||||
} else {
|
||||
error "CHIPSERIES not set. Please do not include amebaz.cfg directly."
|
||||
}
|
||||
|
||||
if { [info exists CPUTAPID] } {
|
||||
# Allow user override
|
||||
set _CPUTAPID $CPUTAPID
|
||||
} else {
|
||||
# Amebaz use a Cortex M4 core.
|
||||
if { $_CHIPSERIES == "amebaz" } {
|
||||
set _CPUTAPID 0x2ba01477
|
||||
}
|
||||
}
|
||||
|
||||
swj_newdap $_CHIPNAME cpu -irlen 4 -expected-id $_CPUTAPID
|
||||
|
||||
set _TARGETNAME $_CHIPNAME.cpu
|
||||
dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu
|
||||
|
||||
set _ENDIAN little
|
||||
|
||||
target create $_TARGETNAME cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap
|
||||
|
||||
adapter speed 1000
|
||||
adapter srst delay 200
|
||||
|
||||
# AmebaZ (Cortex M4 core) support SYSRESETREQ
|
||||
if {![using_hla]} {
|
||||
# if srst is not fitted use SYSRESETREQ to
|
||||
# perform a soft reset
|
||||
cortex_m reset_config sysresetreq
|
||||
}
|
||||
|
||||
$_TARGETNAME configure -event reset-init {amebaz_init}
|
||||
Reference in New Issue
Block a user