Пример #1
0
    def connect_to_tool(self, toolconnection):
        """
        Connect to a tool

        The tool can either be a USB HID tool or a serial port.

        :param ToolConnection: This is an instance of one of the ToolConnection sub-classes.  This object wraps
            parameters needed to identify which tool to connect to like tool name and USB serial or serial port
            name (e.g. 'COM1').

            For USB HID tools there are some special handling:

            * If both tool name and usb_serial are None any tool will be picked.
            * If usb_serial is None any tool matching the tool name will be picked
            * If tool name is None any tool matching the usb_serial will be picked
            * If more than one tool is connected that matches the tool name and usb_serial parameters a
                PymcuprogToolConnectionError exception will be raised.

        :raises PymcuprogToolConnectionError: if more than one matching tool is found or if no matching tool is found
        :raises PymcuprogToolConfigurationError: if the toolconnection configuration is incorrect
        """
        if isinstance(toolconnection, ToolSerialConnection):
            # For serial port connection no connection action is needed, just need to store the
            # Serial port number to be used (e.g. 'COM1')
            self.transport = toolconnection.serialport
        elif isinstance(toolconnection, ToolUsbHidConnection):
            self.transport = hid_transport()
            connect_status = False
            try:
                connect_status = self.transport.connect(
                    serial_number=toolconnection.serialnumber,
                    product=toolconnection.tool_name)
            except IOError as error:
                raise PymcuprogToolConnectionError(
                    "Unable to connect to USB device ({})".format(error))

            if not connect_status:
                raise PymcuprogToolConnectionError(
                    "Unable to connect to USB device")

            self.housekeeper = housekeepingprotocol.Jtagice3HousekeepingProtocol(
                self.transport)
            self.housekeeper.start_session()

        else:
            raise PymcuprogToolConfigurationError(
                "Unknown toolconnection argument type: {})".format(
                    type(toolconnection)))

        self.connected_to_tool = True
Пример #2
0
 def __init__(self, DeviceName):
     # Make a connection
     self.transport = hid_transport()
     self.transport.disconnect()
     # Connect
     self.transport.connect()
     self.deviceInf = deviceinfo.getdeviceinfo(DeviceName)
     self.memoryinfo = deviceinfo.DeviceMemoryInfo(self.deviceInf)
     self.housekeeper = housekeepingprotocol.Jtagice3HousekeepingProtocol(
         self.transport)
     self.housekeeper.start_session()
     self.device = NvmAccessProviderCmsisDapUpdi(self.transport,
                                                 self.deviceInf)
     #self.device.avr.deactivate_physical()
     self.device.avr.activate_physical()
     # Start debug by attaching (live)
     self.device.avr.protocol.attach()
Пример #3
0
    def get_available_hid_tools(serialnumber_substring='', tool_name=None):
        """
        Return a list of Microchip USB HID tools (debuggers) connected to the host

        :param serialnumber_substring: can be an empty string or a subset of a serial number. Not case sensitive
            This function will do matching of the last part of the devices serial numbers to
            the serialnumber_substring. Examples:
            '123' will match "MCHP3252000000043123" but not "MCP32520001230000000"
            '' will match any serial number
        :param tool_name: tool type to connect to. If None any tool matching the serialnumber_substring
            will be returned
        :returns: List of pyedbglib.hidtransport.hidtransportbase.HidTool objects
        """
        # Just use a temporary transport as the request is only to report connected Microchip HID tools,
        # not to connect to any of them
        transport = hid_transport()

        return transport.get_matching_tools(serialnumber_substring, tool_name)
Пример #4
0
"""
Demonstrates reading and writing the SUFFER bits on mEDBG (Xplained Mini kits)

"""
from pyedbglib.hidtransport.hidtransportfactory import hid_transport
from pyedbglib.protocols import medbgprotocol

# Create and connect to transport
transport = hid_transport()
if not transport.connect(product="medbg"):
    raise Exception("mEDBG not found!")

# Create protocol with this transport
medbg = medbgprotocol.mEdbgProtocol(transport)

# Read out suffer
suffer = medbg.read_config(
    medbgprotocol.mEdbgProtocol.CONFIG_REG_SUFFER_BANK,
    medbgprotocol.mEdbgProtocol.CONFIG_REG_SUFFER_OFFSET, 1)[1][0]
print("SUFFER read as 0x{:02X}".format(suffer))

# Modify and write back
suffer = 0xFF
print("Writing SUFFER to 0x{:02X}".format(suffer))
status = medbg.write_config(
    medbgprotocol.mEdbgProtocol.CONFIG_REG_SUFFER_BANK,
    medbgprotocol.mEdbgProtocol.CONFIG_REG_SUFFER_OFFSET, bytearray([suffer]))

# Read out again
suffer = medbg.read_config(
    medbgprotocol.mEdbgProtocol.CONFIG_REG_SUFFER_BANK,