基于Zephyr的i.MX95EVK M核GPIO_IO16切换故障求助
i.MX95EVK M核GPIO_IO16引脚配置总线错误问题
我在使用i.MX95EVK的M核切换GPIO_IO16引脚时遇到问题:该引脚默认复用为SAI3,我通过pinmux将其重映射为gpio_io_bit_16,同时删除SAI3节点避免冲突,但执行gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE)时触发总线错误,错误日志如下:
*** Booting Zephyr OS build v4.1.0-3508-g8b1f06af052f *** Entered Main Function [00:00:00.006,000] <err> os: ***** BUS FAULT ***** [00:00:00.012,000] <err> os: Precise data bus error [00:00:00.018,000] <err> os: BFAR Address: 0x443c0254 [00:00:00.024,000] <err> os: r0/a1: 0x00000001 r1/a2: 0x200003a9 r2/a3: 0x00000000 [00:00:00.032,000] <err> os: r3/a4: 0x443c0000 r12/ip: 0x00001eb9 r14/lr: 0x0000071d [00:00:00.041,000] <err> os: xpsr: 0x01000000 [00:00:00.046,000] <err> os: Faulting instruction address (r15/pc): 0x00000732 [00:00:00.054,000] <err> os: >>> ZEPHYR FATAL ERROR 25: Unknown error on CPU 0 [00:00:00.062,000] <err> os: Current thread: 0x20000198 (unknown) [00:00:00.069,000] <err> os: Halting system
为排查错误,我做了以下操作:
- 修改SM(M33)配置文件mx95evk.cfg,将GPIO2、PIN_GPIO_IO16、IOMUXC、IOMUX_GPR、PERLPI_GPIO2的所有权移至M核
- 尝试定义gpio-hog,但无效
- 在A核的DTS中禁用了gpio2和SAI3
以下是相关文件内容:
DTS覆盖文件
/* boards/imx95_evk_mimx9596_m7.overlay */ #include <zephyr/dt-bindings/rdc/imx_rdc.h> / { aliases { led0 = &user_led; }; leds { compatible = "gpio-leds"; user_led: led_0 { gpios = <&gpio2 16 GPIO_ACTIVE_HIGH>; label = "User LED"; }; }; }; &pinctrl { gpio2_io16_default: gpio2_io16_default { pinmux = <&iomuxc_gpio_io16_gpio_io_bit_gpio2_io_bit16>; bias-pull-down; slew-rate = "slightly-fast"; drive-strength = "x4"; }; }; /* &iomuxc { rdc = < RDC_DOMAIN_PERM(M7_DOMAIN_ID, RDC_DOMAIN_PERM_RW) >; status = "okay"; }; */ &gpio1 { status = "disabled"; }; &gpio2 { pinmux = <&iomuxc_gpio_io16_gpio_io_bit_gpio2_io_bit16>; /* Declare holes so pin 16 -> index 0 */ gpio-reserved-ranges = <0 16>; /*rdc = <RDC_DOMAIN_PERM(M7_DOMAIN_ID, RDC_DOMAIN_PERM_RW)>;*/ status = "okay"; }; /delete-node/ &sai3_default; /delete-node/ &sai3;
main.c文件
#include <zephyr/kernel.h> #include <zephyr/drivers/gpio.h> #include <zephyr/sys/printk.h> #include <zephyr/sys/util.h> #include <zephyr/sys/sys_io.h> // sys_read32/sys_write32 #define PAD_CTL_GPIO_IO16 0x443C0254u static void pad_probe(void) { volatile uint32_t tmp; /* Try a safe READ first. If this bus-faults, M7 has no read permission. */ tmp = sys_read32(PAD_CTL_GPIO_IO16); /* Try a write/restore. If only reads are allowed, this will bus-fault. */ sys_write32(tmp, PAD_CTL_GPIO_IO16); } /* The devicetree node identifier for the "led0" alias. */ #define LED0_NODE DT_ALIAS(led0) #if !DT_NODE_HAS_STATUS(LED0_NODE, okay) #error "Unsupported board: led0 devicetree alias is not defined" #endif static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios); int main(void) { int ret; printk("Entered Main Function\n"); if (!device_is_ready(led.port)) { printk("Error: LED device %s is not ready\n", led.port->name); return -1; } pad_probe(); ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE); if (ret < 0) { printk("Error %d: Failed to configure LED pin\n", ret); return ret; } printk("Starting to blink LED on pin %d\n", led.pin); while (1) { ret = gpio_pin_toggle_dt(&led); if (ret < 0) { printk("Error %d: Failed to toggle LED\n", ret); return ret; } printk("Toggled GPIO\n"); k_msleep(1000); } return 0; }
prj.conf文件
CONFIG_GPIO=y CONFIG_PINCTRL=y CONFIG_PRINTK=y CONFIG_STDOUT_CONSOLE=y CONFIG_LOG=y CONFIG_LOG_MODE_IMMEDIATE=y
内容的提问来源于stack exchange,提问作者Deepshika
相关产品推荐
相关产品推荐

