If you compare the code from e.g. the STM32CubeF2 and STM32CubeF4 archives you'll see that its almost identical. The only differences seem to be the name of the files and defines (have F2 or F4 in them) and the F4 code containing some additional fun...