From: Nicola <pa...@li...> - 2012-08-14 19:41:44
|
This is one way for direct-register access control of the GPIO ARM interface of the Gumstix Overo Water. I mounted the Gumstix on a TOBI board for connections. I obtained to control the gpio_186 digital pin. The procedure can be easily extended to the other digital pins. I haven't recompiled the kernel or touched the setup files or the pre-existing drivers... nothing of this. This is my recipe: 1) install on a formatted SD card the stable Gumstix armstrong linux version ( see http://gumstix.org/get-started/how-to.html ) 2) connect your Overo Water + Tobi system on Internet by LAN cable 3) connect the Gumstix to your windows PC by the USB cable and by the software putty.exe, open a control windows selecting an emulated serial connection (see putty instructions) 3) Check the internet link, use ( on the Gumstix ) ifconfig eth1 192.168.0.5 netmask 255.255.255.0 or whatever the desired IP address+netmask for connecting the Gumstix @ your router 4) install the C cross compiler : $ echo 'src/gz angstrom-base http://www.angstrom-distribution.org/feeds/unstable/ipk/glibc/armv7a/base' > /etc/opkg/angstrom-base.conf $ opkg update $ opkg install task-native-sdk or better use $ opkg update $ opkg install task-native-sdk for updating all the software. 5) Reboot the gustix 6) Put the following code on your home directory ( or wherewer you prefer ) editing it with VI main.c or with any other any other editor you like. I use normally Eclipse for editing my software on the PC and transferring it to the remote system (the Gumstix) ( contact me if you want more info on this); call the file "main.c" /**************************************************************************************** LOCAL INCLUDES DEFINITION ****************************************************************************************/ #include <stdio.h> #include "init_mem.h" #include "init_SPI_1.h" #include <fcntl.h> //ok for mmap param #include <sys/mman.h> //ok for mmap /**************************************************************************************** LOCAL PARAMETERS DEFINITION ****************************************************************************************/ #define SCM_INTERFACE_BASE 0x48002000 #define SCM_PADCONFS_BASE 0x48002030 #define CONTROL_PADCONF_SYS_NIRQ (*(volatile unsigned long *)0x480021E0) #define CONTROL_PADCONF_SYS_NIRQ_OFFSET 0x1B0 #define GPIO6_BASE 0x49058000 #define GPIO6_SYSCONFIG_OFFSET 0x10 #define GPIO6_CLEARDATAOUT_OFFSET 0x90 #define GPIO6_SETDATAOUT_OFFSET 0x94 #define GPIO6_OE_OFFSET 0x34 #define GPIO6_CTRL_OFFSET 0x30 #define MAP_SIZE (volatile unsigned long) 4*1024 #define MAP_MASK (volatile unsigned long)( MAP_SIZE - 1 ) /**************************************************************************************** COMMON VARIABLES DEFINITION ****************************************************************************************/ #define u32 volatile unsigned long u32 *A; u32 *B; /**************************************************************************************** LOCAL FUNCTIONS DEFINITION ****************************************************************************************/ /**************************************************************************************** Function name: int main(void) Last modification: 04/08/2012 Version: 1.10 Notes: ****************************************************************************************/ int main(void){ unsigned long i; int fd; printf("\n\n\n\n\n\n\n"); printf("\n\n"); printf(" ------------------------------------------\n"); printf(" | SPI Sample |\n"); printf(" ------------------------------------------\n"); printf(" | Direct Register Access GPIO |\n"); printf(" ------------------------------------------\n"); printf("Base address GPIO6: 0x%04x\n",(GPIO6_BASE ));// OK printf("\n"); fd = open("/dev/mem", O_RDWR | O_SYNC); if (fd < 0) {printf("Could not open file\n"); return;} A = (u32 *) mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, SCM_INTERFACE_BASE & ~MAP_MASK); if (A == MAP_FAILED) {printf("Mapping failed value 0x%04x\n",A); close(fd); return;} // %d.\n if (A<=0) {printf("Mapping failed\n"); close(fd); return;} printf("SCM_SCM_BASE 0x%08x\n",SCM_INTERFACE_BASE); printf("SCM_PADCONFS_BASE 0x%08x\n",SCM_INTERFACE_BASE+0x30); printf("SCM_PADCONFS offset 0x%08x\n",CONTROL_PADCONF_SYS_NIRQ_OFFSET); printf("Pointer: 0x%08x\n",(u32) A); printf("Pointer+offset: 0x%08x\n",(u32)A+0x30+CONTROL_PADCONF_SYS_NIRQ_OFFSET ); printf("Pointer+offset content: 0x%08x\n",*(u32 *)((u32)A+0x30+CONTROL_PADCONF_SYS_NIRQ_OFFSET) ); *(u32 *)((u32)A+0x30+CONTROL_PADCONF_SYS_NIRQ_OFFSET)|=(0b100<<16); // imposta mode 4 sul registro configurazione pad 186; abilita uso pin digitale close(fd); printf("PAD configuration done.\n",MAP_SIZE); /************************************************/ fd = open("/dev/mem", O_RDWR | O_SYNC); if (fd < 0) {printf("Could not open file\n"); return;} B = (volatile unsigned long*) mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, GPIO6_BASE & ~MAP_MASK); // COM1 0x4806A000 if (B == MAP_FAILED) {printf("Mapping failed value 0x%04x\n",B); close(fd); return;} // %d.\n if (B<=0) {printf("Mapping failed\n"); close(fd); return;} printf("Map_Size: 0x%08x ",MAP_SIZE); printf("Map_Mask: 0x%08x ",MAP_MASK); printf("Map_Mask: Reverse 0x%08x\n",~MAP_MASK); printf("Base address: 0x%08x ",(GPIO6_BASE & ~MAP_MASK)); printf("Offset: 0x%08x ",GPIO6_CTRL_OFFSET); printf("Base address+offset: 0x%08x\n",(GPIO6_BASE +GPIO6_CTRL_OFFSET)); printf("Pointer: 0x%08x\n",(u32)B); // gpio_186 handling printf("Pointer+offset: 0x%08x ",(u32)B+(GPIO6_SYSCONFIG_OFFSET)); printf("Pointer+offset content: 0x%08x ",*(u32 *)((u32)B+GPIO6_SYSCONFIG_OFFSET)); *(u32 *)((u32)B+GPIO6_SYSCONFIG_OFFSET)|= 0x00000004;// bit2=1 enable/wake up, free running clock printf("Pointer+offset content: 0x%08x\n",*(u32 *)((u32)B+GPIO6_SYSCONFIG_OFFSET)); printf("***\n"); printf("Pointer+offset: 0x%08x ",(u32)B+(GPIO6_CTRL_OFFSET)); printf("Pointer+offset content: 0x%08x ",*(u32 *)((u32)B+GPIO6_CTRL_OFFSET)); *(u32 *)((u32)B+GPIO6_CTRL_OFFSET)&= 0xfffffffe; // bit0=0 module enabled, clock not gated , clock=interface clock divided by 8 //*(u32 *)((u32)B+GPIO6_CTRL_OFFSET)&= 0xfffffff8; // bit0=0,bit1=0,bit2=0 module enabled, clock not gated , clock=interface clock not divided printf("Pointer+offset content mod: 0x%08x\n",*(u32 *)((u32)B+GPIO6_CTRL_OFFSET)); printf("***\n"); printf("Pointer+offset: 0x%08x ",(u32)B+(GPIO6_OE_OFFSET)); printf("Pointer+offset content: 0x%08x ",*(u32 *)((u32)B+GPIO6_OE_OFFSET)); *(u32 *)((u32)B+GPIO6_OE_OFFSET)&= 0xfbffffff; // bit26=0, gpio_186 output printf("Pointer+offset content mod: 0x%08x\n",*(u32 *)((u32)B+GPIO6_OE_OFFSET)); printf("***\n"); // generate a pulse stream on gpio_186 pin output for (i=0;i<100000;i++){ *(u32 *)((u32)B+(GPIO6_CLEARDATAOUT_OFFSET))|= 0x04000000; *(u32 *)((u32)B+(GPIO6_SETDATAOUT_OFFSET)) |= 0x04000000; } close(fd); printf("pointers to memory are ok\n") ; return(0); }// eof 7) compile the file "main.c" you have just created with gcc -o main main.c 8) execute the compiled file ./main and you'll see on gpio-186 ( on the TOBI board, the pin 17) the square waveform of 1.8Vpp. See http://www.gumstix.org/hardware-design/overo-coms/74-overo-connectors/97-gumstix-overo-series-40-pin-header.html for the TOBI connector pinout. That's all! PS Thanks to Dave Hylands for the advices. -- View this message in context: http://gumstix.8.n6.nabble.com/Direct-register-access-control-of-GPIO-ARM-interface-on-Overo-Water-TOBI-SOLVED-tp4965117.html Sent from the Gumstix mailing list archive at Nabble.com. |