element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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
  • 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
Code Exchange
  • Technologies
  • More
Code Exchange
Forum Beaglebone & C
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Code Exchange to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 11 replies
  • Answers 2 answers
  • Subscribers 49 subscribers
  • Views 1648 views
  • Users 0 members are here
  • c
  • compilers
  • embedded
Related

Beaglebone & C

Former Member
Former Member over 11 years ago

I've been playing with I/O ports in Javascript, that works fine, but basically I'm a C programmer.  I want to do the same, read a sensor and turn things on & off with the beaglebone using C.  The only information I've found so far is a wiki about embedded C that references a header file, iohw.h that makes it all possible, but which doesn't exist within the C compiler in the Angstrom or Debian distributions.  Shall I assume that what I want to do cannot be done in C on the beaglebone?  A standard ansi C manual has nothing on the topic for obvious reasons, and if there's any documentation for the beaglebone's C compiler it has escaped my searches so far.  Can this be done, and if so, what is the function to write a bit to gpio44 or read a bit from gpio46?

  • Sign in to reply
  • Cancel

Top Replies

  • Former Member
    Former Member over 11 years ago in reply to mconners +2
    Michael Conners wrote: Realize that is one of the things you give up when going from bare metal to working with an operating system. The OS becomes the gatekeeper between you and the underlying hardware…
  • mconners
    mconners over 11 years ago in reply to Former Member +1
    There is nothing stopping you from getting to the specific architecture of the chip as far as the compiler goes. You can still get there, that's how they wrote the OS in the first place. I'm just saying…
  • mconners
    mconners over 11 years ago in reply to mconners +1
    Another good resource http ://derekmolloy.ie/beaglebone/beaglebone-gpio-programming-on-arm-embedded-linux/ Mike
  • johnbeetem
    0 johnbeetem over 11 years ago

    I've accessed GPIOs on a BeagleBoard using mmap().  Here's an old Google Groups thread on the topic: https://groups.google.com/forum/#!topic/beagleboard/_29qqEOv2VA

     

    I suspect the Bone is similar, with different addresses.  You will probably have to "sudo" to be able to mmap() the GPIOs directly.  The thread has some other methods that may be easier.

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

    Thanks.  I'll give that a try. I thought about writing direct to the registers, but the chip data sheet only gives the offsets to the registers, I'm still looking for the base address.  With the microcontrollers I'm used to working with if you want to do something to PORTB you just call it PORTB or PORTB,4 to play with bit 4. there's no need to plow through a 4700 page chip manual to find an address you can attach to a symbolic name.  It doesn't look like any of the names for ports are in the C compiler, unless they're in a header file I haven't found yet.  I'll admit I'm a bit rusty, my last serious exposure to unix was System 5 Rev. 4 on Unisys 6000-50's handling 911 call centers.  Yeah, that long ago. :-)

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

    No, C wouldn't know about the device registers for any particular SoC.  There may be header files somewhere, but I don't know where.  A lot of GNU/Linux programmers use a device driver on SBCs like Raspberry Pi and Beagles.  Personally, I prefer mmap() and accessing the registers, but maybe I'm still stuck in the PDP-11 days :-)

     

    Raspberry Pi GPIO is quite well developed and supported, and maybe some of this applies to Beagle: RasPi Hardware Wiki

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

    Realize that is one of the things you give up when going from bare metal to working with an operating system. The OS becomes the gatekeeper between you and the underlying hardware. This is by design. There are concepts that the beagle bone uses where they expose the pins via device drivers. This is how bonescript works underneath. It's been a while since I have looked at it, but I know it's there and with a little research you could probably find it. The next best thing would be to write your own device driver that behaves the way you want it to. There are free documents available on writing linux device drivers, so maybe that is a direction you could go.

     

    I'll try to take a look around this weekend and see if I can find the sources I used when I looked into this earlier.

     

    Good luck, learn and have fun,

     

    Mike

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

    BTW, though, the things you gain by using an OS are incredible as well, you don't have to include your disk IO routines in every program, you don't have to worry about user IO, networking etc. But there are tradeoffs.

     

    Mike

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

    So basically programming a beaglebone in C isn't all that different from writing programs on the old AMD K-7 with Debian on the other side of my room, just a lot smaller.  With Linux being a lot more generic as opposed to a C compiler written for a specific architecture the chip specific stuff will suffer.

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

    There is nothing stopping you from getting to the specific architecture of the chip as far as the compiler goes. You can still get there, that's how they wrote the OS in the first place. I'm just saying that when there is on OS involved you should look at the problem a little differently.

     

    You may not know at any given time what the OS is doing with the underlying hardware. I don't believe you would damage anything, but you could certainly introduce instability and unexpected system lockups.

     

    Take a look at this blog post from shabaz ,a very knowledgeable element14 contributor. It might get you started on your way. This isn't the documentation I mentioned I had found before, it's better. image

     

    http://www.element14.com/community/community/knode/single-board_computers/next-gen_beaglebone/blog/2013/10/10/bbb--beaglebone-black-io-library-for-c

     

    Hope this is helpful,

     

    Mike

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mconners
    0 mconners over 11 years ago in reply to mconners

    Another good resource

     

     

    http://derekmolloy.ie/beaglebone/beaglebone-gpio-programming-on-arm-embedded-linux/

     

    Mike

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

    Thanks, it looks like that will save me a year or two of work.  It looks like what I was planning to try to write. image

    • 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 mconners

    Michael Conners wrote:

     

    Realize that is one of the things you give up when going from bare metal to working with an operating system. The OS becomes the gatekeeper between you and the underlying hardware. This is by design. There are concepts that the beagle bone uses where they expose the pins via device drivers.

    GPIOs in Linux typically get exposed by the driver under /sys/class/gpio and you can do a lot of things that way including interrupt driven.  There are of course trade-offs, the interface can be slow - certainly much slower than direct register manipulation.  One of the big advantages though is that code you write to use /sys/class/gpio can run on virtually any linux system that has a gpio driver, your code no longer needs to know SoC specific details.

     

    One of the other trade-offs of using linux is that the gpio driver for your SoC will rightly assume that when it's loaded then it owns all of the registers and resources associated with the gpios it's been asked to control.

    So when you go behind it's back and do some direct register manipulation you shouldn't be surprised if at some point your code doesn't behave well, it's highly likely to be due to the 'owner' of the registers you're using overwriting what you're trying to do.

    Ideally you want to stop the driver touching those registers, but often that's not so easy due to the heavy use of gpios by other things on the board.

    • Cancel
    • Vote Up +2 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