I am Using Atollic and cubemx on ubuntu.
Your question deserves a tutorial by its own, but in short you need to
Please take a look to the book Mastering STM32 by Carmine Noviello. Also read the section of STM32 user manual Page 785 chapter 27