cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX deleted my usbpd_dpm_user.c

JChau
Associate II

Hello there,

I don't know if I can call this a bug, but it shouldn't happen at all.

Thing goes like this:

  1. I have a STM32G071, I enabled UCPD1 and 2, also CMSIS, USBPD library in CubeMX
  2. I generated code for SW4STM32, I write my custom board code in usbpd_dpm_user.c
  3. I touched CubeMX again, but for some reason due to conflicts USBPD library is disabled, without noticing it I regenerated the project files
  4. BOOM, usbpd related files are deleted, including all my custom code in usbpd_dpm_user.c

Fortunately we have internal Git and therefore not all code is gone, but I guess this shouldn't happen at the very first, I don't know other toolchains, and I don't know if this happens to other library (say USBD), but because SW4STM32/eclipse has an "exclude file from build" option, I guess CubeMX should use this option instead of deleting files that potentially containing user codes.

2 REPLIES 2
Frederic G
Associate

Hello,

in your question there are 2 different points :

  • "usbpd related files are deleted" : I don't reproduce this without disabling the USBPD MW in CubeMX

This fact can occur if you change the FREERTOS from "CMSIS V1" to "CMSIS V2" - because USBPD in actual CubeFW version is not compatible with the FREERTOS CMSIS V2, only CMSIS V1

  • user code need to be included between the /* USER CODE BEGIN ... */ and /* USER CODE END ... */ like :
/* USER CODE BEGIN Private_Typedef */
Private_Typedef;
/* USER CODE END Private_Typedef */

This code is never modified by CubeMX generation - except when IP or MW disabling. This is the protection level defined by CubeMX ( to allow new release of CubeMX & CubeFW incorporated in your code ).

Regards

Hello Frederic,

  • Yes the 1st point is my point, I changed CMSIS to v2 and noticed that USBPD will not work with it, later I think I changed it back to V1, or I did not save the change before closing CubeMX, USBPD is disabled and files are deleted, also I do see USB_DEVICE or USB_HOST do also delete files when it is disabled or device class is changed. But anyway what I want to say is, instead of deleting files, CubeMX should instead rename the file to .old or as I suggested use "exclude file from build" option so user without recent backup can undo that change.
  • Yes I understand that user code are put in between /* USER CODE BEGIN ... */ and /* USER CODE END ... */, that part is intuitive and no problem to me.

Best Regards,

John