打印
[应用相关]

使用MicroLIB

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

1、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().


使用特权

评论回复
沙发
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:










使用特权

评论回复
板凳
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.


使用特权

评论回复
5
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().


使用特权

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



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


使用特权

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

本版积分规则

91

主题

4082

帖子

1

粉丝