• Stars
    star
    165
  • Rank 228,906 (Top 5 %)
  • Language
    C
  • Created almost 12 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Minimal printf() implementation for embedded projects.

mini-printf

Minimal printf() implementation for embedded projects.

Motivation

I was recently working on an embedded project with a STM32 MCU. The chip had 32kB of flash memory - that's heaps for a microcontroller! How surprised I was when the linker suddelnly failed saying that the program is too big and won't fit! How come?!

It's just some USB, I2C, GPIO, a few timers ... and snprintf() It turned out the memory hog was indeed the glibc's snprintf() - it took nearly 24kB out of my 32kB and left very little for my program.

Now what? I looked around the internet for some stripped down printf() implementations but none I really liked. Then I decided to develop my own minimal snprintf().

Here are some numbers (.bin file size of my STM32 project):

no snprintf():      10768 bytes
mini snprintf():    11420 bytes     (+  652 bytes)
glibc snprintf():   34860 bytes     (+24092 bytes!!)

Why SNprintf()?

Why snprintf() and not printf()? Simply because there are so many different ways to print from an embedded system that I can't really make an universal-enough printf().

The way I chose makes printing really easy - use mini_snprintf() to print into a "char buffer[]" and then output that buffer to your chip's USART, USB or network or whatever other channel you fancy.

As a by-product there's also a mini_vsnprintf() function available.

Compatibility

I didn't implement each and every formatting sequence the glibc does. For now only these are supported:

%%       - print '%'
%c       - character
%s       - string
%d, %u   - decimal integer
%x, %X   - hex integer

The integer formatting also supports 0-padding up to 9 characters wide. (no space-padding or left-aligned padding yet).

The implementation should be compatible with any GCC-based compiler. Tested with native x86-64 gcc, arm-none-eabi-gcc and avr-gcc.

It's completely standalone without any external dependencies.

Usage

  1. Include "mini-printf.h" into your source files.
  2. Add mini-printf.o to your objects list.
  3. Use snprintf() as usual in your project.
  4. Compile, Flash, Test

Etc.

Written by: Michal Ludvig [email protected]

Project homepage: http://logix.cz/michal/devel/mini-printf

Source download: https://github.com/mludvig/mini-printf

Donations: http://logix.cz/michal/devel/donations

License

Copyright (c) 2013,2014 Michal Ludvig [email protected] All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the auhor nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

More Repositories

1

aws-ethereum-miner

CloudFormation template for mining Ethereum crypto currency on AWS
Python
268
star
2

aws-ssm-tools

Handy tools for AWS Systems Manager - ssm-session, ecs-session, ssm-ssh and ssm-tunnel
Python
231
star
3

smtp-cli

The ultimate command line SMTP client
Perl
185
star
4

yubikey-ldap

LDAP schema and tools for Yubico YubiKey authentication
Python
58
star
5

aws-utils

Useful AWS scripts and utilities
Shell
50
star
6

sss_deobfuscate

Decode obfuscated ldap_default_authtok from sssd.conf
Python
22
star
7

aws-crypto-miner

CloudFormation template for mining Ravencoin (RVN), Ergo (ERG), Kaspa (KAS), and Ethereum Classic (ETC) altcoins on AWS GPU-enabled EC2 instances, with a support for payouts in Bitcoin (BTC)
Python
16
star
8

gcp-ethereum-miner

Mine ETH on Google Cloud Platform
Shell
15
star
9

amazon-textract-parser

Amazon "Textract Results Parser" (trp) module packaged and improved for ease of use.
Python
15
star
10

nagios-plugins

Useful set of Nagios plugins
Perl
13
star
11

amazon-textract-cloudformation

Automated solution for parsing PDF files using Amazon Textract. Complete solution with CloudFormation template, Step Function State Machine, Lambda functions, etc.
Python
9
star
12

aws-ipranges-updater

Update AWS RouteTable and/or SecurityGroup with selected AWS IP prefixes
Python
5
star
13

ipset-init

IPset "init script" for automatic loading and saving existing ipset tables.
5
star
14

aws-polly

Make Raspberry Pi talk with AWS Polly
Python
3
star
15

ddns-cli

Dynamic DNS updater
Python
3
star
16

aws-cloudwatch-logmailer

AWS CloudWatch Logs watcher and mailer.
Python
3
star
17

net-policy

Manage per-user network policy with LDAP, OpenVPN and Linux firewall
Python
2
star
18

sms-cli

Command line SMS sender
Python
2
star
19

aws-standard-templates

CloudFormation templates for creating some standard EC2 stacks.
Python
2
star
20

messagemedia-simple

Easy to use Python module for sending SMS and MMS messages through MessageMedia API.
Python
1
star
21

filebench

Filebench is a file system and storage benchmark that allows to generate a large variety of workloads using rich Workload Model Language (WML). See http://filebench.sourceforge.net for more info.
C
1
star
22

scan2pdf

Scan documents to PDF from Linux command line.
Shell
1
star
23

guess-number-gym

Guess a Number - simple OpenAI Gym for reinforcement learning
Python
1
star
24

zoneminder-filter

Filter ZoneMinder events using image recognition (AWS Rekognition)
Python
1
star
25

ec2-start-stop

Demo of AWS EC2 Instance Start/Stop scheduling
Python
1
star