STM32F4 USB虚拟串口VCP程序教程

所需积分/C币:42 2018-09-12 11:01:02 4.08MB PDF
收藏 收藏 2

STM32F4 USB虚拟串口VCP教程,是讲述怎么通过USB直接连接STM32 F4和电脑直接拿进行通讯
增电池 4囗〔CM和LPn STMicroelectronics Virtual COM Port(COM4) ZTE Handset Diagnostic Interface(COM11 T ZTE Handset NMEA Device(COM12 D■计算机 DL监视器 Options for nodeusbd vep Category. Factory S eneral options 厂 Multi-file Compilation C/C++ Compiler 厂 Discard Unused publics Output Converter Code Optimizations Output List I Preprocessor I Dian iN Custom build Bild Actions Level 西ab]音d Linker COmmon subexpression eliminati Debugger □ Loop unr1ling Simulator C墨div 口 Function inlining Ann C距h 口 Code moti om GDB Server UTypebased alias analysis HAR ROM-monitor 口 Static clustering J-Link]-Trace TI Stellaris Macraiqor PE micro RDI JTAGjet ST-LINK Third-Party Driver TI XDS ON Cancel Hils Eat tsw traject Tool: Lindow Hel STM324G-EWAL_USED FS 日bdvP-5TM324 G-EVAL.ˇ 105日 L06 L0 w1B32 Ei= 0: 田国smn32 too itc /aje At this stage the microcontroller clock setting is already configure 109 this is dowe throh SysteaInit( fanction which is called trou startLE 1026(aCd2ttB2累,a) Before to hana t4 pp2Icat10N副d HED usbd_odc_vcp. c Io reconfigure the defaule see timg of SystesInier) funetion, refer to Ha Usbd_desc.c 112 systea.e rile Lo usbd usr.c 113 回口STM2E 14 但STM32F1D 15 USBD_ Inst(4usB oTc de 但STM32F2 16 wiEder USE USB OTG围 □STM32F4 117 USB UTG H9 CORE IDr 田口STM24 sldPeriph_D USB OIT PS CORE IP, 田导spm32 L的 stem stm324xc 121 4USR cesc, 口 USB Device 4U3BP CDC cb, □as 124 La Usbd_cdc- core c /Min】 e【a LIbrary 12?日1 usbd_ core.c i(10100000 Ha usbd_joreqc 国 usbd_reg c ST EVAL LEDToggle(LEDL): 甲□Us日Ds ST EVAL LEDToygle(LED2): a usb core.c r EAL LEDToggle(LED3): B usb dod. c 13 ETM EVAL LEDToggle (LED45 LE B usb dod inte LaDOutput 135 139日deU3 E PULL ASSERT 105 /* Configure and enable the USARt */ 106 STH EVAL COMTnit(CoHl, &USART_ Initstructure 108 Enable the USRXT ReceIve interrupt */A USART ITConf1q(EVAL CoNl, USART IT RXNE, ENABLE); 360□/所 361 82 wier EVAL CoM工QHae 362 sprag None retval None 365 366 void EVAL COM IRQHandler(void) 367日 if (UsART GetITStatus(EVAL COMl, USART IT RNE)!- RESET) 369日 370 /4 Send the received data to the pC Host/ 371 vCP DataTx (00)F 373 374 /s If overrun condition occurs, clear the oRE flag and recover communicatIon *A 375 if (USART GetFlagstatus(EVAL CoMl, USART FLAG ORE)!- RESET) 376 37 (void)USART ReceiveData(EVAL COMI) 378 379} 380 208 static uint16 t vCP DataTx (uinta t* But, uint32 t Len) 209日 210 if (linecoding datatype s= 7) 211 212 APP Rx Butter[APP RK ptr in]- USART RecelveData(EVAL COM1)4 0x7F: 214 else if (linecoding datatype aa 8) 215□ 216 APP_ Rx BuFfer[APP Rx ptr_ in] USART_ ReceiveData(EVAL CoMl): 之17 219 APP_ Rx ptt_in++; 220 221 /* To avoid butter overflow *A 222 if(APP Rx per in =s APP_ RX DATA SIZE) 223 APP Rx per in: 225 226 227 return USBD OK 228) 624 static uint8 t usbd cdc DataIn (void *pdev, uint8 t enum) 625日 626 uintl6 t USB Tx ptr: 627 uintl6 t USB Tx length 628 629 if (USB Tx State == 1) 630日 631 if (APP Rx length =s 0) 632日 633 USB Tx state 0: 634 635 else 637日 if (APP Rx length CDC DATA IN PACKET SIZE)( USB Tx ptr APP Rx ptr out: 639 USB Tx length CDC DATA IN PACKET SIZE; 640 641 APP Rx ptr out + CDC DATA IN PACKET SIZE; 642 APP Rx length - CDC DATA IN PACKET SIZE; 643 644 else 645白 646 USB Tx ptr APP Rx ptr out 647 USB Tx length APP Rx length: 648 APP Rx ptr out + APP Rx length; 650 APP Rx lenath s 0 651 652 t Prepare the available datd buffer to be sent on IN endpoint * 654 DCD EP Tx (dew 655 CDC IN EP, 656 (uint8 t*)GAPP RX Buffer [UsB Tx ptr] 657 USB Tx length]: 658 65s 660 661 return USBD OK 662 230日 231 a② brref vcp batak Data recerved over USB OUT endpoint are sent over cDc interface 233 th2ouoi2 thais f22n2cE1022 235 Cote 23 this function wl2 block any our packet reception on USB endpoint 244*:12 evi*nm th?g faction. Ir uou eyr* thig fazmetian he fome *ranefer 238 Is complete on CaC Interface (ze. usIng 2MA controler) 1t w22 result in receiving more datd while previous ones are still not sent 240 2:1 araz Buf: Buffer of data to be received 242 Param Len: Number of data received (i2 bytes) 243 Eretwa2 Result of the opeartion: USBD ok If 422 operations are ox else vC2 FAIL 244 zi5 siatic uintio_t ci_vataRx uinta_;Dui,uinesz_t ieni 246日 247 uint32ti 248 tor (1=02 1 <Lens 250日 SART SendData(EVAL COHl, *(But 1)): 252 hi1e( USART GetFlagstatu(E" AL COM,邯 SART FLAG T)■RE亞T) 253 254 255 return USBD OF 256 69 CDC IF Prop TypeDef vCP fops 70日 vCP Initi VCP DeInitr vCP Ctrl 74 YCP Datal 75 vcP DataRy 76}: 且 133日 Cdergroup usbd cac private variables l34 8 l35 A 136 extern CDC_IF_Prop_TypeDef APP_FOPS: 664日 665 brier usbd cdc Da taout 666 Data received on n2o2-contro1 Out endpoint 667 Garak pder. device Instance 668 paran ep2azz: endpoint number 669 Greta】 status 670 671 static uints t ushd cdc DataOut void *pdey uinta t epmm) 672日 673 uintl6 t USB Rx Cnt 674 675 /* Get the received data buffer and update the counter * 676 USB Rx Cnt =((USB OTG CORE HANDLE*)pdev)->dev. out ep[enum].xfer count. 677 678 / USB data will be immediately processed, this allow next Usb traffic being 679 NAned till the end of the applIcation Xfer + 680 APP FOPS pIf DataRx (USB Rx Bufferr USB Rx Cnt): 682 /* prepare out endpoint to receive next packet *y 683 DCD EP PrepareRs (pdev, 664 CDC OUT EPr 65 Quinta t*)(USB RX Butter) 6a6 CDC DATA OUT PACKET SIZE): 68 668 return USBD OK 6893 ST Evaluation Host (PC) Board USH Terminall USARI lerminal? ST Evaluation Host(PC) Board USB Terminal USARI 366 //void EVAL COM IBQHander(void) 367日/A 368// i (UsAKT GetIrstatus(EVAL COMt, USART IT RNNE) /. RESET) 39∥ /s Send the recerved data to the PC Host*/ 371 // vCP DataTx (0,) 372// 373 374/// If overrun condition occurs, clear the ORE flag and recover communication./ 375// if (USART Get Flagstdeus(EVAL COMl, USART FLAG ORE)/. RESET) 376 377// (void)USAMT ReceiveData(EVAL CaM1): 378/ 379 R unprocessed data read write position position circular buffer /s Prepare the available data baffer to be sent oz IN endpoint *y DCD EP Tx(pdev, DC工NEP (uint8 t*)GAPP Rx Buffer[USB Tx ptr], USB Tx length): 51/以下定义全周堂要交量 52 u8 Rox Butter[ 2048]-": 53 u32 Rx Length 0: 以上定义全雪要变量 56 extern u8 Rx_Butter[20481 57 extern u32 Rx Length: 95 extern u8 Rx Buffer[2048]: 96 extern u32 Rx Length; 7 269 static uintl6 t VCP DataRx (uint8 t* But, uint 32 t Len 270日 271 Rx Lengthen 272 or〔u321=0:1<Len:1++ 273 275 276 原来自带图序序 〃ain2ti 278// for (i= 0: i Len: i++) 279 USAKi Senda cd(EvA coMit(Bar t i// 281//// while(USART Get Flagstatus(EVAL COMI, USART FLAG TXE)== RESET); 282 284 return USBD OK: 285}

试读 24P STM32F4 USB虚拟串口VCP程序教程
立即下载 低至0.43元/次 身份认证VIP会员低至7折
    家猫戏很足 讲了一些内容,做参考还是蛮好的,没办法直接用在自己的项目里。
    forever0609 资源很不错,可以参考
    关注 私信 TA的资源
    STM32F4 USB虚拟串口VCP程序教程 42积分/C币 立即下载
    STM32F4 USB虚拟串口VCP程序教程第1页
    STM32F4 USB虚拟串口VCP程序教程第2页
    STM32F4 USB虚拟串口VCP程序教程第3页
    STM32F4 USB虚拟串口VCP程序教程第4页
    STM32F4 USB虚拟串口VCP程序教程第5页
    STM32F4 USB虚拟串口VCP程序教程第6页
    STM32F4 USB虚拟串口VCP程序教程第7页
    STM32F4 USB虚拟串口VCP程序教程第8页


    42积分/C币 立即下载 >