Apalis TK1 - Unable to read GPIO pins via K20

Hello support!

Environment:
Apalis TK1
L4T BSP2.8 ubuntu

I am trying to read GPIO pin states for couple of pins which internally connected via K20 processor.
For my reads I use sysfs because I am under older BSP where GPIOD utility is not available.
I was able successfully find pin numbers for K20 pins and initialize them via sysfs
However at all times pins return value 0. I think that possibly something is wrong with K20 configuration.
Just to confirm: K20 has a proper firmware inside. This firmware works well for CAN bus, also allows pins to be initialized as GPIO via sysfs.

Questions:
Is there any list of which pins of K20 are set by default as GPIO ?

Maybe the way how K20 GPIO pins state should be read is different from standard old school sysfs reads ? Pins on main TK1 board which are not connected via K20 can be well read and set.

Please advise.
Thank you.

Hi @avionics,

I’m sorry for the delay.

Please take a look at these articles:

Do they immediately return to 0 or after something is done with your board? Like setting as input, trying to read the pin…

Another question from my side, are you developing a new product with the Apalis TK1?

Best Regards,
Hiago.

Hi Hiago,

Yes, lines always return 0 level no matter what.
Here is the example for better understanding. We take 3 input lines which are routed via K20 on Apalis TK1 board:

APALIS_PIN(181) which is K20_PTE5 in datasheet and calculated sysfs pin number 989
APALIS_PIN(173) which is K20_PTE1 in datasheet and calculated sysfs pin number 985
APALIS_PIN(175) which is K20_PTE0 in datasheet and calculated sysfs pin number 984

Commands in terminal:

Export pins

echo 989 > /sys/class/gpio/export

echo 985 > /sys/class/gpio/export

echo 984 > /sys/class/gpio/export

All good at this point

Set direction as input

echo “in” > /sys/class/gpio/gpio989/direction

echo “in” > /sys/class/gpio/gpio985/direction

echo “in” > /sys/class/gpio/gpio984direction

All good at this point.

We now can see these pins if give command:

cat /sys/kernel/debug/gpio

Finally we read their status or level:

cat /sys/class/gpio/gpio989/value

cat /sys/class/gpio/gpio985/value

cat /sys/class/gpio/gpio984/value

The return value is always 0 despite the level on pin is 3V3 measured with the scope or multimeter.
So I am sure that I supply proper level of 3V3 which is logical 1 to correct pins but I am unable to read the value.

If I do the same for any other pin which is NOT connected via K20 on TK1 board it works well.

Can you please do the test and confirm if you have the same issue ?

Answering your question about development - we do have near 100 pcs of TK1 in stock which we purchased in the past and since support of the board was planned for longer period of time we want to keep using these boards and extend functionality by adding extra GPIO inputs.
So we really want to be able to use K20 inputs for GPIO in.
Also I must confirm that K20 firmware looks okay to me because CAN bus is properly supported and I am able to use both CAN1 and CAN2 interfaces via K20.

Thank you

Hi @avionics,

Sorry for the delay.

Can you please confirm which hardware version you’re using? Apalis TK1 2GB V1.2A?

Best Regards,
Hiago.

Hi Hiago,

My version is 1.1A and all of our boards are of this version.
Thank you,

Hi @avionics,

Can you please also share the part number? Should be 0034XXXX. This information is printed on your board.

Thank you!

Best Regards,
Hiago.

The only information available on our boards are:

Apalis TK1 V1.1
94VO
E99006
TYPE2BL B
2.3
1644

Above is printed on both sides of PCB
Also there is a sticker:
Apalis TK1 2GB
028646** (we have multiple boards so last two numbers of serial are different)
V1.1A

This is the only information available on the modules.

Hi @avionics,

Thanks for the information.

I will try to get one of these boards and test the issue myself. As you know, this product is on EOL right now, so I will update you as soon as I have one.

Best Regards,
Hiago.

Hiago,

Thank you, that would be great as we struggling with this issue at the moment. GPIO is something we really need from this board. I know it is EOL but at the moment when boards were sold the GPIO support via K20 was a part of the deal so I hope it can be resolved.
On another note can you confirm that the same feature (GPIO input K20) works on 1.2A revision of the board ? We do have about 10 pcs of this board and expect to work with them later this spring.
Thank you!

Hi @avionics,

Just a quick update, I’m still waiting for the board on my side. Do you have any updates on your side?

For revision history and errata, please check this link Apalis TK1 | Toradex Developer Center.

Let me know if you have any questions.

Best Regards,
Hiago.

Hi Hiago,

I was just trying to ask you that while you are waiting for the Apalis TK1 rev1.1 board so you can test our K20 GPIO issue, maybe you also have in stock some rev1.2A boards ? If so can you also test this K20 GPIO input issue on them ?
It seems to be a problem for us since we are unable to use K20 GPIOs as inputs so this dramatically cuts our possibilities to use this board for multiple GPIO inputs.
Thank you for your efforts to get this solved.

Hi @avionics,

Sorry for my misunderstanding. I will check our local stock, for now I would say I have only the 1.1 version available. I will check if someone else has one and can do this test for you.

Best Regards,
Hiago.

Hi Hiago,

Yes please.
We would like to ask you to test two different boards:

  1. Board TK1 with rev 1.1
  2. Board TK1 with rev 1.2

Please test these two different boards for GPIO pins which go via K20 processor.
You can simply use information below for testing:

APALIS_PIN(181) which is K20_PTE5 in datasheet and calculated sysfs pin number 989
APALIS_PIN(173) which is K20_PTE1 in datasheet and calculated sysfs pin number 985
APALIS_PIN(175) which is K20_PTE0 in datasheet and calculated sysfs pin number 984

Commands in terminal:

Export pins

echo 989 > /sys/class/gpio/export

echo 985 > /sys/class/gpio/export

echo 984 > /sys/class/gpio/export

All good at this point

Set direction as input

echo “in” > /sys/class/gpio/gpio989/direction

echo “in” > /sys/class/gpio/gpio985/direction

echo “in” > /sys/class/gpio/gpio984direction

All good at this point.

We now can see these pins if give command:

cat /sys/kernel/debug/gpio

Finally we read their status or level:

cat /sys/class/gpio/gpio989/value

cat /sys/class/gpio/gpio985/value

cat /sys/class/gpio/gpio984/value

Hi @avionics,

Sorry for the long delay, I was able to test this scenario using an Apalis TK1 rev 1.2. However, checking the revision history, I couldn’t see any changes on the K20 side, so I hope it will be the same case for both boards.

So I first tested the L4T 2.8 ubuntu, same as you, and for me the K20 firmware was not running due to a driver error. I could check that by running # dmesg | grep k20. Tried to reinstall a couple of times but the same happened. So my first question is, for you the k20 is working, have you done any extra steps to make the k20 work?

I would like to ask if you can share your dmesg log with us. You can use this website: share.toradex.com and send me the link for download.

Next, I installed the newer BSP, version 5 minimal image and everything worked: the K20 was working now and the GPIO inputs too. I tested with a 3.3V input to gpio989, as you did:

root@apalis-tk1-03118050:/sys/devices/soc0/7000d600.spi/spi_master/spi1/spi1.1/apalis-tk1-k20-gpio/gpiochip2/gpio/gpio989# echo in > direction 
root@apalis-tk1-03118050:/sys/devices/soc0/7000d600.spi/spi_master/spi1/spi1.1/apalis-tk1-k20-gpio/gpiochip2/gpio/gpio989# cat value 
1
root@apalis-tk1-03118050:/sys/devices/soc0/7000d600.spi/spi_master/spi1/spi1.1/apalis-tk1-k20-gpio/gpiochip2/gpio/gpio989# cat value 
0
root@apalis-tk1-03118050:/sys/devices/soc0/7000d600.spi/spi_master/spi1/spi1.1/apalis-tk1-k20-gpio/gpiochip2/gpio/gpio989# cat value 
1
root@apalis-tk1-03118050:/sys/devices/soc0/7000d600.spi/spi_master/spi1/spi1.1/apalis-tk1-k20-gpio/gpiochip2/gpio/gpio989# 

Have you tried BSP 5 as well? If not, could you test with the minimal image to check if the error still occurs?

Best Regards,
Hiago.

Hi Hiago,

Thank you for getting back to me on this matter.
So first of all YES you are totally right, original K20 firmware from L4T 2.8 Ubuntu does NOT work.
I used different firmware taken from some older release of software.
Here is my info about software in K20:

root@tegra-ubuntu:~# dmesg | grep k20
[ 10.755778] apalis-tk1-k20 spi1.1: Apalis TK1 K20 MFD driver. Firmware version 1.4.
[ 10.834042] Modules linked in: bnep apalis_tk1_k20 bluetooth nvhost_vi
[ 10.834252] Modules linked in: bnep apalis_tk1_k20 bluetooth nvhost_vi
[ 11.003461] input: apalis-tk1-k20-ts as /devices/platform/spi-tegra114.1/spi_master/spi1/spi1.1/apalis-tk1-k20-ts/input/input1
[ 11.006975] apalis-tk1-k20-can apalis-tk1-k20-can.0: probed 0
[ 11.008200] apalis-tk1-k20-can apalis-tk1-k20-can.1: probed 1

After that I updated software in K20 it started to work and I was able to get CAN bus running. However my showstopper was and still it is: GPIO interfaces.

So now can you please tell me what is your firmware version inside of K20 which works with GPIO ?
Please run this command and copy me results:

dmesg | grep k20

Can you please share that firmware.bin with me ? I will update my K20 and will re-test GPIO again.
Possible that the firmware for K20 which I used despite supports CAN bus still does not support GPIO ? From dmesg above I can see that it is version 1.4.

I uploaded my dmesg log here: Download - Toradex File Sharing Platform
Answering your question: no I have not tried BSP5 due to lack of LVDS display support in that version.

Please let me know.
Thank you!!

Hi @avionics,

I confirm this on my side, I will talk to our team here internally so we can fix this issue.

Ok, as we can see you’re using version 1.4. Here I tested on version 1.5, which is the version that worked on my side.

root@apalis-tk1-03118050:~# dmesg | grep k20
[    8.044715] apalis-tk1-k20 spi1.1: Apalis TK1 K20 MFD driver. Firmware version 1.5.
[    8.084482] input: apalis-tk1-k20-ts as /devices/soc0/7000d600.spi/spi_master/spi1/spi1.1/apalis-tk1-k20-ts/input/input2
[    8.086811] apalis-tk1-k20-can apalis-tk1-k20-can.0: probed 0
[    8.107657] apalis-tk1-k20-can apalis-tk1-k20-can.1: probed 1

Checking the lsmod, I can see that changing only the .bin probably won’t be enough, since some kernel drivers are running as well:

root@apalis-tk1-03118050:~# lsmod
Module                  Size  Used by
apalis_tk1_k20_adc     16384  0
apalis_tk1_k20_can     20480  0
gpio_apalis_tk1_k20    16384  1
apalis_tk1_k20_ts      16384  0
xhci_tegra             20480  0
apalis_tk1_k20         20480  4 apalis_tk1_k20_ts,apalis_tk1_k20_can,gpio_apalis_tk1_k20,apalis_tk1_k20_adc
nouveau              1695744  0
ttm                    61440  1 nouveau

And also searching for the drivers and binary on my image, this is what I found:

root@apalis-tk1-03118050:~# ls /lib/firmware/ | grep k20
apalis-tk1-k20.bin
root@apalis-tk1-03118050:~# find /lib/modules/ -name "*k20*"
/lib/modules/5.4.193-5.7.0+git.f5d73fd6e9f8/kernel/drivers/input/touchscreen/apalis-tk1-k20_ts.ko
/lib/modules/5.4.193-5.7.0+git.f5d73fd6e9f8/kernel/drivers/iio/adc/apalis-tk1-k20_adc.ko
/lib/modules/5.4.193-5.7.0+git.f5d73fd6e9f8/kernel/drivers/mfd/apalis-tk1-k20.ko
/lib/modules/5.4.193-5.7.0+git.f5d73fd6e9f8/kernel/drivers/net/can/apalis-tk1-k20-can.ko
/lib/modules/5.4.193-5.7.0+git.f5d73fd6e9f8/kernel/drivers/gpio/gpio-apalis-tk1-k20.ko

So, for testing, I would recommend you download the image that I tested here, BSP 5.7 for Apalis TK1 which you can find it here: Toradex Download Links (Torizon, Linux BSP, WinCE and Partner Demos) | Toradex Developer Center

Inside the compressed file, there is the rootfs compressed file called Reference-Minimal-Image-apalis-tk1.tar.xz Inside, you will find the binary and kos files inside /lib/firmware and /lib/modules. You can test both upstream and downstream image versions.

About this question, which LVDS display are you trying to use? I can check here if the latest BSP supports your display or not.

Best Regards,
Hiago.

Hello Hiago,

Thank you very much for detailed investigation of our issue.
So far we understand that it is likely that our firmware.bin for K20 is of ver. 1.4 and it does not work as expected (GPIO) while you have tested it with firmware.bin ver. 1.5 which is incorporated in to newer BSP5 and it works well.
Also we understand that it is not only about K20 firwmware but also drivers inside of the BSP so likely even though we try to update K20 with 1.5 firmware bin file taken from newer BSP it will still not work (or even not update K20). So looks like we may have a dead end here.

Hiago we would like to ask you please about two possible solutions for our situation. Please note that we have little under 100pcs of TK1 modules so we really need to get them running.
I see two possible solutions here:

Solution1:
Can you guys please make required changes in L4T 2.8 Ubuntu image so it would support and have onboard K20 firmware of version 1.5 ? This would make first possible solution for us and we keep using this older L4T 2.8 version will have correct K20 firmware working along with BSP

Solution2:
Possibly solution 1 sounds too complex, then I would like to propose other solution here. Can you add a support for LVDS in newer BSP 5.7 or newer one ?
Our display is standard Toradex LVDS 10.1 (Capacitive Touch Display - 10 inch LVDS)
We use this exact type of display, it works perfectly with older L4T 2.8 Ubuntu. Our capacitive touch panel is little different though from original which supplied by Toradex but this is not a problem since we wrote own driver part and use it direct via i2c.
So if we can have a proper LVDS 10.1 support in BSP 5.7 this will be the ideal solution since it will allow us to use modern BSP with all its rich capabilities.

Please help with either solution proposed.
Thank you.

Hi @avionics,

Although this might be correct (that we also need the kernel modules), can you test to replace only the firmware to check if that works? I found the binary inside our Yocto Recipes for BSP 5. The firmware is inside meta-toradex-tegra/recipes-bsp/tdx-k20-fw/, with the following recipe:

DESCRIPTION = "Toradex Apalis TK1 K20 MCU Firmware"
HOMEPAGE = "https://developer.toradex.com/"
LICENSE = "CLOSED"

SRC_URI = " \
    file://apalis-tk1-k20.bin \
    file://LICENCE \
"

LIC_FILES_CHKSUM = "file://${WORKDIR}/LICENCE;md5=a1b1cf31b1b3d185409f31cb9beb25dc"

FILES_${PN} = " /lib/firmware/apalis-tk1-k20.bin "

do_install () {
    install -d ${D}/lib/firmware/
    install -m 0644 ${WORKDIR}/apalis-tk1-k20.bin ${D}/lib/firmware/
}

Please download it here: Download - Toradex File Sharing Platform (it will be available for one week).

Please, try the following:

  • Download the binary.
  • Copy to your module under /lib/firmware.
  • Reboot.

Next, check if the K20 is running with the new firmware and if the GPIO works.

Let me know if that helped, if not, we can discuss the other points that you made.

Best Regards,
Hiago.

Thank you Hiago,
I will test it today or tomorrow and will let you know.
Regards,

Hi Hiago,

I have done the test and results are below:

Test1:
Downloaded provided by you file firmware.bin
Copied it directly to /lib/firmware folder on TK1 board. Original firmware.bin I renamed to firmware.old
Rebooted board
Did command:
dmesg | grep k20

Got result:
[ 9.775562] apalis-tk1-k20 spi1.1: Apalis TK1 K20 MFD driver. Firmware version 1.4.
(there were more lines here but we interested in particular this one)

As you can see firmware version has not changed, means K20 have not updated on its own.

Tried to test GPIO - same result, it does not work as it was before.

Test2:
I decided to force K20 firmware update.
To do that I first created empty file firmware.bin with 1 kb size by giving command:
dd if=/dev/zero of=/lib/firmware/apalis-tk1-k20.bin bs=1 count=1

After that I rebooted board. It did completely erased K20 chip.
dmesg | grep k20
apalis-tk1-k20 spi1.1: Chip fully erased.

Now I copied again file which you provided in to /lib/firmware and rebooted board.
I would expect now that firmware gets flashed in to K20 from the file which you provided
but got this message after reboot (tried twice)

dmesg | grep k20
apalis-tk1-k20 spi1.1: Unsupported firmware version in both the device as well as the local firmware file.

After that I took my older firwmare.bin which is version 1.4 and copied it over yours file and rebooted board. It flashed it correct again but GPIO still does not work.

I suspect that inside of the L4T 2.8 image there is some mechanism which verify the version of the firmware.bin file in /lib/firmware folder vs whatever internal version it expects to have and if that does not match it refuses to flash it.

So I do not see any way of flashing 1.5 version in to my current L4T 2.8 image unless we have modified expectations in image for firmware of K20.

Can you please advise if there is a way for you guys to get us either BSP 5 with support of 10.1 LVDS display or modified L4T 2.8 with functional GPIO block in K20 ?
We do have too many of these boards and also our goal is to use specifically TK1 because we use OpenGL graphics a lot in our program so NVIDIA is ideal candidate for that purpose for us.
TK1 so far demonstrated much better GPU speed vs T30 and we happy with outcome except GPIO in K20.

Thank you,