Skip to content

Commit 4ea5a1e

Browse files
authored
Tasmota 203
* Update OCD Apple Silicon to build from 20220424 * esptool.py v3.3 now in registry * Add CMSIS-DAP as available debug probe * Use GetBuildType for detecting debug mode * rm Python2 add C3 exception decoder * remove fix firmware address 0x10000 * Apple arm toolchains for IDF * Arduino framework based on IDF4.4.1
1 parent aacdc58 commit 4ea5a1e

File tree

6 files changed

+104
-73
lines changed

6 files changed

+104
-73
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# Tasmota Espressif 32: development platform for [PlatformIO](http://platformio.org)
55

6-
[![Examples](https://github.com/Jason2866/platform-espressif32/actions/workflows/examples.yml/badge.svg)](https://github.com/Jason2866/platform-espressif32/actions/workflows/examples.yml)[![GitHub Releases](https://img.shields.io/github/downloads/Tasmota/platform-espressif32/total?label=downloads)](https://github.com/Tasmota/platform-espressif32/releases/latest)
6+
[![Examples](https://github.com/Jason2866/platform-espressif32/actions/workflows/examples.yml/badge.svg)](https://github.com/Jason2866/platform-espressif32/actions/workflows/examples.yml)[![GitHub Releases](https://img.shields.io/github/downloads/Jason2866/platform-espressif32/total?label=downloads)](https://github.com/Jason2866/platform-espressif32/releases/latest)
77

88
Espressif Systems is a privately held fabless semiconductor company. They provide wireless communications and Wi-Fi chips which are widely used in mobile devices and the Internet of Things applications.
99

builder/frameworks/espidf.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,24 @@
5050
idf_variant = mcu.lower()
5151

5252
FRAMEWORK_DIR = platform.get_package_dir("framework-espidf")
53-
TOOLCHAIN_DIR = platform.get_package_dir(
54-
"toolchain-%s"
55-
% (
56-
"riscv32-esp"
57-
if mcu == "esp32c3"
58-
else ("xtensa-%s" % mcu)
53+
if "darwin" in get_systype() and "arm64" in get_systype():
54+
TOOLCHAIN_DIR = platform.get_package_dir(
55+
"toolchain-%s"
56+
% (
57+
"riscv32-esp-arm"
58+
if mcu == "esp32c3"
59+
else ("xtensa-%s-arm" % mcu)
60+
)
61+
)
62+
if not "arm64" in get_systype():
63+
TOOLCHAIN_DIR = platform.get_package_dir(
64+
"toolchain-%s"
65+
% (
66+
"riscv32-esp"
67+
if mcu == "esp32c3"
68+
else ("xtensa-%s" % mcu)
69+
)
5970
)
60-
)
6171

6272
assert os.path.isdir(FRAMEWORK_DIR)
6373
assert os.path.isdir(TOOLCHAIN_DIR)
@@ -587,11 +597,8 @@ def generate_project_ld_script(sdk_config, ignore_targets=None):
587597
def prepare_build_envs(config, default_env):
588598
build_envs = []
589599
target_compile_groups = config.get("compileGroups")
590-
is_build_type_debug = (
591-
set(["debug", "sizedata"]) & set(COMMAND_LINE_TARGETS)
592-
or default_env.GetProjectOption("build_type") == "debug"
593-
)
594600

601+
is_build_type_debug = "debug" in env.GetBuildType()
595602
for cg in target_compile_groups:
596603
includes = []
597604
sys_includes = []

builder/main.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def _parse_partitions(env):
8080

8181
result = []
8282
next_offset = 0
83+
bound = 0x10000 # default value
8384
with open(partitions_csv) as fp:
8485
for line in fp.readlines():
8586
line = line.strip()
@@ -97,13 +98,14 @@ def _parse_partitions(env):
9798
"flags": tokens[5] if len(tokens) > 5 else None
9899
}
99100
result.append(partition)
100-
next_offset = _parse_size(partition["offset"]) + _parse_size(
101-
partition["size"]
102-
)
103-
104-
bound = 0x10000 if partition["type"] in ("0", "app") else 4
101+
next_offset = _parse_size(partition["offset"])
102+
#print("App start from .csv:", hex(next_offset))
103+
#print("Partition subtype from .csv:", partition["subtype"])
104+
if (partition["subtype"] == "ota_0"):
105+
bound = next_offset
105106
next_offset = (next_offset + bound - 1) & ~(bound - 1)
106-
107+
#print("Main Firmware will be flashed to:", hex(bound))
108+
env["ESP32_APP_OFFSET"] = hex(bound)
107109
return result
108110

109111

@@ -213,8 +215,6 @@ def __fetch_fs_size(target, source, env):
213215
"ESP32_FS_IMAGE_NAME", env.get("ESP32_SPIFFS_IMAGE_NAME", filesystem)
214216
),
215217

216-
ESP32_APP_OFFSET=board.get("upload.offset_address", "0x10000"),
217-
218218
PROGSUFFIX=".elf"
219219
)
220220

monitor/filter_exception_decoder.py

Lines changed: 70 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import subprocess
1818
import sys
1919

20-
from platformio.compat import path_to_unicode, WINDOWS, PY2
20+
from platformio.compat import path_to_unicode, WINDOWS
2121
from platformio.project.exception import PlatformioException
2222
from platformio.project.helpers import load_project_ide_data
2323
from platformio.commands.device import DeviceMonitorFilter
@@ -31,53 +31,74 @@ class Esp32ExceptionDecoder(DeviceMonitorFilter):
3131

3232
def __call__(self):
3333
self.buffer = ""
34-
self.backtrace_re = re.compile(
35-
r"^Backtrace: ?((0x[0-9a-fA-F]{8}:0x[0-9a-fA-F]{8} ?)+)\s*"
36-
)
34+
# regex matches potential PC value (0x4xxxxxxx)
35+
# Logic identical to https://github.com/espressif/esp-idf/blob/master/tools/idf_monitor_base/constants.py#L56
36+
self.pcaddr_re = re.compile(r'0x4[0-9a-f]{7}', re.IGNORECASE)
3737

3838
self.firmware_path = None
3939
self.addr2line_path = None
4040
self.enabled = self.setup_paths()
4141

42-
if self.config.get("env:" + self.environment, "build_type") != "debug":
43-
print(
42+
return self
43+
44+
def setup_paths(self):
45+
self.project_dir = path_to_unicode(os.path.abspath(self.project_dir))
46+
47+
self.project_strip_dir = os.environ.get("esp32_exception_decoder_project_strip_dir")
48+
self.firmware_path = os.environ.get("esp32_exception_decoder_firmware_path")
49+
self.addr2line_path = os.environ.get("esp32_exception_decoder_addr2line_path")
50+
51+
if self.project_strip_dir is None:
52+
self.project_strip_dir = self.project_dir
53+
54+
try:
55+
if self.firmware_path is None or self.addr2line_path is None:
56+
# Only load if necessary, as the call is expensive
57+
data = load_project_ide_data(self.project_dir, self.environment)
58+
59+
if self.firmware_path is None:
60+
# Only do this check when the firmware path is not externally provided
61+
if self.config.get("env:" + self.environment, "build_type") != "debug":
62+
print(
4463
"""
4564
Please build project in debug configuration to get more details about an exception.
4665
See https://docs.platformio.org/page/projectconf/build_configurations.html
4766
4867
"""
49-
)
50-
51-
return self
68+
)
69+
self.firmware_path = data["prog_path"]
5270

53-
def setup_paths(self):
54-
self.project_dir = path_to_unicode(os.path.abspath(self.project_dir))
55-
try:
56-
data = load_project_ide_data(self.project_dir, self.environment)
57-
self.firmware_path = data["prog_path"]
5871
if not os.path.isfile(self.firmware_path):
5972
sys.stderr.write(
60-
"%s: firmware at %s does not exist, rebuild the project?\n"
73+
"%s: disabling, firmware at %s does not exist, rebuild the project?\n"
6174
% (self.__class__.__name__, self.firmware_path)
6275
)
6376
return False
6477

65-
cc_path = data.get("cc_path", "")
66-
if "-gcc" in cc_path:
67-
path = cc_path.replace("-gcc", "-addr2line")
68-
if os.path.isfile(path):
69-
self.addr2line_path = path
70-
return True
78+
if self.addr2line_path is None:
79+
cc_path = data.get("cc_path", "")
80+
if "-gcc" in cc_path:
81+
self.addr2line_path = cc_path.replace("-gcc", "-addr2line")
82+
else:
83+
sys.stderr.write(
84+
"%s: disabling, failed to find addr2line.\n" % self.__class__.__name__
85+
)
86+
return False
87+
88+
if not os.path.isfile(self.addr2line_path):
89+
sys.stderr.write(
90+
"%s: disabling, addr2line at %s does not exist\n"
91+
% (self.__class__.__name__, self.addr2line_path)
92+
)
93+
return False
94+
95+
return True
7196
except PlatformioException as e:
7297
sys.stderr.write(
7398
"%s: disabling, exception while looking for addr2line: %s\n"
7499
% (self.__class__.__name__, e)
75100
)
76101
return False
77-
sys.stderr.write(
78-
"%s: disabling, failed to find addr2line.\n" % self.__class__.__name__
79-
)
80-
return False
81102

82103
def rx(self, text):
83104
if not self.enabled:
@@ -97,36 +118,36 @@ def rx(self, text):
97118
self.buffer = ""
98119
last = idx + 1
99120

100-
m = self.backtrace_re.match(line)
101-
if m is None:
102-
continue
121+
# Output each trace on a separate line below ours
122+
# Logic identical to https://github.com/espressif/esp-idf/blob/master/tools/idf_monitor_base/logger.py#L131
123+
for m in re.finditer(self.pcaddr_re, line):
124+
if m is None:
125+
continue
126+
127+
trace = self.get_backtrace(m)
128+
if len(trace) != "":
129+
text = text[: last] + trace + text[last :]
130+
last += len(trace)
103131

104-
trace = self.get_backtrace(m)
105-
if len(trace) != "":
106-
text = text[: idx + 1] + trace + text[idx + 1 :]
107-
last += len(trace)
108132
return text
109133

110134
def get_backtrace(self, match):
111135
trace = ""
112136
enc = "mbcs" if WINDOWS else "utf-8"
113137
args = [self.addr2line_path, u"-fipC", u"-e", self.firmware_path]
114-
if PY2:
115-
args = [a.encode(enc) for a in args]
116138
try:
117-
for i, addr in enumerate(match.group(1).split()):
118-
if PY2:
119-
addr = addr.encode(enc)
120-
output = (
121-
subprocess.check_output(args + [addr])
122-
.decode(enc)
123-
.strip()
124-
)
125-
output = output.replace(
126-
"\n", "\n "
127-
) # newlines happen with inlined methods
128-
output = self.strip_project_dir(output)
129-
trace += " #%-2d %s in %s\n" % (i, addr, output)
139+
addr = match.group()
140+
output = (
141+
subprocess.check_output(args + [addr])
142+
.decode(enc)
143+
.strip()
144+
)
145+
output = output.replace(
146+
"\n", "\n "
147+
) # newlines happen with inlined methods
148+
output = self.strip_project_dir(output)
149+
# Output the trace in yellow color so that it is easier to spot
150+
trace += "\033[33m=> %s: %s\033[0m\n" % (addr, output)
130151
except subprocess.CalledProcessError as e:
131152
sys.stderr.write(
132153
"%s: failed to call %s: %s\n"
@@ -136,8 +157,8 @@ def get_backtrace(self, match):
136157

137158
def strip_project_dir(self, trace):
138159
while True:
139-
idx = trace.find(self.project_dir)
160+
idx = trace.find(self.project_strip_dir)
140161
if idx == -1:
141162
break
142-
trace = trace[:idx] + trace[idx + len(self.project_dir) + 1 :]
163+
trace = trace[:idx] + trace[idx + len(self.project_strip_dir) + 1 :]
143164
return trace

platform.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"type": "framework",
3838
"optional": true,
3939
"owner": "tasmota",
40-
"version": "https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/803/framework-arduinoespressif32-v4.4_dev-40d126bfd1.tar.gz"
40+
"version": "https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/829/framework-arduinoespressif32-v4.4.1-3010c4571f.tar.gz"
4141
},
4242
"framework-espidf": {
4343
"type": "framework",
@@ -97,7 +97,7 @@
9797
"type": "debugger",
9898
"optional": true,
9999
"owner": "tasmota",
100-
"version": "https://github.com/Jason2866/openocd-esp32/releases/download/v0.11.0-esp32-20220404/openocd-esp32-macos-arm-0.11.0-esp32-20220406.zip"
100+
"version": "https://github.com/Jason2866/openocd-esp32/releases/download/v0.11.0-esp32-20220404/openocd-esp32-macos-arm64-0.11.0-esp32-20220424.zip"
101101
},
102102
"toolchain-esp32ulp": {
103103
"type": "toolchain",
@@ -119,8 +119,8 @@
119119
},
120120
"tool-esptoolpy": {
121121
"type": "uploader",
122-
"owner": "tasmota",
123-
"version": "https://github.com/tasmota/esptool/releases/download/v3.3/esptool-3.3.zip"
122+
"owner": "platformio",
123+
"version": "~1.30300.0"
124124
},
125125
"tool-mbctool": {
126126
"optional": true,

platform.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ def _add_dynamic_options(self, board):
173173
debug = board.manifest.get("debug", {})
174174
non_debug_protocols = ["esptool", "espota", "mbctool"]
175175
supported_debug_tools = [
176+
"cmsis-dap",
176177
"esp-prog",
177178
"iot-bus-jtag",
178179
"jlink",
@@ -202,6 +203,8 @@ def _add_dynamic_options(self, board):
202203

203204
if link == "jlink":
204205
openocd_interface = link
206+
elif link == "cmsis-dap":
207+
openocd_interface = link
205208
elif link in ("esp-prog", "ftdi"):
206209
if board.id == "esp32-s2-kaluga-1":
207210
openocd_interface = "ftdi/esp32s2_kaluga_v1"

0 commit comments

Comments
 (0)