Skip to content

analog: add comp enable/disable ioctl and STM32 support - #20149

Open
daniel-p-carvalho wants to merge 4 commits into
apache:masterfrom
daniel-p-carvalho:feat/stm32-comp-ioctl
Open

daniel-p-carvalho wants to merge 4 commits into
apache:masterfrom
daniel-p-carvalho:feat/stm32-comp-ioctl

Conversation

@daniel-p-carvalho

Copy link
Copy Markdown
Contributor

Summary

This PR adds standard IOCTL commands to control analog comparator devices and implements them for STM32 (M3/M4 v2 architecture).

  1. include/nuttx/analog/ioctl.h:

    • Adds ANIOC_COMP_ENABLE and ANIOC_COMP_DISABLE commands.
    • Bumps AN_NCMDS to 14.
  2. arch/arm/src/common/stm32/stm32_comp_m3m4_v2.c:

    • Implements ao_ioctl to handle enable and disable requests via ANIOC_COMP_ENABLE and ANIOC_COMP_DISABLE.
    • Adds CONFIG_STM32_COMP_INIT_DISABLED in Kconfig.comp to optionally keep the comparator disabled during driver setup until explicitly requested.
    • Cleans up coding style alignment.
  3. boards/arm/stm32g4/nucleo-g431kb/configs/comp/defconfig:

    • Enables CONFIG_EXAMPLES_COMP=y and sets default DAC path to /dev/dac5 for comparator verification.

Impact

  • Allows user-space applications to dynamically control the comparator state via standard IOCTL.
  • Backward compatible with existing comparator lower-half drivers (unknown commands return -ENOTTY).

Testing

  • Host OS: Linux x86_64
  • Target Board: STMicroelectronics NUCLEO-G431KB (STM32G431KB)
  • Configuration: nucleo-g431kb:comp
  • Toolchain: arm-none-eabi-gcc 13.2.1

Execution Logs on Physical Hardware:

nsh> comp
Running comparator test on /dev/comp0...
  1. Initial output state: 0
  2. ANIOC_COMP_DISABLE: OK
  3. Output state when disabled: 0
  4. ANIOC_COMP_ENABLE: OK
  5. Output state when enabled: 1
Comparator test PASSED on /dev/comp0

Individual commands:

nsh> comp disable
/dev/comp0: Comparator disabled successfully

nsh> comp read
/dev/comp0: output = 0

nsh> comp enable
/dev/comp0: Comparator enabled successfully

nsh> comp read
/dev/comp0: output = 1
  • Verified with checkpatch.sh: 0 errors, 0 warnings.

Define standard IOCTL commands to enable and disable analog comparator
devices from user-space applications.

Assisted-by: Gemini:gemini-2.5-pro
Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com>
Implement ao_ioctl in stm32_comp_m3m4_v2.c to handle ANIOC_COMP_ENABLE and
ANIOC_COMP_DISABLE commands. Also add CONFIG_STM32_COMP_INIT_DISABLED to
allow keeping the comparator disabled after driver initialization until
explicitly enabled.

Update nucleo-g431kb:comp defconfig to enable CONFIG_EXAMPLES_COMP and
set default DAC path for comparator ramp verification.

Assisted-by: Gemini:gemini-2.5-pro
Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com>
@daniel-p-carvalho

Copy link
Copy Markdown
Contributor Author

Companion example tool PR in apps: apache/nuttx-apps#3783

@github-actions github-actions Bot added Arch: arm Issues related to ARM (32-bit) architecture Area: Drivers Drivers issues Size: M The size of the change in this PR is medium Board: arm labels Sep 15, 2026
@github-actions

github-actions Bot commented Sep 15, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

qemu-armv8a

  • Code: .rodata +464 B, .text.init_service_check +24 B, .text.ostest_main +52 B, .text.tester +68 B, .text.verifier +148 B, .text.wqueue_priority_test -240 B, .text.wqueue_test -184 B (+2.2%, 344,288 B)

qemu-intel64

jerpelea
jerpelea previously approved these changes Sep 15, 2026
CONFIG_EXAMPLES_COMP_DACPATH matched its Kconfig default value, which
make savedefconfig drops as redundant. The stale explicit line made
the committed defconfig differ from what a clean savedefconfig
produces, failing CI's defconfig-completeness check even though the
board builds fine either way.

Assisted-by: Claude:claude-sonnet-5
Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com>
jerpelea
jerpelea previously approved these changes Sep 15, 2026
acassis
acassis previously approved these changes Sep 15, 2026
Comment thread arch/arm/src/common/stm32/stm32_comp_m3m4_v2.c Outdated
In comp_ioctl(), propagate the return code of comp_enable() to caller so
failures (such as when the comparator CSR register is locked) return -EPERM.
Also call comp_lock_set() if the comparator was configured with locking,
handling cases where initialization was delayed.

Assisted-by: Gemini:gemini-2.5-pro
Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com>
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 Area: Drivers Drivers issues Board: arm 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.

5 participants