单片机型号:STM32F407VGT6
microLIB 是缺省 C 库的备选库,它旨在与需要装入到极少量内存中的深层嵌入式应用程序配合使用。LwIP中使用了microLIB,如果不勾选microLIB选项,则程序不能够正常运行,其主要原因在于LwIP使用了microLIB提供的标准输入和输出函数。本文对microLIB做详细介绍。
Microlib is an alternative library to the default C library. It is intended for use with deeply embedded applications that must fit into extremely small memory footprints(内存占用).These applications do not run under an operating system.
Note:
Microlib does not attempt to be an ISO C-compliant library.
Microlib is highly optimized for small code size. It has less functionality than the default C library and some ISO C features are completely missing. Some library functions are also slower.
Functions in microlib are responsible for:
Creating an environment that a C program can execute in. This includes:
Creating a stack.
Creating a heap, if required.
Initializing the parts of the library the program uses.
Starting execution by calling main().
There are a number of differences between microlib and the default C library. The main differences are:
• Microlib is not compliant with the ISO C library standard. Some ISO features are not supported and others have less functionality.
• Microlib is not compliant with the IEEE 754 standard for binary floating-point arithmetic.
• Microlib is highly optimized for small code size.
• Locales are not configurable. The default C locale is the only one available.
• main() must not be declared to take arguments and must not return. In main, argc and argv parameters are undefined and cannot be used to access command-line arguments.
• Microlib provides limited support for C99 functions. Specifically, microlib does not support the following C99 functions:
• Microlib does not support C++.
• Microlib does not support operating system functions.
• Microlib does not support position-independent code.
• Microlib does not provide mutex locks to guard against code that is not thread safe.
• Microlib does not support wide characters or multibyte strings.
• Microlib does not support selectable one or two region memory models as the standard library (stdlib) does. Microlib provides only the two region memory model with separate stack and heap regions.
• Microlib does not support the bit-aligned memory functions _membitcpy[b|h|w][b|l]() and membitmove[b|h|w][b|l]().
• Microlib can be used with either --fpmode=std or --fpmode=fast.
• The level of ANSI C stdio support that is provided can be controlled with #pragma import(__use_full_stdio).
• #pragma import(__use_smaller_memcpy) selects a smaller, but slower, version of memcpy().
• setvbuf() and setbuf() always fail because all streams are unbuffered.
• feof() and ferror() always return 0 because the error and EOF indicators are not supported.
Library heap usage requirements for microlib differ to those of standardlib.The differences are:
• The size of heap memory allocated for fopen() is 20 bytes for the FILE structure.
• No buffer is ever allocated.
You must not declare main() to take arguments if you are using microlib.
Microlib provides a limited stdio subsystem. To use high-level I/O functions you must reimplement the base I/O functions. Microlib provides a limited stdio subsystem that supports unbuffered stdin, stdout and stderr only. This enables you to use printf() for displaying diagnostic messages from your application. To use high-level I/O functions you must provide your own implementation of the following base functions so that they work with your own I/O device.
fputc()
Implement this base function for all output functions. For example, fprintf(), printf(), fwrite(), fputs(), puts(), putc() and putchar().
fgetc()
Implement this base function for all input functions. For example, fscanf(), scanf(), fread(), read(), fgets(), gets(), getc() and getchar().
__backspace()
Implement this base function if your input functions use scanf() or fscanf().
以上就是有关microLIB的主要特性介绍,STM32CubeMX生成的代码默认是使用microLIB,我们可以在工程的配置属性中查看如下图所示。
实际上,我们大部分工程用到的标准C库函数很少,而且keil中的microLIB默认已将printf重定向到UART1,我们可以直接使用printf通过串口1输出数据,所以勾选使用microLIB是一种非常好的方法,如果不勾选microLIB,则keil变压器会自动链接标准库函数。
原创性文章,转载请注明出处
CSDN:http://blog.csdn.net/qingwufeiyang12346