I have a board that mounts STM32L4R9 MCU. I'm interested in the native USB bootloader, the one that resides in system memory.
The BOOT0 pin can be pulled-down or pulled-up by resistors, but those resistors can't be moved (soldered/unsoldered) at every upgrade.
What I'd like to do is:
- at startup, if a USB cable is connected, system memory should be selected as boot memory area
- at startup, if no USB cable is connected, main Flash should be selected as boot memory area
Unfortunately this isn't how it works. I see that boot memory area is selected by BOOT0 pin and some options bytes.
If I fix BOOT0 to GND, Main Flash is selected if it isn't empty. So it can't be used for upgrade, but only for first programming (when Main Flash is empty).
If I set nSWBOOT0 to 0, system memory is always selected at startup. However the bootloader seems block, even if no USB cable is connected, so the application will not ever launched.
I think the only solutions is to change the PCB (and use a jumper to select Main or system memory) or to implement a custom USB bootloader that exits automatically after a timeout. In the latter case, do you know if ST USB DFU bootloader source code is publicly available?