stlink is not in the dfu mode code example
Example: st link is not in dfu mode
1) click on ST-LINK->Firmware update.
2) When the "ST-Link Upgrade" dialog appears, unplug and physically reconnect the board.
3) Finally click the "Device Connect" button from the dialog.