Browse Source

clean up switch to bootloader so that it doesn't cause unexpected USB disconnects

isp-mehfet
sys64738 4 months ago
parent
commit
c21a9ec431
  1. 1
      .gitignore
  2. 4
      README.md
  3. 15
      host/dmctl/commands.py
  4. 2
      host/dmctl/protocol.py
  5. 4
      host/setup.py
  6. 5
      src/modeset.c
  7. 5
      src/vnd_cfg.c

1
.gitignore

@ -1,5 +1,6 @@
cmake-build/
build/
build-flash/
ex/
compile_commands.json
_old/

4
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

15
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:

2
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<<i)) != 0 }
return { i for i in range(0, 8) if (pl[0] & (1<<i)) != 0 }
# mode 1 commands

4
host/setup.py

@ -12,7 +12,7 @@ setup(
url='',
author='sys64738',
author_email='sys64738@disroot.org',
license='???',
license='GPL-3.0',
packages=['dmctl'],
install_requires=[
"pyusb>=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",

5
src/modeset.c

@ -3,6 +3,7 @@
#include <assert.h>
#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

5
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 {

Loading…
Cancel
Save