GPIO Speed Problem.

darksoul
 
Posts: 45
Joined: Fri Nov 14, 2014 2:29 am

Re: GPIO Speed Problem.

Mon Nov 24, 2014 3:03 am

Pyrofer wrote:You can also memory map the gpio for more speed.

Any example how to do that?

Peter H wrote:It isn't necessary to close and re-open the device each time you write to it. You can also save a little time by avoiding formatting the string every time you write to the device, since you're always writing "0" or "1".


It is necessary to close and re-open, the value gets active only after the file is closed.
voiding formatting the string every time you write to the device

thx for the notice, changed to writing char, reduced state change delay for around 30us.

Peter H
 
Posts: 58
Joined: Wed Nov 12, 2014 10:24 pm

Re: GPIO Speed Problem.

Mon Nov 24, 2014 5:40 pm

darksoul wrote:It is necessary to close and re-open, the value gets active only after the file is closed.


It shouldn't be necessary. You probably just need to flush the file after writing to it.

Pyrofer
 
Posts: 61
Joined: Tue Oct 21, 2014 11:35 am

Re: GPIO Speed Problem.

Mon Nov 24, 2014 8:36 pm

So, first a Macro to make setting and clearing the GPIO pins easy,
#define set(pin) gpio[0x62c>>2]=1<<pin
#define clear(pin) gpio[0x630>>2]=1<<pin

Some defines so you know which GPIO does what, (These are just the ones I chose, fit to your hardware)
#define CLK 0
#define DAT 18
#define RST 19
#define SS 20

And in your setup routine you want to map the memory for GPIO,
fd = open("/dev/mem", O_RDWR);
if(fd==-1) printf("Error opening /dev/mem\n\r");
else gpio = (unsigned int*) mmap(0, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x10000000);


This worked fine for me on my first run getting Doom working bit-banging out SPI for the LCD.

darksoul
 
Posts: 45
Joined: Fri Nov 14, 2014 2:29 am

Re: GPIO Speed Problem.

Tue Nov 25, 2014 12:43 am

Peter H wrote:
darksoul wrote:It is necessary to close and re-open, the value gets active only after the file is closed.


It shouldn't be necessary. You probably just need to flush the file after writing to it.


And this is the correct answer, Sir!

Reduced from 250us to 10us! Working like a charm!

darksoul
 
Posts: 45
Joined: Fri Nov 14, 2014 2:29 am

Re: GPIO Speed Problem.

Tue Nov 25, 2014 12:44 am

Pyrofer wrote:So, first a Macro to make setting and clearing the GPIO pins easy,
#define set(pin) gpio[0x62c>>2]=1<<pin
#define clear(pin) gpio[0x630>>2]=1<<pin

Some defines so you know which GPIO does what, (These are just the ones I chose, fit to your hardware)
Code: Select all
#define CLK 0
#define DAT 18
#define RST 19
#define SS  20

And in your setup routine you want to map the memory for GPIO,
fd = open("/dev/mem", O_RDWR);
  if(fd==-1) printf("Error opening /dev/mem\n\r");
        else gpio = (unsigned int*) mmap(0, 4096, PROT_READ|PROT_WRITE,  MAP_SHARED, fd, 0x10000000);


This worked fine for me on my first run getting Doom working bit-banging out SPI for the LCD.


Any explanation? Or better a working example that will just toggle gpio0?

Kampi
 
Posts: 14
Joined: Tue Nov 25, 2014 6:50 am

Re: GPIO Speed Problem.

Tue Nov 25, 2014 7:00 am

You have to write to the specific registers in the Chip.
Take a look at the Datasheet Site 19 and 56

https://dlnmh9ip6v2uc.cloudfront.net/da ... RT5350.pdf

On Site 19 you find a memory map. You have to map the PIO Register 0x10000600.
For this you can use the function

gpio = (unsigned int*) mmap(0, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x10000600);

Now the Baseadress of the Register is pointet by "gpio".
With *(gpio + 1) you can access the first register and so on. Now you can modify the register.

Why you use the address 0x10000000 in your example? Is this for GPIO?

I just want to write a simple GPIO Lib for me if I got gcc running on my VoCore, so I don´t have to switch GPIOs over the driver.

Pyrofer
 
Posts: 61
Joined: Tue Oct 21, 2014 11:35 am

Re: GPIO Speed Problem.

Tue Nov 25, 2014 9:05 am

All fairly easy.

Open the file handler for memory.
mmap the memory to "gpio"

use set(pin) to turn a gpio high and clear(pin) to turn it low.
"pin" is the GPIO pin number you want, if you want gpio0 its simply 0.

so,

set(0); // turn gpio 0 to high
clear(0); // turn gpio 0 to low.

Vonger
 
Posts: 896
Joined: Sun Oct 19, 2014 6:00 am

Re: GPIO Speed Problem.

Tue Nov 25, 2014 2:18 pm

Pyrofer wrote:So, first a Macro to make setting and clearing the GPIO pins easy,
#define set(pin) gpio[0x62c>>2]=1<<pin
#define clear(pin) gpio[0x630>>2]=1<<pin

Some defines so you know which GPIO does what, (These are just the ones I chose, fit to your hardware)
#define CLK 0
#define DAT 18
#define RST 19
#define SS 20


Good way :) Directly write to register.

Previous
Return to VoCore & VoCore+Dock

Who is online

Users browsing this forum: No registered users and 3 guests