How to hit a breakpoint multiple times in a loop
PyOCD version: 0.36.0 Hardware: STM32F407ZGT6 (ARM Cortex-M4) CMSIS-DAP debugger
I have set a breakpoint for a certain function using the Python API "target.set_breakpoin()". My firmware program calls this function multiple times.
My expectation is that each time the MCU reaches this function, the Core will halt, allowing me to perform read and write operations on some registers or RAM values. I would then use a Python API to resume the Core to running status. This process would repeat whenever the MCU executes this function again.
The question is: when I use the API "tarrget.resume()" to resume the Core, it does not take effect. I have to remove the breakpoint before calling resume(), only then can the Core continue running. However, after doing so, the Core will not halt when the MCU executes this function again in the future.
Is there a method to allow the Core to resume running without having to remove the breakpoint? Or are there any other approaches to achieve the desired effect?
Below is my test code:
#!/usr/bin/env python3
from pyocd.core.helpers import ConnectHelper
from pyocd.core.target import Target
from pyocd.debug.elf.symbols import ELFSymbolProvider
from pyocd.flash.file_programmer import FileProgrammer
options = {
'target_override': 'stm32f407zgtx',
'config_file': "pyocd.yaml"
}
session = ConnectHelper.session_with_chosen_probe(options=options)
with session:
target = session.target
target_context = target.get_target_context()
# programmer = FileProgrammer(session)
# program_options = {
# 'erase': 'auto',
# 'trust_crc': False,
# 'smart_flash': True
# }
# programmer.program('Template.axf', **program_options)
target.elf = 'Template.elf'
provider = ELFSymbolProvider(target.elf)
address = provider.get_symbol_value("halt_and_wait")
ret = target.set_breakpoint(address)
target.reset_and_halt()
target.resume()
while target.get_state() != Target.State.HALTED:
pass
pc = target.read_core_register("pc")
print(" pc: 0x%X" % pc)
assert pc == address & ~0x01 # mask off LSB
Having the same problem using the commander: I am setting a breakpoint but can't resume the execution afterwards using continue as I keep getting
pyocd> continue
Device is halted; a debug event may have occurred
pyocd> continue
Device is halted; a debug event may have occurred
The only way to move on is to remove the breakpoint. I am using Nucleo-F429ZI (Cortex-M4) with onboard ST-Link and observed same behavior with STM32N6 (Cortex-M55). Tested with pyOCD V0.36 on Windows 11 and Ubuntu 22.04.5