[ISSUE-242] Un-conditionally Halt the CPU#244
Conversation
In some instances, `.halt()` not being called can lead to un-expected behaviour when attempting to flash or erase a target as the CPU may still be running. This patch addresses that by removing the `.halted()` check to ensure that `.halt()` is called un-conditionally.
There was a problem hiding this comment.
Pull Request Overview
This PR removes conditional halting checks to ensure the CPU is always halted before erase and flash operations. The change addresses rare instances where the .halted() check fails, preventing the .halt() call and potentially causing unexpected behavior during target operations.
Key changes:
- Removes
.halted()conditional checks before calling.halt()in erase, flash, and flash_file methods - Updates test cases to reflect the new unconditional halt behavior
- Simplifies the halt logic while maintaining exception handling
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pylink/jlink.py | Removes conditional .halted() checks and calls .halt() unconditionally in erase, flash, and flash_file methods |
| tests/unit/test_jlink.py | Updates test mocks and assertions to reflect unconditional halt behavior, removes halted-related test scenarios |
|
|
||
| # Halted exception | ||
| self.jlink.halted.side_effect = JLinkException(-1) | ||
| # Halt exception |
There was a problem hiding this comment.
[nitpick] The comment should be "# Halt exception" to match the change from halted to halt, but it should be more descriptive. Consider "# Test halt exception handling" for clarity.
| # Halt exception | |
| # Test halt exception handling |
|
|
||
| # Halted | ||
| self.jlink.halted.return_value = True | ||
| # Halt exception |
There was a problem hiding this comment.
[nitpick] The comment should be more descriptive. Consider "# Test halt exception handling" for clarity.
| # Halt exception | |
| # Test halt exception handling during flash_file execution |
[ISSUE-242] Un-conditionally Halt the CPU
Overview
In rare instances, the call to
.halted()fails, resulting in.halt()not being called, which can lead to un-expected behaviour when attempting to flash or erase a target as the CPU may still be running. This patch addresses that by removing the.halted()check to ensure that.halt()is called un-conditionally.