element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Avnet Boards Forums
  • Products
  • Dev Tools
  • Avnet Boards Community
  • Avnet Boards Forums
  • More
  • Cancel
Avnet Boards Forums
ZedBoard Hardware Design Accessing LEDs and Switches in Xillinux
  • Forum
  • Documents
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Avnet Boards Forums to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 21 replies
  • Subscribers 333 subscribers
  • Views 2625 views
  • Users 0 members are here
Related

Accessing LEDs and Switches in Xillinux

Former Member
Former Member over 11 years ago

Hi there,

I've installed Xillinux on my ZedBoard, and I'm wanting to simply read switch values and write LED values, like in the ZedBoard Getting Started Guide, but I don't see anything in /sys/class/gpio, only export, unexport and gpiochip0. I've read and tried a lot of things to get it working, but don't seem to be getting anywhere.

Can anybody please explain to me how to go about achieving this?

Thanks

  • Sign in to reply
  • Cancel

Top Replies

  • jafoste4
    jafoste4 over 8 years ago +1
    Hi, You could try taking a look at these documents, especially lab 3 http://zynqhowto.blogspot.kr/search?updated-max=2014-04-02T19:44:00-07:00&max-results=7 --Josh
Parents
  • Former Member
    0 Former Member over 11 years ago

    Hello,

    Xillinux uses Linux' standard GPIO convention for accessing LEDs and switches (and PMODs for that matter)

    Please refer to the xillydemo.ucf file under verilog/src (or vhdl/src, they're the same). Even if you don't understand all the details, it's clear that the following segment

    <------- Cut here -------->

    # On-board LEDs. Note that only for LEDs are allocated, as opposed to
    # Digilent's eight, and all placements that follow are shifted by four.
    # There was no other choice, as the tools don't allow unplaced PS GPIO pins.

    NET  PS_GPIO[7] LOC = V22 | IOSTANDARD = LVCMOS33;    # LD4
    NET  PS_GPIO[8] LOC = W22 | IOSTANDARD = LVCMOS33;    # LD5
    NET  PS_GPIO[9] LOC = U19 | IOSTANDARD = LVCMOS33;    # LD6
    NET  PS_GPIO[10] LOC = U14 | IOSTANDARD = LVCMOS33;    # LD7

    <------- Cut here -------->

    tells us that one of the LEDs is mapped at GPIO7. In order to access the LED from Linux, the standard command line interface can be used. There is an offset between the GPIO number in the UCF file and the one used in Linux, and it's 54 on Xillinux. So in Linux, the GPIO number for this LED should be 54+7=61.

    Which means that the following sequence should turn the LED on and off.

    At shell prompt, try

    echo 61 > /sys/class/gpio/export
    echo out > /sys/class/gpio/gpio61/direction
    echo 1 > /sys/class/gpio/gpio61/value
    echo 0 > /sys/class/gpio/gpio61/value

    There is plenty of documentation on Linux GPIO interface. There's also a faster API for application programming.

    For example, see http://falsinsoft.blogspot.co.il/2012/11/access-gpio-from-linux-user-space.html

    Hope this helped,
       Eli

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • Former Member
    0 Former Member over 11 years ago

    Hello,

    Xillinux uses Linux' standard GPIO convention for accessing LEDs and switches (and PMODs for that matter)

    Please refer to the xillydemo.ucf file under verilog/src (or vhdl/src, they're the same). Even if you don't understand all the details, it's clear that the following segment

    <------- Cut here -------->

    # On-board LEDs. Note that only for LEDs are allocated, as opposed to
    # Digilent's eight, and all placements that follow are shifted by four.
    # There was no other choice, as the tools don't allow unplaced PS GPIO pins.

    NET  PS_GPIO[7] LOC = V22 | IOSTANDARD = LVCMOS33;    # LD4
    NET  PS_GPIO[8] LOC = W22 | IOSTANDARD = LVCMOS33;    # LD5
    NET  PS_GPIO[9] LOC = U19 | IOSTANDARD = LVCMOS33;    # LD6
    NET  PS_GPIO[10] LOC = U14 | IOSTANDARD = LVCMOS33;    # LD7

    <------- Cut here -------->

    tells us that one of the LEDs is mapped at GPIO7. In order to access the LED from Linux, the standard command line interface can be used. There is an offset between the GPIO number in the UCF file and the one used in Linux, and it's 54 on Xillinux. So in Linux, the GPIO number for this LED should be 54+7=61.

    Which means that the following sequence should turn the LED on and off.

    At shell prompt, try

    echo 61 > /sys/class/gpio/export
    echo out > /sys/class/gpio/gpio61/direction
    echo 1 > /sys/class/gpio/gpio61/value
    echo 0 > /sys/class/gpio/gpio61/value

    There is plenty of documentation on Linux GPIO interface. There's also a faster API for application programming.

    For example, see http://falsinsoft.blogspot.co.il/2012/11/access-gpio-from-linux-user-space.html

    Hope this helped,
       Eli

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • Former Member
    0 Former Member over 11 years ago in reply to Former Member

    Thanks Eli, that perfectly explained it.

    Just a follow up, I don't really need to, but is it possible to use LD0-3 easily? Would I just change this line:

    NET  "GPIO_LED[0]"          LOC = T22  | IOSTANDARD=LVCMOS33;  # "LD0"

    to something like this:

    NET  PS_GPIO[56] LOC = T22 | IOSTANDARD = LVCMOS33;t# LD0

    or would that cause problems with GPIO_LED[0] not being able to be found?

    Thanks again.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to Former Member

    Hi,

    There's no problem taking over the four LEDs that are currently used by the Xillybus IP core (heartbeat + activity indicators).

    I would suggest assigning a vacant pin to the GPIO_LED[] port that has been removed from its led, or turn it into a wire (Verilog) or signal (VHDL) rather than a port in the toplevel HDL module.

    Either way, Xillinux is configured for 56 GPIOs, so there is no PS_GPIO[56]. You'll have to take one from the PMODs or something.

    Which brings me to the simplest solution -- just swap pins between a GPIO_LED[] and a PS_GPIO[] pin.

    Regards,
       Eli

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to Former Member

    Good to know, thank you.

    Sorry for all the questions, but you've been very helpful so far, so I figure I may as well ask...

    I've been following this guide: http://forums.xilinx.com/xlnx/attachments/xlnx/ELINUX/8467/1/zedboard_CTT_v2013_2_130807.pdf particularly part 5.4 Controlling LEDs and Switches in Linux Example. So instead of accessing the LEDs directly, I'm controlling them from within the PL.

    I'm fine with the creation of the design, but when I put this on the SD card, it doesn't appear to boot up properly. I've tried replacing both the boot.bin and xillydemo.bit files. What should I be doing?

    Thanks

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to Former Member

    Hello,

    I'm afraid I'm not going to be so helpful this time...

    When you mix binaries from different settings (i.e. Xillinux' and Xilinx' sample designs), there are so many things that can go wrong, that it's quite hopeless (and even more so, pointless) to attempt debugging it remotely.

    If you're interested in controlling the LEDs as shown in Xilinx' guide, I suggest adopting the spirit shown there, and implement it on Xillinux' development bundle. Or go 100% for Xilinx' sample design.

    Alternatively, you can adopt Xillinux' method of talking with the hardware -- through Xillybus pipes.

    Regards,
       Eli

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to Former Member

    How do you determine the base offset to add to the number obtained from the UCF file. (the 54 in the Xillinux case)

    I searched everywhere but I wasn't able to find a reference for this information.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube