Fast Pin Toggling Using MMAP

I just noticed the faster way of toggling pins by using mmap, and after trying chiragnagpal’s example, I could achieve 2.6MHz.

Example was for 1 pin only, now I want to use 8 pins, so I edited .dtc file as following:

`
/*

I just noticed the faster way of toggling pins by using mmap, and after trying chiragnagpal’s example, I could achieve 2.6MHz.

Example was for 1 pin only, now I want to use 8 pins, so I edited .dtc file as following:

`
/*

/dts-v1/;
/plugin/;

/{
compatible = “ti,beaglebone”, “ti,beaglebone-black”;
part-number = “DM-GPIO-Test”;
version = “00A0”;

fragment@0 {
target = <&am33xx_pinmux>;

overlay {
pinctrl_test: DM_GPIO_Test_Pins {
pinctrl-single,pins = <

0x070 0x07 /* P9_11 60 OUTPUT MODE7 - The LED Output /
0x078 0x07 /
P9_12 60 OUTPUT MODE7 - The LED Output /
0x074 0x07 /
P9_13 60 OUTPUT MODE7 - The LED Output /
0x048 0x07 /
P9_14 60 OUTPUT MODE7 - The LED Output /
0x040 0x07 /
P9_15 60 OUTPUT MODE7 - The LED Output /
0x04c 0x07 /
P9_16 60 OUTPUT MODE7 - The LED Output /
0x15c 0x07 /
P9_17 60 OUTPUT MODE7 - The LED Output /
0x158 0x07 /
P9_18 60 OUTPUT MODE7 - The LED Output */

/* OUTPUT GPIO(mode7) 0x07 pulldown, 0x17 pullup, 0x?f no pullup/down /
/
INPUT GPIO(mode7) 0x27 pulldown, 0x37 pullup, 0x?f no pullup/down */

;
};
};
};

fragment@1 {
target = <&ocp>;
overlay {
test_helper: helper {
compatible = “bone-pinmux-helper”;
pinctrl-names = “default”;
pinctrl-0 = <&pinctrl_test>;
status = “okay”;
};
};
};
};
`

However I could not figure out how to edit the header file used in the example. Here is the header file of the example:

`
#ifndef BEAGLEBONE_GPIO_H
#define BEAGLEBONE_GPIO_H

#define GPIO1_START_ADDR 0x4804C000
#define GPIO1_END_ADDR 0x4804DFFF
#define GPIO1_SIZE (GPIO1_END_ADDR - GPIO1_START_ADDR)
#define GPIO_OE 0x134
#define GPIO_SETDATAOUT 0x194
#define GPIO_CLEARDATAOUT 0x190

#define PIN (1<<28)

#endif
`

Questions:

1) I could not find START_ADDR, END_ADDR, OE, SETDATAOUT, CLEARDATAOUT from technical manual. Where can I find them for the pins from P9_11 … upto P9_18

See AM3358 TRM Table 2-3 GPIO1

2) what is the explanation of the following statement? What does it do?
define PIN ( 1<<28)

Take a 1 and left shift by 28. This means bit 28 is set.

From Section 25.4

134h GPIO_OE
190h GPIO_CLEARDATAOUT
194h GPIO_SETDATAOUT

Learn to read the TRM. Section 2.1, Memory Map. Last section of each chapter is the register layout, for example, 25.4 is the GPIO register layout.

3)I am going to use it for SPI communication, so since the timing is critical, and Linux is not RT, there is a possibility that some other interrupts may damage my communaction. Do you think that it would be a problem? If yes, what precautions can I get?

It is possible because the data is synchronized to the clock. However, I would recommend doing this with PRU.

Regards,
John

Hi Frank!

Your example controls one GPIO subsystem. The pins P9_11 to P9_18 are connected to two GPIO subsystems. That’s why you cannot control all pins at 2.6 MHz. You’ll have to find a set of pins connected to a single GPIO subsystem (either GPIO0 or GPIO1).

As John mentioned, this is stuff for the PRUSS.

BR

1) I could not find START_ADDR, END_ADDR, OE, SETDATAOUT, CLEARDATAOUT from technical manual. Where can I find them for the pins from P9_11 … upto P9_18

Setdataout, and cleardataout are in the TRM. Pages 4093-4094.

2) what is the explanation of the following statement? What does it do?
`
define PIN ( 1<<28)

`

If you do not know what this does, then you need to read, and understand how bit manipulation works in C. This specifically is what is known as a bit shift.

3) I am going to use it for SPI communication, so since the timing is critical, and Linux is not RT, there is a possibility that some other interrupts may damage my communaction. Do you think that it would be a problem? If yes, what precautions can I get?

Bad idea. You have SPI modules on the board already. Why would you not use them ? Also, if you know Linux is not real time( enough ) then why would you use Linux ?

use the PRU it’s faster ^^