PyOCD and Picoprobe will not flash an NRF51822, exiting with the error cannot read register r0 because core #0 is not halted
.
Setup:
Windows 11
Python 3.9.6
PyOCD 0.33.1
Output from pyocd load firmware.hex --target nrf51822
:
0001527 I Loading C:\Users\henri\NRF5x\NRF_LED\.pio\build\nrf51822_y5_mbug\firmware.hex [load_cmd]
0006932 C cannot read register r0 because core #0 is not halted [__main__]
Traceback (most recent call last):
File "C:\Users\henri\AppData\Local\Programs\Python\Python39\lib\site-packages\pyocd\flash\builder.py", line 259, in _enable_read_access
self.flash.init(self.flash.Operation.VERIFY)
File "C:\Users\henri\AppData\Local\Programs\Python\Python39\lib\site-packages\pyocd\flash\flash.py", line 250, in init
raise FlashFailure('flash init timed out')
pyocd.core.exceptions.FlashFailure: flash init timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\henri\AppData\Local\Programs\Python\Python39\lib\site-packages\pyocd\__main__.py", line 161, in run
status = cmd.invoke()
File "C:\Users\henri\AppData\Local\Programs\Python\Python39\lib\site-packages\pyocd\subcommands\load_cmd.py", line 117, in invoke
programmer.program(filename,
File "C:\Users\henri\AppData\Local\Programs\Python\Python39\lib\site-packages\pyocd\flash\file_programmer.py", line 170, in program
self._loader.commit()
File "C:\Users\henri\AppData\Local\Programs\Python\Python39\lib\site-packages\pyocd\flash\loader.py", line 289, in commit
perf = builder.program(chip_erase=chipErase,
File "C:\Users\henri\AppData\Local\Programs\Python\Python39\lib\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 "C:\Users\henri\AppData\Local\Programs\Python\Python39\lib\site-packages\pyocd\flash\builder.py", line 666, in _compute_sector_erase_pages_and_weight
self._analyze_pages_with_crc32(fast_verify)
File "C:\Users\henri\AppData\Local\Programs\Python\Python39\lib\site-packages\pyocd\flash\builder.py", line 645, in _analyze_pages_with_crc32
self._enable_read_access()
File "C:\Users\henri\AppData\Local\Programs\Python\Python39\lib\site-packages\pyocd\flash\builder.py", line 262, in _enable_read_access
self.flash.init(self.flash.Operation.ERASE)
File "C:\Users\henri\AppData\Local\Programs\Python\Python39\lib\site-packages\pyocd\flash\flash.py", line 243, in init
result = self._call_function_and_wait(self.flash_algo['pc_init'],
File "C:\Users\henri\AppData\Local\Programs\Python\Python39\lib\site-packages\pyocd\flash\flash.py", line 620, in _call_function_and_wait
return self.wait_for_completion(timeout=timeout)
File "C:\Users\henri\AppData\Local\Programs\Python\Python39\lib\site-packages\pyocd\flash\flash.py", line 616, in wait_for_completion
return self.target.read_core_register('r0')
File "C:\Users\henri\AppData\Local\Programs\Python\Python39\lib\site-packages\pyocd\core\soc_target.py", line 218, in read_core_register
return self.selected_core_or_raise.read_core_register(id)
File "C:\Users\henri\AppData\Local\Programs\Python\Python39\lib\site-packages\pyocd\coresight\cortex_m.py", line 971, in read_core_register
regValue = self.read_core_register_raw(reg_info.index)
File "C:\Users\henri\AppData\Local\Programs\Python\Python39\lib\site-packages\pyocd\coresight\cortex_m.py", line 988, in read_core_register_raw
vals = self.read_core_registers_raw([reg])
File "C:\Users\henri\AppData\Local\Programs\Python\Python39\lib\site-packages\pyocd\coresight\cortex_m.py", line 1009, in read_core_registers_raw
return self._base_read_core_registers_raw(reg_list)
File "C:\Users\henri\AppData\Local\Programs\Python\Python39\lib\site-packages\pyocd\coresight\cortex_m.py", line 1023, in _base_read_core_registers_raw
raise exceptions.CoreRegisterAccessError(
pyocd.core.exceptions.CoreRegisterAccessError: cannot read register r0 because core #0 is not halted
If more information is needed, don't hesitate to ask.
The error message indicates that the debugger is unable to communicate with the target device because the processor is not in a halted state or debugger is unable to halt the target CPU core before attempting to read a register.
Let me know if these steps worked for you.