From c21a9ec431dad6201c6e509f338bf07d5636fead Mon Sep 17 00:00:00 2001 From: sys64738 Date: Sun, 8 Aug 2021 18:37:27 +0200 Subject: [PATCH] clean up switch to bootloader so that it doesn't cause unexpected USB disconnects --- .gitignore | 1 + README.md | 4 ---- host/dmctl/commands.py | 15 +++++++++++++-- host/dmctl/protocol.py | 2 +- host/setup.py | 4 ++-- src/modeset.c | 5 ++++- src/vnd_cfg.c | 5 ++++- 7 files changed, 25 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index f2ff998..0396c15 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ cmake-build/ build/ +build-flash/ ex/ compile_commands.json _old/ diff --git a/README.md b/README.md index 6b05154..04210d2 100644 --- a/README.md +++ b/README.md @@ -95,10 +95,6 @@ projects. These respective licenses can be found in supports 7-bit ones). - [ ] **1-wire** - [ ] **make modes persistent?** -- [ ] CMSIS-DAP SWO support? - - ~~Needs edits in the CMSIS-DAP code~~ ok no theyre weak symbols - - needs PIO stuff tho - - SWO = TDO ! - [ ] FT2232 emulation mode? - watch out, still need a vnd cfg interface! libftdi expects the following stuff: (TODO: acquire detailed protocol description) - interface 0 ("A"): index 1, epin 0x02, epout 0x81 diff --git a/host/dmctl/commands.py b/host/dmctl/commands.py index f82c939..05ed2c0 100644 --- a/host/dmctl/commands.py +++ b/host/dmctl/commands.py @@ -8,6 +8,13 @@ from typing import * from .protocol import * +FEATURES_OF_MODE = { + 1: ["UART", "CMSIS-DAP", "SPI", "I2C", "temperature sensor", "1-wire"], + 3: ["JTAG", "SWD"], + 4: ["SUMP"] +} + + def get_device_info(dev: DmjDevice) -> int: print("%s: protocol version: %02x.%02x, currently in mode %d (%s)" % \ (dev.infotext, dev.protocol_version >> 8, dev.protocol_version & 0xff, @@ -39,19 +46,23 @@ def get_mode_info(dev: DmjDevice, mode: Optional[str]) -> int: if mode == "all" or (is_int(mode) and int(mode) < 0): for mi, mv in dev.mode_info.items(): + featlist = FEATURES_OF_MODE.get(mi, "01234567") + print("mode % 2d: %s: version %02x.%02x with %sfeatures %s" % \ (mi, mv.infotext, mv.version >> 8, mv.version & 0xff, ("no " if len(mv.features) == 0 else ""), - ', '.join(str(x) for x in mv.features)) # TODO: better features display? + ', '.join(featlist[x] for x in mv.features)) # TODO: better features display? ) elif is_int(mode): mode = int(mode) + featlist = FEATURES_OF_MODE.get(mode, "01234567") + if mode in dev.mode_info: mv = dev.mode_info[mode] print("mode %d: %s: version %02x.%02x with %sfeatures %s" % \ (mode, mv.infotext, mv.version >> 8, mv.version & 0xff, ("no " if len(mv.features) == 0 else ""), - ', '.join(str(x) for x in list(mv.features))) # TODO: better features display? + ', '.join(featlist[x] for x in list(mv.features))) # TODO: better features display? ) return 0 else: diff --git a/host/dmctl/protocol.py b/host/dmctl/protocol.py index 3e8f96a..9364eee 100644 --- a/host/dmctl/protocol.py +++ b/host/dmctl/protocol.py @@ -234,7 +234,7 @@ class DmjDevice: stat, pl = self.read_resp() check_statpl(stat, pl, "get mode features", 1, 1) - return { i for i in range(1, 8) if (pl[0] & (1<=1.1.1" @@ -20,7 +20,7 @@ setup( python_requires=">=3.9", classifiers=[ "Programming Language :: Python :: 3", - "License :: OSI Approved :: GNU Affero General Public License v3", + "License :: OSI Approved :: GNU General Public License v3", "Operating System :: Unix", "Topic :: Software Development :: User Interfaces", "Topic :: System :: Hardware :: Hardware Drivers", diff --git a/src/modeset.c b/src/modeset.c index 35105d9..53ed69c 100644 --- a/src/modeset.c +++ b/src/modeset.c @@ -3,6 +3,7 @@ #include #include "alloc.h" +#include "board.h" /* bsp_reset_bootloader() */ #include "mode.h" extern struct mode m_01_default, m_03_jscan, m_04_sump; @@ -93,8 +94,10 @@ void modes_switch(uint8_t newmode) { // maybe wait a second or so for the host to notice this sleep_ms(500/2); + if (newmode == 0) bsp_reset_bootloader(); + // now apply the new tusb settings - mode_current_id = (newmode >= 16 || newmode == 0) ? (-1) : newmode; + mode_current_id = (newmode >= 16) ? (-1) : newmode; //mode_next_id = -1; if (mode_current) { // clang-format off diff --git a/src/vnd_cfg.c b/src/vnd_cfg.c index d195a88..d881d74 100644 --- a/src/vnd_cfg.c +++ b/src/vnd_cfg.c @@ -177,7 +177,10 @@ void vnd_cfg_task(void) { verbuf[0] = vnd_cfg_read_byte(); if (verbuf[0] == 0) { // reset - bsp_reset_bootloader(); + // don't do this here, see the comment below in the 'else' branch + //bsp_reset_bootloader(); + mode_next_id = 0; + vnd_cfg_write_resp(cfg_resp_ok, 0, NULL); } else if (verbuf[0] >= 0x10 || mode_list[verbuf[0]] == NULL) { vnd_cfg_write_resp(cfg_resp_nosuchmode, 0, NULL); } else {