I am trying to build a simple GPIO Toggle Example on the IMX6UL UltraLite Board.
I have had no success yet.
I have created a simple HelloWorld project.
But, I can not expand it to include GPIO Access.
I can Not figure out how to include files such as gpio.h
But all of these fail: <gpio.h> <Linux/gpio.h> "Linux/gpio.h" etc..
#include <stdio.h>
#include <gpio.h>
typedef unsigned long U32;
typedef unsigned short U16;
typedef unsigned char U8;
#define MX6SL_PAD_EPDC_SDCLK__GPIO1_IO23 0x110 0x400 0x000 0x5 0x0
// IOMUXC_SW_MUX_CTL_PAD_GPIO_1_23 = 20E_0000h base + 0x010
#define GPIO_1_23_MUX_CTL ( 0x2000000 + 0x0110 )
// IOMUXC_SW_PAD_CTL_PAD_GPIO_1_23 = 20E_0000h base + 0x000
#define GPIO_1_23_PAD_CTL ( 0x2000000 + 0x0400 )
// IOMUXC_SW_PAD_INPUT_GPIO_1_23 = 20E_0000h base + 0x0000
#define GPIO_1_23_INPUT ( 0x2000000 + 0x0000 )
// IOMUXC_SW_MUX_DATA_GPIO_1_23 = 0x05
#define GPIO_1_23_MUX_DATA ( 0x05 )
// IOMUXC_SW_CTL_DATA_GPIO_1_23 = 1 << 0x00
#define GPIO_1_23_CTL_DATA ( 0x01 << 0x00 )
#define MX6SL_PAD_EPDC_SDLE__GPIO1_IO24 0x114 0x404 0x000 0x5 0x0
#define MX6SL_PAD_EPDC_SDOE__GPIO1_IO25 0x118 0x408 0x000 0x5 0x0
#define MX6SL_PAD_EPDC_SDSHR__GPIO1_IO26 0x11c 0x40c 0x000 0x5 0x0
int _t_;
#define msleep(n) for(_t_=1; _t_<10000; _t_++){_t_=_t_;}
#define true 1
//#define IMX_GPIO_NR(port, index) ((((port)-1)*32)+((index)&31))
#define IMX_GPIO_NR(b,p) ( ((b - 1) * 32) + p )
int main(int argc, char **argv)
{
printf("Hello World!\n");
gpio_request(IMX_GPIO_NR(3, 11), "external_gpio_0");
gpio_export(IMX_GPIO_NR(3, 11), true);
gpio_request(IMX_GPIO_NR(3, 27), "external_gpio_1");
gpio_export(IMX_GPIO_NR(3, 27), true);
gpio_direction_output( IMX_GPIO_NR(1,0) , 1 );
msleep(300);
gpio_direction_output( IMX_GPIO_NR(2,18) , 1 );
msleep(300);
gpio_direction_output( IMX_GPIO_NR(2,19) , 1 );
msleep(300);
gpio_direction_output( IMX_GPIO_NR(1,20) , 0 );
gpio_direction_output( UART2_TX_DATA , 0 );
gpio_direction_output( IMX_GPIO_NR(1,21) , 0 );
gpio_direction_output( UART2_RX_DATA , 0 );
gpio_set_value(IMX_GPIO_NR(1, 0) , 1);
gpio_set_value(IMX_GPIO_NR(2, 18) , 1);
gpio_set_value(IMX_GPIO_NR(2, 19) , 1);
gpio_direction_output( IMX_GPIO_NR(1,23) , 1 );
gpio_set_value(IMX_GPIO_NR(1, 23) , 1);
msleep(1000);
gpio_set_value(IMX_GPIO_NR(1, 23) , 0);
msleep(1000);
gpio_set_value(IMX_GPIO_NR(1, 23) , 1);
msleep(1000);
gpio_export(IMX_GPIO_NR(1, 23), true);
gpio_direction_output( IMX_GPIO_NR(1,23) , 1 );
gpio_set_value(IMX_GPIO_NR(1, 23) , 1);
return 0;
}
I have also tried direct register access, but just got segment faults:
#include <stdio.h>
int main(int argc, char **argv)
{
printf("Hello World!\n");
//printf("\nset MUX\n");
// *((long*)0x0209C000??) = (5); // -set MUX
printf("\nset DIR\n");
*((long*)0x0209C004) = (1 << 23); // -set GPIO_1_23.Dir = 1
printf("\nset DATA 23\n");
*((long*)0x0209C000) = (1 << 23); // -set GPIO_1_23.Dat = 1
return 0;
}
Also this segmentation fault :
#include <stdio.h>
#define AIPS1_ARB_BASE_ADDR 0x02000000
#define AIPS1_ARB_END_ADDR 0x020FFFFF
#define AIPS2_ARB_BASE_ADDR 0x02100000
#define AIPS2_ARB_END_ADDR 0x021FFFFF
#define AIPS_TZ1_BASE_ADDR AIPS1_ARB_BASE_ADDR
#define AIPS_TZ2_BASE_ADDR AIPS2_ARB_BASE_ADDR
#define AIPS1_ON_BASE_ADDR (AIPS_TZ1_BASE_ADDR+0x7C000)
#define AIPS1_OFF_BASE_ADDR (AIPS_TZ1_BASE_ADDR+0x80000)
#define GPIO1_BASE_ADDR (AIPS1_OFF_BASE_ADDR+0x1C000)
#define IOMUXC_BASE_ADDR (AIPS1_OFF_BASE_ADDR+0x60000)
#define CCM_BASE_ADDR (AIPS1_OFF_BASE_ADDR+0x44000)
#define reg_32_CSU_SA (*(volatile U32*)(0x021C0218))
#define NSA_CP15 1
#define R32 (volatile unsigned long *)
#define R16 (volatile unsigned short *)
#define R8 (volatile unsigned char *)
typedef unsigned long U32;
typedef unsigned short U16;
typedef unsigned char U8;
int _t_;
#define msleep(n) for(_t_=1; _t_<10000; _t_++){_t_=_t_;}
#define true 1
int main(int argc, char **argv)
{
printf("Hello World!\n");
//Write to DIR register [DIR]
*R32(GPIO1_BASE_ADDR+4) = 0x00000004; // 1 : GPIO 1_2 - output
*R32 (GPIO1_BASE_ADDR) = 0x00000004; // 1 --> GPIO 1_2
*R32 ( GPIO1_BASE_ADDR) = 0 ; // 0 --> GPIO 1_2
return 0;
}
//
I also tried adding these lines below in the conf/bblayers.conf file, but still with No Results :
FILESPATH_append = "~/yocto_3.14.38-6UL/build/tmp/work/cortexa7hf-vfp-neon-poky-linux-gnueabi/linux-libc-headers/3.14-r0/linux-3.14/include/linux:"
FILESPATH_append = "~/yocto_3.14.38-6UL/build/tmp/work/cortexa7hf-vfp-neon-poky-linux-gnueabi/linux-libc-headers/3.14-r0/linux-3.14/include:"
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
FILESEXTRAPATHS_append = "~/yocto_3.14.38-6UL/build/tmp/work/cortexa7hf-vfp-neon-poky-linux-gnueabi/linux-libc-headers/3.14-r0/linux-3.14/include/linux:"
FILESEXTRAPATHS_append = "~/yocto_3.14.38-6UL/build/tmp/work/cortexa7hf-vfp-neon-poky-linux-gnueabi/linux-libc-headers/3.14-r0/linux-3.14/include:"
SRC_URI += "~/yocto_3.14.38-6UL/build/tmp/work/cortexa7hf-vfp-neon-poky-linux-gnueabi/linux-libc-headers/3.14-r0/linux-3.14/include/linux/gpio.h"