GPIO调试方法
提示:这里可以添加技术概要
例如:
openAI 的 GPT 大模型的发展历程。
kernel下调试gpio
简易版
cat /sys/kernel/debug/gpio | grep GPIOH_13
结果:gpio-496 (GPIOH_13 )
echo 496 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio496/direction
echo 1 > /sys/class/gpio/gpio496/value
1、496是代表GPIO ID,上面三条指令的GPIO ID注意保持一致
2、direction out代表输出,in代表输入,如果in,就用cat /sys/class/gpio/gpio496/value 获取值
3、value 1代表拉高,0代表拉低
详细版
1.首先获取想要控制的GPIO ID
举个栗子,我想在线调试 GPIOH_13
新增两个gpiochip
gpio-aw9523b 前置按键板上扩展GPIO P0.0对应gpio-200后续依次递增总共16个IO
MCU_GPIO MCU芯片上所有GPIO(有白名单限制,SOC实际只能控制部分IO,具体需要修改MCU。白名单用于防止SOC误操作到某些关键IO导致功能失效)PA0 对应gpio-300后续依次递增总共48个IO。
前置按键板
串口输入指令:
cat /sys/kernel/debug/gpio
gpiochip2: GPIOs 200-215, parent: i2c/3-005b, gpio-aw9523b:
gpiochip3: GPIOs 300-347, parent: no-bus/mcu_gpio_0, MCU_GPIO:
gpiochip1: GPIOs 373-375, parent: platform/fe000000.apb4:analog-pinctrl@4054, analog-banks:
gpio-373 (CDAC_IOUT )
gpio-374 (CVBS0 )
gpio-375 (CVBS1 )
gpiochip0: GPIOs 376-511, parent: platform/fe000000.apb4:pinctrl@4000, periphs-banks:
gpio-376 (GPIOB_0 )
gpio-377 (GPIOB_1 )
gpio-378 (GPIOB_2 )
gpio-379 (GPIOB_3 )
gpio-380 (GPIOB_4 )
gpio-381 (GPIOB_5 )
gpio-382 (GPIOB_6 )
gpio-383 (GPIOB_7 )
gpio-384 (GPIOB_8 )
gpio-385 (GPIOB_9 )
gpio-386 (GPIOB_10 )
gpio-387 (GPIOB_11 )
gpio-388 (GPIOB_12 )
gpio-389 (GPIOB_13 )
gpio-390 (GPIOC_0 )
gpio-391 (GPIOC_1 )
gpio-392 (GPIOC_2 )
gpio-393 (GPIOC_3 )
gpio-394 (GPIOC_4 )
gpio-395 (GPIOC_5 )
gpio-396 (GPIOC_6 )
gpio-397 (GPIOC_7 |sdio_wifi ) out hi
gpio-398 (GPIOC_8 |cam_rdv30_pwr ) out hi
gpio-399 (GPIOC_9 |wifi_rdv30_pwr ) out hi
gpio-400 (GPIOC_10 )
gpio-401 (GPIOC_11 |sdio_wifi ) out hi
gpio-402 (GPIOC_12 )
gpio-403 (GPIOC_13 |bt_rfkill ) out lo
gpio-404 (GPIOC_14 )
gpio-405 (GPIOC_15 )
gpio-406 (GPIOW_0 )
gpio-407 (GPIOW_1 )
gpio-408 (GPIOW_2 )
gpio-409 (GPIOW_3 )
gpio-410 (GPIOW_4 )
gpio-411 (GPIOW_5 )
gpio-412 (GPIOW_6 )
gpio-413 (GPIOW_7 )
gpio-414 (GPIOW_8 )
gpio-415 (GPIOW_9 )
gpio-416 (GPIOW_10 )
gpio-417 (GPIOW_11 )
gpio-418 (GPIOW_12 )
gpio-419 (GPIOD_0 )
gpio-420 (GPIOD_1 )
gpio-421 (GPIOD_2 )
gpio-422 (GPIOD_3 )
gpio-423 (GPIOD_4 )
gpio-424 (GPIOD_5 )
gpio-425 (GPIOD_6 )
gpio-426 (GPIOD_7 )
gpio-427 (GPIOD_8 |avout_mute ) out hi
gpio-428 (GPIOD_9 |ad82120-reset-pin ) out hi
gpio-429 (GPIOD_10 )
gpio-430 (GPIOE_0 )
gpio-431 (GPIOE_1 )
gpio-432 (GPIOZ_0 )
gpio-433 (GPIOZ_1 )
gpio-434 (GPIOZ_2 )
gpio-435 (GPIOZ_3 )
gpio-436 (GPIOZ_4 )
gpio-437 (GPIOZ_5 )
gpio-438 (GPIOZ_6 )
gpio-439 (GPIOZ_7 )
gpio-440 (GPIOZ_8 |flo_sw20_sel1 ) out lo
gpio-441 (GPIOZ_9 |flo_sw20_sel0 ) out lo
gpio-442 (GPIOZ_10 )
gpio-443 (GPIOZ_11 |cam_sw20_sel0 ) out lo
gpio-444 (GPIOZ_12 |cam_sw20_sel1 ) out hi
gpio-445 (GPIOZ_13 )
gpio-446 (GPIOZ_14 )
gpio-447 (GPIOZ_15 )
gpio-448 (GPIOZ_16 |side_sw20_sel ) out hi
gpio-449 (GPIOZ_17 |side_rdv30_pwr ) out lo
gpio-450 (GPIOZ_18 )
gpio-451 (GPIOZ_19 )
gpio-452 (GPIOM_0 )
gpio-453 (GPIOM_1 )
gpio-454 (GPIOM_2 )
gpio-455 (GPIOM_3 )
gpio-456 (GPIOM_4 )
gpio-457 (GPIOM_5 )
gpio-458 (GPIOM_6 )
gpio-459 (GPIOM_7 )
gpio-460 (GPIOM_8 |front_hub_reset ) out lo
gpio-461 (GPIOM_9 )
gpio-462 (GPIOM_10 |front_port_pwr ) out hi
gpio-463 (GPIOM_11 )
gpio-464 (GPIOM_12 )
gpio-465 (GPIOM_13 )
gpio-466 (GPIOM_14 )
gpio-467 (GPIOM_15 )
gpio-468 (GPIOM_16 )
gpio-469 (GPIOM_17 )
gpio-470 (GPIOM_18 )
gpio-471 (GPIOM_19 )
gpio-472 (GPIOM_20 )
gpio-473 (GPIOM_21 )
gpio-474 (GPIOM_22 )
gpio-475 (GPIOM_23 |front_rdv30_pwr ) out hi
gpio-476 (GPIOM_24 )
gpio-477 (GPIOM_25 |touchin_sw_sel ) out lo
gpio-478 (GPIOM_26 )
gpio-479 (GPIOM_27 )
gpio-480 (GPIOM_28 )
gpio-481 (GPIOM_29 )
gpio-482 (GPIOM_30 )
gpio-483 (GPIOH_0 )
gpio-484 (GPIOH_1 )
gpio-485 (GPIOH_2 )
gpio-486 (GPIOH_3 )
gpio-487 (GPIOH_4 )
gpio-488 (GPIOH_5 )
gpio-489 (GPIOH_6 )
gpio-490 (GPIOH_7 )
gpio-491 (GPIOH_8 )
gpio-492 (GPIOH_9 )
gpio-493 (GPIOH_10 )
gpio-494 (GPIOH_11 )
gpio-495 (GPIOH_12 )
gpio-496 (GPIOH_13 )
gpio-497 (GPIOH_14 )
gpio-498 (GPIOH_15 )
gpio-499 (GPIOH_16 )
gpio-500 (GPIOH_17 )
gpio-501 (GPIOH_18 )
gpio-502 (GPIOH_19 )
gpio-503 (GPIOH_20 )
gpio-504 (GPIOH_21 )
gpio-505 (GPIOH_22 )
gpio-506 (GPIOH_23 )
gpio-507 (GPIOH_24 |spi2.0 ) out hi
gpio-508 (GPIOH_25 )
gpio-509 (GPIOH_26 )
gpio-510 (GPIOH_27 )
gpio-511 (GPIO_TEST_N )
console:/ #
在这里能看到,GPIOH_13 对应的ID 是496
2.依次输入下面指令:
cd /sys/class/gpio/
echo 496 > export
然后检查下是否生成gpio496文件夹:
console:/sys/class/gpio # ls
export gpio496 gpiochip373 gpiochip376 unexport
console:/sys/class/gpio #
确认生成之后:
echo out > gpio496/direction(设置输出)
echo 1 > gpio496/value(设置1拉高)
如果gpio496文件夹没有生成成功,打开kernel log会有下面提示(下面是另外一个IO GPIOC_4):
1|console:/sys/class/gpio # echo 394 > export
[ 1617.349939@1] meson-t3-pinctrl fe000000.apb4:pinctrl@4000: pin GPIOC_4 already requested by fe08a000.sd; cannot claim for periphs-banks:394
[ 1617.357033@1] meson-t3-pinctrl fe000000.apb4:pinctrl@4000: pin-18 (periphs-banks:394) status -22
1|console:/sys/class/gpio #
这个报错打印说明这个GPIO已经被内核占用了资源没有释放,无法用串口调试,有必要的话,可以优化内核相关gpio使用的代码,在用到gpio处去申请gpio资源,使用完之后及时释放,这样我们能在内核释放gpio资源后在系统终端进行调试
uboot下调试gpio
上电后ctrl+c进控制台
敲gpio 会列出帮助信息
gpio status -a : 列出所有GPIO的状态
gpio input GPIOD_7 :设置GPIOD_7为输入状态(GPIOD_7可以用IO号替代)
gpio set GPIOD_7: 设置io状态为1
gpio clear GPIOD_7:设置io状态为0