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

target_kinetis.py AttributeError: 'AccessPort' object has no attribute 'read32' #1015

Closed Hoohaha closed 3 years ago

Hoohaha commented 3 years ago

Hi @flit ,

I met a strange problem on kl28z target. Sometimes there occur exception in target\family\target_kinetis.py: AttributeError: 'AccessPort' object has no attribute 'read32', I know it is hardware issue, but how to make it do not display AttributeError.

Thanks.

Full logs:

0000250:WARNING:common:STLink and CMSIS-DAPv2 probes are not supported because no libusb library was found.
0000250:INFO:board:Target type is kl28z
0000254:INFO:coresight_target:Asserting reset prior to connect
0000269:INFO:dap:DP IDR = 0x2ba01477 (v1 rev2)
0005276:INFO:ap:AP#0 IDR = 0x02000000 (AP var0 rev0)
0005276:INFO:ap:AP#1 IDR = 0x02000000 (AP var0 rev0)
0005276:INFO:ap:AP#2 IDR = 0x02000000 (AP var0 rev0)
0005276:ERROR:target_kinetis:KL28x: bad MDM-AP IDR (is 0x02000000)
0015286:CRITICAL:__main__:uncaught exception: 'AccessPort' object has no attribute 'read32'
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\pyocd\__main__.py", line 398, in run
    self._COMMANDS[self._args.cmd](self)
  File "C:\Python27\lib\site-packages\pyocd\__main__.py", line 742, in do_gdbserver
    with session:
  File "C:\Python27\lib\site-packages\pyocd\core\session.py", line 343, in __enter__
    self.open()
  File "C:\Python27\lib\site-packages\pyocd\core\session.py", line 461, in open
    self._board.init()
  File "C:\Python27\lib\site-packages\pyocd\board\board.py", line 85, in init
    self.target.init()
  File "C:\Python27\lib\site-packages\pyocd\core\soc_target.py", line 120, in init
    seq.invoke()
  File "C:\Python27\lib\site-packages\pyocd\utility\sequencer.py", line 213, in invoke
    resultSequence.invoke()
  File "C:\Python27\lib\site-packages\pyocd\utility\sequencer.py", line 208, in invoke
    resultSequence = call()
  File "C:\Python27\lib\site-packages\pyocd\target\family\target_kinetis.py", line 121, in check_flash_security
    self.aps[0].read32(CortexM.DHCSR)
AttributeError: 'AccessPort' object has no attribute 'read32'
flit commented 3 years ago

Hi @Hoohaha. This is a strange error! For some reason I don't recall seeing anything like this when I was working on the KL28 after we got the silicon back.

The AttributeError exception is caused because the code in check_flash_security() attempts to use AP#0 as a MEM_AP object. It calls the read32() method that doesn't exist because AP#0 is not detected as an AHB-AP due to the invalid IDR value.

The simple way to avoid the exception is to add a test in check_flash_security() for isinstance(self.aps[0], MEM_AP). But that just avoids the exception, and you'll end up with a "no cores found" error. If there is a way to recover, we could add another init task that checks for this problem and recovers.

Some questions for you:

Anything else you know about the issue would be helpful. (We can chat by email if you want.)