cancel
Showing results for 
Search instead for 
Did you mean: 

[CubeMX feature request]Please add an user section after the HAL_Init()

martonmiklos
Senior
Posted on January 27, 2017 at 10:05

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Sirma Siang
ST Employee
Posted on September 12, 2017 at 14:08

USB_DEVICE user code section has been

delivered in CubeMX4.22.1

Kind regards

Sirma

View solution in original post

15 REPLIES 15
Nesrine M_O
Lead II
Posted on January 27, 2017 at 12:01

Hi

Marton.Miklos

‌,

Thanks for the suggestion! I will forward this to MX our team.

-Nesrine-

Posted on January 27, 2017 at 13:16

Thanks for the fast response, please let me know their feedback!

Jeanne Joly
Senior III
Posted on January 30, 2017 at 10:59

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

Posted on February 03, 2017 at 09:55

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 */�?�?�?�?�?�?�?

Posted on March 25, 2017 at 08:56

Any news on this one?

Posted on March 30, 2017 at 10:50

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

Posted on May 31, 2017 at 16:10

Hi Eric,

Do you any updates on this?

Thanks in advance!

Sirma Siang
ST Employee
Posted on July 06, 2017 at 10:53

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

Sirma

Posted on July 06, 2017 at 11:50

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);}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?