Skip to content

arch/arm/rtl8721f: add GPIO character driver support - #19582

Merged
jerpelea merged 2 commits into
apache:masterfrom
dcgong2917:rtl8721f-gpio
Jul 31, 2026
Merged

arch/arm/rtl8721f: add GPIO character driver support#19582
jerpelea merged 2 commits into
apache:masterfrom
dcgong2917:rtl8721f-gpio

Conversation

@dcgong2917

@dcgong2917 dcgong2917 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds GPIO character-driver support for the RTL8721F and the RTL8721F EVB
board, plus a fix to the shared Ameba GPIO ISR that this port uncovered on
hardware.

Two commits:

  1. arch/arm/common/ameba: fix level-triggered GPIO interrupt storm
    The shared port ISR clears interrupt status with
    GPIO_INTStatusClearEdge(), which only clears edge latches. For a
    level-triggered pin the status stays asserted while the level is active,
    so the ISR re-enters forever once the level fires — the system hangs
    before the application can service the event. The pin is now masked in
    the ISR before the callback and re-enabled by the application via
    go_enable(). Edge pins are unchanged. This also affects RTL8721Dx
    (already in-tree).

  2. arch/arm/rtl8721f: add GPIO character driver support
    Wires the shared ameba_gpio.c into the RTL8721F build (three GPIO
    ports A/B/C), adds the chip header, board glue, a minimal gpio NSH
    defconfig, and documentation. On amebagreen2 the ROM GPIO_Init does
    not call PAD_PullCtrl/GPIO_INTMode, so the driver now calls both
    explicitly (harmless redundant writes on RTL8721Dx).

Impact

  • New feature for RTL8721F; no impact on other architectures.
  • Behavioural fix for level-triggered GPIO interrupts on all Ameba ARM
    chips (RTL8721Dx, RTL8721F). Edge-triggered and non-interrupt GPIO
    behaviour is unchanged.
  • New board config: rtl8721f_evb/gpio.

Testing

Hardware-verified on the RTL8721F EVB (rtl8721f_evb/gpio config) via
apps/examples/gpio:

  • Output pin (PA25): drive high/low, read-back confirmed.
  • Input pin (PA24): read high/low confirmed.
  • Interrupt pin (PA26): all trigger/polarity combinations exercised —
    rising edge, falling edge, level high, level low. Level cases confirmed
    the storm fix (system survives; without the fix it hangs).

The shared port ISR clears interrupt status with GPIO_INTStatusClearEdge(),
which only clears edge latches.  For a level-triggered pin the status stays
asserted as long as the level is active, so the ISR re-enters forever once
the level fires -- the system hangs before the application can even service
the event.

Remember at configure time whether a pin is level-triggered, and in the ISR
mask such a pin (GPIO_INTConfig DISABLE) before invoking the callback.  The
application re-enables it via go_enable() after servicing.  Edge pins are
left unmasked, so their behaviour is unchanged.

This fixes a hang reproducible on RTL8721Dx and RTL8721F when a
level-high/level-low interrupt pin is used.

Signed-off-by: dechao_gong <dechao_gong@realsil.com.cn>
Assisted-by: Claude <noreply@anthropic.com>
Wire the shared Ameba GPIO driver into the RTL8721F (amebagreen2) build and
add the EVB board glue:

  - arch/arm/src/rtl8721f: build ameba_gpio.c (CMake/Make.defs), source the
    common Ameba Kconfig, and add ameba_gpio_chip.h describing the chip's
    three GPIO ports (A/B/C), their IRQs and the APBPeriph clock bit.
  - arch/arm/src/common/ameba: teach the driver that amebagreen2's ROM
    GPIO_Init does not call PAD_PullCtrl or GPIO_INTMode, so call both
    explicitly after GPIO_Init; on RTL8721Dx (ram_common) these are harmless
    redundant writes.  Add the AMEBA_PORT_C / AMEBA_PC() helpers.
  - boards/arm/rtl8721f/rtl8721f_evb: register output/input/interrupt demo
    pins, add the bringup hook, and provide a minimal 'gpio' NSH defconfig.
  - Documentation: add a GPIO section for the RTL8721F EVB and fix a
    rising/falling typo in the PKE8721DAF page.

Hardware-verified on the RTL8721F EVB: output, input, and all interrupt
trigger/polarity combinations (rising/falling edge, level high/low).

Signed-off-by: dechao_gong <dechao_gong@realsil.com.cn>
Assisted-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added Area: Documentation Improvements or additions to documentation Arch: arm Issues related to ARM (32-bit) architecture Size: M The size of the change in this PR is medium Board: arm labels Jul 30, 2026
@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@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 replace

Co-Authored-By:
with
Assisted-by:

@dcgong2917

Copy link
Copy Markdown
Contributor Author

@jerpelea Thanks for the review. Replaced Co-Authored-By: with Assisted-by: in both commits and force-pushed. Please take another look.

@xiaoxiang781216
xiaoxiang781216 requested a review from jerpelea July 31, 2026 02:15
@jerpelea
jerpelea merged commit d960bc3 into apache:master Jul 31, 2026
39 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 Area: Documentation Improvements or additions to documentation 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.

3 participants