pyocd / pyOCD

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

I encountered an issue while using pyOCD with a Cortex-M33 microcontroller. The error occurs during the session initialization and seems to be related to the AP (Access Port) address. #1637

Open enzheng128 opened 1 year ago

enzheng128 commented 1 year ago

Error Log

0000542 D Project directory: d:\code [session]
0000573 D Project directory: d:\code [session]
0000608 D CMSIS-DAP v2 probe 000100011a5a5bb6000000000001badfa5a5a5a597969908: firmware version 0258, protocol version 2.1.0 [dap_access_cmsis_dap]
0000609 W Board ID 0001 is not recognized [mbed_board]
0000611 D GeckoPlatform_EFR32BG22_DFP DFP: skipping non-Keil flash algorithm [cmsis_pack]
0000611 D GeckoPlatform_EFR32BG22_DFP DFP: skipping non-Keil flash algorithm [cmsis_pack]
0000611 D GeckoPlatform_EFR32BG22_DFP DFP: skipping non-Keil flash algorithm [cmsis_pack]
0000611 D GeckoPlatform_EFR32BG22_DFP DFP: skipping non-Keil flash algorithm [cmsis_pack]
0000611 D GeckoPlatform_EFR32BG22_DFP DFP: skipping non-Keil flash algorithm [cmsis_pack]
0000611 D GeckoPlatform_EFR32BG22_DFP DFP: skipping non-Keil flash algorithm [cmsis_pack]
0000611 D GeckoPlatform_EFR32BG22_DFP DFP: skipping non-Keil flash algorithm [cmsis_pack]
0000611 D GeckoPlatform_EFR32BG22_DFP DFP: skipping non-Keil flash algorithm [cmsis_pack]
0000611 D GeckoPlatform_EFR32BG22_DFP DFP: skipping non-Keil flash algorithm [cmsis_pack]
0000611 D GeckoPlatform_EFR32BG22_DFP DFP: skipping non-Keil flash algorithm [cmsis_pack]
0000618 I Target type is efr32bg22c224f512gm32 [board]
0000639 D Board: LuatOS Air32 MINI DAPLink [cmsis_dap_probe]
0000639 D Target: LuatOS Air32F103CB [cmsis_dap_probe]
0000639 D Running task load_svd [sequencer]
0000705 D Running task pre_connect [sequencer]
0000720 D Running task dp_init [sequencer]
0000736 D Running task lock_probe [sequencer]
0000752 D Running task get_probe_capabilities [sequencer]
0000767 D Running task connect [sequencer]
0000799 D Default wire protocol selected; using SWD [dap]
0000799 D Sending deprecated SWJ sequence to select SWD [swj]
0000799 I DP IDR = 0x6ba02477 (v2 rev6) [dap]
0000799 D Running task clear_sticky_err [sequencer]
0000799 D Running task power_up_debug [sequencer]
0000799 D Running task check_version [sequencer]
0000799 D Running task unlock_probe [sequencer]
0000799 D Running task unlock_device [sequencer]
0000799 D Running task create_discoverer [sequencer]
0000799 D Running task discovery [sequencer]
0000799 D Running task find_aps [sequencer]
0000799 D Running task create_aps [sequencer]
0000799 D Running task create_ap.0 [sequencer]
0000814 D AHB-AP#0 default HPROT=3 HNONSEC=0 [ap]
0000814 D AHB-AP#0 implemented HPROT=f HNONSEC=1 [ap]
0000814 I AHB-AP#0 IDR = 0x84770001 (AHB-AP var0 rev8) [discovery]
0000814 D Running task create_ap.1 [sequencer]
0000814 D APB-AP#1 default HPROT=0 HNONSEC=0 [ap]
0000814 D APB-AP#1 implemented HPROT=0 HNONSEC=0 [ap]
0000814 I APB-AP#1 IDR = 0x54770002 (APB-AP var0 rev5) [discovery]
0000814 D Running task create_ap.3 [sequencer]
0000814 D AHB-AP#3 default HPROT=3 HNONSEC=0 [ap]
0000814 D AHB-AP#3 implemented HPROT=f HNONSEC=1 [ap]
0000814 I AHB-AP#3 IDR = 0x84770001 (AHB-AP var0 rev8) [discovery]
0000814 D Running task find_components [sequencer]
0000814 D Running task init_ap.0 [sequencer]
0000814 I AHB-AP#0 Class 0x1 ROM table #0 @ 0xe00fe000 (designer=673 part=d41) [rom_table]
0000814 I [0]<e00ff000:ROM class=1 designer=43b:Arm part=4c9> [rom_table]
0000814 I   AHB-AP#0 Class 0x1 ROM table #1 @ 0xe00ff000 (designer=43b:Arm part=4c9) [rom_table]
0000814 I   [0]<e000e000:SCS M33 class=9 designer=43b:Arm part=d21 devtype=00 archid=2a04 devid=0:0:0> [rom_table]
0000814 I   [1]<e0001000:DWT M33 class=9 designer=43b:Arm part=d21 devtype=00 archid=1a02 devid=0:0:0> [rom_table]
0000814 I   [2]<e0002000:BPU M33 class=9 designer=43b:Arm part=d21 devtype=00 archid=1a03 devid=0:0:0> [rom_table]
0000814 I   [3]<e0000000:ITM M33 class=9 designer=43b:Arm part=d21 devtype=43 archid=1a01 devid=0:0:0> [rom_table]
0000814 D   [4]<fff41002 not present> [rom_table]
0000814 I   [5]<e0041000:ETM M33 class=9 designer=43b:Arm part=d21 devtype=13 archid=4a13 devid=0:0:0> [rom_table]
0000814 I   [6]<e0042000:CTI M33 class=9 designer=43b:Arm part=d21 devtype=14 archid=1a14 devid=40800:0:0> [rom_table]
0000814 D   [7]<fff44002 not present> [rom_table]
0000814 I [1]<e0040000:TPIU M33 class=9 designer=43b:Arm part=d21 devtype=11 archid=0000 devid=ca1:0:0> [rom_table]
0000814 I [2]<e00fd000:TSGEN class=15 designer=43b:Arm part=101> [rom_table]
0000814 D Running task init_ap.1 [sequencer]
0000814 I APB-AP#1 Class 0x1 ROM table #0 @ 0x000000 (designer=673 part=db6) [rom_table]
0000814 I [0]<00001000:??? class=15 designer=673 part=051> [rom_table]
0000814 D Running task init_ap.3 [sequencer]
0000814 I AHB-AP#3 Class 0x1 ROM table #0 @ 0xf0000000 (designer=673 part=52d) [rom_table]
0000814 I [0]<e00ff000:ROM class=1 designer=43b:Arm part=4c0> [rom_table]
0000814 I   AHB-AP#3 Class 0x1 ROM table #1 @ 0xe00ff000 (designer=43b:Arm part=4c0) [rom_table]
0000814 I   [0]<e000e000:SCS v6-M class=14 designer=43b:Arm part=008> [rom_table]
0000814 I   [1]<e0001000:DWT v6-M class=14 designer=43b:Arm part=00a> [rom_table]
0000814 I   [2]<e0002000:BPU v6-M class=14 designer=43b:Arm part=00b> [rom_table]
0000814 I [1]<f0001000:CTI M0+ class=9 designer=43b:Arm part=9a6 devtype=14 archid=1a14 devid=1040800:0:0> [rom_table]
0000814 D Running task create_cores [sequencer]
0000814 D Creating SCS component [discovery]
0000814 D selected core #0 [soc_target]
0000830 I CPU core #0: Cortex-M33 r0p4, v8.0-M architecture [cortex_m]
0000830 I   Extensions: [DSP, FPU, FPU_V5, MPU, SEC] [cortex_m]
0000830 I   FPU present: FPv5-SP-D16-M [cortex_m]
0000830 D Creating SCS component [discovery]
0000830 D uninit session <pyocd.core.session.Session object at 0x0000025905828AC0> [session]
0000830 C Error: <APv1Address@0x25909297df0 #3 dp=0> [__main__]
Traceback (most recent call last):
  File "C:\Users\zhengen\AppData\Local\Programs\Python\Python310\lib\site-packages\pyocd\__main__.py", line 161, in run
    status = cmd.invoke()
  File "C:\Users\zhengen\AppData\Local\Programs\Python\Python310\lib\site-packages\pyocd\subcommands\load_cmd.py", line 100, in invoke
    with session:
  File "C:\Users\zhengen\AppData\Local\Programs\Python\Python310\lib\site-packages\pyocd\core\session.py", line 415, in __enter__
    self.open()
  File "C:\Users\zhengen\AppData\Local\Programs\Python\Python310\lib\site-packages\pyocd\core\session.py", line 553, in open
    self._board.init()
  File "C:\Users\zhengen\AppData\Local\Programs\Python\Python310\lib\site-packages\pyocd\board\board.py", line 143, in init
    self.target.init()
  File "C:\Users\zhengen\AppData\Local\Programs\Python\Python310\lib\site-packages\pyocd\coresight\coresight_target.py", line 123, in init
    super().init()
  File "C:\Users\zhengen\AppData\Local\Programs\Python\Python310\lib\site-packages\pyocd\core\soc_target.py", line 174, in init
    seq.invoke()
  File "C:\Users\zhengen\AppData\Local\Programs\Python\Python310\lib\site-packages\pyocd\utility\sequencer.py", line 213, in invoke
    resultSequence.invoke()
  File "C:\Users\zhengen\AppData\Local\Programs\Python\Python310\lib\site-packages\pyocd\utility\sequencer.py", line 208, in invoke
    resultSequence = call()
  File "C:\Users\zhengen\AppData\Local\Programs\Python\Python310\lib\site-packages\pyocd\coresight\discovery.py", line 63, in _create_cores
    self._apply_to_all_components(self._create_component,
  File "C:\Users\zhengen\AppData\Local\Programs\Python\Python310\lib\site-packages\pyocd\coresight\discovery.py", line 74, in _apply_to_all_components
    ap.rom_table.for_each(action, filter)
  File "C:\Users\zhengen\AppData\Local\Programs\Python\Python310\lib\site-packages\pyocd\coresight\rom_table.py", line 330, in for_each
    component.for_each(action, filter)
  File "C:\Users\zhengen\AppData\Local\Programs\Python\Python310\lib\site-packages\pyocd\coresight\rom_table.py", line 338, in for_each
    action(component)
  File "C:\Users\zhengen\AppData\Local\Programs\Python\Python310\lib\site-packages\pyocd\coresight\discovery.py", line 56, in _create_component
    cmp = cmpid.factory(cmpid.ap, cmpid, cmpid.address)
  File "C:\Users\zhengen\AppData\Local\Programs\Python\Python310\lib\site-packages\pyocd\coresight\cortex_m.py", line 222, in factory
    root.add_core(core)
  File "C:\Users\zhengen\AppData\Local\Programs\Python\Python310\lib\site-packages\pyocd\target\pack\pack_target.py", line 511, in _pack_target_add_core
    pname = _self._pack_device.processors_ap_map[cast(CortexM, core).ap.address].name
KeyError: <APv1Address@0x1dc2b903af0 #3 dp=0>

Steps to Reproduce

  1. pyocd flash -t efr32bg22c224f512gm32 Sample.hex

Environment

Any help would be appreciated. Thank you!

hagibr commented 1 year ago

Try editing this file:

C:\Users\zhengen\AppData\Local\Programs\Python\Python310\lib\site-packages\pyocd\target\pack\pack_target.py

At line 511, change this:

    def _pack_target_add_core(_self, core: CoreTarget) -> None:
        """@brief Override to set node name of added core to its pname."""
        pname = _self._pack_device.processors_ap_map[cast(CortexM, core).ap.address].name
        core.node_name = pname
        CoreSightTarget.add_core(_self, core)

to this:

    def _pack_target_add_core(_self, core: CoreTarget) -> None:
        """@brief Override to set node name of added core to its pname."""
        if( cast(CortexM, core).ap.address in _self._pack_device.processors_ap_map ):
            pname = _self._pack_device.processors_ap_map[cast(CortexM, core).ap.address].name
            core.node_name = pname
            CoreSightTarget.add_core(_self, core)

I'm investigating a similar problem (#1642) with my EFR32BG24.

enzheng128 commented 1 year ago

Try editing this file:

C:\Users\zhengen\AppData\Local\Programs\Python\Python310\lib\site-packages\pyocd\target\pack\pack_target.py

At line 511, change this:

    def _pack_target_add_core(_self, core: CoreTarget) -> None:
        """@brief Override to set node name of added core to its pname."""
        pname = _self._pack_device.processors_ap_map[cast(CortexM, core).ap.address].name
        core.node_name = pname
        CoreSightTarget.add_core(_self, core)

to this:

    def _pack_target_add_core(_self, core: CoreTarget) -> None:
        """@brief Override to set node name of added core to its pname."""
        if( cast(CortexM, core).ap.address in _self._pack_device.processors_ap_map ):
            pname = _self._pack_device.processors_ap_map[cast(CortexM, core).ap.address].name
            core.node_name = pname
            CoreSightTarget.add_core(_self, core)

I'm investigating a similar problem (#1642) with my EFR32BG24.

I'm still having issues. I suspect it's a problem with the EFR32 pack.

hagibr commented 1 year ago

I'm using version 0.34.3, it's working partially. Give a try.