https://github.com/aj528/mprintf
simple no-float 32-bit printf
https://github.com/aj528/mprintf
arm c embedded printf simple
Last synced: 3 months ago
JSON representation
simple no-float 32-bit printf
- Host: GitHub
- URL: https://github.com/aj528/mprintf
- Owner: AJ528
- License: gpl-3.0
- Created: 2024-04-21T04:45:25.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-01-05T00:45:11.000Z (about 1 year ago)
- Last Synced: 2025-01-05T01:25:09.767Z (about 1 year ago)
- Topics: arm, c, embedded, printf, simple
- Language: C
- Homepage:
- Size: 70.3 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mprintf
simple no-float 32-bit printf
### Status
Does everything I need it to. Will fix bugs as I come across them.
### How to use this in an embedded project
1. Copy `mprint.h` and `mprint.c` into your project
2. In `mprint.c`, replace all the calls to `putchar()` with the appropriate one for your platform. In embedded projects, this is commonly a function that outputs data over UART.
3. Once `putchar()` is replaced, the `#include ` line in `mprintf.c` should no longer be needed. Feel free to delete it.
4. If needed, adjust the newline encoding in `print_newline()`.
5. Done!
### How to measure the size of this project
1. copy these files into an embedded project.
2. compile the project.
3. measure the size of the `mprintf.o` object file using `size -A`.
4. the total size is found from summing all relevant sections together.
### Details
Compiles down to 1554 bytes on `arm-none-eabi-gcc` with `-Os` optimizations. This can be made slightly smaller depending on which functions are actually called.
mprintf is about 450 lines of code (per David A. Wheeler's `SLOCCount`).
Max RAM usage can be controlled by changing the `printf()` buffer size. Shrinking the buffer saves RAM at the cost of decreasing the maximum string length `printf()` can handle.
Supports b, c, d, i, p, s, u, X, x, and % conversion flags, minimum field widths, and 0- +# format flags.
Designed with Cortex-M microcontrollers in mind, but there's no microcontroller-specific code in the file.
I also included testing using Greatest from https://github.com/silentbicycle/greatest. There's a number of tests that compare mprintf against the standard printf.