这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 活动中心 » 板卡试用 » 【zephyr】S32K3 GPIO 驱动

共2条 1/1 1 跳转至页

【zephyr】S32K3 GPIO 驱动

高工
2026-10-25 16:35:21   被打赏 40 分(兑奖)     打赏

【简介】

S32K3 的GPIO 驱动在 zephyr  的如下路径\zephyr\drivers\gpio  以下两个文件分别对应S32K3 的siul2 的 GPIO 驱动和对应的配置文件

image.png

以下是对应的GPIO的驱动配置

# Copyright 2022, 2025 NXP
# SPDX-License-Identifier: Apache-2.0

config GPIO_NXP_SIUL2
	bool "NXP SIUL2 GPIO driver"
	default y
	depends on DT_HAS_NXP_SIUL2_GPIO_ENABLED
	select NOCACHE_MEMORY if ARCH_HAS_NOCACHE_MEMORY_SUPPORT
	help
	  Enable the GPIO driver for NXP SIUL2.

对应Cmake 中对应配置和驱动文件的关联如下

image.png

工程如果需要编译GPIO驱动只要在工程中加入“CONFIG_GPIO=y”即可将驱动文件加入编译。

menuconfig GPIO
    bool "General-Purpose Input/Output (GPIO) drivers"
    help
      Include GPIO drivers in system config

if GPIO

module = GPIO
module-str = gpio
source "subsys/logging/Kconfig.template.log_config"

config GPIO_SHELL
    bool "GPIO Shell"
    depends on SHELL
    help
      Enable GPIO Shell for testing.

config GPIO_SHELL_INFO_CMD
    bool "GPIO Shell info command"
    default y
    depends on GPIO_SHELL
    help
      Enable GPIO Shell information command.
      This command provides a shell user extra information about gpio
      controller reserved pins and line names.

config GPIO_SHELL_TOGGLE_CMD
    bool "GPIO Shell toggle command"
    default y
    depends on GPIO_SHELL
    help
      Enable GPIO Shell toggle command.

config GPIO_SHELL_BLINK_CMD
    bool "GPIO Shell blink command"
    default y
    depends on GPIO_SHELL
    help
      Enable GPIO Shell blink command.
      This command provides a shell user the ability to 'blink' a pin
      at 1Hz.

config GPIO_INIT_PRIORITY
    int "GPIO init priority"
    default KERNEL_INIT_PRIORITY_DEFAULT
    help
      GPIO driver device initialization priority.

config GPIO_GET_DIRECTION
    bool "Support for querying GPIO direction [EXPERIMENTAL]"
    select EXPERIMENTAL
    help
      Enable this option if the application does not maintain its own GPIO
      direction state.

      With this option enabled, the application may query GPIO direction
      via gpio_port_get_direction(), gpio_pin_is_input(), and
      gpio_pin_is_output().

config GPIO_GET_CONFIG
    bool "Support for get configuration function [EXPERIMENTAL]"
    select EXPERIMENTAL
    help
      This option enables the support for getting the current configurations
      of GPIOs. The driver must implement it to work.

config GPIO_HOGS
    bool "Support for GPIO hogs"
    default $(dt_gpio_hogs_enabled)
    help
      Enable support for GPIO hogs. GPIO hogging is a mechanism for providing
      automatic GPIO configuration via devicetree.

config GPIO_HOGS_INIT_PRIORITY
    int "GPIO hogs init priority"
    default 41
    depends on GPIO_HOGS
    help
      GPIO hogs initialization priority. GPIO hogs must be initialized after the
      GPIO controller drivers.

config GPIO_ENABLE_DISABLE_INTERRUPT
    bool "Support for enable/disable interrupt without re-config [EXPERIMENTAL]"
    select EXPERIMENTAL
    help
      This option enables the support for enabling/disabling interrupt with
      previous configuration, and enabling/disabling the interrupt only turns
      on/off the interrupt signal without changing other registers, such as
      pending register, etc. The driver must implement it to work.

# zephyr-keep-sorted-start
...
source "drivers/gpio/Kconfig.nxp_siul2"
...
# zephyr-keep-sorted-stop

endif # GPIO

上述配置会加载 Kconfig.nxp_siul2 的配置,对应配置如下:

config GPIO_NXP_SIUL2
    bool "NXP SIUL2 GPIO driver"
    default y
    depends on DT_HAS_NXP_SIUL2_GPIO_ENABLED
    select NOCACHE_MEMORY if ARCH_HAS_NOCACHE_MEMORY_SUPPORT

只要在设备树中开启 DT_HAS_NXP_SIUL2_GPIO_ENABLED 就会生成CONFIG_GPIO_NXP_SIUL2 的配置从而将驱动文件加入到工程中,工程中加入CONFIG_GPIO_SHELL的配置就会在shell中添加gpio 的命令。本地的shell 的工程配置中添加如下的配置加入gpio 测试命令。

image.png

 编译完成后shell 中已经添加了gpio的测试命令。

image.png


管理员
2026-11-01 22:08:39     打赏
2楼

Zephyr下GPIO驱动移植与适配,底层驱动可复用


共2条 1/1 1 跳转至页

回复

匿名不能发帖!请先 [ 登陆 注册 ]