This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] TMS320F28335:有关 C2000 项目中未定义的 uint8_t 的查询

Guru**** 2774335 points

Other Parts Discussed in Thread: TMS320F28335

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1616995/tms320f28335-inquiry-regarding-uint8_t-undefined-in-c2000-project

器件型号: TMS320F28335

尊敬的技术支持工程师

我目前正在研究一个针对图书馆项目的项目 TMS320F28335 消息流 Code Composer Studio (CCS) V12.6.0.00008 TI-CGT-C2000_22.6.1.LTS 当前主页。

在编译过程中、我遇到以下编译错误:

error #20: identifier "uint8_t" is undefined

我的测试代码中出现错误 (单元测试源)。

我想问:

  1. 是否预计uint8_t不能在当前项目环境中使用?

  2. 如果不是、uint8_t在 C2000 环境中使用 C99 标准固定宽度整数类型(例如)的建议方法是什么?

此外、我想知道这个问题是否与有关 编译器版本 目标 MCU 两者可兼得

感谢您的帮助。

Hyeondo

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

     Hyeondo  

    C2000 架构 可进行 16 位字寻址、这意味着最小可寻址单元为 16 位、而不是 8 位。
    因此 、char、 short 和 int 都是 16 位。 您 必须使用 uint16_t 而非 uint8_t

    此致

    Siddharth

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Siddharth:

    如果我通过手动定义uint8_t为强制编译typedef unsigned char uint8_t;、这是否会在实际操作中造成重大风险?

    鉴于char此环境中为 16 位、我担心任何依赖于 8 位溢出行为、位掩码或结构打包/对齐的逻辑都可能出现中断或行为异常。
    在这种情况下、假设uint16_tuint_least8_t在 C2000 上唯一推荐的安全做法是使用(或)是正确的吗?

    谢谢、
    Hyeondo

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    Hyeondo  

    通常、 建议使用 uint16_t  

    如果您希望  以 8 位增量(字节)访问 16 位字中的数据、主要用于处理打包字节数据、则必须使用  
    "__byte" 编译器内在函数  

    用于 e.gl

         uint16_t my_word = 0xABCD; // 16-bit value
    
        // Read the Low Byte (LSB) -> 0x00CD
        uint16_t low_byte = __byte(&my_word, 0);
    
        // Read the High Byte (MSB) -> 0x00AB
        uint16_t high_byte = __byte(&my_word, 1);

    此致

    Siddharth