cancel
Showing results for 
Search instead for 
Did you mean: 

Need to Modify a HAL USB Library

Loren
Associate III

I need to make a change to the library file usbd_hid.c under the Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src directory.

I can do this and it changes the local copy, but regenerating the code overwrites the changes I make to it.

I don't want to change the original library file, but I would like to be able to substitute the modified file without the trouble of resaving a modified copy to the above directory every time I regenerate code.

Is there a simple way to do this?

1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III

Aha. In this case, I do the following:

1. Clone the whole Cube library package (or only some middlewares) into a separate directory, and add a branch in the version control. 

2. Modify the Eclipse project so that it uses links into that cloned package instead of subdirectories under the project directory. In the Cube[MX] .ioc project change option "copy library files" to "add references", and change the ST library path to your new clone. Change also all the include paths and so on.

Then re-generation won't touch your changes in the cloned directory, and it can be shared among several projects. Some of projects can use the original library and others can use the clone, or other clones.

But this is much less simple as the previous recipe.   Using Eclipse "build variables" makes this a bit easier.

Another way is to delete Drivers and Middlewares directories from the project and replace them with symlinks to the cloned & patched libraries (symlinks work great in Windows, yep) - but this will confuse CubeMX re-generation: it will copy original lib. files to your clone so you again will have to recover your changes.

 

View solution in original post

4 REPLIES 4
Pavel A.
Evangelist III

Yes, there is. depends on definition of simple. You can check your whole project in a version control, including the middlewares, as soon as it is "working". After re-generation, review changes and  reject/reverse undesired changes. Is this simple enough?

 

Yes, I'll try that, thank you.  However, the modified file is also used in other projects.  I could do this on a project-by-project basis or it would be nice if this library file could be saved as a custom module that could be substituted for the standard library module as required.

 

Pavel A.
Evangelist III

Aha. In this case, I do the following:

1. Clone the whole Cube library package (or only some middlewares) into a separate directory, and add a branch in the version control. 

2. Modify the Eclipse project so that it uses links into that cloned package instead of subdirectories under the project directory. In the Cube[MX] .ioc project change option "copy library files" to "add references", and change the ST library path to your new clone. Change also all the include paths and so on.

Then re-generation won't touch your changes in the cloned directory, and it can be shared among several projects. Some of projects can use the original library and others can use the clone, or other clones.

But this is much less simple as the previous recipe.   Using Eclipse "build variables" makes this a bit easier.

Another way is to delete Drivers and Middlewares directories from the project and replace them with symlinks to the cloned & patched libraries (symlinks work great in Windows, yep) - but this will confuse CubeMX re-generation: it will copy original lib. files to your clone so you again will have to recover your changes.

 

Thank you.  I will try the clone method.  It may be a little more upfront work, but sounds like a better long-term solution.

 

Thanks!!