fast GPIO

Started by deck, September 12, 2013, 04:12:46 PM

Previous topic - Next topic

deck

Hello everyone,

I have an OLinuXino A10s with the debian image from olimex site.
I have successfully written code in Python to control of GPIOs, but my problem now is that the faster frequency I can get is 125KHz (read with an oscilloscope). This is the testing code:

import A10S_GPIO as GPIO

def main():
    GPIO.init()
    GPIO.setcfg(GPIO.PIN39, GPIO.OUTPUT)
   
    while True:
        GPIO.output(GPIO.PIN39, GPIO.HIGH)
        GPIO.output(GPIO.PIN39, GPIO.LOW)

if __name__ == "__main__":
    main()


I have seen in a post about A13 that is possible to get faster frequencies (also MHz) trough the access to /dev/mem (in C language). I have tried to adapt the code already written for the A13 but it doesn't work. Has anyone already tried it?
I also have a question about SPI. Is there any way to access to SPI hardware within the processor rather than simulates it in software? (I think so, again via /dev/mem, am I wrong?).
thank you in advance for the replies

soenke

https://www.olimex.com/forum/index.php?topic=436.0;last_msg=5206

But i just discovered a bug in the input/output-config, so it is not 100% reliable that you get the correct port in the direction you want it to. I am currently working on it, if i find a solution i will post it here.

soenke

got it! there was a *4 missing on the index so the next config-register was not addressed correctly.


//------------------------------------------------------------------------------
void my_gpio_cfg_output(unsigned int port_base,unsigned int pin_idx)
//------------------------------------------------------------------------------
{
   unsigned int cfg;

   unsigned int index  = (pin_idx>>3)*4;
   unsigned int offset = (pin_idx& 0x7) << 2;
   unsigned int *c     = (unsigned int*)  ((SUNXI_PIO_BASE + port_base + index));

   #ifdef SUNXI_GPIO_DEBUG
     printf("%20s base: %lu addr: %lu dat:%lu pin_idx: %lu\r\n",__func__,SUNXI_PIO_BASE,c,pin_idx);
   #endif
   ....


//------------------------------------------------------------------------------
void my_gpio_cfg_input(unsigned int port_base,unsigned int pin_idx)
//------------------------------------------------------------------------------
{
   unsigned int cfg;

   unsigned int index  = (pin_idx>>3)*4;
   unsigned int offset = (pin_idx& 0x7) << 2;
   unsigned int *c     = (unsigned int *) ((SUNXI_PIO_BASE + port_base + index));

   #ifdef SUNXI_GPIO_DEBUG
     printf("%20s base: %lu addr: %lu dat:%lu pin_idx: %lu\r\n",__func__,SUNXI_PIO_BASE,c,pin_idx);
   #endif
   ...