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

pyOCD fails to flash imxrt1061 when flexRAM configuration changed #1457

Open fbeaulier opened 2 years ago

fbeaulier commented 2 years ago

Hi,

I've been using pyOCD to flash and debug my imxRT1061 based board. now i would like to change the FlexRAM configuration. Default is 128k ITCM, 128k DTCM, 256k OCRAM I have changed this to 0k ITCM, 256k DTCM, 256k OCRAM with few lines of code in the startup file. Everything seems to work but now there is no way i can flash my board anymore ! The only solution i have found is to use NXP's mcuxpresso once to flash a dummy hello world project, it puts the FlexRAM to it's default config again and then pyOCD is back to normal .

FYI with the modified FlexRAM config, loading the NXP Flashloader with USB works but when sending the command to start the flashloader the MCU resets. No way to erase flash with this tool.

Thanks for your great work.

Francois

Here is the pyocd log:

pyocd flash my_app.elf --target mimxrt1061dvl6a
0000952 W CMSIS-Pack device MIMXRT1061DVL6A has no identifiable boot memory [cmsis_pack]
0001677 I Loading /home/francois/blabla/my_app.elf [load_cmd]
0001852 C Memory transfer fault @ 0xe000edf0-0xe000edf3 [__main__]
Traceback (most recent call last):
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/probe/cmsis_dap_probe.py", line 502, in read_ap_result_callback
    value = result()
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/probe/pydapaccess/dap_access_cmsis_dap.py", line 1060, in read_reg_cb
    res = transfer.get_result()
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/probe/pydapaccess/dap_access_cmsis_dap.py", line 154, in get_result
    self.daplink._read_packet()
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/utility/concurrency.py", line 29, in _locking
    return func(self, *args, **kwargs)
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/probe/pydapaccess/dap_access_cmsis_dap.py", line 1146, in _read_packet
    decoded_data = cmd.decode_data(raw_data)
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/probe/pydapaccess/dap_access_cmsis_dap.py", line 480, in decode_data
    data = self._decode_transfer_data(data)
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/probe/pydapaccess/dap_access_cmsis_dap.py", line 386, in _decode_transfer_data
    self._check_response(data[2])
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/probe/pydapaccess/dap_access_cmsis_dap.py", line 364, 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/francois/.local/lib/python3.8/site-packages/pyocd/__main__.py", line 161, in run
    status = cmd.invoke()
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/subcommands/load_cmd.py", line 125, in invoke
    programmer.program(filename,
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/flash/file_programmer.py", line 170, in program
    self._loader.commit()
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/flash/loader.py", line 289, in commit
    perf = builder.program(chip_erase=chipErase,
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/flash/builder.py", line 490, in program
    sector_erase_count, page_program_time = self._compute_sector_erase_pages_and_weight(fast_verify)
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/flash/builder.py", line 669, in _compute_sector_erase_pages_and_weight
    self._analyze_pages_with_partial_read()
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/flash/builder.py", line 604, in _analyze_pages_with_partial_read
    self._enable_read_access()
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/flash/builder.py", line 259, in _enable_read_access
    self.flash.init(self.flash.Operation.VERIFY)
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/flash/flash.py", line 252, in init
    result = self._call_function_and_wait(self.flash_algo['pc_init'],
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/flash/flash.py", line 653, in _call_function_and_wait
    self._call_function(pc, r0, r1, r2, r3, init)
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/flash/flash.py", line 555, in _call_function
    self.target.write_core_registers_raw(reg_list, data_list)
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/core/soc_target.py", line 235, in write_core_registers_raw
    self.selected_core_or_raise.write_core_registers_raw(reg_list, data_list)
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/coresight/cortex_m.py", line 1175, in write_core_registers_raw
    self._base_write_core_registers_raw(reg_list, data_list)
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/coresight/cortex_m.py", line 1188, in _base_write_core_registers_raw
    if not self.is_halted():
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/coresight/cortex_m.py", line 942, in is_halted
    return self.get_state() == Target.State.HALTED
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/coresight/cortex_m.py", line 908, in get_state
    dhcsr = self.read_memory(CortexM.DHCSR)
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/coresight/cortex_m.py", line 478, in read_memory
    result = self.ap.read_memory(addr, transfer_size, now)
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/utility/concurrency.py", line 29, in _locking
    return func(self, *args, **kwargs)
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/coresight/ap.py", line 1084, in _read_memory
    result = read_mem_cb()
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/coresight/ap.py", line 1062, in read_mem_cb
    res = result_cb()
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/coresight/dap.py", line 877, in read_ap_cb
    result = result_cb()
  File "/home/francois/.local/lib/python3.8/site-packages/pyocd/probe/cmsis_dap_probe.py", line 507, in read_ap_result_callback
    raise self._convert_exception(error) from error
pyocd.core.exceptions.TransferFaultError: Memory transfer fault @ 0xe000edf0-0xe000edf3
fbeaulier commented 2 years ago

Update: after all it does not work so well with NXP's mcuxpresso either. After messing around i finally found a way to erase flash but just after the Flexram config change the probe can't connect to MCU anymore. I've contacted NXP's support.