GPIO and UART

  • Hello,
    I have installed the armStoneA8-V1.1 package and already written a simple hello world to ensure the toolchain works. It does.
    Because I am a Linux newbie, I am already proud of what I reached so far.
    Now, I am trying to address a 3,3V serial device via rx and tx pins on the armstone A8 rev1.0. but i do not have any idea how to do this.
    I transferred the gpio example I downloaded from your site and tried to start it. It crashed.
    in your source you use:
    #define SYS_DIR "/sys/class/gpio/gpio145/direction"
    #define SYS_VAL "/sys/class/gpio/gpio145/value".
    Those directories do not exist on my system.
    There are a lot of other "gpio" directories, but none of them contains a "direction" or a "value" folder.
    Are there any other examples how to "talk" to hardware?
    The spi example does not work either.
    #define DEFAULT_ADAPTER "/dev/spidev1.0" odes not exist...


    Regards,
    Johann

  • Quote from "johann"

    I transferred the gpio example I downloaded from your site and tried to start it. It crashed.
    in your source you use:
    #define SYS_DIR "/sys/class/gpio/gpio145/direction"
    #define SYS_VAL "/sys/class/gpio/gpio145/value".


    Please use the pin numbers that are listed in the armStoneA8 GPIO Reference Card. But for simply using a standard serial connection, just use the serial device /dev/ttySAC2 and RX/TX on pins 36 and 38. You don't need to write your own serial driver.

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • as you read in the last post you need to use the reference card. then you can use the gpio sysfs to export the pins you need and to setup the direction etc.. see gpio.txt in the Linux Kernel Documentation http://git.kernel.org/?p=linux…516018846f60c2ab5501900bc

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Hello,
    first of all I want to say thank you for the response.
    I have a new problem, still concerning the UART.
    When I try to open a connection to /dev/ttySAC2 the system breaks stopps and a few seconds later the following appears:



    BUG: soft lockup - CPU#0 stuck for 23s! [a.out:780]
    Modules linked in:


    Pid: 780, comm: a.out
    CPU: 0 Not tainted (3.3.7-F+S #1)
    PC is at __do_softirq+0x40/0x100
    LR is at irq_exit+0x44/0xa8
    pc : [<c0022058>] lr : [<c00224f8>] psr: 20000113
    sp : cf38dc98 ip : 00000001 fp : 00000000
    r10: c0584500 r9 : 0000000a r8 : 00000017
    r7 : c0584544 r6 : cf38c000 r5 : 00000000 r4 : 00000002
    r3 : 00000102 r2 : cf38c000 r1 : 00000001 r0 : 00000000
    Flags: nzCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment user
    Control: 10c5387d Table: 4f394019 DAC: 00000015
    [<c0011a34>] (unwind_backtrace+0x0/0xe0) from [<c005095c>] (watchdog_timer_fn+0xe8/0x13c)
    [<c005095c>] (watchdog_timer_fn+0xe8/0x13c) from [<c00375c8>] (__run_hrtimer.isra.21+0x50/0xec)
    [<c00375c8>] (__run_hrtimer.isra.21+0x50/0xec) from [<c0037cdc>] (hrtimer_interrupt+0xf0/0x22c)
    [<c0037cdc>] (hrtimer_interrupt+0xf0/0x22c) from [<c0018bf8>] (s5p_clock_event_isr+0x10/0x18)
    [<c0018bf8>] (s5p_clock_event_isr+0x10/0x18) from [<c005120c>] (handle_irq_event_percpu+0x30/0x170)
    [<c005120c>] (handle_irq_event_percpu+0x30/0x170) from [<c0051388>] (handle_irq_event+0x3c/0x5c)
    [<c0051388>] (handle_irq_event+0x3c/0x5c) from [<c0053510>] (handle_level_irq+0xb8/0xd0)
    [<c0053510>] (handle_level_irq+0xb8/0xd0) from [<c0050c24>] (generic_handle_irq+0x2c/0x40)
    [<c0050c24>] (generic_handle_irq+0x2c/0x40) from [<c00196e0>] (s3c_irq_demux_vic_timer+0x54/0x6c)
    [<c00196e0>] (s3c_irq_demux_vic_timer+0x54/0x6c) from [<c0050c24>] (generic_handle_irq+0x2c/0x40)
    [<c0050c24>] (generic_handle_irq+0x2c/0x40) from [<c000e094>] (handle_IRQ+0x60/0x84)
    [<c000e094>] (handle_IRQ+0x60/0x84) from [<c0008548>] (vic_handle_irq+0x90/0xd4)
    [<c0008548>] (vic_handle_irq+0x90/0xd4) from [<c000d400>] (__irq_svc+0x40/0x70)
    Exception stack(0xcf38dc50 to 0xcf38dc98)
    dc40: 00000000 00000001 cf38c000 00000102
    dc60: 00000002 00000000 cf38c000 c0584544 00000017 0000000a c0584500 00000000
    dc80: 00000001 cf38dc98 c00224f8 c0022058 20000113 ffffffff
    [<c000d400>] (__irq_svc+0x40/0x70) from [<c0022058>] (__do_softirq+0x40/0x100)
    [<c0022058>] (__do_softirq+0x40/0x100) from [<c00224f8>] (irq_exit+0x44/0xa8)
    [<c00224f8>] (irq_exit+0x44/0xa8) from [<c000e098>] (handle_IRQ+0x64/0x84)
    [<c000e098>] (handle_IRQ+0x64/0x84) from [<c0008548>] (vic_handle_irq+0x90/0xd4)
    [<c0008548>] (vic_handle_irq+0x90/0xd4) from [<c000d400>] (__irq_svc+0x40/0x70)
    Exception stack(0xcf38dd10 to 0xcf38dd58)
    dd00: c053d440 60000113 cf2c5b00 00000001
    dd20: 60000113 cf3779c0 0000004c 00000000 c053d440 60000113 c053d420 00000000
    dd40: 00000000 cf38dd58 c03c6218 c03c621c 60000113 ffffffff
    [<c000d400>] (__irq_svc+0x40/0x70) from [<c03c621c>] (_raw_spin_unlock_irqrestore+0x10/0x3c)
    [<c03c621c>] (_raw_spin_unlock_irqrestore+0x10/0x3c) from [<c00521ac>] (__setup_irq+0x2fc/0x3c4)
    [<c00521ac>] (__setup_irq+0x2fc/0x3c4) from [<c0052350>] (request_threaded_irq+0xdc/0x12c)
    [<c0052350>] (request_threaded_irq+0xdc/0x12c) from [<c021d18c>] (s3c64xx_serial_startup+0x30/0x7c)
    [<c021d18c>] (s3c64xx_serial_startup+0x30/0x7c) from [<c021bb68>] (uart_startup.part.7+0x70/0x1b8)
    [<c021bb68>] (uart_startup.part.7+0x70/0x1b8) from [<c021c6b0>] (uart_open+0xd0/0x12c)
    [<c021c6b0>] (uart_open+0xd0/0x12c) from [<c0205cd4>] (tty_open+0x34c/0x4ec)
    [<c0205cd4>] (tty_open+0x34c/0x4ec) from [<c0080cbc>] (chrdev_open+0x178/0x1a0)
    [<c0080cbc>] (chrdev_open+0x178/0x1a0) from [<c007bd4c>] (__dentry_open.isra.13+0x1e4/0x2f0)
    [<c007bd4c>] (__dentry_open.isra.13+0x1e4/0x2f0) from [<c0089850>] (do_last.isra.34+0x688/0x6b8)
    [<c0089850>] (do_last.isra.34+0x688/0x6b8) from [<c0089a44>] (path_openat+0xb4/0x350)
    [<c0089a44>] (path_openat+0xb4/0x350) from [<c0089dc0>] (do_filp_open+0x2c/0x78)
    [<c0089dc0>] (do_filp_open+0x2c/0x78) from [<c007ca60>] (do_sys_open+0xd8/0x170)
    [<c007ca60>] (do_sys_open+0xd8/0x170) from [<c000d800>] (ret_fast_syscall+0x0/0x30)



    Executing the same programm with e.g. /dev/ttySAC0 works fine. Changing Baudrate and sending data is no problem here.
    What might be the reason for this?
    Part of my code:

    Code
    1. ...
    2. int fd;
    3. struct termios options;
    4. fd = open(argv[1], O_RDWR | O_NOCTTY | O_NDELAY);
    5. if(fd == -1)
    6. {
    7. printf("ERROR Open Serial Port!");
    8. }
    9. ...


    As I already mentioned in my last post, I have the armstone A8 rev1.0.
    Is the second serial device "dev/ttySAC1", with RX/TX on pins 12 and 14?


    Thank you in advance,
    Johann

  • Yes, pins 12+14 belong to ttySAC1 on Rev 1.10. By the way there is no Rev 1.0, only Rev 1.10 or Rev 1.20.


    But please be careful! ttySAC0 is using RS232 levels, i.e. +/-12V. So this port can be connected directly to the PC. But ttySAC1 and ttySAC2 are using TTL levels (0 + 3.3V) on Rev1.10. This pins can not be connected directly to a PC!!! You need an external level shifter if you want to do this.


    Remark: ttySAC2 will be changed to RS232 levels on Rev1.20 to have a second serial line available without the need for an external level shifter.

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Hello,
    you are right, i have revision 1.1
    Board: armStoneA8-V1.10
    Software: armStoneA8-V1.1 (23.05.2012)
    I accidently took the version from the reference card (ArmStoneA8 GPIO Reference Card (V1.0))


    The RS232 <-> TTL Level differences i know. Thank you.


    Measuring with my oscilloscope i have following: Pin 14 (ttySAC1,TX) -> 0V; Pin 38 (ttySAC2,TX) ->3.3V directly after switching on?!?!
    Using the following code:


    calling ./a.out /dev/ttySAC0 works fine and prints a lot of 'a's on my console (clearly visible on my osci)
    calling ./a.out /dev/ttySAC1 nothing happens (on the osci)
    calling ./a.out /dev/ttySAC2 system crashes.
    What am I doing wrong?
    I already re-installed the OS, but nothing changed...


    Regard,
    Johann

  • Hi,


    please, would you be a bit more precise:


    Quote from "fs-support_HK"


    Please use the pin numbers that are listed in the armStoneA8 GPIO Reference Card. But for simply using a standard serial connection, just use the serial device /dev/ttySAC2 and RX/TX on pins 36 and 38. You don't need to write your own serial driver.


    Quote from "fs-support_DK"

    as you read in the last post you need to use the reference card. then you can use the gpio sysfs to export the pins you need and to setup the direction etc.. see gpio.txt in the Linux Kernel Documentation http://git.kernel.org/?p=linux…516018846f60c2ab5501900bc


    The armstrongA8 GPIO Reference Card and <!-- m --><a class="postlink" href="http://git.kernel.org/?p=linux/kernel/git/stable/linux-stable.git;a=blob;f=Documentation/gpio.txt;h=620a07844e8cee6af9fe7415c7cd016766252250;hb=76e10d158efb6d4516018846f60c2ab5501900bc">http://git.kernel.org/?p=linux/kernel/g ... b5501900bc</a><!-- m --> are talking about /sys/class/gpio/gpio#, but


    $ cd /sys/class/gpio
    $ ls
    export gpiochip137 gpiochip181 gpiochip226 gpiochip40 gpiochip89
    gpiochip0 gpiochip14 gpiochip188 gpiochip23 gpiochip47 gpiochip9
    gpiochip104 gpiochip146 gpiochip197 gpiochip235 gpiochip56 gpiochip96
    gpiochip112 gpiochip155 gpiochip206 gpiochip244 gpiochip62 unexport
    gpiochip120 gpiochip164 gpiochip212 gpiochip29 gpiochip71
    gpiochip128 gpiochip172 gpiochip221 gpiochip35 gpiochip80


    <!-- m --><a class="postlink" href="http://git.kernel.org/?p=linux/kernel/git/stable/linux-stable.git;a=blob;f=Documentation/gpio.txt;h=620a07844e8cee6af9fe7415c7cd016766252250;hb=76e10d158efb6d4516018846f60c2ab5501900bc#l674">http://git.kernel.org/?p=linux/kernel/g ... 900bc#l674</a><!-- m -->



    Does this mean, all GPIOs on the armstoneA8 board are read only? How to read or write a specific pin?


    TIA,
    Chris

  • You first have to write the GPIO number that you are interested in to /sys/class/gpio/export. Then the appropriate /sys/class/gpio/gpio# subdir will appear.


    So if you want to use Pin #3 of the armStone's feature connector, you'll find by looking into the reference card that this is GPIO number 146. So you write this number to the export file:

    Code
    1. echo 146 >/sys/class/gpio/export


    Now you have a subdirectory /sys/class/gpio/gpio146 with all the settings that you need.


    In fact this is explained in exactly the same file that you cited, only a few lines earlier:

    Code
    1. 617 /sys/class/gpio/
    2. 618
    3. 619 "export" ... Userspace may ask the kernel to export control of
    4. 620 a GPIO to userspace by writing its number to this file.
    5. 621
    6. 622 Example: "echo 19 > export" will create a "gpio19" node
    7. 623 for GPIO #19, if that's not requested by kernel code.


    And also the example program (from the examples directory of the armStoneA8 release archive) shows the access to the export file.

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Quote from "fs-support_HK"

    You first have to write the GPIO number that you are interested in to /sys/class/gpio/export. Then the appropriate /sys/class/gpio/gpio# subdir will appear.


    ARGL :) Thank's, it's working now.


    Chris

  • Quote from "johann"

    calling ./a.out /dev/ttySAC0 works fine and prints a lot of 'a's on my console (clearly visible on my osci)
    calling ./a.out /dev/ttySAC1 nothing happens (on the osci)
    calling ./a.out /dev/ttySAC2 system crashes.


    We have found the UART problem and have a patch available. Please see here.

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

    Edited once, last by fs-support_HK ().

  • I have fixed the link above. Thanks for pointing this out.


    Your F&S Support Team

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.