Skip to content

arch/arm/stm32: Add getedges support to timer capture drivers - #21052

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
Swatantra-66:stm32/capture-getedges
Nov 2, 2026
Merged

xiaoxiang781216 merged 1 commit into
apache:masterfrom
Swatantra-66:stm32/capture-getedges

Conversation

@Swatantra-66

@Swatantra-66 Swatantra-66 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR implements pulse edge counting and the getedges callback in the timer capture lower-half drivers for STM32H7, STM32H5, and common STM32 (M3/M4).

Previously, these drivers did not implement the .getedges operation. Consequently:

  1. Querying ioctl(fd, CAPIOC_EDGES, &edges) failed with -ENOTTY.
  2. Applications such as examples/capture aborted execution upon querying edge counts.
  3. On older builds, this triggered a fatal assertion panic in drivers/timers/capture.c:344 (DEBUGASSERT(lower[i]->ops->getedges != NULL)).

Changes made across STM32 capture lower-half drivers:

  1. Added uint32_t edges; to struct stm32_lowerhalf_s.
  2. Incremented lower->edges++ on each captured edge in the timer interrupt handler (stm32_cap_handler).
  3. Cleared priv->edges = 0 upon capture initialization in stm32_start().
  4. Implemented stm32_getedges() to return priv->edges atomically inside a critical section.
  5. Registered .getedges = stm32_getedges in g_cap_ops.

Fixes #16828

Impact

  • Is new feature added? Yes, adds edge counting support to STM32 timer capture drivers.
  • User impact: Users can now query pulse edge counts via CAPIOC_EDGES and CAPIOC_ALL.
  • Build impact: None.
  • Hardware impact: STM32H7, STM32H5, and STM32 M3/M4 MCUs using timer capture.
  • Documentation impact: None.
  • Security impact: None.
  • Compatibility: Backward and forward compatible.

Testing

  • Host: Windows 11 / WSL2
  • Target Configurations: nucleo-h743zi:capture, nucleo-h563zi:capture
  • Verification:
    1. Code inspection against upper-half requirements in drivers/timers/capture.c and include/nuttx/timers/capture.h.
    2. Formatted strictly according to NuttX coding style (0 lines exceeding 78 cols, no trailing whitespace, no tabs).

Implement the getedges callback and edge counting in the timer capture lower-half drivers for STM32H7, STM32H5, and STM32 M3/M4. This enables users to query pulse edge counts via CAPIOC_EDGES and CAPIOC_ALL ioctls, and resolves issue apache#16828.

Signed-off-by: Swatantra Yadav <[email protected]>
@github-actions github-actions Bot added Arch: arm Issues related to ARM (32-bit) architecture Size: M The size of the change in this PR is medium labels Oct 27, 2026
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@jerpelea jerpelea left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please provide tests on a real HW

@Swatantra-66

Copy link
Copy Markdown
Contributor Author

the testing listed in the description was build/compile verification (nucleo-h743zi:capture and nucleo-h563zi:capture built cleanly on WSL2), as I do not have physical STM32H7/H5 boards with a pulse generator setup

The change implements the missing .getedges callback (which previously was NULL, returning -ENOTTY and hitting DEBUGASSERT(lower[i]->ops->getedges != NULL) in capture.c as reported in #16828)
It increments an internal counter (priv->edges++) inside the existing interrupt handler where captured edges are already serviced.
Returns priv->edges atomically under a critical section in stm32_getedges().
The logic is straightforward software accounting matching the upper-half expectations in drivers/timers/capture.c

@xiaoxiang781216
xiaoxiang781216 merged commit 3cf4fbf into apache:master Nov 2, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: arm Issues related to ARM (32-bit) architecture Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] STM32H7 timer capture driver does not have edge IOC operation

3 participants