DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • Integrate Cucumber in Playwright With Java
  • Alpha Testing Tutorial: A Comprehensive Guide With Best Practices
  • Mastering Go-Templates in Ansible With Jinja2
  • Step Into Serverless Computing

Trending

  • Integrate Cucumber in Playwright With Java
  • Alpha Testing Tutorial: A Comprehensive Guide With Best Practices
  • Mastering Go-Templates in Ansible With Jinja2
  • Step Into Serverless Computing
  1. DZone
  2. Data Engineering
  3. IoT
  4. FRDM with Arduino Ethernet Shield R3, Part 4: MinIni

FRDM with Arduino Ethernet Shield R3, Part 4: MinIni

Erich Styger user avatar by
Erich Styger
·
May. 02, 14 · Interview
Like (0)
Save
Tweet
Share
5.31K Views

Join the DZone community and get the full member experience.

Join For Free

i admit: my ethernet shield project got stuck because of too many urgent other priorities. i was not happy with the way the project was using configuration data from flash memory: i have now multiple ethernet shields in use, and configuring the ip address for each shield is a pain. i have not got dhcp working (yet), so why not using the sd card on the shield for configuration data? and right on time i received a tip from marc about minini : perfect, exactly what i need!

ethernet shield with sd card

ethernet shield with sd card

minini

minini (see http://www.compuphase.com/minini.htm ) is a programmers library to read and write ini files for embedded systems. ini files are text files with ‘sections’ and ‘keys’, like this one:

[w5100]
gateway = 192.168.1.1
netmask = 255.255.255.0
mac  = 90-a2-da-0d-42-dd
ip  = 192.168.0.90

the minini library is small and efficient, basically is only one source and one header file, and is used with ‘glue’ files for different memory systems. one of it is fatfs which i already use a lot. so minini is just perfect for what i need.

minini component

while it the minini sources can be used ‘as is’, i wanted to bring it to the next level, so i have created a minini processor expert component for it:

minini component methods

minini component methods

that way i have tool tips help for each of the methods:

minini tooltip help

minini tooltip help

it does not stop here: right-click on the component and use ‘ help on component ‘, and you have access to the user manual (pdf) too:

component help with miniini user manual

component help with miniini user manual

below is a screenshot of the properties of the component:

  • portable strnicmp() : if enabled, the library has a library for strnicmp().
  • use real : if enabled, the library enables reading and writing floating point values.
  • read only : if enabled, it only reads from the configuration file, and all write methods are disabled.
  • no debug : if enabled, assert() in the library is not used. if you disable it, make sure assert() is provided either in your application code or in the standard library.
  • fatfs buffer size : this size (in bytes) defines the maximum file name size and the size of a configuration line item. the library does not use any global variables, so make sure that your stack has enough space available.
minini component properites

minini component properites

fatfs string functions

because minini uses the fatfs string functions f_gets() and f_puts(), make sure you have them enabled:

enabled string functions in fatfs

u enabled string functions in fatfs

usage

the following code shows how i read configuration data from the sd card to configure the wiznet 5100 chip:

#if pl_use_ini
  {
    uint8_t buf[32];
    int val;
    const unsigned char *p;
    uint8_t res;
 
    cls1_sendstr((unsigned char*)"loading values from " ini_file_name "\r\n", cls1_getstdio()->stdout);
    /* gateway */
    val = mini1_ini_gets(ini_section_name, "gateway", "192.168.1.1", (char*)buf, sizeof(buf), ini_file_name);
    cls1_sendstr((unsigned char*)"gateway: ", cls1_getstdio()->stdout);
    cls1_sendstr(buf, cls1_getstdio()->stdout);
    cls1_sendstr((unsigned char*)"\r\n", cls1_getstdio()->stdout);
    if (val!=0) {
      p = &buf[0];
      res = util1_scanseparatednumbers(&p, &w5100_config.gateway[0], sizeof(w5100_config.gateway), '.', util1_sep_num_type_uint8);
      if (res!=err_ok) {
        cls1_sendstr((unsigned char*)"gateway failed!\r\n", cls1_getstdio()->stdout);
      }
    }
    /* netmask */
    val = mini1_ini_gets(ini_section_name, "netmask", "255.255.255.0", (char*)buf, sizeof(buf), ini_file_name);
    cls1_sendstr((unsigned char*)"netmask: ", cls1_getstdio()->stdout);
    cls1_sendstr(buf, cls1_getstdio()->stdout);
    cls1_sendstr((unsigned char*)"\r\n", cls1_getstdio()->stdout);
    if (val!=0) {
      p = &buf[0];
      res = util1_scanseparatednumbers(&p, &w5100_config.netmask[0], sizeof(w5100_config.netmask), '.', util1_sep_num_type_uint8);
      if (res!=err_ok) {
        cls1_sendstr((unsigned char*)"netmask failed!\r\n", cls1_getstdio()->stdout);
      }
    }
    /* ip */
    val = mini1_ini_gets(ini_section_name, "ip", "192.168.0.1", (char*)buf, sizeof(buf), ini_file_name);
    cls1_sendstr((unsigned char*)"ip: ", cls1_getstdio()->stdout);
    cls1_sendstr(buf, cls1_getstdio()->stdout);
    cls1_sendstr((unsigned char*)"\r\n", cls1_getstdio()->stdout);
    if (val!=0) {
      p = &buf[0];
      res = util1_scanseparatednumbers(&p, &w5100_config.ipaddr[0], sizeof(w5100_config.ipaddr), '.', util1_sep_num_type_uint8);
      if (res!=err_ok) {
        cls1_sendstr((unsigned char*)"ip failed!\r\n", cls1_getstdio()->stdout);
      }
    }
    /* ip */
    val = mini1_ini_gets(ini_section_name, "mac", "ff-ff-ff-ff-ff-ff", (char*)buf, sizeof(buf), ini_file_name);
    cls1_sendstr((unsigned char*)"mac: ", cls1_getstdio()->stdout);
    cls1_sendstr(buf, cls1_getstdio()->stdout);
    cls1_sendstr((unsigned char*)"\r\n", cls1_getstdio()->stdout);
    if (val!=0) {
      p = &buf[0];
      res = util1_scanseparatednumbers(&p, &w5100_config.hwaddr[0], sizeof(w5100_config.hwaddr), '-', util1_sep_num_type_uint8_hex_no_prefix);
      if (res!=err_ok) {
        cls1_sendstr((unsigned char*)"mac failed!\r\n", cls1_getstdio()->stdout);
      }
    }
  }
#endif

with this, the output to the shell in my application is as below:

reset w5100.
configure network.
loading values from config.ini
gateway: 192.168.1.1
netmask: 255.255.255.0
ip: 192.168.0.90
mac: 90-a2-da-0d-42-dd
configure rx/tx memory.
done!
running web server...

the full source code can be found in the github project link at the end of this article.

summary

with minini i have a convenient way to configure my projects based on fatfs and minini . having both parts as processor expert components makes things even simpler and faster to use. my ethernet project for the frdm-kl25z has been updated on github to use minini . the component sources are on github too and will be released with the next *.peupd update.

and of course i have some more ideas:

  1. adding command line interface to the component
  2. offer other storage than fatfs: microcontroller flash memory, external eeprom would be great!

ps: thanks again to marc!

Library arduino

Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Integrate Cucumber in Playwright With Java
  • Alpha Testing Tutorial: A Comprehensive Guide With Best Practices
  • Mastering Go-Templates in Ansible With Jinja2
  • Step Into Serverless Computing

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: