Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/software/glasgow/applet/debug/msp430/__init__.py b/software/glasgow/applet/debug/msp430/__init__.py
- index 493dc9f..a123120 100644
- --- a/software/glasgow/applet/debug/msp430/__init__.py
- +++ b/software/glasgow/applet/debug/msp430/__init__.py
- @@ -41,6 +41,7 @@ import struct
- from ....support.aobject import *
- from ....support.bits import *
- from ....arch.msp430.jtag import *
- +from ....database.ti.msp430 import *
- from ...interface.jtag_probe import JTAGProbeApplet
- from ...interface.sbw_probe import SpyBiWireProbeApplet
- from ... import *
- @@ -57,6 +58,7 @@ class MSP430DebugInterface(aobject):
- self._level = logging.DEBUG if self._logger.name == __name__ else logging.TRACE
- self.jtag_id = None
- + self._dev = None
- self._family = None
- self.device_id = None
- self._core = None
- @@ -70,7 +72,7 @@ class MSP430DebugInterface(aobject):
- jtag_id_bits = await self.lower.read_ir(8)
- self.jtag_id = int(jtag_id_bits.reversed())
- - if self.jtag_id not in (0x89, 0x91, 0x98, 0x99):
- + if self.jtag_id not in devices_tree.keys():
- raise MSP430DebugError("unknown JTAG ID {:#04x}".format(self.jtag_id))
- self._log("found core with JTAG ID %#04x", self.jtag_id,
- level=logging.INFO)
- @@ -81,6 +83,31 @@ class MSP430DebugInterface(aobject):
- self._log("discover family=%s", self._family)
- # self._core will be set later, in target_stop().
- + async def _probe_device(self):
- + dev_id_addr = 0x0ff0 if self.jtag_id == 0x89 else 0x1a04
- + dev_id_data = await self.target_read_memory(dev_id_addr, 2)
- + dev_id = struct.unpack(">H", dev_id_data)[0]
- + self._log("discover device-id=%#06x at %#06x", dev_id, dev_id_addr)
- +
- + if dev_id not in devices_tree[self.jtag_id]:
- + raise MSP430DebugError("unknown Device ID {:#06x} with JTAG ID {:#04x}".format(dev_id, self.jtag_id))
- +
- + dev_list = devices_tree[self.jtag_id][dev_id]
- +
- + if (len(dev_list) == 1) and (None in dev_list):
- + self._dev = dev_list[None]
- + else:
- + ext_id = (await self.target_read_memory(0x0ffd, 1))[0]
- + if ext_id not in dev_list:
- + if None in dev_list:
- + self._dev = dev_list[None]
- + else:
- + raise MSP430DebugError("unknown Device ID {:#06x}:{:#04x} with JTAG ID {:#04x}".format(dev_id, ext_id, self.jtag_id))
- + else:
- + self._dev = dev_list[ext_id]
- +
- + self._log("probed device=%s (core=%s)", self._dev.device, self._dev.core)
- +
- @property
- def _DR_CNTRL_SIG(self):
- if self._family == "124":
- @@ -93,14 +120,14 @@ class MSP430DebugInterface(aobject):
- if self._family == "124":
- cntrl_sig = self._DR_CNTRL_SIG(R_W=1, TAGFUNCSAT=1, TCE1=1)
- elif self._family == "56":
- - raise NotImplementedError # FIXME
- + cntrl_sig = self._DR_CNTRL_SIG(R_W=1, TCE1=1)
- else:
- assert False
- for arg, value in kwargs.items():
- setattr(cntrl_sig, arg, value)
- cntrl_sig_bits = cntrl_sig.to_bits()
- - self._log("write CNTRL_SIG %s", cntrl_sig.bits_repr(omit_zero=True),
- - level=logging.TRACE)
- + self._log("write CNTRL_SIG %04x %s", cntrl_sig.to_int(), cntrl_sig.bits_repr(omit_zero=True),
- + level=logging.INFO)
- await self.lower.write_ir(IR_CNTRL_SIG_16BIT)
- await self.lower.write_dr(cntrl_sig_bits.reversed())
- @@ -108,8 +135,8 @@ class MSP430DebugInterface(aobject):
- 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("read CNTRL_SIG %s", cntrl_sig.bits_repr(omit_zero=True),
- - level=logging.TRACE)
- + self._log("read CNTRL_SIG %04x %s", cntrl_sig.to_int(), cntrl_sig.bits_repr(omit_zero=True),
- + level=logging.INFO)
- return cntrl_sig
- @property
- @@ -124,10 +151,18 @@ class MSP430DebugInterface(aobject):
- assert False
- async def _write_address_dr(self, address):
- - # FIXME: mangle address bits
- address_bits = bits(address & 0xfffff, self._address_width)
- + if self._address_width == 20:
- + address_bits = address_bits[16:20] + address_bits[0:16]
- await self.lower.write_dr(address_bits.reversed())
- + async def _read_address_dr(self):
- + address_bits = await self.lower.read_dr(self._address_width)
- + address_bits = address_bits.reversed()
- + if self._address_width == 20:
- + address_bits = address_bits[4:20] + address_bits[0:4]
- + return int(address_bits)
- +
- async def _write_data_dr(self, data):
- data_bits = bits(data & 0xffff, 16)
- await self.lower.write_dr(data_bits.reversed())
- @@ -210,12 +245,36 @@ class MSP430DebugInterface(aobject):
- await self._write_control(TCE1=1)
- elif self._family == "56":
- # Reference function: GetDevice_430Xv2
- - raise NotImplementedError # FIXME
- + await self._write_control(TCE1=1, CPUSUSP=1, RELEASE_LBYTE=1)
- else:
- assert False
- cntrl_sig = await self._read_control()
- if not cntrl_sig.TCE:
- raise MSP430DebugError("cannot stop target")
- + if self._family == "56":
- + await self.lower.set_tclk(0)
- + await self.lower.set_tclk(1)
- + await self.lower.write_ir(IR_CNTRL_SIG_16BIT)
- + await self._write_control(POR=1)
- + await self._write_control(POR=0)
- + for i in range(5):
- + await self.lower.set_tclk(0)
- + await self.lower.set_tclk(1)
- + await self._write_control(CPUSUSP=1)
- + await self.lower.set_tclk(0)
- + await self.lower.set_tclk(1)
- +
- + await self.lower.write_ir(IR_COREIP_ID)
- + core_ip = await self._read_data_dr()
- + await self.lower.write_ir(IR_DEVICE_ID)
- + addr = await self._read_address_dr()
- +
- + self._log("%#08x %#010x", core_ip, addr)
- +
- + for i in range(16):
- + device_id_bytes = await self.target_read_memory(addr, 16)
- +
- +# await self._probe_device()
- if self.device_id is None:
- # And now we can determine which specific device it is.
- if self._family == "124":
- @@ -290,7 +349,25 @@ class MSP430DebugInterface(aobject):
- await self._release_bus()
- elif self._family == "56":
- # Reference function: ReadMem_430Xv2
- - raise NotImplementedError # FIXME
- + await self.lower.set_tclk(0)
- + #await self._write_control(RELEASE_LBYTE=0, TCE1=1, CPUSUSP=1, R_W=1)
- + await self.lower.write_ir(IR_CNTRL_SIG_16BIT)
- + await self._write_data_dr(0x2409)
- +
- + offset = 0
- + while offset < length:
- + await self.lower.write_ir(IR_ADDR_16BIT)
- + await self._write_address_dr(address + offset)
- + await self.lower.write_ir(IR_DATA_TO_ADDR)
- + await self.lower.set_tclk(1)
- + await self.lower.set_tclk(0)
- + data_word = await self._read_data_dr()
- + self._log("read memory [%#07x]=%#06x", address + offset, data_word)
- + data += struct.pack("<H", data_word)
- + offset += 2
- + await self.lower.set_tclk(1)
- + await self.lower.set_tclk(0)
- + await self.lower.set_tclk(1)
- else:
- assert False
- return data
- @@ -328,6 +405,11 @@ class DebugMSP430AppletMixin:
- async def interact(self, device, args, msp430_iface):
- await msp430_iface.target_stop()
- + self.logger.info("attached to target %#06x", msp430_iface.device_id)
- +
- + x = await msp430_iface.target_read_memory(0xfc00, 1024)
- + #open('/tmp/dump.bin', 'wb').write(x)
- +
- await msp430_iface.target_detach(reset=True)
- diff --git a/software/glasgow/arch/msp430/jtag.py b/software/glasgow/arch/msp430/jtag.py
- index 4968b7c..070e37c 100644
- --- a/software/glasgow/arch/msp430/jtag.py
- +++ b/software/glasgow/arch/msp430/jtag.py
- @@ -7,9 +7,10 @@ from ...support.bitstruct import *
- __all__ = [
- # IR
- - "IR_ADDR_16BIT", "IR_ADDR_CAPTURE", "IR_DATA_TO_ADDR", "IR_DATA_16BIT", "IR_DATA_QUICK",
- - "IR_BYPASS", "IR_CNTRL_SIG_16BIT", "IR_CNTRL_SIG_CAPTURE", "IR_CNTRL_SIG_RELEASE",
- - "IR_DATA_PSA", "IR_SHIFT_OUT_PSA", "IR_PREPARE_BLOW", "IR_EX_BLOW", "IR_JMB_EXCHANGE",
- + "IR_ADDR_16BIT", "IR_ADDR_CAPTURE", "IR_DATA_TO_ADDR", "IR_DATA_16BIT", "IR_DATA_CAPTURE",
- + "IR_DATA_QUICK", "IR_BYPASS", "IR_CNTRL_SIG_16BIT", "IR_CNTRL_SIG_CAPTURE",
- + "IR_CNTRL_SIG_RELEASE", "IR_DATA_PSA", "IR_SHIFT_OUT_PSA", "IR_PREPARE_BLOW", "IR_EX_BLOW",
- + "IR_JMB_EXCHANGE", "IR_COREIP_ID", "IR_DEVICE_ID",
- # DR
- "DR_CNTRL_SIG_124", "DR_CNTRL_SIG_56",
- ]
- @@ -23,6 +24,7 @@ IR_ADDR_CAPTURE = bits(0x84, 8)
- # Controlling the Memory Data Bus (MDB)
- IR_DATA_TO_ADDR = bits(0x85, 8)
- IR_DATA_16BIT = bits(0x41, 8)
- +IR_DATA_CAPTURE = bits(0x42, 8)
- IR_DATA_QUICK = bits(0x43, 8)
- IR_BYPASS = bits(0xFF, 8)
- # Controlling the CPU
- @@ -37,6 +39,9 @@ IR_PREPARE_BLOW = bits(0x22, 8)
- IR_EX_BLOW = bits(0x24, 8)
- # JTAG Mailbox System
- IR_JMB_EXCHANGE = bits(0x61, 8)
- +# Misc
- +IR_COREIP_ID = bits(0x17, 8)
- +IR_DEVICE_ID = bits(0x87, 8)
- # CNTRL_SIG DR layout
- diff --git a/software/glasgow/database/ti/msp430.py b/software/glasgow/database/ti/msp430.py
- index 1121d58..6ee3258 100644
- --- a/software/glasgow/database/ti/msp430.py
- +++ b/software/glasgow/database/ti/msp430.py
- @@ -459,3 +459,13 @@ devices_tree = {}
- for dev in devices:
- devices_tree.setdefault(dev.jtag_id, {}).setdefault(dev.device_id, {})[dev.ext_id] = dev
- +
- +# Dummy devices when all we have is the JTAG ID
- +#devices_dummy = {
- +# 0x89: MSP430Device('Generic MSP430/MSP430X', 0x89, 0xffff, None, core='430', type='flash', features=[]),
- +# # We default to FRAM for 0x91 because even if the device is flash, the couple extra steps used for
- +# # FRAM won't hurt (at least for the process used before the actual device ID can be read)
- +# 0x91: MSP430Device('Generic MSP430Xv2', 0x91, 0xffff, None, core='430Xv2', type='fram', features=[]),
- +# 0x98: MSP430Device('Generic MSP430Xv2', 0x91, 0xffff, None, core='430Xv2', type='fram', features=[]),
- +# 0x99: MSP430Device('Generic MSP430Xv2', 0x91, 0xffff, None, core='430Xv2', type='fram', features=[]),
- +#}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement