Sample scripts for the MCU SDK

This section contains the sample scripts for the MCU SDK referenced in the code examples, as well as download links for convenience.

Script Download Link
init_DIG.sh http://downloadmirror.intel.com/24910/eng/init_DIG.sh
init_i2c8.sh http://downloadmirror.intel.com/24910/eng/init_i2c8.sh
init_mcu_PWM.sh http://downloadmirror.intel.com/24910/eng/init_mcu_PWM.sh
set_DIG.sh http://downloadmirror.intel.com/24910/eng/set_DIG.sh
read_DIG.sh http://downloadmirror.intel.com/24910/eng/read_DIG.sh
init_UART1.sh http://downloadmirror.intel.com/24910/eng/init_UART1.sh

init_DIG.sh

This shell script is available from the following location: http://downloadmirror.intel.com/24910/eng/init_DIG.sh

#!/bin/sh
#author: David Pierret (davidx.pierret@intel.com)
#this script setup Edison/Arduino board to use DIG0 to DIG13 as GPIOs
#
#history
#
# V1 : only use debugfs for SoC gpios
# V2 : only use sysfs for SoC gpios
# V3 : use both debugfs and sysfs for SoC gpios
# V4 : correction of bugs.

DIG=""
DIR=""

usage() {
echo "usage $0 -o [num] -d [direction]" >&2
echo "work only on build edison-latest-99-2014-07-16_14-39-50 and next"
echo "num : number of the digital output 0->13" >&2
echo "direction : 'input' or 'output'" >&2
exit 1
}

export_gpio() {
        if [ $# -ne 1 ]; then
                echo "erreur appel fonction $0"
                exit 2
        fi
        if [ ! -d /sys/class/gpio/gpio$1 ]; then
                echo $1 > /sys/class/gpio/export
        fi
}

while getopts "o:(output)d:(direction)" optname
        do
                case "$optname" in
        "o")
                        DIG=$OPTARG
          ;;
        "d")
                        DIR=$OPTARG
          ;;
        "?")
                        usage
          ;;
        ":")
                        usage
          ;;
        *)
        # Should not occur
          echo "Unknown error while processing options"
          ;;
                esac
        done

echo "DIG = $DIG"
echo "DIR = $DIR"
# check the dig number var
if [ ! "$DIG" -ge 0 -a "$DIG" -le 13 ]; then
        usage
fi
# check the direction var
if [ "$DIR" != "output" -a "$DIR" != "input" ]; then
        usage
fi

export_gpio 214

echo low > /sys/class/gpio/gpio214/direction

case $DIG in
#gp130 to DIG0
0)
        export_gpio 248
        echo mode0 > /sys/kernel/debug/gpio_debug/gpio130/current_pinmux
        if [ $DIR == "output" ]; then
                echo high > /sys/class/gpio/gpio248/direction #config as output
                echo out > /sys/class/gpio/gpio130/direction
        else
                echo low > /sys/class/gpio/gpio248/direction #config as input
                echo in > /sys/class/gpio/gpio130/direction
        fi
;;

#gp131 to DIG1
1)
        export_gpio 249
        echo mode0 > /sys/kernel/debug/gpio_debug/gpio131/current_pinmux
        if [ $DIR == "output" ]; then
                echo high > /sys/class/gpio/gpio249/direction #config as output
                echo out > /sys/class/gpio/gpio131/direction
        else
                echo low > /sys/class/gpio/gpio249/direction #config as input
                echo in > /sys/class/gpio/gpio131/direction
        fi
;;

#gp128 to DIG2
2)
        export_gpio 250
        echo mode0 > /sys/kernel/debug/gpio_debug/gpio128/current_pinmux
        if [ $DIR == "output" ]; then
                echo high > /sys/class/gpio/gpio250/direction #config as output
                echo out > /sys/class/gpio/gpio128/direction
        else
                echo low > /sys/class/gpio/gpio250/direction #config as input
                echo in > /sys/class/gpio/gpio128/direction
        fi
;;

#gp12 to DIG3
3)
        export_gpio 251
        export_gpio 12
        echo mode0 > /sys/kernel/debug/gpio_debug/gpio12/current_pinmux
        if [ $DIR == "output" ]; then
                echo high > /sys/class/gpio/gpio251/direction #config as output
                echo out > /sys/class/gpio/gpio12/direction
        else
                echo low > /sys/class/gpio/gpio251/direction #config as input
                echo in > /sys/class/gpio/gpio12/direction
        fi
;;

#gp129 to DIG4
4)
        export_gpio 252
        echo mode0 > /sys/kernel/debug/gpio_debug/gpio129/current_pinmux
        if [ $DIR == "output" ]; then
                echo high > /sys/class/gpio/gpio252/direction #config as output
                echo out > /sys/class/gpio/gpio129/direction
        else
                echo low > /sys/class/gpio/gpio252/direction #config as input
                echo in > /sys/class/gpio/gpio129/direction
        fi
;;

#gp13 to DIG5
5)
        export_gpio 253
        export_gpio 13
        echo mode0 > /sys/kernel/debug/gpio_debug/gpio13/current_pinmux
        if [ $DIR == "output" ]; then
                echo high > /sys/class/gpio/gpio253/direction #config as output
                echo out > /sys/class/gpio/gpio13/direction
        else
                echo low > /sys/class/gpio/gpio253/direction #config as input
                echo in > /sys/class/gpio/gpio13/direction
        fi
;;

#gp182 to DIG6
6)
        export_gpio 254
        export_gpio 182
        echo mode0 > /sys/kernel/debug/gpio_debug/gpio182/current_pinmux
        if [ $DIR == "output" ]; then
                echo high > /sys/class/gpio/gpio254/direction #config as output
                echo out > /sys/class/gpio/gpio182/direction
        else
                echo low > /sys/class/gpio/gpio254/direction #config as input
                echo in > /sys/class/gpio/gpio182/direction
        fi
;;

#gp48 to DIG7
7)
        export_gpio 255
        export_gpio 48
        echo mode0 > /sys/kernel/debug/gpio_debug/gpio48/current_pinmux
        if [ $DIR == "output" ]; then
                echo high > /sys/class/gpio/gpio255/direction #config as output
                echo out > /sys/class/gpio/gpio48/direction
        else
                echo low > /sys/class/gpio/gpio255/direction #config as input
                echo in > /sys/class/gpio/gpio48/direction
        fi
;;

#gp49 to DIG8
8)
        export_gpio 256
        export_gpio 49
        echo mode0 > /sys/kernel/debug/gpio_debug/gpio49/current_pinmux
        if [ $DIR == "output" ]; then
                echo high > /sys/class/gpio/gpio256/direction #config as output
                echo out > /sys/class/gpio/gpio49/direction
        else
                echo low > /sys/class/gpio/gpio256/direction #config as input
                echo in > /sys/class/gpio/gpio49/direction
        fi
;;

#gp183 to DIG9
9)
        export_gpio 257
        export_gpio 183
        echo mode0 > /sys/kernel/debug/gpio_debug/gpio183/current_pinmux
        if [ $DIR == "output" ]; then
                echo high > /sys/class/gpio/gpio257/direction #config as output
                echo out > /sys/class/gpio/gpio183/direction
        else
                echo low > /sys/class/gpio/gpio257/direction #config as input
                echo in > /sys/class/gpio/gpio183/direction
        fi
;;

#gp41 to DIG10
10)
        export_gpio 258
        export_gpio 240
        export_gpio 263
        echo low > /sys/class/gpio/gpio240/direction
        echo high > /sys/class/gpio/gpio263/direction

        if [ ! -d /sys/class/gpio/gpio41 ]; then
                echo 41 > /sys/class/gpio/export
        fi
        echo mode0 > /sys/kernel/debug/gpio_debug/gpio41/current_pinmux
        if [ $DIR == "output" ]; then
                echo high > /sys/class/gpio/gpio258/direction #config as output
                echo out > /sys/class/gpio/gpio41/direction
        else
                echo low > /sys/class/gpio/gpio258/direction #config as input
                echo in > /sys/class/gpio/gpio41/direction
        fi
;;

#gp43 to DIG11
11)
        export_gpio 259
        export_gpio 241
        export_gpio 262
        export_gpio 43
        echo low > /sys/class/gpio/gpio241/direction
        echo high > /sys/class/gpio/gpio262/direction
        
        echo mode0 > /sys/kernel/debug/gpio_debug/gpio43/current_pinmux
        if [ $DIR == "output" ]; then
                echo high > /sys/class/gpio/gpio259/direction #config as output
                echo out > /sys/class/gpio/gpio43/direction
        else
                echo low > /sys/class/gpio/gpio259/direction #config as input
                echo in > /sys/class/gpio/gpio43/direction
        fi
;;

#gp42 to DIG12
12)
        export_gpio 260
        export_gpio 242
        export_gpio 42
        echo low > /sys/class/gpio/gpio242/direction
        echo mode0 > /sys/kernel/debug/gpio_debug/gpio42/current_pinmux
        if [ $DIR == "output" ]; then
                echo high > /sys/class/gpio/gpio260/direction #config as output
                echo out > /sys/class/gpio/gpio42/direction
        else
                echo low > /sys/class/gpio/gpio260/direction #config as input
                echo in > /sys/class/gpio/gpio42/direction
        fi
;;

#gp40 to DIG13
13)
        export_gpio 261
        export_gpio 243
        export_gpio 40
        echo low > /sys/class/gpio/gpio243/direction
        echo mode0 > /sys/kernel/debug/gpio_debug/gpio40/current_pinmux
        if [ $DIR == "output" ]; then
                echo high > /sys/class/gpio/gpio261/direction #config as output
                echo out > /sys/class/gpio/gpio40/direction
        else
                echo low > /sys/class/gpio/gpio261/direction #config as input
                echo in > /sys/class/gpio/gpio40/direction
        fi
;;
*) 
        usage
;;
esac

echo high > /sys/class/gpio/gpio214/direction

init_i2c8.sh

This shell script is available from the following location: http://downloadmirror.intel.com/24910/eng/init_i2c8.sh

echo 28 > /sys/class/gpio/export
echo 27 > /sys/class/gpio/export
echo 204 > /sys/class/gpio/export
echo 205 > /sys/class/gpio/export
echo 236 > /sys/class/gpio/export
echo 237 > /sys/class/gpio/export
echo 14 > /sys/class/gpio/export
echo 165 > /sys/class/gpio/export
echo 212 > /sys/class/gpio/export
echo 213 > /sys/class/gpio/export
if [ ! -d /sys/class/gpio/gpio214 ]; then
        echo 214 > /sys/class/gpio/export
fi
echo high > /sys/class/gpio/gpio214/direction
echo low > /sys/class/gpio/gpio204/direction
echo low > /sys/class/gpio/gpio205/direction
echo in > /sys/class/gpio/gpio14/direction
echo in > /sys/class/gpio/gpio165/direction
echo low > /sys/class/gpio/gpio236/direction
echo low > /sys/class/gpio/gpio237/direction
echo in > /sys/class/gpio/gpio212/direction
echo in > /sys/class/gpio/gpio213/direction
echo mode2 > /sys/kernel/debug/gpio_debug/gpio28/current_pinmux
echo mode2 > /sys/kernel/debug/gpio_debug/gpio27/current_pinmux

init_mcu_PWM.sh

This shell script is available from the following location: http://downloadmirror.intel.com/24910/eng/init_mcu_PWM.sh

#!/bin/sh
#based on exemple from GSG_GPIO_PinMux_Control_FabB.pdf Intel internal document.
#exporting TRI_STATE_ALL
if [ ! -d /sys/class/gpio/gpio214 ]; then
        echo 214 > /sys/class/gpio/export
fi
echo low > /sys/class/gpio/gpio214/direction
#PWM 0 to DIG3
echo 251 > /sys/class/gpio/export
echo 219 > /sys/class/gpio/export
echo high > /sys/class/gpio/gpio251/direction
echo in > /sys/class/gpio/gpio219/direction

#PWM 1 to DIG5
echo 253 > /sys/class/gpio/export
echo 221 > /sys/class/gpio/export
echo high > /sys/class/gpio/gpio253/direction
echo in > /sys/class/gpio/gpio221/direction

#PWM 2 to DIG6
echo 254 > /sys/class/gpio/export
echo 222 > /sys/class/gpio/export
echo high > /sys/class/gpio/gpio254/direction
echo in > /sys/class/gpio/gpio222/direction

#PWM 3 to DIG9
echo 257 > /sys/class/gpio/export
echo 225 > /sys/class/gpio/export
echo high > /sys/class/gpio/gpio257/direction
echo in > /sys/class/gpio/gpio225/direction

#PWM 4 to DIG10 (PWM2)
#echo 263 > /sys/class/gpio/export
#echo 258 > /sys/class/gpio/export
#echo 225 > /sys/class/gpio/export
#echo high > /sys/class/gpio/gpio214/direction
#echo high > /sys/class/gpio/gpio263/direction
#echo high > /sys/class/gpio/gpio258/direction
#echo in > /sys/class/gpio/gpio226/direction
#echo mode1 > /sys/kernel/debug/gpio_debug/gpio182/current_pinmux
#echo low > /sys/class/gpio/gpio214/direction
#echo 2 > /sys/class/pwm/pwmchip0/export

echo high > /sys/class/gpio/gpio214/direction

set_DIG.sh

This shell script is available from the following location: http://downloadmirror.intel.com/24910/eng/set_DIG.sh

#!/bin/sh
#author: David Pierret (davidx.pierret@intel.com)
#this script setup Edison/Arduino board to use DIG0 to DIG13 as GPIOs

DIG=""
VAL=""

usage() {
echo "usage $0 -o [num] -v [value]" >&2
echo "init_DIG.sh must be called before"
echo "num : number of the digital output 0->13" >&2
echo "value : 'low' or 'high'" >&2
exit 1
}

## set_output [mux] [gpio] [value]
## [mux] gpio to check to control level switcher
## [gpio] gpio number to read
## [value] value to apply
set_output() {
        if [ $# -ne 3 ]; then
                echo "erreur appel fonction $0"
                exit 2
        fi
        if [ ! -d /sys/class/gpio/gpio$1 ]; then
                usage
        fi
        if [ ! $(cat /sys/class/gpio/gpio$1/direction) == "out" ]; then
                usage
        fi
#       echo $VAL > /sys/kernel/debug/gpio_debug/gpio130/current_value
        echo $3 > /sys/class/gpio/gpio$2/direction
}

while getopts "o:(output)v:(value)" optname
        do
                case "$optname" in
        "o")
                        DIG=$OPTARG
          ;;
        "v")
                        VAL=$OPTARG
          ;;
        "?")
                        usage
          ;;
        ":")
                        usage
          ;;
        *)
        # Should not occur
          echo "Unknown error while processing options"
          ;;
                esac
        done


echo "DIG = $DIG"
echo "VAL = $VAL"
# check the dig number var
if [ ! "$DIG" -ge 0 -a "$DIG" -le 13 ]; then
        usage
fi
# check the direction var
if [ "$VAL" != "high" -a "$VAL" != "low" ]; then
        usage
fi

if [ ! -d /sys/class/gpio/gpio214 ]; then
        echo 214 > /sys/class/gpio/export
fi
echo low > /sys/class/gpio/gpio214/direction

case $DIG in
#gp130 to DIG0
0)
        set_output 248 130 $VAL
;;
#gp131 to DIG1
1)
        set_output 249 131 $VAL

;;

#gp128 to DIG2
2)
        set_output 250 128 $VAL
;;

#gp12 to DIG3
3)
        set_output 251 12 $VAL
;;

#gp129 to DIG4
4)
        set_output 252 129 $VAL
;;

#gp13 to DIG5
5)
        set_output 253 13 $VAL
;;

#gp182 to DIG6
6)
        set_output 254 182 $VAL

;;

#gp48 to DIG7
7)
        set_output 255 48 $VAL
;;

#gp49 to DIG8
8)
        set_output 256 49 $VAL
;;

#gp183 to DIG9
9)
        set_output 257 183 $VAL
;;

#gp41 to DIG10
10)
        set_output 258 41 $VAL
;;

#gp43 to DIG11
11)
        set_output 259 43 $VAL
;;

#gp42 to DIG12
12)
        set_output 260 42 $VAL
;;

#gp40 to DIG13
13)
        set_output 261 40 $VAL
;;

*) 
        usage
;;

esac

echo high > /sys/class/gpio/gpio214/direction

read_DIG.sh

This shell script is available from the following location: http://downloadmirror.intel.com/24910/eng/read_DIG.sh

#!/bin/sh
#author: David Pierret (davidx.pierret@intel.com)
#this script setup Edison/Arduino board to use DIG0 to DIG13 as GPIOs

DIG=""
VAL=""

usage() {
echo "usage $0 -o [num]" >&2
echo "init_DIG.sh must be called before"
echo "num : number of the digital input 0->13" >&2
exit 1
}

## set_output [mux] [gpio]
## [mux] gpio to check to control level switcher
## [gpio] gpio number to read
read_input() {
        if [ $# -ne 2 ]; then
                echo "erreur appel fonction $0"
                exit 2
        fi
        if [ ! -d /sys/class/gpio/gpio$1 ]; then
                usage
        fi
        if [ ! $(cat /sys/class/gpio/gpio$1/direction) == "out" ]; then
                usage
        fi
#       cat /sys/kernel/debug/gpio_debug/gpio$2/current_value
        cat /sys/class/gpio/gpio$2/value
}

while getopts "o:(output)" optname
        do
                case "$optname" in
        "o")
                        DIG=$OPTARG
          ;;
        "?")
                        usage
          ;;
        ":")
                        usage
          ;;
        *)
        # Should not occur
          echo "Unknown error while processing options"
          ;;
                esac
        done

# check the dig number var
if [ ! "$DIG" -ge 0 -a "$DIG" -le 13 ]; then
        usage
fi

if [ ! -d /sys/class/gpio/gpio214 ]; then
        echo 214 > /sys/class/gpio/export
fi
echo high > /sys/class/gpio/gpio214/direction

case $DIG in
#gp130 to DIG0
0)
        read_input 248 130
;;
#gp131 to DIG1
1)
        read_input 249 131

;;

#gp128 to DIG2
2)
        read_input 250 128
;;

#gp12 to DIG3
3)
        read_input 251 12
;;

#gp129 to DIG4
4)
        read_input 252 129
;;

#gp13 to DIG5
5)
        read_input 253 13
;;

#gp182 to DIG6
6)
        read_input 254 182

;;

#gp48 to DIG7
7)
        read_input 255 48
;;

#gp49 to DIG8
8)
        read_input 256 49
;;

#gp183 to DIG9
9)
        read_input 257 183
;;

#gp41 to DIG10
10)
        read_input 258 41
;;

#gp43 to DIG11
11)
        read_input 259 43
;;

#gp42 to DIG12
12)
        read_input 260 42
;;

#gp40 to DIG13
13)
        read_input 261 40
;;

*) 
        usage
;;

esac

echo low > /sys/class/gpio/gpio214/direction

init_UART1.sh

This shell script is available from the following location: http://downloadmirror.intel.com/24910/eng/init_UART1.sh

#!/bin/sh
#author:Jiujin Hong (Jiujinx.hong@intel.com)
#
#this script setup Edison/Arduino board to use DIG0/DIG1 as UART1 RX/UART1 TX
#
#

export_gpio() {
        if [ $# -ne 1 ]; then
                echo "erreur appel fonction $0"
                exit 2
        fi
        if [ ! -d /sys/class/gpio/gpio$1 ]; then
                echo $1 > /sys/class/gpio/export
        fi
}

export_gpio 214
echo low > /sys/class/gpio/gpio214/direction

#config DIG0 UART1 RX mode and level shiffter
export_gpio 248
echo mode1 > /sys/kernel/debug/gpio_debug/gpio130/current_pinmux
echo low > /sys/class/gpio/gpio248/direction #config as input
echo in > /sys/class/gpio/gpio130/direction

#config DIG1 UART1 RX mode and level shiffter
export_gpio 249
echo mode1 > /sys/kernel/debug/gpio_debug/gpio131/current_pinmux
echo high > /sys/class/gpio/gpio249/direction #config as output
echo out > /sys/class/gpio/gpio131/direction

echo high > /sys/class/gpio/gpio214/direction
For more complete information about compiler optimizations, see our Optimization Notice.