STM32 Custom Bootloader from scratch - Bootloader Tutorial series.
Please check the text explanation.
Web version - https://embetronicx.com/bootloader-tutorials/
Video version - https://www.youtube.com/watch?v=jzo7z2gNBgg&list=PLArwqFvBIlwHRgPtsQAhgZavlp42qpkiG