Hi Guy, Thanks a lot! It solved the problem! I can't believe I missed it! Thanks to you it works well.
There's something which is not clear to me. Even without compiling the Device-Tree Overlay (and without of course exporting it to *slots*) - i.e. without configuring GPIO1_16 (P9.15) to Mode 7 (= GPIO Mode), I manage to run the above C program and control the LED as if P9.15 is GPIO (Mode 7). How come I don't need to configure P9.15 to GPIO Mode 7, in order to operate it as GPIO? Thank you very much. On Saturday, February 15, 2014 1:00:31 AM UTC+2, Guy Grotke wrote: > > Hi matt, > > You are calculating the wrong addresses when you add the offsets to > reg_base. Instead of reg_base + 0x134 it does reg_base + (0x134 * 4). The > compiler is being “helpful” by converting your integer offset into a > unsigned int[index]! > > You could define the address pointers as unsigned ints or as unsigned char > *, and then cast them into (unsigned int *) just before you use them to get > the addition right. > > *From:* matt <javascript:> > *Sent:* Friday, February 14, 2014 12:29 PM > *To:* [email protected] <javascript:> > *Subject:* [beagleboard] GPIO does not turn on LED > > Hi, > I used the following device tree overlay to configure "GPIO1_16" (which is > P9-15) to Mode-7 (=GPIO): > //file name: BB-gpio-set-00A0.dts > > /dts-v1/; > /plugin/; > > > / { > compatible = "ti,beaglebone", "ti,beaglebone-black"; > > > /* identification */ > part-number = "BB-LED"; > version = "00A0"; > > > /* state the resources this cape uses */ > exclusive-use = > /* the pin header uses */ > "P9.15", /* GPIO1_16 */ > /* the hardware ip uses */ > "GPIO1_16"; > > > fragment@0 { > target = <&am33xx_pinmux>; > __overlay__ { > bb_GPIO1_16_pins: pinmux_bb_GPIO1_16_pins { > pinctrl-single,pins = < > 0x40 0x07 /* P9.15 OUTPUT */ > >; > }; > }; > }; > }; > > > Then, I compiled it with dtc, copied the dtbo file to /lib/firmware/, > and performed *echo BB-gpio-set* *> slots* > > Now, I ran the following Code to turn on GPIO1_16, but the code does not > turn it ON. > > *Why it that please?* > > > #include <stdio.h> > #include <unistd.h> > #include <string.h> > #include <sys/mman.h> > #include <sys/stat.h> > #include <fcntl.h> > #include <stdlib.h> > > > #define GPIO1_BASE 0x4804C000 > #define GPIO1_END 0x4804CFFF > #define GPIO1_SIZE GPIO1_END-GPIO1_BASE > #define GPIO_OE 0x0134 > #define GPIO_DATAOUT 0x013C > #define GPIO_USERBUTTON 7 > #define GPIO1_16 16 //GPIO1_16 > #define GPIO_SETDATAOUT 0x194 > #define GPIO_CLEARDATAOUT 0x190 > > > int main(int argc, char** argv) > { > volatile unsigned int *reg, *reg_base, *reg_clr; > unsigned int value; > int fd = open("/dev/mem", O_RDWR); > > > /* LED0 Setup and Turn-on */ > > //Set GPIO_OE to Output > reg_base =(volatile unsigned int*) mmap(0,GPIO1_SIZE, PROT_READ > |PROT_WRITE > , MAP_SHARED, fd, GPIO1_BASE); > reg = (volatile unsigned int*)(reg_base + GPIO_OE); > value = *(reg); > value &= ~(1 << GPIO1_16); > *(reg) = value; > > //set GPIO_SETDATAOUT to turn LED on > reg = (volatile unsigned int*)(reg_base + GPIO_SETDATAOUT); > value = *(reg); > value |= (1 << GPIO1_16); > *(reg) = value; > > > return 0; > } > > > -- > For more options, visit http://beagleboard.org/discuss > --- > You received this message because you are subscribed to the Google Groups > "BeagleBoard" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] <javascript:>. > For more options, visit https://groups.google.com/groups/opt_out. > -- For more options, visit http://beagleboard.org/discuss --- You received this message because you are subscribed to the Google Groups "BeagleBoard" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
