This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Turning on the User LEDs on the AM335x EVM

Other Parts Discussed in Thread: TCA6408A, TPS65910, TLC59108, TMP275, OMAP-L138

I was attempting to enable the LEDs on the AM335x EVM and I was running into some issues.

I've been looking at the Rev 1.4A schematic and I found the User LED's section (Page 6). The are labeled D4-D7. Taking a look at one of the LEDs (D7) It looks like if any of the three inputs:
AM335X_UART1_TXD (D15)
AM335X_MCASP0_AHCLKX (A14)
AM335X_GPMC_A9 (U16)

are driven high, then the LED should turn on. Examining sheet 2 of the schematic, these Lines are connected to A14, D15, and U16 respectively. Each of these lines have GPIO functions

A14->GPIO3_21
D15->GPIO0_15
U16->GPIO1_25

I checked the /sys/kernel/debug/gpio and see none of these pins are in use, so I enabled them all as outputs:

root@am335x-evm: /sys/class/gpio# echo 15 > export
root@am335x-evm: /sys/class/gpio# echo 21 > export
root@am335x-evm: /sys/class/gpio# echo 25 > export
root@am335x-evm: /sys/class/gpio# echo "out" > gpio15/direction
root@am335x-evm: /sys/class/gpio# echo "out" > gpio21/direction
root@am335x-evm: /sys/class/gpio# echo "out" > gpio25/direction
root@am335x-evm: /sys/class/gpio# echo 1 > gpio15/value
root@am335x-evm: /sys/class/gpio# echo 1 > gpio21/value
root@am335x-evm: /sys/class/gpio# echo 1 > gpio25/value

Reading back we see:

root@am335x-evm:/sys/class/gpio# cat /sys/kernel/debug/gpio

GPIOs 0-31, gpio:
gpio-2 (volume-up ) in hi
gpio-3 (volume-down ) in hi
gpio-6 (mmc_cd ) in lo
gpio-15 (sysfs ) out hi
gpio-21 (sysfs ) out hi
gpio-25 (sysfs ) out hi

So they are enabled, but the LED doesn't turn on, so my question is what else needs to be done?

First I note that the GPIO banks on the schematic (GPIOX) are different so do we have to "export" something else special?

Is there a way to check via the file system if the chip is correctly configured for GPIO operation on each of these pads?

Is there a way to check via the file system if there is power on each circuit or do I need to measure that with a meter?

  • To convert (Bank, pin) to a linux gpio #:

    GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))

    Examples: 

    bank 1, pin 0 is linux gpio # 32. 

    bank 2, pin 1 id linux gpio # 65.

    Use in the linux gpio #s in sysfs.  If a gpio has been allocated in the kernel, it won't be available for export in sysfs.

  • Thanks for that insight. So that means that the proper GPIOs should be:

    A14->GPIO3_21 (GPIO117)
    D15->GPIO0_15 (GPIO15)
    U16->GPIO1_25 (GPIO57)

    Looks like:

    root@am335x-evm:/sys/class/gpio# echo 57 > export
    -sh: echo: write error: Device or resource busy
    root@am335x-evm:/sys/class/gpio# echo 117 > export
    -sh: echo: write error: Device or resource busy

    GPIO3_21 and GPIO1_25 must be in use by the kernel since they are not available to be exported. Still I would have though a single channel (GPIO15) should have been sufficient to enable the LED but clearly it was not so there's something else wrong...

  • Mike,

    Mike Worster said:
    I've been looking at the Rev 1.4A schematic and I found the User LED's section (Page 6). The are labeled D4-D7.

    Those LEDs are all labeled "DNI".  Are they actually present on your board? It seems the "real" LEDs are actually on the daughterboard:

    http://processors.wiki.ti.com/index.php/AM335x_General_Purpose_EVM_Board_Design_Files#Daughterboard

    In particular I'm looking at page 7 of Rev 1.2A.  Components D1-D8 hang off the I2C GPIO expanders.  Are those perhaps the ones you're trying to turn on?

  • Brad,

        You are totally correct, I was looking at the daughter card's LEDs. I just checked the PCB again and I see that both the daughter card and the processor board use the same naming for the User LEDs but on the processor board the LEDs are not placed. So it turns out I was looking to get the User LEDs on the Daughter card working.

    On sheet 7 of the daughter card schematic I see the feed in for the LEDs is VEXPD and the circuit is activated by a high signal on IOEXPAND0_DX (3 < X < 8)

    The rest of the schematic shows that these are output from the TCA6408A (U39) and available to be read via the J18 header.

    Now that link you pointed me to says they were able to turn the LEDs on by writing directly to the I2C, strange thing is I don't see this TCA6408A device in the I2C listings:

    root@am335x-evm:/sys/class# ls i2c-dev/
    i2c-1  i2c-2

    root@am335x-evm:/sys/class# ls i2c-dev/i2c-1/
    dev        device     name       power      subsystem  uevent
    root@am335x-evm:/sys/class# ls i2c-dev/i2c-1/device
    1-001b         1-0040         delete_device  name           subsystem
    1-002d         1-0050         device         new_device     uevent
    1-0035         1-0051         i2c-dev        power
    root@am335x-evm:/sys/class/i2c-dev/i2c-1/device# cat 1-001b/name
    tlv320aic3x
    root@am335x-evm:/sys/class/i2c-dev/i2c-1/device# cat 1-002d/name
    tps65910
    root@am335x-evm:/sys/class/i2c-dev/i2c-1/device# cat 1-0035/name
    cpld_reg
    root@am335x-evm:/sys/class/i2c-dev/i2c-1/device# cat 1-0040/name
    tlc59108
    root@am335x-evm:/sys/class/i2c-dev/i2c-1/device# cat 1-0050/name
    24c256
    root@am335x-evm:/sys/class/i2c-dev/i2c-1/device# cat 1-0051/name
    24c256

    root@am335x-evm:/sys/class# ls i2c-dev/i2c-2/device
    2-0018         2-0048         i2c-dev        power
    2-001b         delete_device  name           subsystem
    2-0039         device         new_device     uevent
    root@am335x-evm:/sys/class# cat i2c-dev/i2c-2/device/2-0018/name
    lis331dlh
    root@am335x-evm:/sys/class# cat i2c-dev/i2c-2/device/2-001b/name
    tlv320aic3x
    root@am335x-evm:/sys/class# cat i2c-dev/i2c-2/device/2-0039/name
    tsl2550
    root@am335x-evm:/sys/class# cat i2c-dev/i2c-2/device/2-0048/name
    tmp275

    Could you advise on how I can find and write to this device to verify the LEDs are working?

  • I found on the Hardware Guide:

    http://processors.wiki.ti.com/index.php/AM335x_General_Purpose_EVM_HW_User_Guide#I2C_Address_Assignments

    That the I/O expanders on the daughter card are what I'm looking for:

    I/O Expander 0

    I2C1/I2C2

    0x20

    I/O Expander 1

    I2C1/I2C2

    0x21

    I see the addresses are 0x20 and 0x21, and from the daughter card specification I see there are two TCA6408A expanders (U39 and U40). I assume these are 0x20 and 0x21 respectively.

    I tried to just do a dump on these addresses, but I end up hitting some bus timeout conditions:

    root@am335x-evm:/sys/class/i2c-dev/i2c-2/device# i2cdump -f -y 2 33
    No size specified (using byte-data access)
    0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
    00: 00 ff 00 ff [ 2727.241394] omap_i2c omap_i2c.2: timeout waiting for bus ready
    XX [ 2728.261383] omap_i2c omap_i2c.2: timeout waiting for bus ready
    XX [ 2729.281402] omap_i2c omap_i2c.2: timeout waiting for bus ready

    So since 0x20 and 0x21 are not listed in /sys/class/i2c-device, and since I can't directly read the registers... I'm not sure how I should be communicating with this device.

     

  • Mike,

    I'm glad that we're both on the same page.  Unfortunately it seems we're both stumped!  I've escalated this LED blinking question to our developers.  Hopefully they can shed some light on this situation and educate us on how to blink these LEDs!  I really thought I'd see those GPIO expanders mentioned in the am335xevm.c file, but I didn't see any mention. 

    We had a similar setup on the OMAP-L138 EVM.  You might want to take a look at board-da850-evm.c to see what was done there.  In particular at line 899 is a i2c_board_info structure that has a couple of GPIO expanders at addresses 0x20 and 0x21.  I'm hoping someone may already have a patch for this, but thought I'd mention this just in case.

    Brad

  • Brad,

        Thanks for the assistance. I have thought on it a bit and used the Qt code at the link (http://e2e.ti.com/support/arm/sitara_arm/f/791/t/223896.aspx) you pointed me to to hobble something together:

    #include <stdio.h>
    #include <stdlib.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <linux/i2c-dev.h>

    // I want to include this i2c.h, but it's a kernel file and can't be included in user code
    //#include "../board-support/linux-3.2.0-psp04.06.00.11/include/linux/i2c.h"

    void main() {

      int file;
      int adapter_nr = 2;
      int addr = 0x20; /* The I2C address for GPIO expander */
      char filename[20];
      char buf[10];

      snprintf(filename, 19, "/dev/i2c-%d", adapter_nr);
      file = open(filename, O_RDWR);
      if (file < 0) {
        /* add check for errno */
        exit(1);   }

      if (ioctl(file, I2C_SLAVE, addr) < 0) {
         /* add check for errno */
        exit(1);   }

    // I can't use the i2c_smbus_write_byte_data function because I can't seem to find it... it's in the
    // i2c.h file, but I can't find one to include from user space...
    //  if(i2c_smbus_write_byte_data(file,0x03, 0x00) < 0) {   buf[0] = 0x03;   buf[1] = 0x00;

       if(write(file,buf, 2) != 2) {
        /* if we got here we didn't configure the chip */
        exit(1);   }

    //  if(i2c_smbus_write_byte_data(file,0x01, 0x10) < 0) {   buf[0] = 0x01;   buf[1] = 0x10;
       if(write(file,buf, 2) != 2) {
        /* if we got here we didn't set the data */
        exit(1);   }

      close(file); }

    Anyway this works but I still have a few questions:
    1) can these LEDs be configured just in the file system (without extra code)?
    2) Is there a good description of the registers for the TCA6408A so that I know what is possible to do with the LEDs?
    3) Is there a way to use the SMBus (i2c_smbus_write_byte_data) to write the data?

    I've been following the example in the Qt code from the other question, so i'm not positive what I'm doing; but it's working. ;)

  • I'm glad you've made some progress!  Thanks for the updates.

    Mike Worster said:
    2) Is there a good description of the registers for the TCA6408A so that I know what is possible to do with the LEDs?

    Yes, see page 9 "Register Descriptions" in the data manual.  I'm trying to get some additional assistance for the other questions.

  • I'm a bit confused.  I was expecting to see devices on I2C1 at addresses 0x20 and 0x21, though i2cdetect doesn't actually see anything:

    root@am335x-evm:/sys/devices/platform# i2cdetect -r 1
    WARNING! This program can confuse your I2C bus, cause data loss and worse!
    I will probe file /dev/i2c-1 using read byte commands.
    I will probe address range 0x03-0x77.
    Continue? [Y/n] y
         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
    00:          -- -- -- -- -- -- -- -- -- -- -- -- --
    10: -- -- 12 -- -- -- -- -- -- -- -- UU -- -- -- --
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- UU -- --
    30: -- -- -- -- -- UU -- -- -- -- -- -- -- -- -- --
    40: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    50: UU UU 52 -- -- -- -- -- -- -- -- -- -- -- -- --
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70: -- -- -- -- -- 75 -- --
    root@am335x-evm:/sys/devices/platform# i2cdetect -r 2
    WARNING! This program can confuse your I2C bus, cause data loss and worse!
    I will probe file /dev/i2c-2 using read byte commands.
    I will probe address range 0x03-0x77.
    Continue? [Y/n] y
         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
    00:          -- -- -- -- -- -- -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- UU -- -- UU -- -- -- --
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- UU -- -- -- -- -- --
    40: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70: -- -- -- -- -- -- -- --

  • Mike,

    I received some very useful inputs from the SW Apps Manager.  (Thanks, Ron!!!)  In particular, he pointed me to some of the I2C tools that are available:

    http://www.lm-sensors.org/wiki/i2cToolsDocumentation

    The "i2cdetect" utility that I ran previously is actually part of this collection.  However, there's also i2cset/i2cget which are also very useful.  If your profile is configured such that these I/O expanders are on I2C1, then you can run the following commands to turn on the LEDs:

    • Configure all pins as outputs (register 0x03)
      • i2cset -y 1 0x20 0x03 0x00
      • i2cset -y 1 0x21 0x03 0x00
    • By default that will turn on all the pins since those pins default to "high".
    • Changes to the state of the output can be done through the "Output Port Register" (Register 1).  So for example, to turn off all the LEDs:
      • i2cset -y 1 0x20 0x01 0x00
      • i2cset -y 1 0x21 0x01 0x00

    One thing I still haven't solved is that i2cdetect was not working quite the way I expected.  In particular, re-running the same i2cdetect commands after having manipulated the LEDs yielded the following result:

         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
    00:          -- -- -- -- -- -- -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- UU -- -- UU -- -- -- --
    20: 20 21 -- -- -- -- -- -- -- -- -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- UU -- -- -- -- -- --
    40: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70: -- -- -- -- -- -- -- --

    If anyone can explain that one, please do!  :-)

  • Brad, Thank you so much! That was exactly what I needed! My profile is set that the expanders are on i2c-2 so I just had to tweak the command:

    i2cset -y 2 0x20 0x03 0x00

    i2cset -y 2 0x20 0x01 0x00

    and now I see them lighting up. I see the same results as you in the i2cdetect (nothing before the set, then they're present after) I still don't have an answer as to why that is, but at least everything's working.

  • Hi,

    I've sperimented the same situation so I've read the datasheet for the I2C expander. The command 0x03 isn't for control the output, it's for configure the pin as input or output. So for correct use:

    1) Configure expander's pin as output

    i2cset -y 2 0x20 0x03 0x00

    3) Set the pin that you want:

    ex. i2cset -y 2 0x20 0x01 0x00 -> all the leds are off

           i2cset -y 2 0x20 0x01 0x10 -> D1 on

           i2cset -y 2 0x20 0x01 0x20 -> D2 on

    And so on.