pyocd / pyOCD

Open source Python library for programming and debugging Arm Cortex-M microcontrollers
https://pyocd.io
Apache License 2.0
1.11k stars 477 forks source link

LPC5526 - Memory Transfer Fault #1136

Closed stephendpmurphy closed 3 years ago

stephendpmurphy commented 3 years ago

Hi all,

I am getting a repeated issue when attempting to flash a blank LPC5526 using pyocd. It always results in a Memory Transfer Fault. This issue persists when using a custom DAP-Link programmer as well as a JLink Plus.

The only way to get the device usable is to use the JLinkExe utility with my JLink Plus to program the part. Once the part is programmed, I can then use PyOCD and any of my probes to flash and debug the part. The issue comes back as soon as I erase the part again.

@flit I know when working with you recently on the LPC55S69 and DAP-Link there were noted issues with programming the part in which I was ALSO able to get around by using the full Segger suite. Is this related/still a known issue?

$ pyocd --version
0.30.3
$ pyocd flash -vvv -t lpc5526 debug/LPC5526/uMeasurement.hex

Error output:

0000382:DEBUG:pyusb_backend:[Errno 13] Access denied (insufficient permissions) while trying to interrogate a USB device (VID=1532 PID=0233). This can probably be remedied with a udev rule. See <https://github.com/pyocd/pyOCD/tree/master/udev> for help.
0000382:DEBUG:pyusb_backend:[Errno 13] Access denied (insufficient permissions) while trying to interrogate a USB device (VID=1bcf PID=2c9a). This can probably be remedied with a udev rule. See <https://github.com/pyocd/pyOCD/tree/master/udev> for help.
0000384:DEBUG:pyusb_backend:[Errno 13] Access denied (insufficient permissions) while trying to interrogate a USB device (VID=0bda PID=48f0). This can probably be remedied with a udev rule. See <https://github.com/pyocd/pyOCD/tree/master/udev> for help.
0000384:DEBUG:pyusb_backend:[Errno 13] Access denied (insufficient permissions) while trying to interrogate a USB device (VID=046d PID=c341). This can probably be remedied with a udev rule. See <https://github.com/pyocd/pyOCD/tree/master/udev> for help.
0000384:DEBUG:pyusb_backend:[Errno 13] Access denied (insufficient permissions) while trying to interrogate a USB device (VID=046d PID=c08b). This can probably be remedied with a udev rule. See <https://github.com/pyocd/pyOCD/tree/master/udev> for help.
0000384:DEBUG:pyusb_v2_backend:[Errno 13] Access denied (insufficient permissions) while trying to interrogate a USB device (VID=1532 PID=0233). This can probably be remedied with a udev rule. See <https://github.com/pyocd/pyOCD/tree/master/udev> for help.
0000384:DEBUG:pyusb_v2_backend:[Errno 13] Access denied (insufficient permissions) while trying to interrogate a USB device (VID=1bcf PID=2c9a). This can probably be remedied with a udev rule. See <https://github.com/pyocd/pyOCD/tree/master/udev> for help.
0000387:DEBUG:pyusb_v2_backend:[Errno 13] Access denied (insufficient permissions) while trying to interrogate a USB device (VID=0bda PID=48f0). This can probably be remedied with a udev rule. See <https://github.com/pyocd/pyOCD/tree/master/udev> for help.
0000387:DEBUG:pyusb_v2_backend:[Errno 13] Access denied (insufficient permissions) while trying to interrogate a USB device (VID=046d PID=c341). This can probably be remedied with a udev rule. See <https://github.com/pyocd/pyOCD/tree/master/udev> for help.
0000387:DEBUG:pyusb_v2_backend:[Errno 13] Access denied (insufficient permissions) while trying to interrogate a USB device (VID=046d PID=c08b). This can probably be remedied with a udev rule. See <https://github.com/pyocd/pyOCD/tree/master/udev> for help.
0000689:DEBUG:pemicro:Opened PEMicro library: /home/stephen/.local/lib/python3.6/site-packages/pypemicro/libs/Linux/unitacmp-64.so
0000744:DEBUG:session:Project directory: /home/stephen/git/glasslabs/gl-umeasurement-firmware/armgcc
0000925:INFO:board:Target type is lpc5526
0000934:DEBUG:dap_access_cmsis_dap:CMSIS-DAP probe 00000080066bff535654868367111915a5a5a5a597969908 protocol version: 2.0.0
0000935:DEBUG:sequencer:Running task load_svd
0001018:DEBUG:sequencer:Running task pre_connect
0001018:DEBUG:sequencer:Running task dp_init
0001023:DEBUG:sequencer:Running task lock_probe
0001023:DEBUG:sequencer:Running task get_probe_capabilities
0001029:DEBUG:sequencer:Running task connect
0001105:DEBUG:dap:Default wire protocol selected; using SWD
0001106:DEBUG:swj:Sending deprecated SWJ sequence to select SWD
0001107:INFO:dap:DP IDR = 0x6ba02477 (v2 rev6)
0001107:DEBUG:sequencer:Running task clear_sticky_err
0001107:DEBUG:sequencer:Running task power_up_debug
0001108:DEBUG:sequencer:Running task check_version
0001108:DEBUG:sequencer:Running task unlock_probe
0001108:DEBUG:sequencer:Running task create_discoverer
0001108:DEBUG:sequencer:Running task discovery
0001108:DEBUG:sequencer:Running task set_max_invalid_aps
0001108:DEBUG:sequencer:Running task find_aps
0001112:DEBUG:sequencer:Running task create_aps
0001112:DEBUG:sequencer:Running task create_ap.0
0001113:INFO:ap:AHB-AP#0 IDR = 0x84770001 (AHB-AP var0 rev8)
0001114:DEBUG:ap:AHB-AP#0 default HPROT=3 HNONSEC=0
0001115:DEBUG:ap:AHB-AP#0 implemented HPROT=f HNONSEC=1
0001116:DEBUG:sequencer:Running task create_ap.2
0001117:INFO:ap:AP#2 IDR = 0x002a0000 (AP var0 rev0)
0001117:DEBUG:sequencer:Running task check_locked_state
0001118:DEBUG:sequencer:Running task find_components
0001118:DEBUG:sequencer:Running task init_ap.0
0001123:INFO:rom_table:AHB-AP#0 Class 0x1 ROM table #0 @ 0xe00fe000 (designer=015 part=000)
0001128:INFO:rom_table:[0]<e00ff000:ROM class=1 designer=43b part=4c9>
0001128:INFO:rom_table:  AHB-AP#0 Class 0x1 ROM table #1 @ 0xe00ff000 (designer=43b part=4c9)
0001133:INFO:rom_table:  [0]<e000e000:SCS-M33 class=9 designer=43b part=d21 devtype=00 archid=2a04 devid=0:0:0>
0001136:INFO:rom_table:  [1]<e0001000:DWT-M33 class=9 designer=43b part=d21 devtype=00 archid=1a02 devid=0:0:0>
0001139:INFO:rom_table:  [2]<e0002000:BPU-M33 class=9 designer=43b part=d21 devtype=00 archid=1a03 devid=0:0:0>
0001142:INFO:rom_table:  [3]<e0000000:ITM-M33 class=9 designer=43b part=d21 devtype=43 archid=1a01 devid=0:0:0>
0001145:INFO:rom_table:[1]<e0040000:TPIU-M33 class=9 designer=43b part=d21 devtype=11 archid=0000 devid=ca0:0:0>
0001145:DEBUG:sequencer:Running task create_cores
0001148:INFO:cortex_m_v8m:CPU core #0 is Cortex-M33 r0p3
0001151:INFO:cortex_m:FPU present: FPv5-SP-D16-M
0001152:DEBUG:sequencer:Running task set_default_reset_type
0001152:DEBUG:sequencer:Running task enable_traceclk
0001154:DEBUG:sequencer:Running task create_components
0001154:DEBUG:discovery:Creating DWT-M33 component
0001156:INFO:dwt:4 hardware watchpoints
0001157:DEBUG:discovery:Creating BPU-M33 component
0001159:INFO:fpb:8 hardware breakpoints, 1 literal comparators
0001159:DEBUG:fpb:fpb has been disabled
0001159:DEBUG:discovery:Creating ITM-M33 component
0001163:DEBUG:discovery:Creating TPIU-M33 component
0001164:DEBUG:sequencer:Running task restore_max_invalid_aps
0001164:DEBUG:sequencer:Running task check_for_cores
0001164:DEBUG:sequencer:Running task halt_on_connect
0001164:DEBUG:cortex_m:halting core 0
0001165:DEBUG:sequencer:Running task post_connect
0001165:DEBUG:sequencer:Running task post_connect_hook
0001165:DEBUG:sequencer:Running task create_flash
0001165:DEBUG:sequencer:Running task notify
0001182:DEBUG:cortex_m:halting core 0
0001187:INFO:target_lpc5500:required flash area is erased
0001191:DEBUG:cortex_m:halting core 0
0001260:DEBUG:cortex_m:resuming core 0
0001260:DEBUG:manager:added=[] removed=[]
0001260:DEBUG:manager:bps after flush={}
0001265:DEBUG:session:uninit session <pyocd.core.session.Session object at 0x7fa28cf8cf28>
0001265:DEBUG:board:uninit board <pyocd.board.mbed_board.MbedBoard object at 0x7fa2927573c8>
0001267:DEBUG:cortex_m:resuming core 0
0001267:DEBUG:manager:added=[] removed=[]
0001267:DEBUG:manager:bps after flush={}
0001269:CRITICAL:__main__:Memory transfer fault @ 0x00000130-0x000001ff
Traceback (most recent call last):
  File "/home/stephen/.local/lib/python3.6/site-packages/pyocd/probe/cmsis_dap_probe.py", line 401, in read_ap_repeat_callback
    values = result()
  File "/home/stephen/.local/lib/python3.6/site-packages/pyocd/probe/pydapaccess/dap_access_cmsis_dap.py", line 934, in reg_read_repeat_cb
    res = transfer.get_result()
  File "/home/stephen/.local/lib/python3.6/site-packages/pyocd/probe/pydapaccess/dap_access_cmsis_dap.py", line 144, in get_result
    self.daplink._read_packet()
  File "/home/stephen/.local/lib/python3.6/site-packages/pyocd/utility/concurrency.py", line 28, in _locking
    return func(self, *args, **kwargs)
  File "/home/stephen/.local/lib/python3.6/site-packages/pyocd/probe/pydapaccess/dap_access_cmsis_dap.py", line 978, in _read_packet
    decoded_data = cmd.decode_data(raw_data)
  File "/home/stephen/.local/lib/python3.6/site-packages/pyocd/probe/pydapaccess/dap_access_cmsis_dap.py", line 455, in decode_data
    data = self._decode_transfer_data(data)
  File "/home/stephen/.local/lib/python3.6/site-packages/pyocd/probe/pydapaccess/dap_access_cmsis_dap.py", line 362, in _decode_transfer_data
    self._check_response(data[2])
  File "/home/stephen/.local/lib/python3.6/site-packages/pyocd/probe/pydapaccess/dap_access_cmsis_dap.py", line 341, in _check_response
    raise DAPAccessIntf.TransferFaultError()
pyocd.probe.pydapaccess.dap_access_api.DAPAccessIntf.TransferFaultError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/stephen/.local/lib/python3.6/site-packages/pyocd/__main__.py", line 402, in run
    self._COMMANDS[self._args.cmd](self)
  File "/home/stephen/.local/lib/python3.6/site-packages/pyocd/__main__.py", line 579, in do_flash
    file_format=self._args.format)
  File "/home/stephen/.local/lib/python3.6/site-packages/pyocd/flash/file_programmer.py", line 157, in program
    self._loader.commit()
  File "/home/stephen/.local/lib/python3.6/site-packages/pyocd/flash/loader.py", line 168, in commit
    keep_unwritten=self._keep_unwritten)
  File "/home/stephen/.local/lib/python3.6/site-packages/pyocd/flash/builder.py", line 421, in program
    self._build_sectors_and_pages(keep_unwritten)
  File "/home/stephen/.local/lib/python3.6/site-packages/pyocd/flash/builder.py", line 286, in _build_sectors_and_pages
    fill_end_of_page_gap()
  File "/home/stephen/.local/lib/python3.6/site-packages/pyocd/flash/builder.py", line 264, in fill_end_of_page_gap
    old_data = self.flash.target.read_memory_block8(page_data_end, old_data_len)
  File "/home/stephen/.local/lib/python3.6/site-packages/pyocd/core/soc_target.py", line 167, in read_memory_block8
    return self.selected_core.read_memory_block8(addr, size)
  File "/home/stephen/.local/lib/python3.6/site-packages/pyocd/coresight/cortex_m.py", line 451, in read_memory_block8
    data = self.ap.read_memory_block8(addr, size)
  File "/home/stephen/.local/lib/python3.6/site-packages/pyocd/core/memory_interface.py", line 97, in read_memory_block8
    mem = self.read_memory_block32(addr, size // 4)
  File "/home/stephen/.local/lib/python3.6/site-packages/pyocd/utility/concurrency.py", line 28, in _locking
    return func(self, *args, **kwargs)
  File "/home/stephen/.local/lib/python3.6/site-packages/pyocd/coresight/ap.py", line 1083, in _read_memory_block32
    resp += self._read_block32_page(addr, n//4)
  File "/home/stephen/.local/lib/python3.6/site-packages/pyocd/coresight/ap.py", line 1041, in _read_block32_page
    resp = self.dp.read_ap_multiple(self.address.address + self._reg_offset + MEM_AP_DRW, size)
  File "/home/stephen/.local/lib/python3.6/site-packages/pyocd/coresight/dap.py", line 788, in read_ap_multiple
    return read_ap_multiple_cb()
  File "/home/stephen/.local/lib/python3.6/site-packages/pyocd/coresight/dap.py", line 778, in read_ap_multiple_cb
    return result_cb()
  File "/home/stephen/.local/lib/python3.6/site-packages/pyocd/probe/cmsis_dap_probe.py", line 408, in read_ap_repeat_callback
    six.raise_from(self._convert_exception(exc), exc)
  File "<string>", line 3, in raise_from
pyocd.core.exceptions.TransferFaultError: Memory transfer fault @ 0x00000130-0x000001ff
stephendpmurphy commented 3 years ago

I should add that executing an erase command on the part ALWAYS works, regardless of the current ability to flash the part.

stephendpmurphy commented 3 years ago

So I have some more info to report back. I am also debugging and building the same source for the LPC55S28 which is the micro used when purchasing an LPC55xx dev kit.. I am able to flash and erase the dev kit no problem using my same DAPLink probe with PyOCD.

So after some digging I noticed that the LPC55S28 is shipped with PyOCD and the target_lpc55s28.py includes the target_lpc5500.py file which had a comment that seems very suspicious and likely my problem.

https://github.com/pyocd/pyOCD/blob/5a835e1017182975a11a4caddd83332f74b75fa4/pyocd/target/family/target_lpc5500.py#L286

Is the suggested fix for getting LPC5526 support in PyOCD to add the target as a buit-in then?

stephendpmurphy commented 3 years ago

Just finished adding a built-in target for the LPC5526 and this appears to have cleared up my issues. I can now flash, erase and debug no problem :+1: