Fast Pin Toggling Using MMAP

108 views
Skip to first unread message

frank brewer

unread,
Apr 28, 2016, 7:46:18 AM4/28/16
to BeagleBoard

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:

/*
* Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Purpose License Version 2 as
* published by the Free Software Foundation
*
* Original from: github.com/jadonk/validation-scripts/blob/master/test-capemgr/
*
* Modified by Derek Molloy for the example on www.derekmolloy.ie
* that maps GPIO pins for the example
*/



/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

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

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?

Regards,
Frank

John Syne

unread,
Apr 28, 2016, 8:36:06 AM4/28/16
to beagl...@googlegroups.com
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

Regards,
Frank

--
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 beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/fe2ed36d-96bb-43d3-aeee-9e85fcbfd04b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

TJF

unread,
Apr 28, 2016, 11:02:36 AM4/28/16
to BeagleBoard
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

William Hermans

unread,
Apr 28, 2016, 11:55:22 AM4/28/16
to beagl...@googlegroups.com
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 ?

--
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 beagleboard...@googlegroups.com.

Micka

unread,
Apr 28, 2016, 11:57:19 AM4/28/16
to beagl...@googlegroups.com
use the PRU it's faster ^^ 

Reply all
Reply to author
Forward
0 new messages