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
  • 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
RoadTests & Reviews
  • Products
  • More
RoadTests & Reviews
Blog HARTING MICA: Develop and Debug a C GPIO Example in Eclipse - Part 1: User Experience
  • Blog
  • RoadTest Forum
  • Documents
  • RoadTests
  • Reviews
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join RoadTests & Reviews to participate - click to join for free!
  • Share
  • More
  • Cancel
  • Author Author: Jan Cumps
  • Date Created: 24 Apr 2019 9:00 PM Date Created
  • Views 2998 views
  • Likes 10 likes
  • Comments 17 comments
Related
Recommended
  • cross-compiling
  • mica
  • harting
  • eclipse

HARTING MICA: Develop and Debug a C GPIO Example in Eclipse - Part 1: User Experience

Jan Cumps
Jan Cumps
24 Apr 2019

I'm road testing the Harting MICA Complete IIoT Starter Kit.

In this post, I present a cross-compile and cross-debug example that talks to the MICA hardware.

 

I develop a Linux C GPIO example on a Windows 10 laptop, in Eclipse.

The binary is built in Eclipse using a cross-compiler for ARM Linux.

The Eclipse debugger then moves the binary to the Harting MICA, and starts a remote debug session.

I step through the code from the Windows Eclipse session, while the program executes on the MICA.

The usual debug options, such as variable view and breakpoints, are available just like in a local debug session.

image

I have done this kind of exercise before, on other linux boards (Pi, BBB). But with the MICA it's different.

The applications for the MICA run in a dedicated container, in my case a Linux virtual machine.

 

 

GPIO Library and Example

 

Harting provdes a Linux shared library for the MICA I/O. It has the option to set direction, get and read state of an I/O line.

It also supports listening to state changes via a callback.

It comes with a small example program that runs through the input, output and listen options.

 

This is a great candidate to check how to set up a cross-platform development chain for the MICA.

Even thought the example is small, it ticks many boxes to try out cross-compilation on Windows:

  • dependent on a Linux shared library
  • that library is depending on other shared libraries
  • talk to MICA hardware
  • ideal to test if the build process works
  • ideal to do the first remote debug session, from Windows Eclipse, on the MICA running Linux
  • Requires installation and preparation of a container (=VM) on the MICA,
    but it is understandable because the missing dependencies are small.

 

A snippet of the example code:

 

#include "mica_gpio.h"
// ...
void cb(int id, enum MICA_GPIO_STATE state, void *data) {
  printf("Input: %d state: %d changed (data: %s)\n", id, state, (char *) data);
  fflush(stdout);
}

int main(int argc, char* argv[]) {
  char *data = "user data";
  mica_gpio_set_callback(cb, data);

  int direction = mica_gpio_get_direction(1);
  printf("Direction %d\n", direction);
  mica_gpio_set_direction(1, INPUT);
  mica_gpio_set_enable(1, TRUE);
  sleep(1);
  mica_gpio_set_enable(1, FALSE);
  int state = mica_gpio_get_state(1);
  printf("State %d\n", state);
// ...

 

Example GPIO API functions:

 

image

source: HARTING MICA GPIO Library Documentation

 

Fun fact: the GPIO pins are industrial range. In my case 24 V image.

 

The example first registers a listener for I/O changes, then does manipulations of I/O pin 1.

It will set the output direction and values, and read them too.

All the time, the listener will wake up when the pin changes, and logs info (that you can see real-time in Eclipse running on Windows if you are debugging!)

 

What Does Eclipse Offer?

 

The Harting example lets you build your code on the MICA, from the command line.

I want to up the user experience by showing how it can be done from an IDE, with build and debug integration (and version control integration is possible too).

goal: How to set up an interactive environment where you can write code, deploy, test and debug.

 

I'm using he ARM DS-5 Community version of Eclipse. It offers a cross-compile and remote debug environment.

The compile and link toolset is Linaro's Windows cross-compilation suite with Linux ARM as target.

For remote debugging, I use the Eclipse GDB plugin. It connects to the MICA at debug time to upload the binary and execute it in debug mode on Linux.

 

While developing, you get the usual eclipse features like syntax highlighting and include management.

Building - done by the cross-compile toolchain - is similar to making a native application or firmware for a microcontroller. You push the build button.

When you debug, the Eclipse plugin moves the binary to the MICA via sFTP (to be installed, see later) and sets the executable flag.

It then starts the GDB server on the MICA (to be installed, see later) that loads your binary and halts it at the main().

You can then use the typical debug features to step through the code, set breakpoints, watch variables, expressions and memory.

 

image

This is a rich tool set.

 

In the next posts I'll cover:

  • Configure the MICA option 1: Linux Debian Stretch container
  • Set up Eclipse and Tool chain
  • Getting Linux dependencies on the Windows development environment.
  • Starting a debug session.
  • Configure the MICA option 2: Busybox container

 

Thank you for reading.

 

Related Blog
HARTING MICA: Develop and Debug a C GPIO Example in Eclipse - Part 1: User Experience
HARTING MICA: Develop and Debug a C GPIO Example in Eclipse - Part 2: MICA Debian Stretch Setup
HARTING MICA: Develop and Debug a C GPIO Example in Eclipse - Part 3: Eclipse Configuration on Windows
HARTING MICA: Develop and Debug a C GPIO Example in Eclipse - Part 4: Build and Debug the GPIO Example
HARTING MICA: Make a Safe(r) MQTT Container with Certificate and TLS/SSL
HARTING MICA: Manage Access to USB and other Devices
HARTING MICA: SD Card as Shared Storage
HARTING MICA: Alpine Linux and another MQTT Container with Certificate and TLS/SSL
HARTING MICA: Connect to Amazon Web Services
HARTING MICA: Install Java 8 VM in a Debian Stretch Container
HARTING MICA: Read BOSCH CISS Sensor with Java - part 1: USB Connect and Listen
  • Sign in to reply

Top Comments

  • stevesmythe
    stevesmythe over 6 years ago in reply to jc2048 +2
    Yes, I think you're right. The "GPIO" descriptor is a bit confusing for people coming from the world of logic-level GPIOs.
  • micsup
    micsup over 6 years ago +2
    Really good tutorial!
  • szoke12
    szoke12 over 5 years ago in reply to Jan Cumps +2
    Hi! I found a solution. I wrote a webservice from the C library and I used the ulfius C solution. It works now like the original webservice. (The original gpio_webserwice was written for FreeBSD and not…
  • szoke12
    szoke12 over 5 years ago in reply to Jan Cumps

    Thanks!

    I read a lot, but i found this answer... But I will use variables to store the statements. So I write this variables by every change. I made an /all  http endpoint, and it works fine!

    image

    On the picture you can see, this values are real image

     

    Thanks!

    Ádám

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 5 years ago in reply to szoke12

    Not 100% sure, but I think you can only read inputs.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • szoke12
    szoke12 over 5 years ago in reply to Jan Cumps

    Hi!

     

    I found a solution. I wrote a webservice from the C library and I used the ulfius C solution. It works now like the original webservice.

    (The original gpio_webserwice was written for FreeBSD and not for Debian.)

    But there is one issue. I can't get the actual statement of the output pins.

    The inputs come back, but the outputs...

     

    Thanks!

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 5 years ago in reply to szoke12

    I haven't tried that - and I have no clue if it would work. Do you happen to have (or know where they are available) the C sources?

    This is not my forte- but if I (and fellow e14 members) could have a look at the code, maybe we'd be able to find out with you.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • szoke12
    szoke12 over 5 years ago in reply to Jan Cumps

    Thanks the answer!

     

    In this case... is there any possibility to install the /bin/gpio_webservice binary into a debian container?

    I would like to merge the GPIO container with my Debian.

    But I see,  the GPIO container runs not Debian...

     

    Did you try it?

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • 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