在 ARM 中使用 uIP 的注意事项
鉴于 GCC 针对 ARM 是使用字(32bit)对齐的,因此在使用基于 buffer 的强制类型转换时,应使用 __attribute__((packed)) 对类型进行修饰说明(关于其详细的说明,可以参看 GCC 手册的 5.32 章节)。如:对于 uIP 的 uip_arp.h 文件中的结构 struct uip_eth_addr 定义,需要做类似以下的修饰。
struct uip_eth_addr {
u8_t addr;
} __attribute__((packed));
其他的结构类型也需要做相应地修改。
还有一个很奇怪的现象,就是如果使用 uip.h 的 uip_buf 定义,程序会跑飞,目前处理办法是
将 uip.h 中的 uip_buf 声明由
extern u8_t uip_buf;
改为
extern u8_t *uip_buf;
同时,将 uip.c 中的 uip_buf 定义由
u8_t uip_buf; /* The packet buffer that contains incoming packets. */
改为
u8_t *uip_buf; /* The packet buffer that contains incoming packets. */
然后在使用时,作如下处理:
static uint8_t data;
uip_buf = data;
参考了一下 FreeRTOS 中提供的例子(FreeRTOS\Demo\uIP_Demo_Rowley_ARM7\uip),在 uip.h 文件中对 uip_buf 的声明做了如下的处理
extern u8_t uip_buf __attribute__ ((aligned (4)));
经过这样的修改后,系统运行正常了。看来在 ARM 中定义缓冲区是要多多注意啊!
之前的办法之所以奏效,其原因恰恰是 data 的定义是按字对齐的。
各位如果想在 ARM 中使用 uIP,那么 FreeRTOS 中提供的 demo 可是不可多得的资料。 赞一个! 犀利 太好了。
页:
[1]