MKD5 RTX-USB 问题
在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)
osThreadIdcon_discon_thread_id;
osThreadIdreceive_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;
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);
}
} 帮顶,还没有用过MDK5里面带的中间件 搞定了 直接在
data = USBH_Initialize (0);后面加上一句
USBH_CustomClass_Initialize(0);这个函数在USBH_PL2303.c 文件中,就是这样就可以了,搞了半天。。。。
void USBH_Thread (void const *arg) {
static bool con_last = false;
bool con;
uint8_t data = 0;
data = USBH_Initialize (0); /* Initialize USB Host 0 */
USBH_CustomClass_Initialize(0);
while (1) {
con = (USBH_CustomClass_GetDeviceStatus(0) == usbOK);
if (con ^ con_last) {
if (con == true) {
con_last = true; 谢谢楼主告知解决办法
回 eric2013 的帖子
eric2013:谢谢楼主告知解决办法 (2017-03-22 11:06) images/back.gif回 ppcult 的帖子
ppcult:搞定了 直接在data = USBH_Initialize (0);后面加上一句
USBH_CustomClass_Initialize(0);这个函数在USBH_PL2303.c 文件中,就是这样就可以了,搞了半天。。。。
void USBH_Thread (void const *arg) {
static bool con_last = false;
....... (2017-03-21 18:27) images/back.gif
楼主能否把你的例子代码发我看下,我最近在研究这个,没搞懂 多谢楼主分享
页:
[1]