我们首先总结一下Microlib和缺省C库的差异:

  • MicroLib 不符合 ISO C 库标准。不支持某些 ISO 特性,并且其他特性具有的功能也较少。
  • MicroLib 不符合 IEEE 754 二进制浮点算法标准。
  • MicroLib 进行了高度优化以使代码变得很小。
  • 无法对区域设置进行配置。缺省 C 区域设置是唯一可用的区域设置。
  • 不能将 main() 声明为使用参数,并且不能返回内容。
  • 不支持 stdio,但未缓冲的 stdin、stdout 和 stderr 除外。
  • MicroLib对 C99 函数提供有限的支持。
  • MicroLib不支持操作系统函数。
  • MicroLib不支持与位置无关的代码。
  • MicroLib不提供互斥锁来防止非线程安全的代码。
  • MicroLib不支持宽字符或多字节字符串。
  • 与stdlib不同,MicroLib不支持可选择的单或双区内存模型。MicroLib只提供双区内存模型,即单独的堆栈和堆区
  • Microlib不支持C++
    在keil中使用mcirolib只需在此勾选即可:
    在这里插入图片描述
    下图是一个性能基准测试代码,可以发现,微库在不同内核下代码量明显少很多。减小代码量带来的结果就是会带来一定的性能损失(毕竟很多代码优化的方法就是以空间换取时间)。
    在这里插入图片描述
    在不使用Mcirolib的工程中,如果使用了printf等函数,会导致一个半主机semihosting的问题发生,表现为启动工程时候像死机一样,那么我们在工程中需要显示的关闭半主机semihosting调试,并且实现一些对应的接口:
#if defined(__MICROLIB)
void __aeabi_assert(const char *chCond, const char *chLine, int wErrCode) 
{
    (void)chCond;
    (void)chLine;
    (void)wErrCode;
    
    while(1) {
    }
}
#else
#if (__ARMCC_VERSION >= 6010050)
    __asm(".global __use_no_semihosting");
    __asm(".global __ARM_use_no_argv");
#else
    #pragma import(__use_no_semihosting)

struct __FILE
{
    int handle;
    /* Whatever you require here. If the only file you are using is */
    /* standard output using printf() for debugging, no file handling */
    /* is required. */
};

#endif

typedef int FILEHANDLE;
FILEHANDLE _sys_open(const char *name,int openmode)
{
 return 0;
}
int _sys_close(FILEHANDLE fh)
{
    return 0;
}
int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
{
    return 0;
}
int _sys_read(FILEHANDLE fh, unsigned char*buf, unsigned len, int mode)
{
    return 0;
}

int _sys_istty(FILEHANDLE fh)
{
    return 0;
}
int _sys_seek(FILEHANDLE fh, long pos)
{
    return 0;
}

int _sys_ensure(FILEHANDLE fh)
{
    return 0;
}

long _sys_flen(FILEHANDLE fh)
{
    return 0;
}
void _sys_exit(int status)
{
    //while(1);
}
int _sys_tmpnam(char *name, int fileno, unsigned maxlength)
{
    return 0;
}

void _ttywrch(int ch)
{
}
int remove(const char *filename)
{
    return 0;
}
char *_sys_command_string(char *cmd, int len)
{
 return NULL;
}
extern void HardFault_Handler(void);
void __aeabi_assert(const char *chCond, const char *chLine, int wErrCode) 
{
    (void)chCond;
    (void)chLine;
    (void)wErrCode;
    while(1) {
		HardFault_Handler();	
    }
}
int fputc(int ch,FILE *p)
{
	return 0;
}

至此,我们就可以再不使用Microlib的情况下,发挥编译器优化的最佳性能。
MH21xx和MH22xx系列有较大的内存(最大96KB RAM)和FLASH容量(最大1MB),最高主频达216M,非常适合用来做显示类应用加速。
参考链接:
MH22D3新一代性价比之王
MH2103完成对STM32F103的完美替代并实现性能超越

Logo

智能硬件社区聚焦AI智能硬件技术生态,汇聚嵌入式AI、物联网硬件开发者,打造交流分享平台,同步全国赛事资讯、开展 OPC 核心人才招募,助力技术落地与开发者成长。

更多推荐