Esempio n. 1
0
    def test_read_device_id_returns_bytearray_with_raw_id(self):
        # Expected SIB+ID must match mega4809
        atmega4809_sib = array('B', map(ord,
                                        "megaAVR P:0D:1-3M2 (01.59B20.0)"))
        id_expected = bytearray([0x1E, 0x96, 0x51])
        id_expected.reverse()

        mock_tinyxavrtarget_instance = self._mock_tinyxavrtarget()
        # ID is BE24 from the target
        mock_tinyxavrtarget_instance.memory_read.return_value = bytearray(
            [id_expected[2], id_expected[1], id_expected[0]])
        mock_tinyxavrtarget_instance.sib_read.return_value = atmega4809_sib

        dinfo = deviceinfo.getdeviceinfo('atmega4809')

        updi = NvmAccessProviderCmsisDapUpdi(None, dinfo)

        id_read = updi.read_device_id()

        # Check normal path
        self.assertEqual(id_expected, id_read)

        # Check that an exception is raised on unexpected ID
        mock_tinyxavrtarget_instance.memory_read.return_value = bytearray(
            [0, 0, 0])
        with self.assertRaises(PymcuprogSessionError):
            id_read = updi.read_device_id()
Esempio n. 2
0
    def test_release_from_reset_leaves_progmode(self):
        mock_tinyxavrtarget = self._mock_tinyxavrtarget()

        dinfo = deviceinfo.getdeviceinfo('atmega4809')
        updi = NvmAccessProviderCmsisDapUpdi(None, dinfo)
        updi.release_from_reset()

        mock_tinyxavrtarget.leave_progmode.assert_called()
Esempio n. 3
0
    def test_hold_in_reset_does_nothing(self):
        mock_tinyxavrtarget = self._mock_tinyxavrtarget()

        dinfo = deviceinfo.getdeviceinfo('atmega4809')
        updi = NvmAccessProviderCmsisDapUpdi(None, dinfo)
        updi.hold_in_reset()

        mock_tinyxavrtarget.hold_in_reset.assert_not_called()
Esempio n. 4
0
    def test_release_from_reset_leaves_progmode(self):
        mock_updiapplication = self._mock_updiapplication()

        dinfo = deviceinfo.getdeviceinfo('atmega4809')
        serial = NvmAccessProviderSerial(None, dinfo, None)
        serial.release_from_reset()

        mock_updiapplication.leave_progmode.assert_called()
Esempio n. 5
0
    def test_hold_in_reset_does_nothing(self):
        mock_updiapplication = self._mock_updiapplication()

        dinfo = deviceinfo.getdeviceinfo('atmega4809')
        serial = NvmAccessProviderSerial(None, dinfo, None)
        serial.hold_in_reset()

        mock_updiapplication.hold_in_reset.assert_not_called()
Esempio n. 6
0
    def test_read_all_reads_all_memories(self):
        # Pick any offset, but do not use 0 to check that the offset is ignored
        offset = 0x1000
        # Pick any number of bytes to check that numbytes is ignored
        numbytes = 256
        # Just pick any device with more than one memory segment
        device = 'atmega4809'

        device_info = deviceinfo.getdeviceinfo(device)
        device_meminfo = deviceinfo.DeviceMemoryInfo(device_info)

        mock_nvmaccessprovider = self._mock_nvmaccessprovider()
        mock_nvmaccessprovider.read.side_effect = self._read_memory_stub

        self.programmer.load_device(device)
        self.programmer.setup_device()
        memory_read_list = self.programmer.read_memory(
            memory_name=MemoryNameAliases.ALL,
            offset=offset,
            numbytes=numbytes)

        memories = device_meminfo.mem_by_name.keys()
        read_calls = []
        for memory_name_expected in memories:
            meminfo_expected = device_meminfo.memory_info_by_name(
                memory_name_expected)

            found_memory = False
            for memory_read_tuple in memory_read_list:
                if memory_read_tuple.memory_info[
                        DeviceMemoryInfoKeys.NAME] == memory_name_expected:
                    data_expected = self._generate_dummydata(
                        meminfo_expected[DeviceMemoryInfoKeys.SIZE])
                    found_memory = True
                    data_read = memory_read_tuple.data
                    meminfo_read = memory_read_tuple.memory_info

                    self.assertEqual(data_read, data_expected)
                    self.assertEqual(meminfo_read, meminfo_expected)
                    read_calls.append(
                        call.read(meminfo_expected, 0,
                                  meminfo_expected[DeviceMemoryInfoKeys.SIZE]))

            self.assertTrue(
                found_memory,
                msg="Did not find {} memory in returned data".format(
                    memory_name_expected))

        mock_nvmaccessprovider.assert_has_calls(read_calls)
Esempio n. 7
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()
Esempio n. 8
0
    def test_read_device_id_returns_bytearray_with_raw_id(self):
        atmega4809_sib = array('B', map(ord,
                                        "megaAVR P:0D:1-3M2 (01.59B20.0)"))

        id_expected = bytearray([0x01, 0x02, 0x03])
        mock_tinyxavrtarget_instance = self._mock_tinyxavrtarget()
        mock_tinyxavrtarget_instance.memory_read.return_value = bytearray(
            [id_expected[2], id_expected[1], id_expected[0]])
        mock_tinyxavrtarget_instance.sib_read.return_value = atmega4809_sib

        dinfo = deviceinfo.getdeviceinfo('atmega4809')

        updi = NvmAccessProviderCmsisDapUpdi(None, dinfo)

        id_read = updi.read_device_id()

        self.assertEqual(id_expected, id_read)
Esempio n. 9
0
    def test_read_device_id_returns_bytearray_with_raw_id(self):
        # Expected ID must match mega4809 as BE24
        id_expected = bytearray([0x1E, 0x96, 0x51])
        id_expected.reverse()

        mock_updiapplication_instance = self._mock_updiapplication()
        mock_updiapplication_instance.read_data.return_value = bytearray(
            [id_expected[2], id_expected[1], id_expected[0]])

        dinfo = deviceinfo.getdeviceinfo('atmega4809')

        serial = NvmAccessProviderSerial(None, dinfo, None)

        id_read = serial.read_device_id()

        # Check normal path
        self.assertEqual(id_expected, id_read)

        # Check that an exception is raised on unexpected ID
        mock_updiapplication_instance.read_data.return_value = bytearray(
            [0, 0, 0])

        with self.assertRaises(PymcuprogSessionError):
            id_read = serial.read_device_id()
 def setUp(self):
     # pylint does not understand the trick done by parameterized which injects the devicename at runtime
     #pylint: disable=no-member
     self.deviceinfo = getdeviceinfo(self.devicename)
Esempio n. 11
0
 def _get_memory_info(device, memory_name):
     device_info = deviceinfo.getdeviceinfo(device)
     device_meminfo = deviceinfo.DeviceMemoryInfo(device_info)
     return device_meminfo.memory_info_by_name(memory_name)