|
在MDK5下建立工程,根据官方USB Host CDC ACM的例子,USBH_Initialize (0) 后USBH_CDC_ACM_GetDeviceStatus(0) 没有返回usbOK (主要根据LED判断),想问下有没有大神帮忙解答下?
USB设备:是 一根USB转TTL的线(芯片PL2303) 全速模式 经过USB母口 接到PA11 PA12
主控:STM32F407VE
MDK版本 5.14
MDK-Middleware版本 7.20
部分代码如下:
main.c- #include <stdio.h> /* Standard I/O .h-file */
- #include <ctype.h> /* Character functions */
- #include <string.h> /* String and memory functions */
- #include "cmsis_os.h" /* CMSIS RTOS definitions */
- #include "rl_usb.h" /* RL-USB function prototypes */
- //#include "Board_LED.h"
- #include "Driver_USART.h"
- #include "stm32f4xx_hal.h"
-
- /* UART Driver */
- extern ARM_DRIVER_USART Driver_USART9;
- #define ptrUART_USB (&Driver_USART9)
-
- osThreadId con_discon_thread_id;
- osThreadId receive_thread_id;
- bool connected;
-
- extern uint32_t os_time;
- uint32_t HAL_GetTick(void) {
- return os_time;
- }
- void SystemClock_Config(void)
- {
- RCC_OscInitTypeDef RCC_OscInitStruct;
- RCC_ClkInitTypeDef RCC_ClkInitStruct;
- /**Configure the main internal regulator output voltage
- */
- __HAL_RCC_PWR_CLK_ENABLE();
- __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
- /**Initializes the CPU, AHB and APB busses clocks
- */
- RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
- RCC_OscInitStruct.HSEState = RCC_HSE_ON;
- RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
- RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
- RCC_OscInitStruct.PLL.PLLM = 8;
- RCC_OscInitStruct.PLL.PLLN = 336;
- RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
- RCC_OscInitStruct.PLL.PLLQ = 7;
- if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
- {
- // Error_Handler();
- }
- /**Initializes the CPU, AHB and APB busses clocks
- */
- RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
- |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
- RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
- RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
- RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
- RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
- if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
- {
- //Error_Handler();
- }
- /**Configure the Systick interrupt time
- */
- HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
- /**Configure the Systick
- */
- HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
- /* SysTick_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0);
- }
- /*------------------------------------------------------------------------------
- * UART Done Callback
- *----------------------------------------------------------------------------*/
- void UART_Done (uint32_t event) {
- switch (event) {
- case ARM_USART_EVENT_SEND_COMPLETE:
- //LED_On(1);
- break;
- case ARM_USART_EVENT_RECEIVE_COMPLETE:
- //LED_On(2);
- break;
- }
- }
- /*------------------------------------------------------------------------------
- * USB Host Serial Receive Thread
- *----------------------------------------------------------------------------*/
- void USBH_Serial_ReceiveThread (void const *arg) {
- uint8_t receive_buf[64];
- while (1) {
- ptrUART_USB->Receive (receive_buf, 64);
- }
- }
- osThreadDef(USBH_Serial_ReceiveThread, osPriorityNormal, 1, NULL);
-
- /*------------------------------------------------------------------------------
- * USB Host Thread
- *----------------------------------------------------------------------------*/
- void USBH_Thread (void const *arg) {
- static bool con_last = false;
- bool con;
- USBH_Initialize (0); /* Initialize USB Host 0 */
- while (1) {
- con = (USBH_CDC_ACM_GetDeviceStatus(0) == usbOK);
- if (con ^ con_last) {
- HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_SET);
- osDelay(1000);
- } else {
- HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_RESET);
- osDelay(1000);
- }
- }
- }
- osThreadDef(USBH_Thread, osPriorityNormal, 1, NULL);
- static void MX_GPIO_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStruct;
- /* GPIO Ports Clock Enable */
- __HAL_RCC_GPIOH_CLK_ENABLE();
- __HAL_RCC_GPIOA_CLK_ENABLE();
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_SET);
- /*Configure GPIO pin : PA6 */
- GPIO_InitStruct.Pin = GPIO_PIN_6;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_PULLUP;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
- HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
- }
- /*------------------------------------------------------------------------------
- * Application
- *----------------------------------------------------------------------------*/
- int main (void) {
-
- HAL_Init(); /* Initialize the HAL Library */
- SystemClock_Config(); /* Configure the System Clock */
- MX_GPIO_Init();
-
- receive_thread_id = 0;
- con_discon_thread_id = osThreadCreate (osThread(USBH_Thread), NULL);
-
- while (1) {
- osDelay(100);
- }
- }
复制代码 |
|