Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: GlasgowEmbedded/glasgow
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0ce0389c3c38
Choose a base ref
...
head repository: GlasgowEmbedded/glasgow
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8367c3a238be
Choose a head ref
  • 1 commit
  • 4 files changed
  • 1 contributor

Commits on Aug 2, 2019

  1. Copy the full SHA
    8367c3a View commit details
1 change: 1 addition & 0 deletions software/glasgow/applet/all.py
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
from .debug.arc import DebugARCApplet
from .debug.mips import DebugMIPSApplet
from .debug.arm.swd import DebugARMSWDApplet
from .debug.msp430 import DebugMSP430JTAGApplet, DebugMSP430SBWApplet

from .program.avr.spi import ProgramAVRSPIApplet
from .program.ice40_flash import ProgramICE40FlashApplet
2 changes: 1 addition & 1 deletion software/glasgow/applet/debug/mips/__init__.py
Original file line number Diff line number Diff line change
@@ -829,7 +829,7 @@ def add_run_arguments(cls, parser, access):
help="select TAP #INDEX for communication (default: %(default)s)")

async def run(self, device, args):
jtag_iface = await super().run(device, args)
jtag_iface = await self.run_lower(DebugMIPSApplet, device, args)
tap_iface = await jtag_iface.select_tap(args.tap_index)
if not tap_iface:
raise GlasgowAppletError("cannot select TAP #%d" % args.tap_index)
117 changes: 117 additions & 0 deletions software/glasgow/applet/debug/msp430/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Ref: MSP430™ Programming With the JTAG Interface
# Accession: G00038

# Note: for unknown reasons, DR values and captured IR value are bit reversed. However, IR opcodes
# are not bit reversed. This is quite confusing.

import logging
import asyncio
from abc import ABCMeta, abstractmethod, abstractproperty

from ....support.aobject import *
from ....support.bits import *
from ....arch.msp430.jtag import *
from ...interface.jtag_probe import JTAGProbeApplet
from ...interface.sbw_probe import SpyBiWireProbeApplet
from ... import *


class MSP430DebugError(GlasgowAppletError):
pass


class _MSP430FamilyDebugInterface(aobject, metaclass=ABCMeta):
async def __init__(self, interface, logger):
self.lower = interface
self._logger = logger
self._level = logging.DEBUG if self._logger.name == __name__ else logging.TRACE

await self._probe_jtag()

def _log(self, message, *args, level=None):
self._logger.log(self._level if level is None else level, "MSP430: " + message, *args)

async def _probe_jtag(self):
await self.lower.test_reset()
jtag_id_bits = await self.lower.read_ir(8)
jtag_id = int(jtag_id_bits.reversed())
if jtag_id not in (0x89, 0x90, 0x91):
raise MSP430DebugError("unknown JTAG ID {:#04x}".format(jtag_id))
self._log("found MSP430 core with JTAG ID %#04x", jtag_id,
level=logging.INFO)

_DR_CNTRL_SIG = abstractproperty()

async def _set_control(self, **kwargs):
cntrl_sig = self._DR_CNTRL_SIG(**kwargs)
cntrl_sig_bits = cntrl_sig.to_bits()
self._log("set CNTRL_SIG %s", cntrl_sig.bits_repr(omit_zero=True))
await self.lower.write_ir(IR_CNTRL_SIG_16BIT)
await self.lower.write_dr(cntrl_sig_bits.reversed())

async def _get_control(self):
await self.lower.write_ir(IR_CNTRL_SIG_CAPTURE)
cntrl_sig_bits = await self.lower.read_dr(16)
cntrl_sig = self._DR_CNTRL_SIG.from_bits(cntrl_sig_bits.reversed())
self._log("get CNTRL_SIG %s", cntrl_sig.bits_repr(omit_zero=True))
return cntrl_sig

@abstractmethod
async def _do_attach(self):
pass

async def attach(self):
self._log("attach")
await self._do_attach()
cntrl_sig = await self._get_control()
if not cntrl_sig.TCE:
raise MSP430DebugError("cannot attach to target")
self._log("attached to target",
level=logging.INFO)

async def detach(self):
self._log("detach")
await self.lower.write_ir(IR_CNTRL_SIG_RELEASE)
await self.lower.run_test_idle(0)
self._log("detached from target",
level=logging.INFO)


class MSP430DebugInterface(_MSP430FamilyDebugInterface):
_DR_CNTRL_SIG = DR_CNTRL_SIG_124

async def _do_attach(self):
await self._set_control(R_W=1, TAGFUNCSAT=1, TCE1=1)


class _DebugMSP430AppletMixin:
preview = True
description = "" # nothing to add for now

async def interact(self, device, args, msp430_iface):
await msp430_iface.attach()
await msp430_iface.detach()


class DebugMSP430JTAGApplet(_DebugMSP430AppletMixin, JTAGProbeApplet, name="debug-msp430-jtag"):
logger = logging.getLogger(__name__)
help = "debug MSP430 processors via JTAG"
description = """
Debug Texas Instruments MSP430 processors via the 4-wire JTAG interface.
""" + _DebugMSP430AppletMixin.description

async def run(self, device, args):
jtag_iface = await self.run_lower(DebugMSP430JTAGApplet, device, args)
return await MSP430DebugInterface(jtag_iface, self.logger)


class DebugMSP430SBWApplet(_DebugMSP430AppletMixin, SpyBiWireProbeApplet, name="debug-msp430-sbw"):
logger = logging.getLogger(__name__)
help = "debug MSP430 processors via Spy-Bi-Wire"
description = """
Debug Texas Instruments MSP430 processors via the 2-wire Spy-Bi-Wire interface.
""" + _DebugMSP430AppletMixin.description

async def run(self, device, args):
jtag_iface = await self.run_lower(DebugMSP430SBWApplet, device, args)
return await MSP430DebugInterface(jtag_iface, self.logger)
6 changes: 3 additions & 3 deletions software/glasgow/applet/interface/sbw_probe/__init__.py
Original file line number Diff line number Diff line change
@@ -174,9 +174,9 @@ async def run(self, device, args):

async def interact(self, device, args, jtag_iface):
await jtag_iface.test_reset()
version_bits = await jtag_iface.read_ir(8)
version = int(version_bits.reversed())
if version == 0xff:
jtag_id_bits = await jtag_iface.read_ir(8)
jtag_id = int(jtag_id_bits.reversed())
if jtag_id == 0xff:
self.logger.error("no target detected; connection problem?")
else:
self.logger.info("found MSP430 core with JTAG ID %#04x", version)