前段時間公司開發(fā)了一個安卓外設(shè),主要是用某寶淘來的demo 在stm32F103的usb功能來和安卓設(shè)備的usb來通訊
敘述之前先來一個整體的框圖吧:
需要準(zhǔn)備的設(shè)備有:
①.安卓手機或者安卓pad,(手機必須支持otg功能,否則就得用host功能了)
②.otg轉(zhuǎn)接線或者轉(zhuǎn)接頭
③.安卓數(shù)據(jù)線(一定要是能通訊數(shù)據(jù)的線纜,有些山寨的這個線只有2根線,沒有數(shù)據(jù)線)
④.帶有usb功能的單片機(這個usb需要能支持用戶自行定義)
接下來就開始搗鼓stm32單片機的程序了,下面是usb功能的代碼:
usb功能看了一下主要是借助hid的標(biāo)準(zhǔn)協(xié)議上衍生而來的一個usb標(biāo)準(zhǔn)設(shè)備
/******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
* File Name : usb_desc.c
* Author : MCD Application Team
* Version : V3.2.1
* Date : 07/05/2010
* Description : Descriptors for Mass Storage Device
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "usb_desc.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Extern variables ----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/* USB Standard Device Descriptor */
const u8 CustomHID_DeviceDescriptor[CUSTOMHID_SIZ_DEVICE_DESC] =
{
0x12, /*bLength */
USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/
0x00,0x02, /*bcdUSB */
0x00, /*bDeviceClass*/
0x00, /*bDeviceSubClass*/
0x00, /*bDeviceProtocol*/
0x08, /*bMaxPacketSize40*/
0x71,0x04, /*idVendor (0x0471)*/
0x08,0x24, /*idProduct = 0x2408*/
0x00,0x02, /*bcdDevice rel. 2.00*/
1, /*Index of string descriptor describing manufacturer */
2, /*Index of string descriptor describing product*/
3, /*Index of string descriptor describing the device serial number */
0x01 /*bNumConfigurations*/
}
; /* CustomHID_DeviceDescriptor */
/* USB Configuration Descriptor */
/* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
const u8 CustomHID_ConfigDescriptor[ENEPOINT_NUM*7+18] =
{
0x09, /* bLength: Configuation Descriptor size */
USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
ENEPOINT_NUM*7+18, /*CUSTOMHID_SIZ_CONFIG_DESC, wTotalLength: Bytes returned */
0x00,
0x01, /* bNumInterfaces: 1 interface */
0x01, /* bConfigurationValue: Configuration value */
0x00, /* iConfiguration: Index of string descriptor describing
the configuration*/
0xC0, /* bmAttributes: Bus powered */
0x32, /* MaxPower 100 mA: this current is used for detecting Vbus */
/************** Descriptor of Custom HID interface ****************/
/* 09 */
0x09, /* bLength: Interface Descriptor size */
USB_INTERFACE_DESCRIPTOR_TYPE,/* bDescriptorType: Interface descriptor type */
0x00, /* bInterfaceNumber: Number of Interface */
0x00, /* bAlternateSetting: Alternate setting */
ENEPOINT_NUM, /* bNumEndpoints */
0x00, /* bInterfaceClass: HID=0X03,其他選0 */
0x00, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
0x00, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
0, /* iInterface: Index of string descriptor */
/********************以下只對HID的描述符 Descriptor of Custom HID HID ********************/
/* 18 */
// 0x09, /* bLength: HID Descriptor size */
// HID_DESCRIPTOR_TYPE, /* bDescriptorType: HID */
// 0x10, /* bcdHID: HID Class Spec release number */
// 0x01,
// 0x00, /* bCountryCode: Hardware target country */
// 0x01, /* bNumDescriptors: Number of HID class descriptors to follow */
// 0x22, /* bDescriptorType */
// CUSTOMHID_SIZ_REPORT_DESC,/* wItemLength: Total length of Report descriptor */
// 0x00,
/******************** Descriptor of Custom endpoints ******************/
0x07, /* bLength: Endpoint Descriptor size */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */
/* Endpoint descriptor type */
0x01, /* bEndpointAddress: */
/* Endpoint Address (OUT) */
USB_ENDPOINT_TYPE_BULK,/* bmAttributes: Interrupt endpoint */
0x10,0x00, /* wMaxPacketSize: 32 Bytes max */
0x20, /* bInterval: Polling Interval (20 ms) */
/* 27 */
0x07, /* bLength: Endpoint Descriptor size */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */
0x81, /* bEndpointAddress: Endpoint Address (IN) */
USB_ENDPOINT_TYPE_BULK, /* bmAttributes: Interrupt endpoint */
0x10, 0x00, /* wMaxPacketSize: 32 Bytes max */
0x20, /* bInterval: Polling Interval (32 ms) */
/* 34 */
0x07, /* bLength: Endpoint Descriptor size */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */
/* Endpoint descriptor type */
0x82, /* bEndpointAddress: */
/* Endpoint Address (OUT) */
USB_ENDPOINT_TYPE_BULK,/* bmAttributes: Interrupt endpoint */
0x40,0x00, /* wMaxPacketSize: 512 Bytes max */
0x20 /* bInterval: Polling Interval (20 ms) */
}
;
/* USB String Descriptors (optional) */
const u8 CustomHID_StringLangID[CUSTOMHID_SIZ_STRING_LANGID] =
{
CUSTOMHID_SIZ_STRING_LANGID,
USB_STRING_DESCRIPTOR_TYPE,
0x09,
0x04
}
; /* LangID = 0x0409: U.S. English */
const u8 CustomHID_StringVendor[CUSTOMHID_SIZ_STRING_VENDOR] =
{
CUSTOMHID_SIZ_STRING_VENDOR, /* Size of Vendor string */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType*/
/* Manufacturer: "STMicroelectronics" */
'O', 0,
'T', 0,
'G', 0,
};
const u8 CustomHID_StringProduct[CUSTOMHID_SIZ_STRING_PRODUCT] =
{
CUSTOMHID_SIZ_STRING_PRODUCT, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
'S', 0,
'T', 0,
'M', 0,
'3', 0,
'2', 0,
'A',0,
'n',0,
'd',0,
'r',0,
'o',0,
'i',0,
'd',0,
' ',0,
'U',0,
'S',0,
'B',0,
' ',0,
'O', 0,
'T', 0,
'G', 0,
};
u8 CustomHID_StringSerial[CUSTOMHID_SIZ_STRING_SERIAL] =
{
CUSTOMHID_SIZ_STRING_SERIAL, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
'T', 0,
'a', 0,
'o', 0,
'b', 0,
'a', 0,
'o', 0,
'-', 0,
'B', 0,
'e', 0,
'i', 0,
'j', 0,
'i',0,
'n',0,
'g',0,
'Y',0,
上一篇:利用樹莓派打造STM32無線在線調(diào)試器!
下一篇:stm32在linux編譯,遠(yuǎn)程調(diào)試
推薦閱讀最新更新時間:2025-06-23 02:48




- 熱門資源推薦
- 熱門放大器推薦
設(shè)計資源 培訓(xùn) 開發(fā)板 精華推薦
- EVAL-ADF4350EB2Z,用于無線 LAN 的 ADF4350 PLL 時鐘發(fā)生器的評估板
- BM-78-PICTAIL、BM78 PICtail Plus 評估板為經(jīng)典 SPP 或藍(lán)牙低功耗藍(lán)牙數(shù)據(jù)應(yīng)用提供快速原型設(shè)計和開發(fā)
- Wifi四位熒光管時鐘
- LTC3403 的典型應(yīng)用 - 具有旁路晶體管的 1.5MHz、600mA 同步降壓型穩(wěn)壓器
- 【浙江理工電賽】LED閃光燈電源(H題)
- LT1612、2V 至 0.9V 降壓轉(zhuǎn)換器
- SOCORAD32:一個可破解的開源 ESP32 業(yè)余無線電板,具有步話機功能和數(shù)據(jù)通信
- 使用 Aimtec 的 AM3G-4812SH30Z 的參考設(shè)計
- AM1DR-0503SH30Z 3.3V 1 瓦 DC-DC 轉(zhuǎn)換器的典型應(yīng)用
- LTC7813IUH 寬輸入范圍至 24V/5A 低 IQ 級聯(lián)升壓 + 降壓穩(wěn)壓器 (VMID = 28V) 的典型應(yīng)用電路
- 比亞迪宣布實現(xiàn)媲美L4級智能泊車,承諾為安全兜底
- GW2208:同星智能以太網(wǎng)/CANFD/LIN網(wǎng)關(guān)設(shè)備來襲
- 在中國市場,恩智浦繼續(xù)“上強度”
- 越疆機器人正式發(fā)布六足仿生機器狗
- BMW新世代融合獨創(chuàng)駕控超級大腦 重塑智能極致駕趣標(biāo)桿
- 2025年1-5月智能座艙供應(yīng)商裝機量排行榜:本土勢力多領(lǐng)域突圍,德賽西威持續(xù)霸榜
- 座艙車載聲學(xué)裝機量分析:多數(shù)量揚聲器逐漸向下普及
- Lumissil Microsystems推出高側(cè)線性LED驅(qū)動器系列 擴(kuò)展汽車照明產(chǎn)品組合
- Elaphe推出用于高性能電動汽車的Sonic X輪轂電機平臺
- Aigtek高壓放大器在軟體機器人研究中的應(yīng)用
- 5年內(nèi)全面投產(chǎn)、1年內(nèi)技術(shù)落地的智能座艙長什么樣?
- 從傳統(tǒng)汽車到智能網(wǎng)聯(lián)汽車的艱苦發(fā)展之路
- 大奔變形記:德式智能汽車長這樣!
- 汽車有了FOTA,真的可以“為所欲為”嗎?
- 6月動力電池排行榜:寧德時代市占率再次過半
- 英特爾接連發(fā)布90款“至強”芯片
- Warp新虛擬安全網(wǎng)路(VPN)服務(wù),讓用戶遠(yuǎn)離侵害
- 離職不到一天,前高通CFO改換門庭出任英特爾CFO
- 僅成立一周就遇攔路虎,谷歌的AI技術(shù)道德監(jiān)督將如何推進(jìn)?
- 百度將于下半年推出自動駕駛出租車