打印
[其他ST产品]

USB OTG定义描述符数组对齐疑问

[复制链接]
252|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
两只袜子|  楼主 | 2023-7-13 10:28 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
__ALIGN_BEGIN static uint8_t USBD_HID_Desc[USB_HID_DESC_SIZ] __ALIGN_END =
{
  /* 18 */
  0x09,                                               /* bLength: HID Descriptor size */
  HID_DESCRIPTOR_TYPE,                                /* bDescriptorType: HID */
  0x11,                                               /* bcdHID: HID Class Spec release number */
  0x01,
  0x00,                                               /* bCountryCode: Hardware target country */
  0x01,                                               /* bNumDescriptors: Number of HID class descriptors to follow */
  0x22,                                               /* bDescriptorType */
  HID_MOUSE_REPORT_DESC_SIZE,                         /* wItemLength: Total length of Report descriptor */
  0x00,
};

查看__ALIGN_BEGIN定义是在ARM,GNUC编译环境下是4字节对齐,但在IAR下不用对齐,为什么?

使用特权

评论回复
沙发
AloneKaven| | 2023-7-13 23:36 | 只看该作者
IAR里也要对齐的

使用特权

评论回复
板凳
香水城| | 2023-7-14 13:43 | 只看该作者
如果需要对齐而在IAR环境下没有相应#pragma语句指定对齐方式时,

不妨自己加上  #pragma data_alignment=4 来满足字对齐。

在ST库函数里有专门提醒:

Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead.

使用特权

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

本版积分规则

2121

主题

8098

帖子

11

粉丝