This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

am3358上在用户空间操作gpio时为啥默认是输出低电平?



在/sys/class/gpio/下操作export,以及对应gpion文件夹下的direction

譬如,当echo “out”  > direction时,引脚自动变成低电平了,是否可以修改这个默认状态?

  • 不建议这样改动,会带来一定危险性,

    如果你要特定某一个引脚默认输出高电平,可以在内核引导的时候,配置该引脚输出高电平,在devicetree文件修改,如gpio0_7,增加:

    &gpio0 {
    /* Do not idle the GPIO used for holding the VTT regulator */
    ti,no-reset-on-init;
    ti,no-idle-on-init;

    p7 {
    gpio-hog;
    gpios = <7 GPIO_ACTIVE_HIGH>;
    output-high;
    line-name = "FET_SWITCH_CTRL";
    };
    };

  • 你好,这样的话,sys/class/gpio就不能再导出对应的gpio了,也就是不能通过echo "out" > direction和echo 0 > value或者echo 1 > value来控制了。我其实目的是,当我执行“echo "out" > direction”时,gpio0_2引脚不要自作聪明地帮我输出低电平,而是要输出高电平或者保持原本电平。

  • 我找到答案了,只需执行“echo “high”  > direction ”即可设置为输出同时输出高电平!!而"echo “out”  > direction"等效于"echo “low”  > direction"