参考:https://developer.ridgerun.com/wiki/index.php/How_to_use_GPIO_signals
#!/bin/sh show_usage() { printf "\ngpio.sh <gpio pin number> [in|out [<value>]]\n" } if [ \( $# -eq 0 \) -o \( $# -gt 3 \) ] ; then show_usage printf "\n\nERROR: incorrect number of parameters\n" exit 255 fi #doesn't hurt to export a gpio more than once echo $1 > /sys/class/gpio/export if [ $# -eq 1 ] ; then cat /sys/class/gpio/gpio$1/value exit 0 fi if [ \( "$2" != "in" \) -a \( "$2" != "out" \) ] ; then show_usage printf "\n\nERROR: second parameter must be 'in' or 'out'\n" exit 255 fi echo $2 > /sys/class/gpio/gpio$1/direction if [ $# -eq 2 ] ; then cat /sys/class/gpio/gpio$1/value exit 0 fi VAL=$3 if [ $VAL -ne 0 ] ; then VAL=1 fi echo $VAL > /sys/class/gpio/gpio$1/value
问题:1、GPIO value值设置无反应?
解:(1) Linux加打印查看值是否有设下去,打印出GPIO相关寄存器的值;
static int davinci_gpio_get(struct gpio_chip *chip, unsigned offset) { int tmp; struct davinci_gpio *d = container_of(chip, struct davinci_gpio, chip); struct gpio_controller *__iomem g = d->regs; /* return (1 << offset) & __raw_readl(&g->in_data); */ tmp = (1 << offset) & __raw_readl(&g->in_data); printk("##### GPIO_GET val[0x%08x] ####\n", tmp); printk("########set_data[0x%08x], out_data[0x%08x], dir[0x%08x], in_data[0x%08x], clr_data[0x%08x]####\n", g->set_data, g->out_data, g->dir, g->in_data, g->clr_data ); return tmp; }
/* * Assuming the pin is muxed as a gpio output, set its output value. */ static void davinci_gpio_set(struct gpio_chip *chip, unsigned offset, int value) { struct davinci_gpio *d = container_of(chip, struct davinci_gpio, chip); struct gpio_controller *__iomem g = d->regs; printk("########GPIO_SET Val[0x%08x] ####\n", value); printk("########set_data[0x%08x], out_data[0x%08x], dir[0x%08x], in_data[0x%08x], clr_data[0x%08x]####\n", g->set_data, g->out_data, g->dir, g->in_data, g->clr_data ); __raw_writel((1 << offset), value ? &g->set_data : &g->clr_data); }
(2) 对应的GPIO PIN MUX是否设置正确;
(3) GPIO方向是否设置正确;
GPIO 参考:
DM365 GPIO
http://blog.163.com/laorenyuhai126@126/blog/static/193507792011328213983/
sys接口概述
http://processors.wiki.ti.com/index.php/Linux_PSP_GPIO_Driver_Guide
https://blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:gpio-sysfs