Open AceAsket opened 6 years ago
I assume there is a issue on writing to gpios...uart1 on gpio is only readable (tx not working)
then we need an instruction otherwise it's useless.
tried a little bit with an 5mm led +220ohm resistor (on pin 12=gpio18+gnd,led is on if pin12 is exchanged with pin17=3v3)
root@bpi-iot-ros-ai:~# GPIO=/sys/devices/platform/1000b000.pinctrl/mt_gpio
root@bpi-iot-ros-ai:~# cat $GPIO | grep "\(PIN\)\|\( 12:\)"
PIN: [MODE] [DIR] [DOUT] [DIN] [PULL_EN] [PULL_SEL] [IES] [SMT] [DRIVE] ( [R)
12: 1 0 0 1-1-1-1-1 0
root@bpi-iot-ros-ai:~# echo "out 12 1" >$GPIO
root@bpi-iot-ros-ai:~# cat $GPIO | grep "\(PIN\)\|\( 12:\)"
PIN: [MODE] [DIR] [DOUT] [DIN] [PULL_EN] [PULL_SEL] [IES] [SMT] [DRIVE] ( [R)
12: 1 0 1 1-1-1-1-1 0 <<<<<<<<<<<<<< out is written correctly
root@bpi-iot-ros-ai:~# echo "dir 12 1" >$GPIO
root@bpi-iot-ros-ai:~# cat $GPIO | grep "\(PIN\)\|\( 12:\)"
PIN: [MODE] [DIR] [DOUT] [DIN] [PULL_EN] [PULL_SEL] [IES] [SMT] [DRIVE] ( [R)
12: 1 0 1 1-1-1-1-1 0 <<<<<< dir is not written correctly
root@bpi-iot-ros-ai:~# echo "dir 12 0" >$GPIO
root@bpi-iot-ros-ai:~# cat $GPIO | grep "\(PIN\)\|\( 12:\)"
PIN: [MODE] [DIR] [DOUT] [DIN] [PULL_EN] [PULL_SEL] [IES] [SMT] [DRIVE] ( [R)
12: 1 1 1 1-1-1-1-1 0 <<<<<<<<<<<<<<<<< seems that dir is negated (led should be on, but its not)
root@bpi-iot-ros-ai:~# echo "out 12 0" >$GPIO
root@bpi-iot-ros-ai:~# cat $GPIO | grep "\(PIN\)\|\( 12:\)"
PIN: [MODE] [DIR] [DOUT] [DIN] [PULL_EN] [PULL_SEL] [IES] [SMT] [DRIVE] ( [R)
12: 1 0 0 1-1-1-1-1 0 <<<<<<<< both values (dir+out) are cleared
now i try to set first dir to 1 (have to set 0) and then set pin to high (1)
root@bpi-iot-ros-ai:~# echo "dir 12 0" >$GPIO
root@bpi-iot-ros-ai:~# echo "out 12 1" >$GPIO
root@bpi-iot-ros-ai:~# cat $GPIO | grep "\(PIN\)\|\( 12:\)"
PIN: [MODE] [DIR] [DOUT] [DIN] [PULL_EN] [PULL_SEL] [IES] [SMT] [DRIVE] ( [R)
12: 1 0 1 1-1-1-1-1 0
oh, pin should be high, but dir was reset to 0 (led still off)
Ok, i need 5 gpio
gpio5 should be pin 29...you can try same steps with this
i have tried my commands with 18(=gpio24) as pin (i know its wrong, but tried it, to test if "pin"=gpio-number)...also without luck
thanks, but i need 5 pins gpio
how does the count of pins matter? there are more than 5 gpio, but all seems have this problem
the count doesn't matter, they just do not work normally
@garywangcn please help.
in Schematics (Page 19) Pin12 (my example) is named GPIO24 (not 18)...maybe i need that as Pin-Number
https://www.file-upload.net/download-12752418/bpi-r2_gpio.png.html
MTK_PIN(
PINCTRL_PIN(24, "EINT2"), <<< EINT2 (=Interrupt #2?) also in schematics for pin 12
"H16", "mt7623",
MTK_EINT_FUNCTION(0, 2),
MTK_FUNCTION(0, "GPIO24"), <<< 0 seems mode for standard-GPIO, maybe its need to set it
MTK_FUNCTION(1, "UCTS1"), <<< UCTS1 is also described in Schematics
MTK_FUNCTION(2, "PCIE2_PERST_N")
),
if that not works i've found another possibility: cat $GPIO gpio base is 233 <<< maybe we need to add pin-number to base to get the results see https://wiki.openwrt.org/doc/hardware/port.gpio Section Software-Example
will try it next days...
root@bpi-iot-ros-ai:~# echo "dir 24 0" >$GPIO
root@bpi-iot-ros-ai:~# cat $GPIO | grep "\(PIN\)\|\( 24:\)"
PIN: [MODE] [DIR] [DOUT] [DIN] [PULL_EN] [PULL_SEL] [IES] [SMT] [DRIVE] ( [R1] )
24: 0 1 1 0-1-1-1-1 0
root@bpi-iot-ros-ai:~# echo "out 24 1" >$GPIO
root@bpi-iot-ros-ai:~# cat $GPIO | grep "\(PIN\)\|\( 24:\)"
PIN: [MODE] [DIR] [DOUT] [DIN] [PULL_EN] [PULL_SEL] [IES] [SMT] [DRIVE] ( [R1] )
24: 0 0 1 0-1-1-1-1 0
root@bpi-iot-ros-ai:~# echo "dir 24 1" >$GPIO
root@bpi-iot-ros-ai:~# echo "out 24 1" >$GPIO
root@bpi-iot-ros-ai:~# echo "out 24 0" >$GPIO
root@bpi-iot-ros-ai:~# echo "dir 24 0" >$GPIO
root@bpi-iot-ros-ai:~# echo "out 24 0" >$GPIO
none is working, led stays off...second one seems also not be needed because i have only 164 "pins" in gpio-table.
now i'm out of ideas...
@AceAsket @frank-w
If you try to use GPIO 22/23/24, please change other bits in a register first see below comments for more information. https://github.com/BPI-SINOVOIP/BPI-R2-bsp/issues/11#issuecomment-326988062
The GPIO12 is used internally, can you please just use the GPIO-s which are connected to 40Pin header.
Please note that the mode should be 0 if these pin-s are configured as GPIO mode.
hi gary, i try pin 12,here named gpio18
https://bananapi.gitbooks.io/banana-pi-bpi-r2-open-source-smart-router/content/assets/GPIO.jpg
(gpio12 is also on the header...)
in schematics It is named 24,which "pin"-number is right? if 24, how to set EINT2_BOND_DIS to 1?
tried again with pin 22 of header (gpio18 in schematics, gpio25 on graphic)
root@bpi-iot-ros-ai:~# echo "dir 25 1" >$GPIO
root@bpi-iot-ros-ai:~# echo "out 25 1" >$GPIO
root@bpi-iot-ros-ai:~# echo "dir 25 0" >$GPIO
root@bpi-iot-ros-ai:~# echo "out 25 1" >$GPIO
root@bpi-iot-ros-ai:~# echo "dir 18 0" >$GPIO
root@bpi-iot-ros-ai:~# echo "out 18 1" >$GPIO
root@bpi-iot-ros-ai:~# echo "dir 18 1" >$GPIO
root@bpi-iot-ros-ai:~# echo "out 18 1" >$GPIO
none of them worked
How about uart tx? I can receive,but not send
Hi Frank,
We should refer to the table (BPI-R2 40 PIN GPIO define) in that link:
GPIO Pin Name | Default Function | Function2:GPIO |
---|---|---|
CON1-P01 | VCC-3V3 |
So the "GPIO12" is CON1-P32->GPIO72, there is an example to configure GPIO72 to out: echo "mode 72 0" >${GPIO} echo "dir 72 1" > ${GPIO}_
As for set bit EINT2_BOND_DIS, we need a tool to write GPIO register directly, the code for the tool is:
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define handle_error(msg) \
do { perror(msg); exit(EXIT_FAILURE); } while (0)
int
main(int argc, char *argv[])
{
int i;
unsigned int val = 0;
char *addr;
int fd;
struct stat sb;
off_t offset, pa_offset;
size_t length;
ssize_t s;
if (argc < 3|| argc > 4) {
fprintf(stderr, "%s file offset length val\n", argv[0]);
exit(EXIT_FAILURE);
}
fd = open(argv[1], O_RDWR|O_SYNC);
if (fd == -1)
handle_error("open");
offset = strtoul(argv[2], NULL, 16);
val = strtoul(argv[3], NULL, 16);
fprintf(stderr, "%s offset : %08x, val : %08x\n", argv[0], offset, val);
pa_offset = offset & 0xfffff000;
offset = offset - pa_offset;
addr = mmap(NULL, 0x1000, PROT_WRITE,
MAP_SHARED, fd, pa_offset);
if (addr == MAP_FAILED)
handle_error("mmap");
*(unsigned int *)(addr + offset) = val;
printf("%08x\r\n", (unsigned int)(addr + offset));
exit(EXIT_SUCCESS);
}
Compiling above code, and I assume the executable binary is mwrite, so the example for writing register 0x10005b10(GPIO Misc Controller register) to 0x00000038: mwrite /dev/mem 0x10005b10 0x00000038
Ok,using that table i have
CON1-P12 GPIO37 GPIO37 (pin 12 right?) => 37 does also not work
Very confusing because jpg above table and schematics are wrong then
Can you reproduce the problem using con1-p12? Which is right gpio-number to write in pinctrl-register?
@garywangcn any infos?
we should start with a gpio that have not to be set to a specific value, but assume that there is a generic problem since uart TX is also not working
tried also to compile you c-programm:
frank@Frank-Laptop:/media/data_ext/download/bpi-r2$ arm-linux-gnueabihf-gcc mwrite.c mwrite.c: In function ‘main’: mwrite.c:35:5: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 4 has type ‘off_t’ [-Wformat=] fprintf(stderr, "%s offset : %08x, val : %08x\n", argv[0], offset, val);
changed the Param to:
fprintf(stderr, "%s offset : %08x, val : %08x\n", argv[0], (unsigned int)offset, val);
now it compiles, but dont know if its right, because it can be a 64bit integer, but these are not compatible with fprint's %x
referring to Schematics, i now tried Pin 16=GPIO25
root@bpi-iot-ros-ai:~# GPIO=/sys/devices/platform/1000b000.pinctrl/mt_gpio
root@bpi-iot-ros-ai:~# echo "dir 25 1" >$GPIO
root@bpi-iot-ros-ai:~# echo "out 25 1" >$GPIO
works like a charm ;)
test-circuit:
pin14 (GND) - resistor (220ohm) - LED (-/long pin/flattened head)
pin16 (GPIO25 in shematics,GPIO23 in Gitbook-image,GPIO18 in tablebelow the image) - LED (+)
so it seems the correct "Pin"-numbers are only in shematics, GPIO22/23/24 need special treatment as mentioned before
Added to my Wiki here
@frank-w please try gpio 49
i've did not found Gpio 33 and 35 in schematics. Please refer table behind my link or schematics
sorry, Pin 35 | GPIO 49 upd: after echo "dir 49 1" gpio work echo "mode 49 0"
GPIO 49 need mwrite (and modeset) too...see special GPIO
pin 33/GPIO73 is always on...also after reboot, can't set it to off
btw. tried also my uart1/0 with mempatch (mwrite), rx works again, but no tx (same as without mempatch) => https://github.com/BPI-SINOVOIP/BPI-R2-bsp/issues/19
@garywangcn how to use normal and special GPIO together? with the mem-rewrite i set the full GPIO-Register to 2nd function, so i can't access the 1st function no more, right? how to reset the mem-rewrite?
@frank-w all work fine! But i doesn't detect press button on GPIO 200
with right circuit it works with kernel 4.14: http://forum.banana-pi.org/t/gpio-python-or-shell/3912/36
dir will not be written