[应用相关]

使用MicroLIB

[复制链接]
944|5
手机看帖
扫描二维码
随时随地手机跟帖
wowu|  楼主 | 2019-7-4 10:10 | 显示全部楼层 |阅读模式
microLIB 是缺省 C 库的备选库,它旨在与需要装入到极少量内存中的深层嵌入式应用程序配合使用。LwIP中使用了microLIB,如果不勾选microLIB选项,则程序不能够正常运行,其主要原因在于LwIP使用了microLIB提供的标准输入和输出函数。本文对microLIB做详细介绍。

1、microLIB介绍

11105d1d600b3ba20.png
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().


使用特权

评论回复
wowu|  楼主 | 2019-7-4 10:11 | 显示全部楼层
2、microLIB与标准C库的差异
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:




643835d1d6040e81bc.png
546315d1d6045da628.png
655165d1d604cc42d7.png
226555d1d605265fe3.png
141385d1d60584e927.png

使用特权

评论回复
wowu|  楼主 | 2019-7-4 10:12 | 显示全部楼层
• 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.


使用特权

评论回复
wowu|  楼主 | 2019-7-4 10:13 | 显示全部楼层
3、microLIB对Heap的需求量
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.


使用特权

评论回复
wowu|  楼主 | 2019-7-4 10:13 | 显示全部楼层
4、裁剪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().


使用特权

评论回复
wowu|  楼主 | 2019-7-4 10:14 | 显示全部楼层
以上就是有关microLIB的主要特性介绍,STM32CubeMX生成的代码默认是使用microLIB,我们可以在工程的配置属性中查看如下图所示。

42815d1d60e1850a3.png

实际上,我们大部分工程用到的标准C库函数很少,而且keil中的microLIB默认已将printf重定向到UART1,我们可以直接使用printf通过串口1输出数据,所以勾选使用microLIB是一种非常好的方法,如果不勾选microLIB,则keil变压器会自动链接标准库函数。


使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

80

主题

3852

帖子

1

粉丝