Skip to content

Commit

Permalink
Merge branch 'meshtastic:master' into t-echo_mod
Browse files Browse the repository at this point in the history
  • Loading branch information
Mictronics authored Jan 10, 2024
2 parents 0a2724b + 0d85069 commit 6404c58
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 57 deletions.
145 changes: 103 additions & 42 deletions bin/exception_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@
* version that's checked into meshtastic repo is based on: https://github.com/me21/EspArduinoExceptionDecoder
which adds in ESP32 Backtrace decoding.
* this also updates the defaults to use ESP32, instead of ESP8266 and defaults to the built firmware.bin
* also updated the toolchain name, which will be set according to the platform
To use, copy the "Backtrace: 0x...." line to a file, e.g., backtrace.txt, then run:
$ bin/exception_decoder.py backtrace.txt
For a platform other than ESP32, use the -p option, e.g.:
$ bin/exception_decoder.py -p ESP32S3 backtrace.txt
To specify a specific .elf file, use the -e option, e.g.:
$ bin/exception_decoder.py -e firmware.elf backtrace.txt
"""

import argparse
import os
import re
import subprocess
from collections import namedtuple

import sys

import os
from collections import namedtuple

EXCEPTIONS = [
"Illegal instruction",
Expand Down Expand Up @@ -55,24 +58,39 @@
"LoadStorePrivilege: A load or store referenced a virtual address at a ring level less than CRING",
"reserved",
"LoadProhibited: A load referenced a page mapped with an attribute that does not permit loads",
"StoreProhibited: A store referenced a page mapped with an attribute that does not permit stores"
"StoreProhibited: A store referenced a page mapped with an attribute that does not permit stores",
]

PLATFORMS = {
"ESP8266": "lx106",
"ESP32": "esp32"
"ESP8266": "xtensa-lx106",
"ESP32": "xtensa-esp32",
"ESP32S3": "xtensa-esp32s3",
"ESP32C3": "riscv32-esp",
}
TOOLS = {
"ESP8266": "xtensa",
"ESP32": "xtensa-esp32",
"ESP32S3": "xtensa-esp32s3",
"ESP32C3": "riscv32-esp",
}

BACKTRACE_REGEX = re.compile(r"(?:\s+(0x40[0-2](?:\d|[a-f]|[A-F]){5}):0x(?:\d|[a-f]|[A-F]){8})\b")
BACKTRACE_REGEX = re.compile(
r"(?:\s+(0x40[0-2](?:\d|[a-f]|[A-F]){5}):0x(?:\d|[a-f]|[A-F]){8})\b"
)
EXCEPTION_REGEX = re.compile("^Exception \\((?P<exc>[0-9]*)\\):$")
COUNTER_REGEX = re.compile('^epc1=(?P<epc1>0x[0-9a-f]+) epc2=(?P<epc2>0x[0-9a-f]+) epc3=(?P<epc3>0x[0-9a-f]+) '
'excvaddr=(?P<excvaddr>0x[0-9a-f]+) depc=(?P<depc>0x[0-9a-f]+)$')
COUNTER_REGEX = re.compile(
"^epc1=(?P<epc1>0x[0-9a-f]+) epc2=(?P<epc2>0x[0-9a-f]+) epc3=(?P<epc3>0x[0-9a-f]+) "
"excvaddr=(?P<excvaddr>0x[0-9a-f]+) depc=(?P<depc>0x[0-9a-f]+)$"
)
CTX_REGEX = re.compile("^ctx: (?P<ctx>.+)$")
POINTER_REGEX = re.compile('^sp: (?P<sp>[0-9a-f]+) end: (?P<end>[0-9a-f]+) offset: (?P<offset>[0-9a-f]+)$')
STACK_BEGIN = '>>>stack>>>'
STACK_END = '<<<stack<<<'
POINTER_REGEX = re.compile(
"^sp: (?P<sp>[0-9a-f]+) end: (?P<end>[0-9a-f]+) offset: (?P<offset>[0-9a-f]+)$"
)
STACK_BEGIN = ">>>stack>>>"
STACK_END = "<<<stack<<<"
STACK_REGEX = re.compile(
'^(?P<off>[0-9a-f]+):\W+(?P<c1>[0-9a-f]+) (?P<c2>[0-9a-f]+) (?P<c3>[0-9a-f]+) (?P<c4>[0-9a-f]+)(\W.*)?$')
"^(?P<off>[0-9a-f]+):\W+(?P<c1>[0-9a-f]+) (?P<c2>[0-9a-f]+) (?P<c3>[0-9a-f]+) (?P<c4>[0-9a-f]+)(\W.*)?$"
)

StackLine = namedtuple("StackLine", ["offset", "content"])

Expand All @@ -96,15 +114,18 @@ def __init__(self):
self.stack = []

def _parse_backtrace(self, line):
if line.startswith('Backtrace:'):
self.stack = [StackLine(offset=0, content=(addr,)) for addr in BACKTRACE_REGEX.findall(line)]
if line.startswith("Backtrace:"):
self.stack = [
StackLine(offset=0, content=(addr,))
for addr in BACKTRACE_REGEX.findall(line)
]
return None
return self._parse_backtrace

def _parse_exception(self, line):
match = EXCEPTION_REGEX.match(line)
if match is not None:
self.exception = int(match.group('exc'))
self.exception = int(match.group("exc"))
return self._parse_counters
return self._parse_exception

Expand Down Expand Up @@ -144,14 +165,22 @@ def _parse_stack_line(self, line):
if line != STACK_END:
match = STACK_REGEX.match(line)
if match is not None:
self.stack.append(StackLine(offset=match.group("off"),
content=(match.group("c1"), match.group("c2"), match.group("c3"),
match.group("c4"))))
self.stack.append(
StackLine(
offset=match.group("off"),
content=(
match.group("c1"),
match.group("c2"),
match.group("c3"),
match.group("c4"),
),
)
)
return self._parse_stack_line
return None

def parse_file(self, file, platform, stack_only=False):
if platform == 'ESP32':
if platform != "ESP8266":
func = self._parse_backtrace
else:
func = self._parse_exception
Expand All @@ -175,7 +204,9 @@ def __init__(self, tool_path, elf_path):
self._address_map = {}

def _lookup(self, addresses):
cmd = [self._tool, "-aipfC", "-e", self._elf] + [addr for addr in addresses if addr is not None]
cmd = [self._tool, "-aipfC", "-e", self._elf] + [
addr for addr in addresses if addr is not None
]

if sys.version_info[0] < 3:
output = subprocess.check_output(cmd)
Expand All @@ -190,19 +221,27 @@ def _lookup(self, addresses):
match = line_regex.match(line)

if match is None:
if last is not None and line.startswith('(inlined by)'):
line = line [12:].strip()
self._address_map[last] += ("\n \-> inlined by: " + line)
if last is not None and line.startswith("(inlined by)"):
line = line[12:].strip()
self._address_map[last] += "\n \-> inlined by: " + line
continue

if match.group("result") == '?? ??:0':
if match.group("result") == "?? ??:0":
continue

self._address_map[match.group("addr")] = match.group("result")
last = match.group("addr")

def fill(self, parser):
addresses = [parser.epc1, parser.epc2, parser.epc3, parser.excvaddr, parser.sp, parser.end, parser.offset]
addresses = [
parser.epc1,
parser.epc2,
parser.epc3,
parser.excvaddr,
parser.sp,
parser.end,
parser.offset,
]
for line in parser.stack:
addresses.extend(line.content)

Expand Down Expand Up @@ -257,8 +296,10 @@ def print_stack(lines, resolver):


def print_result(parser, resolver, platform, full=True, stack_only=False):
if platform == 'ESP8266' and not stack_only:
print('Exception: {} ({})'.format(parser.exception, EXCEPTIONS[parser.exception]))
if platform == "ESP8266" and not stack_only:
print(
"Exception: {} ({})".format(parser.exception, EXCEPTIONS[parser.exception])
)

print("")
print_addr("epc1", parser.epc1, resolver)
Expand All @@ -285,15 +326,33 @@ def print_result(parser, resolver, platform, full=True, stack_only=False):
def parse_args():
parser = argparse.ArgumentParser(description="decode ESP Stacktraces.")

parser.add_argument("-p", "--platform", help="The platform to decode from", choices=PLATFORMS.keys(),
default="ESP32")
parser.add_argument("-t", "--tool", help="Path to the xtensa toolchain",
default="~/.platformio/packages/toolchain-xtensa32/")
parser.add_argument("-e", "--elf", help="path to elf file",
default=".pio/build/esp32/firmware.elf")
parser.add_argument("-f", "--full", help="Print full stack dump", action="store_true")
parser.add_argument("-s", "--stack_only", help="Decode only a stractrace", action="store_true")
parser.add_argument("file", help="The file to read the exception data from ('-' for STDIN)", default="-")
parser.add_argument(
"-p",
"--platform",
help="The platform to decode from",
choices=PLATFORMS.keys(),
default="ESP32",
)
parser.add_argument(
"-t",
"--tool",
help="Path to the toolchain (without specific platform)",
default="~/.platformio/packages/toolchain-",
)
parser.add_argument(
"-e", "--elf", help="path to elf file", default=".pio/build/tbeam/firmware.elf"
)
parser.add_argument(
"-f", "--full", help="Print full stack dump", action="store_true"
)
parser.add_argument(
"-s", "--stack_only", help="Decode only a stractrace", action="store_true"
)
parser.add_argument(
"file",
help="The file to read the exception data from ('-' for STDIN)",
default="-",
)

return parser.parse_args()

Expand All @@ -309,10 +368,12 @@ def parse_args():
sys.exit(1)
file = open(args.file, "r")

addr2line = os.path.join(os.path.abspath(os.path.expanduser(args.tool)),
"bin/xtensa-" + PLATFORMS[args.platform] + "-elf-addr2line")
if os.name == 'nt':
addr2line += '.exe'
addr2line = os.path.join(
os.path.abspath(os.path.expanduser(args.tool + TOOLS[args.platform])),
"bin/" + PLATFORMS[args.platform] + "-elf-addr2line",
)
if os.name == "nt":
addr2line += ".exe"
if not os.path.exists(addr2line):
print("ERROR: addr2line not found (" + addr2line + ")")

Expand Down
3 changes: 2 additions & 1 deletion src/ButtonThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class ButtonThread : public concurrency::OSThread
#ifdef BUTTON_PIN
if (((config.device.button_gpio ? config.device.button_gpio : BUTTON_PIN) !=
moduleConfig.canned_message.inputbroker_pin_press) ||
!(moduleConfig.canned_message.updown1_enabled || moduleConfig.canned_message.rotary1_enabled) ||
!moduleConfig.canned_message.enabled) {
powerFSM.trigger(EVENT_PRESS);
}
Expand Down Expand Up @@ -232,4 +233,4 @@ class ButtonThread : public concurrency::OSThread
}
};

} // namespace concurrency
} // namespace concurrency
27 changes: 15 additions & 12 deletions src/graphics/EInkDisplay2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include "main.h"
#include <SPI.h>

// #ifdef HELTEC_WIRELESS_PAPER
// SPIClass *hspi = NULL;
// #endif
#ifdef HELTEC_WIRELESS_PAPER
SPIClass *hspi = NULL;
#endif

#define COLORED GxEPD_BLACK
#define UNCOLORED GxEPD_WHITE
Expand Down Expand Up @@ -47,7 +47,7 @@

#elif defined(HELTEC_WIRELESS_PAPER)
// #define TECHO_DISPLAY_MODEL GxEPD2_213_T5D
#define TECHO_DISPLAY_MODEL GxEPD2_213_BN
#define TECHO_DISPLAY_MODEL GxEPD2_213_FC1
#endif

GxEPD2_BW<TECHO_DISPLAY_MODEL, TECHO_DISPLAY_MODEL::HEIGHT> *adafruitDisplay;
Expand All @@ -71,7 +71,7 @@ EInkDisplay::EInkDisplay(uint8_t address, int sda, int scl, OLEDDISPLAY_GEOMETRY
// setGeometry(GEOMETRY_RAWMODE, 200, 200);

#elif defined(HELTEC_WIRELESS_PAPER)
// setGeometry(GEOMETRY_RAWMODE, 212, 104);
// GxEPD2_213_BN - 2.13 inch b/w 250x122
setGeometry(GEOMETRY_RAWMODE, 250, 122);
#elif defined(MAKERPYTHON)
// GxEPD2_290_T5D
Expand Down Expand Up @@ -119,7 +119,6 @@ bool EInkDisplay::forceDisplay(uint32_t msecLimit)
// tft.drawBitmap(0, 0, buffer, 128, 64, TFT_YELLOW, TFT_BLACK);
for (uint32_t y = 0; y < displayHeight; y++) {
for (uint32_t x = 0; x < displayWidth; x++) {

// get src pixel in the page based ordering the OLED lib uses FIXME, super inefficient
auto b = buffer[x + (y / 8) * displayWidth];
auto isset = b & (1 << (y & 7));
Expand Down Expand Up @@ -148,7 +147,8 @@ bool EInkDisplay::forceDisplay(uint32_t msecLimit)

#elif defined(PCA10059) || defined(M5_COREINK)
adafruitDisplay->nextPage();

#elif defined(HELTEC_WIRELESS_PAPER)
adafruitDisplay->nextPage();
#elif defined(PRIVATE_HW) || defined(my)
adafruitDisplay->nextPage();

Expand Down Expand Up @@ -231,13 +231,16 @@ bool EInkDisplay::connect()
}
#elif defined(HELTEC_WIRELESS_PAPER)
{
auto lowLevel = new TECHO_DISPLAY_MODEL(PIN_EINK_CS, PIN_EINK_DC, PIN_EINK_RES, PIN_EINK_BUSY);
hspi = new SPIClass(HSPI);
hspi->begin(PIN_EINK_SCLK, -1, PIN_EINK_MOSI, PIN_EINK_CS); // SCLK, MISO, MOSI, SS
delay(100);
pinMode(Vext, OUTPUT);
digitalWrite(Vext, LOW);
delay(100);
auto lowLevel = new TECHO_DISPLAY_MODEL(PIN_EINK_CS, PIN_EINK_DC, PIN_EINK_RES, PIN_EINK_BUSY, *hspi);
adafruitDisplay = new GxEPD2_BW<TECHO_DISPLAY_MODEL, TECHO_DISPLAY_MODEL::HEIGHT>(*lowLevel);
// hspi = new SPIClass(HSPI);
// hspi->begin(PIN_EINK_SCLK, -1, PIN_EINK_MOSI, PIN_EINK_CS); // SCLK, MISO, MOSI, SS
adafruitDisplay->init(115200, true, 10, false, SPI, SPISettings(6000000, MSBFIRST, SPI_MODE0));
adafruitDisplay->init();
adafruitDisplay->setRotation(3);
adafruitDisplay->setPartialWindow(0, 0, displayWidth, displayHeight);
}
#elif defined(PCA10059)
{
Expand Down
Loading

0 comments on commit 6404c58

Please sign in to comment.