letter-shell 移植适配GHS工具链

文章介绍了如何在嵌入式系统中定制Shell模块的配置,包括添加自定义头文件以定义特定选项,如使用SHELL_ENTER_CR。同时,讲解了代码移植过程,涉及串口IO函数和Shell对象初始化。在编译器相关的内容移植中,针对GHS工具链,修改了shell.h和shell.c的段定义,并更新了链接脚本以确保命令表不会被优化掉。最后提到了测试环节,暗示完成上述步骤后需验证功能的正确性。
摘要由CSDN通过智能技术生成

1. 添加自定义配置

新建 shell_user_cfg.h ,加入自己的配置选项。

#ifndef __SHELL_USER_CFG_H__
#define __SHELL_USER_CFG_H__

#include <stdlib.h>

#define SHELL_USING_COMPANION 1
#define SHELL_SUPPORT_END_LINE 1
#define SHELL_ENTER_CR 1
#define SHELL_GET_TICK() ostm1_get_system_tick()
#define SHELL_MALLOC(size) malloc(size)
#define SHELL_FREE(obj) free(obj)

#endif

基础只使用 SHELL_ENTER_CR

SHELL_USING_COMPANION :使用log功能时,需要开启。

SHELL_SUPPORT_END_LINE :使用log功能时,需要开启。用于保持命令提示符在最后一行。

SHELL_GET_TICK :支持TAB双击显示命令帮助时需要开启。不移植这个接口,TAB键单击,既然是支持补全功能的。

一般使用 -DSHELL_CFG_USER="shell_cfg_user.h" 使默认配置生效。不生效时,直接修改 shell.h 中的 SHELL_CFG_USER 宏为 shell_cfg_user.h

2. 代码移植

根据平台移植串口输入输出函数。

完成Shell对象的初始化。

在while(1)中调用 shellTask()

3. 编译器相关内容移植

这里使用的是GHS编译工具链。在 shell.hshell.c 和 链接脚本中移植编译相关的内容。

shell.h 修改:

#ifndef SHELL_SECTION
    #if defined(__CC_ARM) || defined(__CLANG_ARM)
        #define SHELL_SECTION(x)                __attribute__((section(x), aligned(1)))
    #elif defined (__IAR_SYSTEMS_ICC__)
        #define SHELL_SECTION(x)                @ x
    #elif defined(__GNUC__)
        #define SHELL_SECTION(x)                __attribute__((section(x), aligned(1)))
    #elif defined(__ghs__)
        #define SHELL_SECTION(x)                __attribute__((section("." x), aligned(1)))
    #else
        #define SHELL_SECTION(x)
    #endif
#endif

#ifndef SHELL_USED
    #if defined(__CC_ARM) || defined(__CLANG_ARM)
        #define SHELL_USED                      __attribute__((used))
    #elif defined (__IAR_SYSTEMS_ICC__)
        #define SHELL_USED                      __root
    #elif defined(__GNUC__) || defined(__ghs__)
        #define SHELL_USED                      __attribute__((used))
    #else
        #define SHELL_USED
    #endif
#endif

shell.c 修改:

#if SHELL_USING_CMD_EXPORT == 1
    #if defined(__CC_ARM) || (defined(__ARMCC_VERSION) && __ARMCC_VERSION >= 6000000)
        extern const unsigned int shellCommand$$Base;
        extern const unsigned int shellCommand$$Limit;
    #elif defined(__ICCARM__) || defined(__ICCRX__)
        #pragma section="shellCommand"
    #elif defined(__GNUC__)
        extern const unsigned int _shell_command_start;
        extern const unsigned int _shell_command_end;
    #elif defined(__ghs__)
        extern const unsigned int _shell_command_start;
        extern const unsigned int _shell_command_end;
    #endif
#else
    extern const ShellCommand shellCommandList[];
    extern const unsigned short shellCommandCount;
#endif

链接脚本修改:

添加section:

  .shellCommand                     align(4)    :>.

设置命令表的起始地址:

__shell_command_start = ADDR(.shellCommand);
__shell_command_end   = ENDADDR(.shellCommand);

链接选项配置:

取消 -data_delete 选项,否则,上面设置section会被优化掉。

4. 测试

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值