|
| 1 | +# Ref: MSP430™ Programming With the JTAG Interface |
| 2 | +# Accession: G00038 |
| 3 | + |
| 4 | +import logging |
| 5 | +import asyncio |
| 6 | +from abc import ABCMeta, abstractmethod |
| 7 | + |
| 8 | +from ....support.aobject import * |
| 9 | +from ....support.bits import * |
| 10 | +from ....arch.msp430.jtag import * |
| 11 | +from ...interface.jtag_probe import JTAGProbeApplet |
| 12 | +from ...interface.sbw_probe import SpyBiWireProbeApplet |
| 13 | +from ... import * |
| 14 | + |
| 15 | + |
| 16 | +class MSP430DebugError(GlasgowAppletError): |
| 17 | + pass |
| 18 | + |
| 19 | + |
| 20 | +class MSP430FamilyDebugInterface(aobject, metaclass=ABCMeta): |
| 21 | + async def __init__(self, interface, logger): |
| 22 | + self.lower = interface |
| 23 | + self._logger = logger |
| 24 | + self._level = logging.DEBUG if self._logger.name == __name__ else logging.TRACE |
| 25 | + |
| 26 | + def _log(self, message, *args): |
| 27 | + self._logger.log(self._level, "MSP430: " + message, *args) |
| 28 | + |
| 29 | + @abstractmethod |
| 30 | + async def attach(self): |
| 31 | + pass |
| 32 | + |
| 33 | + |
| 34 | +class MSP430DebugInterface(MSP430FamilyDebugInterface): |
| 35 | + async def attach(self): |
| 36 | + self._log("attach") |
| 37 | + await self.lower.write_ir(IR_CNTRL_SIG_16BIT) |
| 38 | + await self.lower.write_dr(DR_CNTRL_SIG_124(R_W=1, TAGFUNCSAT=1, TCE1=1).to_bits()) |
| 39 | + await self.lower.write_ir(IR_CNTRL_SIG_CAPTURE) |
| 40 | + cntrl_sig = DR_CNTRL_SIG_124.from_bits(await self.lower.read_dr(16)) |
| 41 | + if not cntrl_sig.TCE: |
| 42 | + raise MSP430DebugError("cannot attach: CNTRL_SIG {}" |
| 43 | + .format(cntrl_sig.bits_repr(omit_zero=True))) |
| 44 | + |
| 45 | + |
| 46 | +class DebugMSP430AppletMixin: |
| 47 | + preview = True |
| 48 | + description = "" # nothing to add for now |
| 49 | + |
| 50 | + async def interact(self, device, args, msp430_iface): |
| 51 | + await msp430_iface.attach() |
| 52 | + |
| 53 | + |
| 54 | +class DebugMSP430JTAGApplet(DebugMSP430AppletMixin, JTAGProbeApplet, name="debug-msp430-jtag"): |
| 55 | + logger = logging.getLogger(__name__) |
| 56 | + help = "debug MSP430 processors via JTAG" |
| 57 | + description = """ |
| 58 | + Debug Texas Instruments MSP430 processors via the 4-wire JTAG interface. |
| 59 | + """ + DebugMSP430AppletMixin.description |
| 60 | + |
| 61 | + async def run(self, device, args): |
| 62 | + jtag_iface = await self.run_lower(DebugMSP430JTAGApplet, device, args) |
| 63 | + await jtag_iface.test_reset() |
| 64 | + return await MSP430DebugInterface(jtag_iface, self.logger) |
| 65 | + |
| 66 | + |
| 67 | +class DebugMSP430SBWApplet(DebugMSP430AppletMixin, SpyBiWireProbeApplet, name="debug-msp430-sbw"): |
| 68 | + logger = logging.getLogger(__name__) |
| 69 | + help = "debug MSP430 processors via Spy-Bi-Wire" |
| 70 | + description = """ |
| 71 | + Debug Texas Instruments MSP430 processors via the 2-wire Spy-Bi-Wire interface. |
| 72 | + """ + DebugMSP430AppletMixin.description |
| 73 | + |
| 74 | + async def run(self, device, args): |
| 75 | + jtag_iface = await self.run_lower(DebugMSP430SBWApplet, device, args) |
| 76 | + await jtag_iface.test_reset() |
| 77 | + return await MSP430DebugInterface(jtag_iface, self.logger) |
0 commit comments