Skip to content

remove HAL_Delay(1) for liquid-mod#117

Open
niekky wants to merge 2 commits into
mainfrom
nn/flash-delay-remove
Open

remove HAL_Delay(1) for liquid-mod#117
niekky wants to merge 2 commits into
mainfrom
nn/flash-delay-remove

Conversation

@niekky

@niekky niekky commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

Description

A brief description of the changes in the PR

Issue Link

Please provide a link to the issue (e.g. "Closes #1").

Also, if this PR is one of multiple for this issue, link the parent if this is a child OR link
the children if this is the parent. Do not use "closes" keywords on child PRs, only use them on
the parent.

Testing

  • Passes existing unit tests
  • Unit tests modified (link the test changes as a child PR)
  • Integration test performed

Attach any test artifacts here, if relevant.

Other

Leave any additional notes here

Reviewer Checklist

Standards

  • Follows FCF Architectural Standards
  • Follows SDR Coding Standards
  • Code complexity/function Size is minimized
  • Code is testable
  • Code is readable and commented properly
  • License terms are respected

Error Handling

  • Potentially unsafe functions return a status code
  • Error returns properly handled

Memory

  • Stack allocated memory is scoped correctly
  • Heap allocated memory is avoided
  • Globally allocated memory is minimized except when necessary
  • Pointers are used correctly
  • Concurrency has been considered

Performance

  • Rate limiters are respected
  • Busy waiting is avoided
  • "Delay" calls are not used in performance sensitive code

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes a HAL_Delay(1) call from the flash-write busy-wait loop (presumably to avoid delays for the “liquid-mod” variant).

Changes:

  • Removed HAL_Delay(1) inside the flash_write() loop that waits for the flash chip to become ready.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread flash/flash.c Outdated
Comment on lines 820 to 823
else
{
timeout_ctr++;
HAL_Delay( 1 );
}

Copilot AI Apr 13, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With HAL_Delay(1) removed, timeout_ctr++ no longer represents “1 ms elapsed”, so the timeout = num_bytes (documented as “1 ms/byte”) will be reached far too quickly and can cause premature FLASH_TIMEOUT. Consider basing the timeout on elapsed time (e.g., HAL_GetTick()/a deadline) so the loop remains delay-free without changing timeout semantics.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in commit 6c48016. Replaced timeout_ctr with a HAL_GetTick()-based elapsed-time check. The deadline is now computed as timeout_start = HAL_GetTick() at initialization, and the busy-wait checks (HAL_GetTick() - timeout_start) >= timeout — which preserves the original "1 ms/byte" semantics and is safe against uint32_t tick wraparound.

Comment thread flash/flash.c Outdated
@@ -820,7 +820,6 @@ for ( int i = 2; i < pflash_handle -> num_bytes; i += 2 )
else
{
timeout_ctr++;

Copilot AI Apr 13, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This while (flash_is_flash_busy()) loop is now a tight spin with no delay/yield, which can significantly increase CPU usage and potentially starve other time-sensitive work (e.g., USB handling) while waiting for the flash chip. If the delay must be removed, consider adding a lightweight yield/backoff mechanism appropriate for the runtime (RTOS delay/yield, or a bounded poll interval) while still meeting performance requirements.

Suggested change
timeout_ctr++;
timeout_ctr++;
/* Add a small bounded backoff to avoid a tight busy-spin. */
for ( volatile uint32_t backoff_ctr = 0U; backoff_ctr < 64U; backoff_ctr++ )
{
}

Copilot uses AI. Check for mistakes.
@ETSells

ETSells commented Apr 19, 2026

Copy link
Copy Markdown
Member

Recommend not merging this. Flash will no longer be in mod when v2.6.0 is released. You can make a dedicated liquids branch if you want it, otherwise please cherry pick this diff to driver.

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

Successfully merging this pull request may close these issues.

4 participants