The easiest way is to make the application jump into the bootloader. But there are several pitfalls because the bootloader assumes the device is in the reset state. IIRC you need to at least reconfigure the UART to the reset state and probably several other peripherals as well. No, this isn't documented.
IMO, easier to write your own flasher - at least in the long run. You get what you want, and don't need to reverse engineer anything or rely on undocumented behavior. This is very good if the product is ever commercialized and you want to offer firmware updates to the end user through your own UI.
Additionally, the stock STM32 UART bootloader seems to be slow as hell, a bigger firmware tends to take minutes to finish, also a good reason to write your own.
Learning flash programming becomes a useful skill, as EEPROM-like permanent storage is needed in many projects anyway.
It isn't too difficult.
Here's an example of an in-application flasher tool (working through SPI), which can be run any time and includes some basic safety checks:
https://github.com/siwastaja/pulutof1-fw/blob/master/flash.cThis is nice because I can reflash the application in less than 1 second, any time, from an userland program (
https://github.com/siwastaja/pulutof1-devkit/blob/master/spiprog.c ), without needing to press any button or similar.
I avoid the term "bootloader", since it seems to refer to something that runs during boot and loads something (the original meaning). Flash updater tool has nothing to do with this. It's a common misconception that the flasher needs to run "at boot", possibly stemming from the wrong term used to describe it. This is an arbitrary limitation. With your own, you just... write the flash! Whenever and wherever you want. You don't even need to reset afterwards, although that
most likely makes sense and is the most sensible and safe thing to do in most cases.