硬汉嵌入式论坛

 找回密码
 立即注册
查看: 4045|回复: 7
收起左侧

[RL-RTX] MKD5 RTX-USB 问题

[复制链接]

1

主题

26

回帖

29

积分

新手上路

积分
29
发表于 2017-3-20 18:27:51 | 显示全部楼层 |阅读模式
在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
  1. #include <stdio.h>                      /* Standard I/O .h-file               */
  2. #include <ctype.h>                      /* Character functions                */
  3. #include <string.h>                     /* String and memory functions        */
  4. #include "cmsis_os.h"                   /* CMSIS RTOS definitions             */
  5. #include "rl_usb.h"                     /* RL-USB function prototypes         */
  6. //#include "Board_LED.h"
  7. #include "Driver_USART.h"
  8. #include "stm32f4xx_hal.h"
  9. /* UART Driver */
  10. extern ARM_DRIVER_USART       Driver_USART9;
  11. #define ptrUART_USB         (&Driver_USART9)
  12. osThreadId  con_discon_thread_id;
  13. osThreadId  receive_thread_id;
  14. bool        connected;
  15. extern uint32_t os_time;
  16. uint32_t HAL_GetTick(void) {
  17.   return os_time;
  18. }
  19. void SystemClock_Config(void)
  20. {
  21.   RCC_OscInitTypeDef RCC_OscInitStruct;
  22.   RCC_ClkInitTypeDef RCC_ClkInitStruct;
  23.     /**Configure the main internal regulator output voltage
  24.     */
  25.   __HAL_RCC_PWR_CLK_ENABLE();
  26.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  27.     /**Initializes the CPU, AHB and APB busses clocks
  28.     */
  29.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  30.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  31.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  32.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  33.   RCC_OscInitStruct.PLL.PLLM = 8;
  34.   RCC_OscInitStruct.PLL.PLLN = 336;
  35.   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  36.   RCC_OscInitStruct.PLL.PLLQ = 7;
  37.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  38.   {
  39. //    Error_Handler();
  40.   }
  41.     /**Initializes the CPU, AHB and APB busses clocks
  42.     */
  43.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  44.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  45.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  46.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  47.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  48.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  49.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
  50.   {
  51.     //Error_Handler();
  52.   }
  53.     /**Configure the Systick interrupt time
  54.     */
  55.   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
  56.     /**Configure the Systick
  57.     */
  58.   HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  59.   /* SysTick_IRQn interrupt configuration */
  60.   HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0);
  61. }
  62. /*------------------------------------------------------------------------------
  63. *        UART Done Callback
  64. *----------------------------------------------------------------------------*/
  65. void UART_Done (uint32_t event) {
  66.   switch (event) {
  67.     case ARM_USART_EVENT_SEND_COMPLETE:
  68.       //LED_On(1);
  69.       break;
  70.     case ARM_USART_EVENT_RECEIVE_COMPLETE:
  71.       //LED_On(2);
  72.       break;
  73.   }
  74. }
  75. /*------------------------------------------------------------------------------
  76. *        USB Host Serial Receive Thread
  77. *----------------------------------------------------------------------------*/
  78. void USBH_Serial_ReceiveThread (void const *arg) {
  79.   uint8_t receive_buf[64];
  80.   while (1) {
  81.     ptrUART_USB->Receive (receive_buf, 64);
  82.   }
  83. }
  84. osThreadDef(USBH_Serial_ReceiveThread, osPriorityNormal, 1, NULL);
  85. /*------------------------------------------------------------------------------
  86. *        USB Host Thread
  87. *----------------------------------------------------------------------------*/
  88. void USBH_Thread (void const *arg) {
  89.   static bool con_last = false;
  90.          bool con;
  91.   USBH_Initialize (0);                        /* Initialize USB Host 0        */
  92.   while (1) {
  93.     con = (USBH_CDC_ACM_GetDeviceStatus(0) == usbOK);
  94.     if (con ^ con_last) {
  95.                         HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_SET);                        
  96.                         osDelay(1000);
  97.     } else {
  98.                         HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_RESET);
  99.       osDelay(1000);
  100.     }
  101.   }
  102. }
  103. osThreadDef(USBH_Thread, osPriorityNormal, 1, NULL);
  104. static void MX_GPIO_Init(void)
  105. {
  106.   GPIO_InitTypeDef GPIO_InitStruct;
  107.   /* GPIO Ports Clock Enable */
  108.   __HAL_RCC_GPIOH_CLK_ENABLE();
  109.   __HAL_RCC_GPIOA_CLK_ENABLE();
  110.   /*Configure GPIO pin Output Level */
  111.   HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_SET);
  112.   /*Configure GPIO pin : PA6 */
  113.   GPIO_InitStruct.Pin = GPIO_PIN_6;
  114.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  115.   GPIO_InitStruct.Pull = GPIO_PULLUP;
  116.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  117.   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  118. }
  119. /*------------------------------------------------------------------------------
  120. *        Application
  121. *----------------------------------------------------------------------------*/
  122. int main (void) {
  123.   HAL_Init();                                 /* Initialize the HAL Library   */
  124.   SystemClock_Config();                       /* Configure the System Clock   */
  125.         MX_GPIO_Init();
  126.   receive_thread_id    = 0;
  127.   con_discon_thread_id = osThreadCreate (osThread(USBH_Thread), NULL);
  128.   while (1) {
  129.     osDelay(100);
  130.   }
  131. }
复制代码

mdk5_usb.rar

2.98 MB, 下载次数: 154

回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106882
QQ
发表于 2017-3-21 00:44:07 | 显示全部楼层
帮顶,还没有用过MDK5里面带的中间件
回复

使用道具 举报

1

主题

26

回帖

29

积分

新手上路

积分
29
 楼主| 发表于 2017-3-21 18:27:41 | 显示全部楼层
搞定了 直接在
  1. data = USBH_Initialize (0);
复制代码
后面加上一句
  1. USBH_CustomClass_Initialize(0);
复制代码
这个函数在USBH_PL2303.c 文件中,就是这样就可以了,搞了半天。。。。
  1. void USBH_Thread (void const *arg) {
  2.   static bool con_last = false;
  3.          bool con;
  4.     uint8_t data = 0;
  5.   data = USBH_Initialize (0);                        /* Initialize USB Host 0        */
  6.    
  7.     USBH_CustomClass_Initialize(0);
  8.    
  9.   while (1) {
  10.     con = (USBH_CustomClass_GetDeviceStatus(0) == usbOK);
  11.     if (con ^ con_last) {
  12.       if (con == true) {
  13.         con_last = true;
复制代码
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106882
QQ
发表于 2017-3-22 11:06:24 | 显示全部楼层
谢谢楼主告知解决办法[s:142]
回复

使用道具 举报

1

主题

26

回帖

29

积分

新手上路

积分
29
 楼主| 发表于 2017-3-22 13:26:12 | 显示全部楼层

回 eric2013 的帖子

eric2013:谢谢楼主告知解决办法[s:142]  (2017-03-22 11:06) 
[s:142]
回复

使用道具 举报

5

主题

9

回帖

24

积分

新手上路

积分
24
发表于 2017-4-19 09:46:05 | 显示全部楼层

回 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) 
楼主能否把你的例子代码发我看下,我最近在研究这个,没搞懂
回复

使用道具 举报

1

主题

26

回帖

29

积分

新手上路

积分
29
 楼主| 发表于 2017-5-5 15:31:48 | 显示全部楼层
mdk5.rar (3.69 MB, 下载次数: 134)
回复

使用道具 举报

0

主题

7

回帖

7

积分

新手上路

积分
7
发表于 2018-9-18 08:49:17 | 显示全部楼层
多谢楼主分享
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-9 07:56 , Processed in 0.319590 second(s), 28 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表