nik-ii Posted October 1, 2018 Posted October 1, 2018 Hi, I´d like to use the GPIO PINs on my Odriod C2 with the mainline kernel 4.18. I tried to install the User Space IO, which seems to be the right tool to help me with the task. Unfortunately I had no luck trying to install it on my own. Hopefully we can install it together and get the GPIOs to do their job. It says "User space devices are exposed through /dev or /sys. Verify the device is showing up prior to trying demo programs." That is what is shown in this directory's: Picture, are devices installed properly or do I have to configure the C2 to start with User Space IO? That happens if I try to run the example code to access the GPIO or the SPI interface: Picture2 Can someone help me with that? Thank you! Nik
TonyMac32 Posted October 2, 2018 Posted October 2, 2018 @sgjava Obviously comes here sometimes, I don't have a C2 to try it on, and haven't used it in general, but looks interesting. Perhaps I'll try it on my K2, but it's running 4.14 at the moment.
sgjava Posted October 2, 2018 Posted October 2, 2018 @nik-ii I actually have a C2 and I think I just loaded mainline on it a few weeks ago. I'll check tonight, but if your SBC is using mainline then it should work. With armbian-config you need to enable SPI, I2C, etc. I'll reply back here later with C2 specific info. Note from your pic that GPIO is showing up. 1
nik-ii Posted October 2, 2018 Author Posted October 2, 2018 Wow. Thank you for the help! If there is anything I can help with please let me know. Nik
sgjava Posted October 4, 2018 Posted October 4, 2018 @nik-ii OK, I had some time to play around with my C2 which already had Armbian Stretch installed: Linux hostname 4.18.8-odroidc2 #264 SMP PREEMPT Wed Sep 19 12:35:18 CEST 2018 aarch64 GNU/Linux armbian-config has no Hardware menu, but it looks like GPIO and I2C are already enabled: ls /dev/gpio* /dev/i2c* /dev/spi* ls: cannot access '/dev/spi*': No such file or directory/dev/gpiochip0 /dev/gpiochip1 /dev/i2c-0 /dev/i2c-1 If you go to the Odroid C2 wiki you can follow the steps to enable SPI: sudo su - modprobe spidev modprobe spi_gpiomodprobe: FATAL: Module spi_gpio not found in directory /lib/modules/4.18.8-odroidc2 modprobe spi_bitbang lsmod | grep spispi_bitbang 16384 0 spidev 20480 0 ls /dev/spi* ls: cannot access '/dev/spi*': No such file or directory I'm not sure what's going on here because this works with the HardKernel OS images. I'm actually using my C2 as a Jenkins CI server, but I did play around and made sure gpio, i2c and spi worked. I believe that was a 3.x kernel though @Igor may be able to point you in a better direction to get SPI cranking. There are other drivers, but I'm not sure which one to use: ls /lib/modules/4.18.8-odroidc2/kernel/drivers/spispi-bitbang.ko spi-butterfly.ko spidev.ko spi-lm70llp.ko spi-meson-spifc.ko 1
TonyMac32 Posted October 4, 2018 Posted October 4, 2018 55 minutes ago, sgjava said: spi-meson-spifc.ko "meson" is the name of the amlogic processors, I'd put my money on that one given the other choices.
sgjava Posted October 4, 2018 Posted October 4, 2018 @TonyMac32 I loaded that module and: lsmod | grep spi spi_meson_spifc 16384 0 spi_bitbang 16384 0 spidev 20480 0 But still no /dev/spi*
TonyMac32 Posted October 4, 2018 Posted October 4, 2018 Just now, sgjava said: But still no /dev/spi* Yeah, I tried it on my K2, same result. Let me look at the build
sgjava Posted October 4, 2018 Posted October 4, 2018 @TonyMac32 Let me know if I can test something else like a new build.
TonyMac32 Posted October 4, 2018 Posted October 4, 2018 @sgjava the mainline device tree doesn't have the spi nodes the 3.14 had: https://github.com/hardkernel/linux/blob/odroidc2-3.14.y/arch/arm64/boot/dts/meson64_odroidc2.dts#L802 That looks like generic GPIO SPI, and I haven't found, in the last 20 minutes or so, where the spicc and spifc pops out of the processor GPIO wise. It does not appear to be GPIOX, so I think on the C2 the setup has to be a software SPI. NanoPi K2 appears to be in the same position, just plain not having SPI. I will investigate adding it to K2, then someone with a C2 can try it. 1
nik-ii Posted October 4, 2018 Author Posted October 4, 2018 @sgjava Okay, so GPIO and I2C are available. Does your User Space IO installation need the SPI device to be enabled? Or should it be possible to just use the GPIO and I2C commands? That would be enough for my use case at the moment. Thanks for your support!
sgjava Posted October 4, 2018 Posted October 4, 2018 @TonyMac32 I believe the C2 is software SPI. @nik-ii See Tony's reply above, but it looks like I2C and GPIO are enabled. UserSpace IO components can be used individually. In other words I can use just GPIO if it's enabled. You can try a simple flashing LED example.
TonyMac32 Posted October 4, 2018 Posted October 4, 2018 My first crude attempt on the K2 didn't work, but again, different gpio's involved and the bindings have changed somewhat since kernel 3.14. I can build a C2 kernel and we can see if it works for you. I also see a frequency limit of 500 khz, so keep that in mind. It might not be a "real" limit, some testing would be useful to determine.Sent from my Pixel using Tapatalk
sgjava Posted October 4, 2018 Posted October 4, 2018 @TonyMac32 Will this be in the form of a nightly build, or do I need to build it?
TonyMac32 Posted October 4, 2018 Posted October 4, 2018 I can build a kernel and give you a link, or if you can build it yourself, I could send you the proposed code snippet to inject into the dts
sgjava Posted October 4, 2018 Posted October 4, 2018 @TonyMac32 I like option one Send me a link and I'll try tonight.
TonyMac32 Posted October 4, 2018 Posted October 4, 2018 I'll try to get it built after bit, I get off of work in a few hours
sgjava Posted October 4, 2018 Posted October 4, 2018 @TonyMac32 No problem, I just got online at home.
TonyMac32 Posted October 5, 2018 Posted October 5, 2018 @sgjava OK, try out http://electricgraveyard.com/armbian/C2/SPI/ I included the header package in case needed.
sgjava Posted October 5, 2018 Posted October 5, 2018 @TonyMac32 So I just install the deb packages with my current release? I downloaded them and will try tomorrow.
sgjava Posted October 6, 2018 Posted October 6, 2018 @TonyMac32 OK, I get /dev/spidev0.0 now! I'll do a SPI loopback test tomorrow since I have to take it out of the server rack It's full now, but this gives you an idea: 1
TonyMac32 Posted October 6, 2018 Posted October 6, 2018 Now I have to figure out what I did wrong on the K2...
nik-ii Posted October 6, 2018 Author Posted October 6, 2018 @sgjavaKnowing the GPIO should work I tried to get the LED flashing. niklas@odroidc2:~/userspaceio/libgpiod/python/src$ python ledtest.py --chip 0 --line 203 Traceback (most recent call last): File "ledtest.py", line 17, in <module> import sys, time, gpiod ImportError: No module named 'gpiod' So I think the User Space IO installation is suspicious. I found some errors in the libgpiod Java Install Logs: Spoiler 10-06-2018 16:08:28 Generate JNA library for libgpiod 10-06-2018 16:08:28 Compiling demo code src/com/codeferm/demo/ButtonCallback.java:7: error: package com.sun.jna does not exist import com.sun.jna.NativeLong; ^ src/com/codeferm/demo/ButtonCallback.java:8: error: package com.sun.jna does not exist import com.sun.jna.Pointer; ^ src/com/codeferm/demo/ButtonThread.java:10: error: package com.sun.jna does not exist import com.sun.jna.NativeLong; ^ src/com/codeferm/demo/Hcsr501.java:8: error: package com.sun.jna does not exist import com.sun.jna.Pointer; ^ src/com/codeferm/demo/ButtonCallback.java:43: error: cannot find symbol Pointer data) -> { ^ symbol: class Pointer location: class ButtonCallback src/com/codeferm/demo/ButtonCallback.java:42: error: cannot access Callback final GpiodLibrary.gpiod_ctxless_event_handle_cb func = (int evtype, int offset, timespec timeSpec, ^ class file for com.sun.jna.Callback not found src/com/codeferm/demo/ButtonCallback.java:64: error: cannot find symbol new timespec(new NativeLong(10), new NativeLong(0)), null, func, null) != 0) { ^ symbol: class NativeLong location: class ButtonCallback src/com/codeferm/demo/ButtonCallback.java:64: error: cannot find symbol new timespec(new NativeLong(10), new NativeLong(0)), null, func, null) != 0) { ^ symbol: class NativeLong location: class ButtonCallback src/com/codeferm/demo/ButtonCallback.java:63: error: cannot access Library if (lib.gpiod_ctxless_event_loop(chipNum, lineNum, (byte) 0, consumer, ^ class file for com.sun.jna.Library not found src/com/codeferm/demo/ButtonThread.java:62: error: cannot access Structure Instant.ofEpochMilli(event.getTs().tv_sec.longValue() * 1000), ZoneId.systemDefault()); ^ class file for com.sun.jna.Structure not found src/com/codeferm/demo/ButtonThread.java:55: error: cannot find symbol rc = lib.gpiod_line_event_wait(line, new timespec(new NativeLong(timeoutSecs), new NativeLong(0))); ^ symbol: class NativeLong location: class ButtonThread src/com/codeferm/demo/ButtonThread.java:55: error: cannot find symbol rc = lib.gpiod_line_event_wait(line, new timespec(new NativeLong(timeoutSecs), new NativeLong(0))); ^ symbol: class NativeLong location: class ButtonThread src/com/codeferm/demo/ButtonWait.java:45: error: cannot find symbol final int rc = lib.gpiod_line_event_wait(line, new timespec(new NativeLong(5), new NativeLong(0))); ^ symbol: class NativeLong location: class ButtonWait src/com/codeferm/demo/ButtonWait.java:45: error: cannot find symbol final int rc = lib.gpiod_line_event_wait(line, new timespec(new NativeLong(5), new NativeLong(0))); ^ symbol: class NativeLong location: class ButtonWait src/com/codeferm/demo/ButtonWait.java:53: error: cannot access Structure$ByValue System.out.println(event.event_type); ^ class file for com.sun.jna.Structure$ByValue not found src/com/codeferm/demo/Hcsr501.java:42: error: cannot find symbol Pointer data) -> { ^ symbol: class Pointer location: class Hcsr501 The system is out of resources. Consult the following stack trace for details. java.lang.StackOverflowError at com.sun.tools.javac.comp.Resolve.isAccessible(Resolve.java:299) ... ./java-bindings.sh: 67: ./java-bindings.sh: /usr/lib/jvm/jdk1.8.0/bin/jar: not found 10-06-2018 16:08:32 Done Any idea were I made a mistake?
sgjava Posted October 6, 2018 Posted October 6, 2018 @nik-ii I'm going to install on my C2 and see what's up.
sgjava Posted October 7, 2018 Posted October 7, 2018 @nik-ii Take a look at https://github.com/sgjava/userspaceio/issues/2#issuecomment-427615183 I had to update the JNA lib in the Java scripts. Please follow up on github with UserSpaceIO specific issues.
sgjava Posted October 7, 2018 Posted October 7, 2018 @TonyMac32 The following works on the C2: gpiodetect gpiochip0 [aobus-banks] (15 lines) gpiochip1 [periphs-banks] (119 lines) sudo i2cdetect -l i2c-1 i2c DesignWare HDMI I2C adapter i2c-0 i2c Meson I2C adapter I2C adapter ./spidev_test -D /dev/spidev0.0 spi mode: 0 bits per word: 8 max speed: 500000 Hz (500 KHz) I need to figure out the MOSI and MISO pins since it's software, but it looks like all the major subsystems are cranking. It doesn't appear the C2 has pins for SPI? https://wiki.odroid.com/odroid-c2/hardware/expansion_connectors I did get SPI working on C1 here https://forum.odroid.com/viewtopic.php?f=116&t=26674
TonyMac32 Posted October 7, 2018 Posted October 7, 2018 18 minutes ago, sgjava said: It doesn't appear the C2 has pins for SPI? I pulled them out of the source code for the hardkernel 3.14. they align with the spi pins on RPI afaik.
sgjava Posted October 7, 2018 Posted October 7, 2018 @TonyMac32 I'll try that and see if loop back works.
sgjava Posted October 7, 2018 Posted October 7, 2018 @TonyMac32 OK, it uses pins 19 and 20 like Pi and C1. I used a loopback wire and ran a simple Python script: import spidev input = [1 ,2 ,3, 4, 5] print("input: %s" % input) spi = spidev.SpiDev() spi.open(0,0) output = spi.xfer2(input) print("output: %s" % output) python3 spitest.py input: [1, 2, 3, 4, 5] output: [1, 2, 3, 4, 5] So I'm confident gpio, i2c and spi are working. If your changes can be committed for the C2 Armbian build that would be most excellent. @nik-ii For UserSpace IO issues please use my github issues page otherwise it looks like everything works. I tested UserSpace IO with C2. Here's the SPI loopback in Python: python3 spiloopback.py --device /dev/spidev0.0 --maxSpeed 500000 255 128 and Java: java -Djna.nosys=true -Djava.library.path=/usr/local/lib -cp ../../jnaerator/jna-4.5.2.jar:../../jnaerator/jnaerator-runtime.jar:libperiphery.jar:demo.jar com.codeferm.demo.SpiLoopback /dev/spidev0.0 500000 FF, 80
Recommended Posts