|
stmlib version :1.7.1
芯片STM32F407VG
外接晶振8M
使用了usart1 和 usbcdc
打開兩個串口調(diào)試助手,在usb串口上發(fā)送數(shù)據(jù),usb串口顯示helloworld,usart1串口顯示接收的數(shù)據(jù),以及數(shù)據(jù)長度。
0.png (42.33 KB, 下載次數(shù): 97)
下載附件
2017-9-6 17:44 上傳
stm32_vcp_官方虛擬串口驅(qū)動程序:
0.png (3.99 KB, 下載次數(shù): 101)
下載附件
2017-9-6 17:45 上傳
stm32單片機 USB CDC代碼如下:
- /* Includes ------------------------------------------------------------------*/
- #include "usart.h"
- #include "delay.h"
- #include "usbd_cdc_core.h"
- #include "usbd_usr.h"
- #include "usb_conf.h"
- #include "usbd_desc.h"
- #include "usbd_cdc_vcp.h"
- #include "usb_dcd_int.h"
-
- __ALIGN_BEGIN USB_OTG_CORE_HANDLE USB_OTG_dev __ALIGN_END ;
-
- int main(void)
- {
- u8 dat[12] = {"Hello world"};
- __IO uint32_t i = 0;
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//設(shè)置系統(tǒng)中斷優(yōu)先級分組2
- delay_init(168); //初始化延時函數(shù)
- uart_init(115200); //初始化串口波特率為115200
- printf("Hello world!\r\n");
- USBD_Init(&USB_OTG_dev,
- USB_OTG_FS_CORE_ID,
- &USR_desc,
- &USBD_CDC_cb,
- &USR_cb);
-
- /* Main loop */
- while (1)
- {
- if(USB_RecvieCount){
- printf("RecDatalen:%d Start TxData\r\n",USB_RecvieCount);
- APP_FOPS.pIf_DataTx(dat, 12);
- USB_RecvieCount = 0;
- }
- delay_ms(500);
- printf("USB_RecvieCount:%x\r\n",USB_RecvieCount);
- }
- }
復(fù)制代碼
所有資料51hei提供下載:
STM32F4_USBCDC.rar
(11.77 MB, 下載次數(shù): 160)
2017-9-6 17:40 上傳
點擊文件名下載附件
stm32 USB CDC 代碼可以與電腦通信 下載積分: 黑幣 -5
|
評分
-
查看全部評分
|