Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to hit a breakpoint multiple times in a loop #1708

Open
maxwell652 opened this issue Jul 9, 2024 · 0 comments
Open

How to hit a breakpoint multiple times in a loop #1708

maxwell652 opened this issue Jul 9, 2024 · 0 comments

Comments

@maxwell652
Copy link

maxwell652 commented Jul 9, 2024

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
@maxwell652 maxwell652 changed the title Cannot hit the breakpoint with Python API How to hit a breakpoint multiple times in a loop Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant