STM32 USB Host Library 学习笔记 (1) USB_OTG_ReadPacket() USB_ReadPacket()
1 /** 2 * @brief USB_OTG_ReadPacket : Reads a packet from the Rx FIFO 3 * @param pdev : Selected device 4 * @param dest : Destination Pointer 5 * @param bytes : No. of bytes 6 * @retval None 7 */ 8 void *USB_OTG_ReadPacket(USB_OTG_CORE_HANDLE *pdev, 9 uint8_t *dest, 10 uint16_t len) 11 { 12 uint32_t i=0; 13 //uint32_t count32b = (len + 3) / 4; 14 uint32_t count32b = (len) / 4; 15 uint32_t count8b = (len) & 3; 16 17 __IO uint32_t *fifo = pdev->regs.DFIFO[0]; 18 19 for ( i = 0; i < count32b; i++, dest += 4 ) 20 { 21 *(__packed uint32_t *)dest = USB_OTG_READ_REG32(fifo); 22 23 } 24 25 if ( count8b ) 26 { 27 count32b = USB_OTG_READ_REG32(fifo); 28 while ( count8b > 0 ) 29 { 30 *dest = count32b; 31 count32b >>= 8; 32 dest++; 33 count8b--; 34 } 35 }
36 return ((void *)dest); 37 }
/** @file stm32f4xx_ll_usb.c
* @author MCD Application Team
* @version V1.1.0
* @date 19-June-2014
* @brief USB Low Layer HAL module driver.
*/
/** * @brief USB_ReadPacket : read a packet from the Tx FIFO associated * with the EP/channel * @param USBx : Selected device * @param src : source pointer * @param ch_ep_num : endpoint or host channel number * @param len : Noumber of bytes to read * @param dma: USB dma enabled or disabled * This parameter can be one of the these values: * 0 : DMA feature not used * 1 : DMA feature used * @retval pointer to desctination buffer */ void *USB_ReadPacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len) { uint32_t i=0; uint32_t count32b = (len + 3) / 4; for ( i = 0; i < count32b; i++, dest += 4 ) { *(__packed uint32_t *)dest = USBx_DFIFO(0); // dest buffer overflow if (len != n*4) } return ((void *)dest); }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本