標(biāo)題:
STM32F4的usb cdc host通信源程序
[打印本頁]
作者:
rrsmiu8899
時(shí)間:
2019-7-15 09:31
標(biāo)題:
STM32F4的usb cdc host通信源程序
STM32F4的usb cdc host通信
單片機(jī)源程序如下:
/* Includes ------------------------------------------------------------------*/
#include "usbd_cdc_core.h"
#include "usbd_usr.h"
#include "usbd_desc.h"
#include "config.h"
#include "base_driver.h"
#include "delay.h"
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
* @{
*/
/** @defgroup APP_HID
* @brief Mass storage application module
* @{
*/
/** @defgroup APP_HID_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup APP_HID_Private_Defines
* @{
*/
/**
* @}
*/
/** @defgroup APP_HID_Private_Macros
* @{
*/
extern uint8_t USB_StatusDataSended;
extern uint32_t USB_ReceivedCount;
extern uint8_t USB_Tx_Buffer[];
extern uint8_t USB_Rx_Buffer[];
extern __IO uint8_t DeviceConfigured;
/**
* @}
*/
/** @defgroup APP_HID_Private_Variables
* @{
*/
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
#pragma data_alignment=4
#endif
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
__ALIGN_BEGIN USB_OTG_CORE_HANDLE USB_OTG_dev __ALIGN_END;
/**
* @}
*/
/** @defgroup APP_HID_Private_FunctionPrototypes
* @{
*/
/**
* @}
*/
/** @defgroup APP_HID_Private_Functions
* @{
*/
/**
* @brief Program entry point
* @param None
* @retval None
*/
int main(void)
{
static uint32_t SendDataNum = 0;
static uint8_t SendDataBuff[64*1024];
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32fxxx_xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32fxxx.c file
*/
// LED_Config();
RCC_ClocksTypeDef SYS_Clocks;
RCC_GetClocksFreq(&SYS_Clocks);
USBD_Init(&USB_OTG_dev,
#ifdef USE_USB_OTG_HS
USB_OTG_HS_CORE_ID,
#else
USB_OTG_FS_CORE_ID,
#endif
&USR_desc,
&USBD_CDC_cb,
&USR_cb);
// while(DeviceConfigured==0);
//LED_Config();
//LED_On(LED_B);
//POWER_Config(500);
// FSMC_Config();
//FSMC_DMA_Configuration((uint8_t *)SendDataBuff,(uint8_t *)FSMC_READ_ADDR,128);
delay_init(SystemCoreClock/1000000);
while(1)
{
if(USB_ReceivedCount > 0){
USB_ReceivedCount = 0;
//?????????????,???1K
SendDataNum = (USB_Rx_Buffer[0]<<24)|(USB_Rx_Buffer[1]<<16)|(USB_Rx_Buffer[2]<<8)|(USB_Rx_Buffer[3]<<0);
do{
//??????????
USB_StatusDataSended = 0;
//????
DCD_EP_Tx(&USB_OTG_dev,CDC_IN_EP,SendDataBuff,sizeof(SendDataBuff));
//????????,?????????????????????
while(USB_StatusDataSended == 0){
delay_us(1);
}
SendDataNum--;
}while(SendDataNum > 0);
}
#ifdef LED_TEST
/* LED_Off(LED_B);
delay_ms(500);
LED_On(LED_B);
delay_ms(500);*/
#endif
}
}
#ifdef USE_FULL_ASSERT
/**
* @brief assert_failed
* Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param File: pointer to the source file name
* @param Line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{}
}
#endif
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
復(fù)制代碼
所有資料51hei提供下載:
code_F429.7z
(1.01 MB, 下載次數(shù): 42)
2019-7-15 18:26 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
作者:
tom_zhong
時(shí)間:
2019-10-25 15:04
好東西,謝謝分享
作者:
tom_zhong
時(shí)間:
2019-10-25 16:39
這個(gè)是host模式嗎?看用的是device的庫。
作者:
sfd123
時(shí)間:
2021-11-26 12:31
大姐,你這個(gè)是從吧,不是主啊
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1