Over the years ST has provided numerous IAP examples for the F2 and F4 chips and boards. Perhaps look at the Firmware Update example in CubeF4 for the STM32F4-Discovery board.
Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..