2017-01-27 01:05 AM
Dear STM32 Cube MX developers!
I am facing with the following problem, and I have not been able to find a proper solution:
I am using a STM32F103 with CDC stack via USB.
I have to add a code snippet to force the re-enumeration between the debug sessions.
Here is the generated code:
/* USER CODE BEGIN 1 */
uint8_t i, checksum; /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USART1_UART_Init(); MX_USB_DEVICE_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�? */I need to add my code after the
SystemClock_Config();
but before the
MX_USB_DEVICE_Init();
I have not found any user generated sections between these two sections.
Solved! Go to Solution.
2017-09-12 05:08 AM
USB_DEVICE user code section has been
delivered in CubeMX4.22.1
Kind regards
Sirma
2017-01-27 03:01 AM
Hi
Marton.Miklos
,Thanks for the suggestion! I will forward this to MX our team.
-Nesrine-
2017-01-27 05:16 AM
Thanks for the fast response, please let me know their feedback!
2017-01-30 01:59 AM
Hello
Marton.Miklos
,Just for my information and to know where we can put the user section you want, which code do you want to put between the SystemClock_config and USB_Device_Init?
By the way, will it solve your issue if we put the user section begin and end just after the SystemClock_config (hence before the GPIO_Init)?
BR
Eric
2017-02-03 01:55 AM
Hello Eric,
Thank you for your quick response!
I am developing an USB CDC based application for a STM32F103 based board, and my board did not get re-enumerated between debug sessions unless I pull the D+ line to ground for 100 ms, (The re-enumeration would be required for the host application.)
It is going to be an USB powered board, so this feature will not be in the final firmware, but I need it during the development.
Technically the best would be placing user sections to all of the MX_*_Init() functions (MX_USB_DEVICE_Init in my case).
I know the following idea would goes beyond the topic of this question, but I would recommend to extend the CubeMX code parser in such a way that users could put code everywhere between a general comment pair like this:
/* USER CODE BEGIN Custom code */
...
/* USER CODE END Custom code */�?�?�?�?�?�?�?
2017-03-25 01:56 AM
Any news on this one?
2017-03-30 03:50 AM
Hello
Marton.Miklos
,I will keep you informed as soon as we have some news about the target release where the fix will be delivered.
BR. Eric
2017-05-31 09:10 AM
Hi Eric,
Do you any updates on this?
Thanks in advance!
2017-07-06 01:53 AM
Hello
Marton.Miklos
, We propose to add a pre, and post, user code sections into MX_USB_DEVICE_Init function. Then it will looks like: void MX_USB_DEVICE_Init(void) { /* USER CODE BEGIN USB_DEVICE_Init_PreTreatment *//* USER CODE END USB_DEVICE_Init_PreTreatment */
/* Init Device Library,Add Supported Class and Start the library*/
USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS); USBD_RegisterClass(&hUsbDeviceFS, &USBD_AUDIO); USBD_AUDIO_RegisterInterface(&hUsbDeviceFS, &USBD_AUDIO_fops_FS); USBD_Start(&hUsbDeviceFS);/* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */
/* USER CODE END USB_DEVICE_Init_PostTreatment */
}To be sure it will fullfill your needs, could you please share your ioc ?
This will be in CubeMX4.23 planned in Q3 2
Kind Regards Sirma2017-07-06 04:50 AM
Hello
Amazing news!
ThesePreTreatment and PosTreatment sections will be added to each function or just to the MX_USB_DEVICE_Init?
Here is my ioc file:
https://www.dropbox.com/s/nje8srs0gfpoqas/xlineusb.ioc?dl=0
And here is my current code:
/* init function */ void MX_USB_DEVICE_Init(void){ /* USER CODE BEGIN Workaround */ GPIO_InitTypeDef GPIO_InitStruct; /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(USB_R_P_GPIO_Port, USB_R_P_Pin, GPIO_PIN_RESET); /*Configure USB DP pin as GPIO */ __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = USB_R_P_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(USB_R_P_GPIO_Port, &GPIO_InitStruct); HAL_Delay(150); HAL_GPIO_WritePin(USB_R_P_GPIO_Port, USB_R_P_Pin, GPIO_PIN_SET); /* USER CODE END Workaround */ /* Init Device Library,Add Supported Class and Start the library*/ USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS); USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC); USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS); USBD_Start(&hUsbDeviceFS);}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?