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.

beagleboneblack 使用gpiod_direction_output(gpio_rset,1)函数不起作用



gpiod_direction_output(gpio_rset,1)成功返回0,但是引脚电压并没有发生变化。在终端向该GPIO口写0或者写1是没有问题的。

  • &spi1{
    status = "okay";
    pinctrl-names = "default";
    pinctrl-0 = <&spi1_pins>;

    wilc_spi: wilc_spi@0 {
    status = "okay";
    compatible = "microchip,wilc3000";
    spi-max-frequency = <6000000>;
    reg = <0>;
    reset-gpios = <&gpio3 19 1>;
    chip_en-gpios = <&gpio3 21 1>;
    irq-gpios = <&gpio1 17 0>;
    /*reset-gpios = <&reset_pins>;
    chip_en-gpios = <&chipen_pins>;
    irq-gpios = <&irq_pins>;*/
    };
    };
    上面是设备树的配置

    #define GPIO_NUM_CHIP_EN 117
    #define GPIO_NUM_RESET 115
    这是在源码中使用的GPIO
  • 请问是用的哪个GPIO?终端操作指令部分也贴出来看一下。
  • 使用的是GPIO3_21和GPIO3_19
    终端指令echo 117 > export
    echo out > direction
    echo 1 > value
  • static int wilc_wlan_power(struct wilc *wilc, int power)
    {
    struct gpio_desc *gpio_reset;
    struct gpio_desc *gpio_chip_en;
    int ret = 0;

    pr_info("wifi_pm : %d\n", power);

    gpio_reset = gpiod_get(wilc->dt_dev, "reset", GPIOD_ASIS);
    if (IS_ERR(gpio_reset)) {
    dev_warn(wilc->dev, "failed to get Reset GPIO, try default\r\n");
    gpio_reset = gpio_to_desc(GPIO_NUM_RESET);
    if (!gpio_reset) {
    dev_warn(wilc->dev,
    "failed to get default Reset GPIO\r\n");
    return -EIO;
    }
    } else {
    dev_info(wilc->dev, "succesfully got gpio_reset\r\n");
    }

    gpio_chip_en = gpiod_get(wilc->dt_dev, "chip_en", GPIOD_ASIS);
    if (IS_ERR(gpio_chip_en)) {
    gpio_chip_en = gpio_to_desc(GPIO_NUM_CHIP_EN);
    if (!gpio_chip_en) {
    dev_warn(wilc->dev,
    "failed to get default chip_en GPIO\r\n");
    gpiod_put(gpio_reset);
    return -EIO;
    }
    } else {
    dev_info(wilc->dev, "succesfully got gpio_chip_en\r\n");
    }

    if (power) {
    ret = gpiod_direction_output(gpio_chip_en, 1);
    if (ret < 0) {
    dev_warn(wilc->dev,
    "failed to set chip_en GPIO direction\r\n");
    goto out;
    ret = -EIO;
    }
    mdelay(5);
    ret = gpiod_direction_output(gpio_reset, 1);
    if (ret) {
    dev_warn(wilc->dev,
    "failed to set reset GPIO direction\r\n");
    goto out;
    ret = -EIO;
    }
    if (gpiod_get_value(gpio_chip_en) == 1) {
    dev_warn(wilc->dev,
    "wilc en ok\r\n");
    }
    else
    {
    dev_warn(wilc->dev,
    "wilc en not ok\r\n");
    }
    if (gpiod_get_value(gpio_reset) == 1) {
    dev_warn(wilc->dev,
    "wilc reset ok\r\n");
    }
    else
    {
    dev_warn(wilc->dev,
    "wilc reset not ok\r\n");
    }
    } else {
    ret = gpiod_direction_output(gpio_reset, 0);
    if (ret) {
    dev_warn(wilc->dev,
    "failed to set chip_en GPIO direction\r\n");
    goto out;
    ret = -EIO;
    }
    ret = gpiod_direction_output(gpio_chip_en, 0);
    if (ret) {
    dev_warn(wilc->dev,
    "failed to set reset GPIO direction\r\n");
    goto out;
    ret = -EIO;
    }
    }

    out:
    gpiod_put(gpio_chip_en);
    gpiod_put(gpio_reset);

    return ret;
    }


    这个就是源码,我用终端控制GPIO写1,然后用这个函数写0是可以的,但是写1不行
  • gpiod_put(gpio_chip_en);后GPIO就没有输出了
  • user6394011 说:

    我用终端控制GPIO写1,然后用这个函数写0是可以的,但是写1不行

    你的意思是终端不可以控制,但是通过写死程序可以控制吗?

  • 是终端可以,使用程序gpiod_put(gpio_chip_en);后GPIO就没有输出了
  • 请问你是要用GPIO来模拟spi信号?上面贴出的源码部分是哪里的代码?