Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8621

General • Reading gpio returns incorrect value

$
0
0
Hello,

Hello - I am working on lab13-3 about building a usb device driver on this book [1].
Instead of using the recommended board to build the usb device, I went with pico.
The source code for pico usb device and pi5 driver can be found in this repo [2].
The origianl example code can also be found here [3].

Code:

[1648431.571975] usb 3-1: USB disconnect, device number 4[1648431.574962] device offline error, dev sda, sector 260 op 0x1:(WRITE) flags 0x0 phys_seg 1 prio class 2[1648431.594052] Buffer I/O error on dev sda1, logical block 259, lost async page write[1648431.931871] usb 3-1: new full-speed USB device number 5 using xhci-hcd[1648432.102944] usb 3-1: New USB device found, idVendor=cafe, idProduct=4004, bcdDevice= 1.00[1648432.102950] usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3[1648432.102954] usb 3-1: Product: TinyUSB Device[1648432.102956] usb 3-1: Manufacturer: TinyUSB[1648432.102959] usb 3-1: SerialNumber: E660382823619B35[1648432.147020] hid-generic 0003:CAFE:4004.0014: hiddev96,hidraw0: USB HID v1.11 Device [TinyUSB TinyUSB Device] on usb-xhci-hcd.1-1/input0[1648448.598329] usbled 3-1:1.0: led_probe() function is called.[1648448.598338] usbled 3-1:1.0: endpoint size 64, number 1[1648448.598341] usbled 3-1:1.0: ep_in = 1, ep_out = 129
The device was recognized by pi5 without issues.

Code:

# echo '3-1:1.0' > /sys/bus/usb/drivers/usbhid/unbind# echo '3-1:1.0' > /sys/bus/usb/drivers/usbled/bind
I had to run the two commands above to bind the usb device to usbled module.

On pico I have gpio2 connected to an LED and gpio15. The idea is that gpio2
is set as output and gpio15 is input. When I set gpio2 high I expect it to read
1 from gpio15. The same when setting gpio2 low I expect to read 0 on gpio15.
I have an LED connected to gpio2 to make sure it does indeed go high
and I confirmed it the LED turns on when I set gpio2 high.

Unfortunately, reading from gpio15 does not return the expected value.

Here is the test I did

Code:

# echo 0 > /sys/bus/usb/devices/3-1\:1.0/led[1648448.598360] usb 3-1: int_in_urb submitted[1648467.367803] usbled 3-1:1.0: led_store() function is called.[1648467.367813] usb 3-1: read status[1648467.372521] usb 3-1: led_urb_out_callback() function is called.[1648467.380508] usb 3-1: led_urb_in_callback() function is called.[1648467.380512] switch is ON.
This command reads the value of gpio15. It returned 0 as expected.
Above is the command and the kernel messages.

Code:

# echo 1 > /sys/bus/usb/devices/3-1\:1.0/led[1648472.179604] usbled 3-1:1.0: led_store() function is called.[1648472.179610] usb 3-1: led = 1[1648472.180730] usb 3-1: led_urb_out_callback() function is called.
Next I turned gpio2 high using the command above. Both the kernel
messages and the LED confirmed that gpio2 went high.

Code:

# echo 0 > /sys/bus/usb/devices/3-1\:1.0/led[1648475.067560] usbled 3-1:1.0: led_store() function is called.[1648475.067565] usb 3-1: read status[1648475.068858] usb 3-1: led_urb_out_callback() function is called.[1648475.076851] usb 3-1: led_urb_in_callback() function is called.[1648475.076855] switch is ON.
Now reading gpio15. Still reports "switch is ON" which is not expected.

I captured the usb traffic and confirmed all is well. I think the issue
is with pico not reading the correct value on gpio15. I also used another
pico and got the same result.

Any ideas?

Thanks,
Mohamed Khalfella

[1] - https://www.amazon.com/Linux-Driver-Dev ... 096LPVG1X/
[2] - https://github.com/khalfella/lab13.1
[3] - https://github.com/ALIBERA/linux_raspberrypi_book.git

Statistics: Posted by khalfella — Sat Sep 06, 2025 2:23 am



Viewing all articles
Browse latest Browse all 8621

Trending Articles