pyocd / pyocd/pyOCD

pyOCD race condition bugs in write_core_registers_raw and read_core_registers_raw

Open
#819 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug cortex-m
Dominant language
Python
Stars
1.5k
Forks
560
Avg merge
1h 41m
Merged PRs (30d)
3

Description

Quoting: https://github.com/mbedmicro/pyOCD/blob/master/pyocd/coresight/cortex_m.py

        # Technically, we need to poll S_REGRDY in DHCSR here before reading DCRDR. But
        # we're running so slow compared to the target that it's not necessary.
        # Read it and assert that S_REGRDY is set

Technically, this is a bug. And it bit me. :(

This is no longer "technically" true. 5 years of computer improvements makes this statement now false. I had to check the S_REGRDY or my probe smashed the register by executing another write too quickly and then failed the assert on the callbacks.

These comments are in the functions write_core_registers_raw and read_core_registers_raw.

I added a read to validate the S_REGRDY, but this seems like a duct tape patch. And it sort of conflicts with the whole read callback thing, so I'm kind of reluctant to submit a patch given that I really don't understand how to do this immediately and then with the callbacks in a way that isn't redundant.

Edit: Looks like I'm not the only one to see this:
https://github.com/mbedmicro/pyOCD/issues/693

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in pyocd/coresight/cortex_m.py and inspect write_core_registers_raw and read_core_registers_raw, including their S_REGRDY comments and read callbacks. Read the related issue #693 for prior context. Done means the register accesses no longer race with the target and the callback behavior remains correct without assertion failures.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools, embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.