accessing GPIO with ECHO command

Started by aatifshaikh66 7 months ago7 replieslatest reply 7 months ago69 views
hello,

I made a custom board which runs on the AM1705 processor. so far everything works fine. the only issues I'm getting are regarding external interfacing like UART, ETHERNET, and SD-CARD at OS level. I'm using flash memory for loading the OS, ramdisk file(DaVinci-PSP-SDK-03.20.00.14) and uImage(Linux "2.6.33") from "Arago projects"

can anyone explain why I can't make Gpio pin who's second functionality is UART(UART2_TX=GP5[13], UART1_TX=GP3[10] ) high or low through echo process?

these steps I'm using following atm.
for GPIO number I'm using formula-->gpio_no=(port_no*16) +pin_no.

for UART1_TX=gpio93, UART2_TX=gpio58

example:
echo 93 > /sys/class/gpio/export

echo "out" > /sys/class/gpio/gpio93/direction

echo 1 > /sys/class/gpio/gpio93/value

after entering this command I scope the value, but the pin is unchanged

echo 0 > /sys/class/gpio/gpio93/value

after entering this command I scope the value, but the pin is still unchanged.

both UART_TX pin does n't change it's status at all, on other hand data transmit through /dev/ttyS2 working fine. but using these command other gpio pins are properly changing their status.
[ - ]
Reply by ivanovpJanuary 12, 2018

Hi,

UART (or any other peripheral) and GPIO cannot work at the same time. There is a multiplexer inside the MCU which selects the working functionality. If you want to test the lines you have to disable UART by 

#1 not compiling in the corresponding kernel module or 

#2 not loading the kernel module or

#3 change the MUX registers and/or disable UART at run-time.

Best regards,

Peter

[ - ]
Reply by aatifshaikh66January 12, 2018

Hi Peter, 

I see, so can you tell me how to switch the pin's functionality or disable at UI(OS) level. I tried with removing file under /dev/ttyS1, /dev/ttyS2 to make sure it is not using anywhere in the process while running ECHO command, still I think pin's functionality changed before using it for other purpose as you suggested.

thanks and regards
aatif shaikh

 

[ - ]
Reply by ivanovpJanuary 13, 2018

Hi aatif shaikh,

Removing the files from /dev surely not enough. If you want to change those registers from user-space, you need to compile a small C program or write a small script (example Python) and open /dev/mem and map it to register's address using mmap() function. Then you can write the register's value using a pointer.

I think it's easier to recompile the kernel without those serial lines or you may try to disable it from kernel's cmdline by adding a parameter like: 8250.nr_uarts=0 or =1 if the same module provides your terminal. You need to read the corresponding kernel module's documentation, how the arguments are called.

Best regards,

Peter

[ - ]
Reply by BVRameshJanuary 16, 2018

You can try one more method.

Make a shell script to do the following.

Re program the Tx an Rx lines as GPIO 

Then toogle the way you want.

Then every thing is done re program GPIO lines back to RX and TX lines

and then exit shell.

Every thing should be done in shell because you will not have console when the lines are programmed as GPIO.

Best Regards,

BV Ramesh.

[ - ]
Reply by BVRameshJanuary 16, 2018

You can try one more method.

Make a shell script to do the following.

Re program the Tx an Rx lines as GPIO 

Then toogle the way you want.

When every thing is done, re program GPIO lines back to RX and TX lines

and then exit shell.

Every thing should be done in shell because you will not have console when the lines are programmed as GPIO.

Best Regards,

BV Ramesh.

[ - ]
Reply by aatifshaikh66January 24, 2018
hi Ramesh, Peter

I got your point, but honestly I'm not very familiar with scripting. and I've gone through some scripting tutorials but still ain't got no positive result so far.
hence I don't know how to access/switch functionality of processor's pin at UI level. can you or anyone help me some reference codes or link which i can refer to complete my task. it will be a big help.

thanks and regards
Aatif shaikh

[ - ]
Reply by BVRameshJanuary 24, 2018

Please go through the information available at: https://www.kernel.org/doc/Documentation/pinctrl.t...

Accordingly you may have to write code to switch the pin-mux.

This code can be in C or python, and use these function to do multiplexing.

Since it uses kernel, you should ensure that the UART1 or UART2 are not devices, (in sense build an image with UART1 and UART2 not included) and use the above mentioned code, as if they are included kernel will not allow to multiplex the pins.

If you want to use them as UART devices, load the drivers after kernel booting.

I feel this way you will be able do GPIO on these pins.