How to create a static library for a UART sensor for STM32?
It's in the User Guide.

Keep in mind that the resulting library is usable only on a single microcontroller series. It'd be fine as long as you are using it on a single series (e.g. STM32F4xx), and some peripherals are compatible across series, so they might just work (see the STM32 porting guides), but sometimes they are only register level compatible, needing a recompile using another set of headers.

Recompiling for different target should not be a problem.

Unfortunately the documentation writers don't share your opinion.

So you'd end up with several copies of the library sources, where updates have to be copied around and recompiled several times.
What to do instead?
You can add source files outside your project folder to the project

To add a link to a file, right-click on a source folder and select New, File.
In the dialog click on the Advanced button and select Link to file in the file system.

It does even support adding a whole external directory this way.