08-24-2016, 09:55 AM
(This post was last modified: 08-24-2016, 10:43 AM by martind1983.)
(06-10-2016, 03:10 PM)martinayotte Wrote: Ok ! I found the issue and got it working : like many other libs, a 32bits pointer used in 64bits environment !
You need to change the "unsigned int SUNXI_PIO_BASE" for "unsigned long SUNXI_PIO_BASE" in both gpio_lib.c and gpio_lib.h
(BTW, about speed of python vs C/C++, that all depends of you apps. Of course, if you wish to toggle gpio at maximum speed, C/C++ could do better.)
Hello Mr. Martin
Can I ask you how this memory mapping worked for you with base address starting at 0x01c20800 for gpio. Because when I use mmap I get EINVAL "invalid argument" because this address is not aligned to page size multiplication. What address or how could I directly access GPIO registers?
I do it like this (see comments in code below) but LED connected to PB1 does not light. I even tested it over sys/class/ drivers and that works. LED is connected to physical pin 10 according to this pin layout. I just want to test board and play around.
http://joey.hazlett.us/pine64/pine64_pins.html
Thank you very much. Martin
MY CODE:
// map memory image to virtual memory for direct writing in the peripherals
// BASE_ADDR is 0x01C20000
p_mem = mmap(NULL, page_size * 2, PROT_READ | PROT_WRITE, MAP_SHARED, fd, BASE_ADDR);
if (p_mem == (void *) -1) {
perror("mmap");
exit(EXIT_FAILURE);
}
// convert void * to unsigned long *
gpio = (volatile unsigned long *) p_mem;
/*
* add offset 0x800 to maped base address to get to PIO registers
* plus add offset to PB_CFG0_REG 0x24 to PB1 as output, 0x8 should set PB1 to output mode
* for output to log 1, the same I set offset 0x800, plus I add offset to PB_DATA_REG 0x34
* to set 1 for PB1
*/
*(gpio + GPIO_REG_OFFSET + 0x24) = 0x10;
*(gpio + GPIO_REG_OFFSET + 0x34) = 0x02;