Pinebook SDIO gpio control using SD card slot blog post
#1
Lightbulb 
   

This is my first experiment with bringing some of the A64 gpio mux lines to the outside via the SD card slot;  SDIO.  These are data lines D0-D3, CMD, CLK, VDD, & VSS.  The lines are gpio160 - gpio166;  PF0 - PF6.

The pic above is the 48cm ribbon cable that extends the SD micro slot to a full size card adapter;  this ribbon is useful in itself;  but I plan to modify it for pin access on a solderable bread-board.

         

These two shots are the modified ribbon cable;  this was actually easier than I expected.  The cable will extend under the notebook.

         

The two shots above show the finished cable running;  I have the green and red LED(s) initially connected to CMD and CLK.  These are pulsing at regular 3/4 second intervals (or so).  The gpio(s) are not useful in this state;  next I need to hack the dts and make sure that the pin function register has '0' s. 

Please see this important link:
marcushh777    Cool

please join us for a chat @  irc.pine64.xyz:6667   or ssl  irc.pine64.xyz:6697

( I regret that I am not able to respond to personal messages;  let's meet on irc! )
#2
(07-20-2017, 04:56 PM)MarkHaysHarris777 Wrote: This is my first experiment with bringing some of the A64 gpio mux lines to the outside via the SD card slot;  SDIO.  These are data lines D0-D3, CMD, CLK, VDD, & VSS.  The lines are gpio160 - gpio166;  PF0 - PF6.

The pic above is the 48cm ribbon cable that extends the SD micro slot to a full size card adapter;  this ribbon is useful in itself;  but I plan to modify it for pin access on a solderable bread-board.

 

These two shots are the modified ribbon cable;  this was actually easier than I expected.  The cable will extend under the notebook.

 

The two shots above show the finished cable running;  I have the green and red LED(s) initially connected to CMD and CLK.  These are pulsing at regular 3/4 second intervals (or so).  The gpio(s) are not useful in this state;  next I need to hack the dts and make sure that the pin function register has '0' s. 

Stay tuned.

Awesome
#3
This post is just to document the placement of the pins on my breakout with the extender;  the Sparkfun breakout board ( coming soon ) has a slightly different layout.  

Code:
Pin     SD      SPI

PF5     D2      X
PF4     D3      CS
PF3     CMD     DI
+       VDD     VDD
PF2     CLK     SCLK
PF1     D0      DO
PF0     D1      X
-       VSS     VSS

   

Note:  Vss in the pic above (ground) is normally the third pin up from the bottom, between D0 and CLK.  I moved Vss physically to create two logical groups of three pins PF0-2 and PF3-5;  this also allows for good separation between Vdd and Vss.

Note:  See schematic pp 9;  T-card/USB



marcushh777    Cool

please join us for a chat @  irc.pine64.xyz:6667   or ssl  irc.pine64.xyz:6697

( I regret that I am not able to respond to personal messages;  let's meet on irc! )
#4
          

The above pics are option (2);  the model from Sparkfun is a little more expensive, but arrived in two days.  The Chinese version will be here in 30 days from Shenzhen (if I'm lucky with customs).  These plug directly into the micro SD slot (although its a little tricky, I did have to use the dremel tool).  The layout is similar but different; in this model the Vss and Vdd are together in the center.

   

Again, we have tapped the gpio(s) after mounting header pins on the sniffer card;  the sniffer card is designed to be a logic test point for logic analyzer.  I won't be pushing an SD card in the slot but will experiment with the gpio(s) using this direct interface.

Note:  pin (CD) is card-detect ;  also  D3.


marcushh777    Cool

please join us for a chat @  irc.pine64.xyz:6667   or ssl  irc.pine64.xyz:6697

( I regret that I am not able to respond to personal messages;  let's meet on irc! )
#5
          


By disabling the sdmmc for sdc0,  and setting sdc0 to function gpio_in, muxsel 0x0, drive 0x0, (pinctrl and bindings) I have been able to set gpio160 - gpio165 ( PF0 - PF5 ) to ON | OFF with the sysfs method:

echo 160 > export
echo out > gpio160/direction
echo 1 > gpio160/value
echo 0 > gpio160/value

After bootup the gpio(s) were in default input (cmd and clk no longer strobing); all six gpio(s) were successfully exported, defined, and set ON|OFF. In the left pic above the right LED is Vdd monitor while the left LED is monitoring gpio160 which has just been set ON.  In the right pic the gpio160 has been set OFF;  Vdd still indicating 3v3 rail.

Note:  the dts|dtb is static atm;  will want to configure so that uEnv.txt controls dtb "on-the-fly" via variable. 

Note:  the SD card slot can be raw gpio(s) ;  or SD card external storage ; or SPI  (jtag, other)

Note:  All of this assumes ofc that the pinebook is booted via eMMC;  SD card slot is disabled for external storage

Note:  option (2)  sniffer adapter is less than expected;  sloppy in the slot and difficult to control;  the card needs to be just a tad thicker, and the latching mechanism needs to be better defined;  may have to make our own cards !



marcushh777    Cool

please join us for a chat @  irc.pine64.xyz:6667   or ssl  irc.pine64.xyz:6697

( I regret that I am not able to respond to personal messages;  let's meet on irc! )
#6
The purpose of this post is to document the changes I made to the dts;  these changes are experimental and may not be entirely correct. Do not copy these changes;  or do so at your own risk.  These changes are static (I recompiled the dtb and the changes do not modify on-the-fly). 

The dts is decompiled from the ayufan image 0.7.3 using dtc device-tree-compiler. I made three sets of changes; each will be listed in its own code block with line numbers.  Essentially the changes disable the sdmmc for @sdc0 and set the bindings (may not be correct) for @sdc0  gpio(s)  PF0 - PF5.

The changes are listed in the order they appear in the source:

When I make changes to my experimental dts, I will update these code blocks to reflect the most recent revision;  the following is the second revision.

[change 1]

Code:
[old source 1]
948                         sdc0@1 {
949                                 allwinner,pins = "PF0", "PF1", "PF2", "PF3"     , "PF4", "PF5";
950                                 allwinner,function = "io_disabled";
951                                 allwinner,muxsel = <0x7>;
952                                 allwinner,drive = <0x1>;
953                                 allwinner,pull = <0x1>;
954                                 linux,phandle = <0x64>;
955                                 phandle = <0x64>;
956                         };

[new change 1]  950, 951, 953
948                         sdc0@1 {
949                                 allwinner,pins = "PF0", "PF1", "PF2", "PF3"     , "PF4", "PF5";
950                                 allwinner,function = "gpio_in";
951                                 allwinner,muxsel = <0x0>;
952                                 allwinner,drive = <0x0>;
953                                 allwinner,pull = <0x1>;
954                                 linux,phandle = <0x64>;
955                                 phandle = <0x64>;
956                         };

[change 2]

Code:
[old source 2]
1554                         sdc0@0 {
1555                                 linux,phandle = <0xc0>;
1556                                 phandle = <0xc0>;
1557                                 allwinner,pins = "PF0", "PF1", "PF2", "PF3"     , "PF4", "PF5";
1558                                 allwinner,function = "sdc0";
1559                                 allwinner,pname = "sdc0_d1", "sdc0_d0", "sd     c0_clk", "sdc0_cmd", "sdc0_d3", "sdc0_d2";
1560                                 allwinner,muxsel = <0x2>;
1561                                 allwinner,pull = <0x1>;
1562                                 allwinner,drive = <0x2>;
1563                                 allwinner,data = <0xffffffff>;
1564                         };

[new change 2]   1560, 1562
1554                         sdc0@0 {
1555                                 linux,phandle = <0xc0>;
1556                                 phandle = <0xc0>;
1557                                 allwinner,pins = "PF0", "PF1", "PF2", "PF3"     , "PF4", "PF5";
1558                                 allwinner,function = "sdc0";
1559                                 allwinner,pname = "sdc0_d1", "sdc0_d0", "sd     c0_clk", "sdc0_cmd", "sdc0_d3", "sdc0_d2";
1560                                 allwinner,muxsel = <0x0>;
1561                                 allwinner,pull = <0x1>;
1562                                 allwinner,drive = <0x0>;
1563                                 allwinner,data = <0xffffffff>;
1564                         };

[change 3]

Code:
[old source 3]
2169                 sdmmc@01c0f000 {
2170                         compatible = "allwinner,sun50i-sdmmc0";
2171                         device_type = "sdc0";
2172                         reg = <0x0 0x1c0f000 0x0 0x1000>;
2173                         interrupts = <0x0 0x3c 0x104>;
2174                         clocks = <0x6 0x5a 0x60 0x61 0x62>;
2175                         clock-names = "osc24m", "pll_periph", "mmc", "ahb",      "rst";
2176                         pinctrl-names = "default", "sleep";
2177                         pinctrl-1 = <0x64>;
2178                         max-frequency = <0x2faf080>;
2179                         bus-width = <0x4>;
2180                         broken-cd;
2181                         status = "okay";
2182                         pinctrl-0 = <0xc0>;
2183                         cd-gpios = <0x30 0x5 0x6 0x0 0x1 0x2 0xffffffff>;
2184                         sunxi-power-save-mode;
2185                         vmmc = "vcc-sdcv";
2186                         vqmmc = "vcc-sdcvq33";
2187                         vdmmc = "vcc-sdc";
2188                 };

[new change 3]   2181
2169                 sdmmc@01c0f000 {
2170                         compatible = "allwinner,sun50i-sdmmc0";
2171                         device_type = "sdc0";
2172                         reg = <0x0 0x1c0f000 0x0 0x1000>;
2173                         interrupts = <0x0 0x3c 0x104>;
2174                         clocks = <0x6 0x5a 0x60 0x61 0x62>;
2175                         clock-names = "osc24m", "pll_periph", "mmc", "ahb",      "rst";
2176                         pinctrl-names = "default", "sleep";
2177                         pinctrl-1 = <0x64>;
2178                         max-frequency = <0x2faf080>;
2179                         bus-width = <0x4>;
2180                         broken-cd;
2181                         status = "disabled";
2182                         pinctrl-0 = <0xc0>;
2183                         cd-gpios = <0x30 0x5 0x6 0x0 0x1 0x2 0xffffffff>;
2184                         sunxi-power-save-mode;
2185                         vmmc = "vcc-sdcv";
2186                         vqmmc = "vcc-sdcvq33";
2187                         vdmmc = "vcc-sdc";
2188                 };


Note:   Line numbers following [new change X] indicate specific changed lines.

Note:   The original source may be compared with the changed source in each code block.
marcushh777    Cool

please join us for a chat @  irc.pine64.xyz:6667   or ssl  irc.pine64.xyz:6697

( I regret that I am not able to respond to personal messages;  let's meet on irc! )
#7


My first clue that the bindings may not be entirely correct is that inputs with active_low=1 don't work.  By default when I setup an input (used PF4 and PF5) then active_low=0 ;  which means the default state of the pin is zero and it becomes active 'high';  this works !  Set the pin to 3v3 and its value becomes 1.

On the other hand, if I set active_low=1 then the input pin does not work;  its value remains default '1' regardless of grounding the pin ( setting it to low zero ).  So, I suspect I need to revisit 'pull' and 'drive'  and fix whatever I don't understand there.

Note:   ofc an external pullup of 56K ohms works fine to invert the behavior of the input 

Note:   regardless, we have both input and output working with gpio block @sdc0 ( PF0 - PF5 )  gpio160 - gpio165.

Note:   need to make the dts generic ;  and get the C and Python routines working.


marcushh777    Cool

please join us for a chat @  irc.pine64.xyz:6667   or ssl  irc.pine64.xyz:6697

( I regret that I am not able to respond to personal messages;  let's meet on irc! )
#8
Thanks on the GPIO over SD slot post. Now the Pinebook also has GPIO access :-)
#9
(07-22-2017, 02:02 PM)MarkHaysHarris777 Wrote:   

The above pics are option (2);  the model from Sparkfun is a little more expensive, but arrived in two days.  The Chinese version will be here in 30 days from Shenzhen (if I'm lucky with customs).  These plug directly into the micro SD slot (although its a little tricky, I did have to use the dremel tool).  The layout is similar but different; in this model the Vss and Vdd are together in the center.



Again, we have tapped the gpio(s) after mounting header pins on the sniffer card;  the sniffer card is designed to be a logic test point for logic analyzer.  I won't be pushing an SD card in the slot but will experiment with the gpio(s) using this direct interface.

Note:  pin (CD) is card-detect ;  also  D3.



hi, good thread. wanted to mention that sparkfun also has this sd card sniffer.
 https://www.sparkfun.com/products/11468
also, if you are not aware some vendors will also ship from hong kong by request.
i have been getting hk stuff much faster.
#10
(07-22-2017, 02:02 PM)MarkHaysHarris777 Wrote:   

The above pics are option (2);  the model from Sparkfun is a little more expensive, but arrived in two days.  The Chinese version will be here in 30 days from Shenzhen (if I'm lucky with customs).  These plug directly into the micro SD slot (although its a little tricky, I did have to use the dremel tool).  The layout is similar but different; in this model the Vss and Vdd are together in the center.



Again, we have tapped the gpio(s) after mounting header pins on the sniffer card;  the sniffer card is designed to be a logic test point for logic analyzer.  I won't be pushing an SD card in the slot but will experiment with the gpio(s) using this direct interface.

Note:  pin (CD) is card-detect ;  also  D3.




hi again,  well,  the RED card options ( microSD Sniffer , see post #4)  one from Sparkfun , and one from the market in Shenzhen are a bust;  the model from Shenzhen does not work at all ( way too thick ) and the one from Sparkfun is loose and sloopy ( although it does work ) because its way too thin.

The card must be the same size and shape as the micro SD card ; doh.   Specifically the card must not be any thicker than  .75mm  and the one from Shenzhen is 1.0mm,  the one from Sparkfun is less than .50mm.  If I am very careful I can make the Sparkfun model work;  but what a pain.  So, I'm down to using only the microSD extension cables, which work very well.

There are many vendors for this card;  I plan to try to make my own card and not waste any more money are cheap gimmicks.
marcushh777    Cool

please join us for a chat @  irc.pine64.xyz:6667   or ssl  irc.pine64.xyz:6697

( I regret that I am not able to respond to personal messages;  let's meet on irc! )


Possibly Related Threads…
Thread Author Replies Views Last Post
  pinebook 1080p power/barrel connector/cable cel 0 496 08-03-2023, 11:43 AM
Last Post: cel
  eMMC compatible with Pinebook leperotero 0 1,321 07-19-2022, 07:15 AM
Last Post: leperotero
Heart [solved] Anyone selling their Pinebook? feyn 0 1,167 07-11-2022, 03:38 PM
Last Post: feyn
  Move PB Pro eMMC 128 GB to Pinebook 11 1080p petet0n76 1 1,563 06-07-2022, 10:35 PM
Last Post: tllim
  UART switch Pinebook 11.6" irongarment 3 3,216 01-03-2022, 03:28 AM
Last Post: kqlnut
Exclamation "6" Key direly needed for 11" Pinebook Corkonian 1 2,529 09-25-2021, 12:03 AM
Last Post: tllim
  SD card read/write troubles jezek 1 2,919 03-26-2021, 09:27 AM
Last Post: jezek
  Pinebook 14 " Battery Swollen/Bulged billjon 1 3,535 01-13-2021, 11:03 AM
Last Post: barray
  touchpad on pinebook issues? ron_burgundy 14 13,504 12-19-2020, 06:55 PM
Last Post: ron_burgundy
  CH341 boards for GPIO xalius 1 4,065 11-22-2020, 10:50 AM
Last Post: pinephonenewbee

Forum Jump:


Users browsing this thread: 1 Guest(s)