cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 SDK 1.24.0 fails to reconnect HID-Usb on PC reboot

CybDev
Associate

I have got the following problem:

I am working with VisualGDB and updated my STM32 SDK from 1.23.0 to 1.24.0 and now, our device looses USB connection when the host PC restarts and doesn’t reconnect.

Th device sends a report every 5ms to the PC via USBD_CUSTOM_HID_SendReport. This seems to be the problem, as when i delete the line the device is reconnected.

I was able to reproduce this in an tutorial project using the following:

main.cpp

#ifdef __cplusplus
extern "C"
{
#endif
#include <usbd_core.h>
#include <usbd_customhid.h>
#include "usbd_customhid_if.h"
#include <usbd_desc.h>
 
	USBD_HandleTypeDef USBD_Device;
	void SysTick_Handler(void);
	void OTG_FS_IRQHandler(void);
	void OTG_HS_IRQHandler(void);
	extern PCD_HandleTypeDef hpcd;
 
#ifdef __cplusplus
}
#endif
 
static void SystemClock_Config(void)
{
	RCC_ClkInitTypeDef RCC_ClkInitStruct;
	RCC_OscInitTypeDef RCC_OscInitStruct;
 
	__PWR_CLK_ENABLE();
	__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
 
	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;
	HAL_RCC_OscConfig(&RCC_OscInitStruct);
 
	RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK |
		RCC_CLOCKTYPE_HCLK |
		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;
	HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
 
}
 
 
void SysTick_Handler(void)
{
	HAL_IncTick();
	HAL_SYSTICK_IRQHandler();
}
 
#ifdef USE_USB_FS
void OTG_FS_IRQHandler(void)
{
	HAL_PCD_IRQHandler(&hpcd);
}
#elif defined(USE_USB_HS)
void OTG_HS_IRQHandler(void)
{
	HAL_PCD_IRQHandler(&hpcd);
}
#else
#error USB peripheral type not defined
#endif
 
/*
	This is a basic USB CDC device sample based on the ST USB library.
	To test it out:
		1. Install the ST VCP drivers (http://www.st.com/web/en/catalog/tools/PF257938)
		2. Connect to the virtual COM port using SmarTTY or any other terminal program
		3. Type some characters and observe the output
	Read more about the sample: http://visualgdb.com/tutorials/arm/stm32/usb/
*/
 
int main(void)
{
	HAL_Init();
	SystemClock_Config();
	USBD_Init(&USBD_Device, &VCP_Desc, 0);
 
	USBD_RegisterClass(&USBD_Device, USBD_CUSTOM_HID_CLASS);
	USBD_CUSTOM_HID_RegisterInterface(&USBD_Device, &USBD_CUSTOM_HID_Test_fops);
	USBD_Start(&USBD_Device);
	HAL_Delay(1000);
 
	for (;;)
	{
		if (USBD_Device.dev_state == USBD_STATE_CONFIGURED)
		{
			uint8_t test[] = { 1,0,0,0 };
			USBD_CUSTOM_HID_SendReport(&USBD_Device, test, sizeof(test));
		}
		HAL_Delay(10);
	}
}

usb_customhid_if.h

#pragma once
 
#ifdef __cplusplus
 extern "C" {
#endif
 
#include "usbd_customhid.h"
 
 
extern __ALIGN_BEGIN uint8_t m_hidReportDescription[] __ALIGN_END;
 	
extern USBD_CUSTOM_HID_ItfTypeDef  USBD_CUSTOM_HID_Test_fops;
 
#ifdef __cplusplus
}
#endif

usb_customhid_if.c

#include "usbd_customhid_if.h"
static int8_t BSP_Test_Init(void);
static int8_t BSP_Test_DeInit(void);
static int8_t BSP_Test_Control(uint8_t event_idx, uint8_t state);
 
uint8_t m_hidReportDescription[USBD_CUSTOM_HID_REPORT_DESC_SIZE] = {
	/* 7 bytes */
	0x06, 0x00, 0xff,							// USAGE_PAGE (Vendor Defined Page 1)
	0x09, 0x01,									// USAGE (Vendor Usage 1)
	0xa1, 0x01,									// COLLECTION (Application)
 
	/* 19 bytes */
	0x85, 1,									//   REPORT_ID (1)
	0x09, 0x3b,									//   USAGE (Byte Count)
	0x15, 0x00,									//   LOGICAL_MINIMUM (0)
	0x26, 0xff, 0x00,							//   LOGICAL_MAXIMUM (255)
	0x95, 3,									//   REPORT_COUNT (17)
	0x75, 0x08,									//   REPORT_SIZE (8)
	0x81, 0x02,									//   INPUT (Data,Var,Abs)
	0x09, 0x3b,									//   USAGE (Byte Count)
	0x91, 0x02,									//   OUTPUT (Data,Var,Abs)
 
	/* 1 bytes */
	0xc0										// END_COLLECTION
};
 
USBD_CUSTOM_HID_ItfTypeDef USBD_CUSTOM_HID_Test_fops =
{
	m_hidReportDescription,
	BSP_Test_Init,
	BSP_Test_DeInit,
	BSP_Test_Control
};
 
extern USBD_HandleTypeDef USBD_Device;
 
static int8_t BSP_Test_Init(void)
{
	printf("hid_fops_init()\n");
	return (0);
}
 
static int8_t BSP_Test_DeInit(void)
{
	printf("hid_fops_deinit()\n");
	return (0);
}
 
static int8_t BSP_Test_Control(uint8_t event_idx, uint8_t state)
{
	return (0);
}

This outputs:

hid_fops_init()
<Rebooting Host PC here >
hid_fops_deinit()
hid_fops_init()
hid_fops_deinit()

Setup:

Board: STM32F407VG

VisualGDB: 5.5 Preview 1

BSP: 2019.06 (= SDK 1.24.0)

ARM ToolChain: 9.21/8.3.0/r1

Packages:

– STM32F4 HAL Library

– STM32F4 Low-level Driver Library

– STM32 USB Device Library – Custom Human Interface Device

– Fast Semihosting and Embedded Profiler

2 REPLIES 2
CybDev
Associate

This problem still exists using BSP 2020.01 (= SDK 1.24.2)

TTimm
Associate II

the same thing with USB-MCS Device...

using SDK1.24.1

We have this reported directly to STM-Customer-Support:

Answer: ...and assigned to an ST support representative who will contact you shortly.

We will try to investigate this issue and we will inform R&D team responsible for STM32CubeF7 package about this issue

Thats all...

Kind regards Thomas