社区朋友您好! 这段时间一直在看ST提供的USB例程,有很不明白的地方 ,请社区的朋友帮忙解辞。例程中 Device_Serial0 = *(u32*)(0x1FFFF7E8); Device_Serial1 = *(u32*)(0x1FFFF7EC); Device_Serial2 = *(u32*)(0x1FFFF7F0); 这三行是将址(0x1FFFF7E8、0x1FFFF7EC、0x1FFFF7F0)存的内容传给Device_Serial0 、Device_Serial1 、Device_Serial2 请问这三个地址是任意自已定义的吗?有没规定.还有usb hid中的报告好复杂不好解理,我买了圈圈教你玩USB/USB开发大全等书还没搞懂,一知半解,社区的朋友如有关于这方面容易理解资料传一份给我,我的QQ:1668340344 谢谢!! 以下是例程中的Get_SerialNum(void)函数. /******************************************************************************* * Function Name : Get_SerialNum. * Description : Create the serial number string descriptor. * Input : None. * Output : None. * Return : None. *******************************************************************************/ void Get_SerialNum(void) { u32 Device_Serial0, Device_Serial1, Device_Serial2; Device_Serial0 = *(u32*)(0x1FFFF7E8); Device_Serial1 = *(u32*)(0x1FFFF7EC); Device_Serial2 = *(u32*)(0x1FFFF7F0); if(Device_Serial0 != 0) { CustomHID_StringSerial[2] = (u8)(Device_Serial0 & 0x000000FF); CustomHID_StringSerial[4] = (u8)((Device_Serial0 & 0x0000FF00) >> 8); CustomHID_StringSerial[6] = (u8)((Device_Serial0 & 0x00FF0000) >> 16); CustomHID_StringSerial[8] = (u8)((Device_Serial0 & 0xFF000000) >> 24); CustomHID_StringSerial[10] = (u8)(Device_Serial1 & 0x000000FF); CustomHID_StringSerial[12] = (u8)((Device_Serial1 & 0x0000FF00) >> 8); CustomHID_StringSerial[14] = (u8)((Device_Serial1 & 0x00FF0000) >> 16); CustomHID_StringSerial[16] = (u8)((Device_Serial1 & 0xFF000000) >> 24); CustomHID_StringSerial[18] = (u8)(Device_Serial2 & 0x000000FF); CustomHID_StringSerial[20] = (u8)((Device_Serial2 & 0x0000FF00) >> 8); CustomHID_StringSerial[22] = (u8)((Device_Serial2 & 0x00FF0000) >> 16); CustomHID_StringSerial[24] = (u8)((Device_Serial2 & 0xFF000000) >> 24); } } |
stm32 USB的CDC类传输掉数据
STM32F105 USB接收数据不断进入中断,出现“死机”现象
关于STM32CubeMX配置的USB例程电脑无法识别问题
STM32F407 USB-HS-OTG是否不外接PHY可以做虚拟串口?
如何做一个USB从机键盘用stm32f407
用STM32F4 Cube MX生成的USB Device C代码的BUG
USB Device + FatFS + SDIO 模拟U盘意外只读问题
USB Device + FatFS + SDIO 问题
STM32H7配置成USB DEVICE时,连接电脑时不进入中断
STM32F446 USB和串口1 冲突
RE:求助ST提供的USB例程中的Get_SerialNum(void)问题
回复:求助ST提供的USB例程中的Get_SerialNum(void)问题
RE:求助ST提供的USB例程中的Get_SerialNum(void)问题
你说的很对是手册上已定义好的,是产品的唯一身份标识.那定义u8 CustomHID_StringSerial[CUSTOMHID_SIZ_STRING_SERIAL] =
{
CUSTOMHID_SIZ_STRING_SERIAL, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
'S', 0, 'T', 0, 'M', 0,'3', 0,'2', 0, '1', 0, '0', 0
};
这样定义那不是多余的吗?
回复:求助ST提供的USB例程中的Get_SerialNum(void)问题
void Get_SerialNum(void)
{
u32 Device_Serial0, Device_Serial1, Device_Serial2;
Device_Serial0 = *(u32*)(0x1FFFF7E8);
Device_Serial1 = *(u32*)(0x1FFFF7EC);
Device_Serial2 = *(u32*)(0x1FFFF7F0);
if (Device_Serial0 != 0)
{
Joystick_StringSerial[2] = (u8)(Device_Serial0 & 0x000000FF);
Joystick_StringSerial[4] = (u8)((Device_Serial0 & 0x0000FF00) >> 8);
Joystick_StringSerial[6] = (u8)((Device_Serial0 & 0x00FF0000) >> 16);
Joystick_StringSerial[8] = (u8)((Device_Serial0 & 0xFF000000) >> 24);
Joystick_StringSerial[10] = (u8)(Device_Serial1 & 0x000000FF);
Joystick_StringSerial[12] = (u8)((Device_Serial1 & 0x0000FF00) >> 8);
Joystick_StringSerial[14] = (u8)((Device_Serial1 & 0x00FF0000) >> 16);
Joystick_StringSerial[16] = (u8)((Device_Serial1 & 0xFF000000) >> 24);
Joystick_StringSerial[18] = (u8)(Device_Serial2 & 0x000000FF);
Joystick_StringSerial[20] = (u8)((Device_Serial2 & 0x0000FF00) >> 8);
Joystick_StringSerial[22] = (u8)((Device_Serial2 & 0x00FF0000) >> 16);
Joystick_StringSerial[24] = (u8)((Device_Serial2 & 0xFF000000) >> 24);
}
}
有一个条件判断:
if (Device_Serial0 != 0)
加入该寄存器操作失败,那样就不会导致:
u8 CustomHID_StringSerial[CUSTOMHID_SIZ_STRING_SERIAL]
数组为空的现象出现了,至少有一个默认值.....