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.

15 REPLIES 15
Posted on July 06, 2017 at 12:21

Hello

Marton.Miklos

,

As this subject is a large one, we will do it step by step, and USB_DEVICE will be the first updated.

Thanks for your code, and ioc, sharing.

Kind regards

Sirma

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

Posted on September 13, 2017 at 08:40

Well my usb_device.c still has the following generated contents (no user sections):

/* init function */ void MX_USB_DEVICE_Init(void){ /* 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);
}�?�?�?�?�?�?�?�?�?

Also the code generation fails with the following output (however this file got regenerated):

2017-09-13 08:38:26,320 [FATAL] Middleware:652 - 
2017-09-13 08:38:26,324 [INFO] CodeEngine:162 - oldGeneratedFile, /home/mm/STM32-workspace/xlineusb/Src/usb_device.c_save
2017-09-13 08:38:26,420 [INFO] CodeEngine:180 - Generated code: /home/mm/STM32-workspace/xlineusb/Src/usb_device.c
2017-09-13 08:38:26,451 [INFO] CodeEngine:162 - oldGeneratedFile, /home/mm/STM32-workspace/xlineusb/Inc/usb_device.h_save
2017-09-13 08:38:26,516 [INFO] CodeEngine:180 - Generated code: /home/mm/STM32-workspace/xlineusb/Inc/usb_device.h
2017-09-13 08:38:26,541 [INFO] CodeEngine:162 - oldGeneratedFile, /home/mm/STM32-workspace/xlineusb/Inc/usbd_conf.h_save
2017-09-13 08:38:26,599 [INFO] CodeEngine:180 - Generated code: /home/mm/STM32-workspace/xlineusb/Inc/usbd_conf.h
2017-09-13 08:38:26,621 [INFO] CodeEngine:162 - oldGeneratedFile, /home/mm/STM32-workspace/xlineusb/Src/usbd_conf.c_save
2017-09-13 08:38:26,732 [INFO] CodeEngine:180 - Generated code: /home/mm/STM32-workspace/xlineusb/Src/usbd_conf.c
2017-09-13 08:38:26,734 [INFO] CodeEngine:162 - oldGeneratedFile, /home/mm/STM32-workspace/xlineusb/Inc/usbd_desc.h_save
2017-09-13 08:38:26,771 [INFO] CodeEngine:180 - Generated code: /home/mm/STM32-workspace/xlineusb/Inc/usbd_desc.h
2017-09-13 08:38:26,773 [INFO] CodeEngine:162 - oldGeneratedFile, /home/mm/STM32-workspace/xlineusb/Src/usbd_desc.c_save
2017-09-13 08:38:26,812 [INFO] CodeEngine:180 - Generated code: /home/mm/STM32-workspace/xlineusb/Src/usbd_desc.c
2017-09-13 08:38:26,814 [INFO] CodeEngine:162 - oldGeneratedFile, /home/mm/STM32-workspace/xlineusb/Inc/usbd_cdc_if.h_save
2017-09-13 08:38:26,851 [INFO] CodeEngine:180 - Generated code: /home/mm/STM32-workspace/xlineusb/Inc/usbd_cdc_if.h
2017-09-13 08:38:26,869 [INFO] CodeEngine:162 - oldGeneratedFile, /home/mm/STM32-workspace/xlineusb/Src/usbd_cdc_if.c_save
2017-09-13 08:38:26,916 [INFO] CodeEngine:180 - Generated code: /home/mm/STM32-workspace/xlineusb/Src/usbd_cdc_if.c
2017-09-13 08:38:26,934 [INFO] CodeEngine:162 - oldGeneratedFile, /home/mm/STM32-workspace/xlineusb/Src/stm32f1xx_it.c_save
2017-09-13 08:38:27,015 [INFO] CodeEngine:180 - Generated code: /home/mm/STM32-workspace/xlineusb/Src/stm32f1xx_it.c
2017-09-13 08:38:27,041 [INFO] CodeEngine:162 - oldGeneratedFile, /home/mm/STM32-workspace/xlineusb/Inc/stm32f1xx_it.h_save
2017-09-13 08:38:27,079 [INFO] CodeEngine:180 - Generated code: /home/mm/STM32-workspace/xlineusb/Inc/stm32f1xx_it.h
2017-09-13 08:38:27,099 [INFO] CodeEngine:162 - oldGeneratedFile, /home/mm/STM32-workspace/xlineusb/Src/stm32f1xx_hal_msp.c_save
2017-09-13 08:38:27,184 [INFO] CodeEngine:180 - Generated code: /home/mm/STM32-workspace/xlineusb/Src/stm32f1xx_hal_msp.c
2017-09-13 08:38:27,187 [INFO] CodeEngine:162 - oldGeneratedFile, /home/mm/STM32-workspace/xlineusb/Src/system.tmp_save
2017-09-13 08:38:27,225 [INFO] CodeEngine:180 - Generated code: /home/mm/STM32-workspace/xlineusb/Src/system.tmp
2017-09-13 08:38:27,228 [INFO] CodeEngine:162 - oldGeneratedFile, /home/mm/STM32-workspace/xlineusb/Inc/stm32f1xx_hal_conf.h_save
2017-09-13 08:38:27,275 [INFO] CodeEngine:180 - Generated code: /home/mm/STM32-workspace/xlineusb/Inc/stm32f1xx_hal_conf.h
2017-09-13 08:38:27,287 [INFO] CodeEngine:162 - oldGeneratedFile, /home/mm/STM32-workspace/xlineusb/Inc/main.h_save
2017-09-13 08:38:27,332 [INFO] CodeEngine:180 - Generated code: /home/mm/STM32-workspace/xlineusb/Inc/main.h
2017-09-13 08:38:27,351 [INFO] CodeEngine:162 - oldGeneratedFile, /home/mm/STM32-workspace/xlineusb/Src/main.c_save
2017-09-13 08:38:27,442 [INFO] CodeEngine:180 - Generated code: /home/mm/STM32-workspace/xlineusb/Src/main.c
Exception in thread 'Thread-1222' java.lang.NoSuchMethodError: stm32Families.Families.getDefaultDefines(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/util/Vector;
 at com.st.microxplorer.plugins.projectmanager.engine.ProjectBuilder.searchNeededFiles(ProjectBuilder.java:1500)
 at com.st.microxplorer.plugins.projectmanager.engine.ProjectBuilder.createProject(ProjectBuilder.java:442)
 at com.st.microxplorer.plugins.projectmanager.engine.GenerateProjectThread.run(GenerateProjectThread.java:41)�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Posted on September 13, 2017 at 15:43

Hello

Marton.Miklos

,

Have you tested with 4.1 version ?

Mine generates the following code:

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_MSC);

USBD_MSC_RegisterStorage(&hUsbDeviceFS, &USBD_Storage_Interface_fops_FS);

USBD_Start(&hUsbDeviceFS);

/* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */

/* USER CODE END USB_DEVICE_Init_PostTreatment */

}

Or

/* init function */

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_CDC);

USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS);

USBD_Start(&hUsbDeviceFS);

/* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */

/* USER CODE END USB_DEVICE_Init_PostTreatment */

}

If you can share your ioc, I would be able to test in same conditions at my end.

Kind regards

Sirma

Posted on September 13, 2017 at 15:53

Hi

SIRY.Marc

0690X00000608DHQAY.png

Yes I am using the 4.1. I have updated it from 4.0 and using it on Linux if that matters.

Here you can find the ioc file:

https://www.dropbox.com/s/nje8srs0gfpoqas/xlineusb.ioc?dl=0

Thank you for your help!

Posted on September 15, 2017 at 13:11

After reinstallation of the CubeMX this problem solved. In the past I have only updated it.