How do you set boot0 and boot1? You have to apply the signals externally, then do a reset.
Recently I implemented a hardware solution to start the bootloader, as mentione
here in the last answer: A GPIO pin charges as capacitor, which is connected to boot0 and set the pin to 1. Then I do a reset (which turns the GPIO to input, which is the reason for the resistor/capacitor) and the boot pins are sampled from the reset function, which then starts the DFU mode. Might be not the most elegant solution, because it could be done all in software, but works very reliable (tested on a STM32F4 Discovery board, and on the custom hardware of a client) and you can't forget to reset some timers etc., which the DFU bootloader requires, if you jump to it.
The microcontroller is connected by USB to a Beagle Bone in the client hardware, running Linux. I can then detect the device in USB mode with lsusb and flash a new firmware with
this program.