Yes, managing all these targets is just a pain.
If we remove the unused LED2, the HID BL deals with 3 pins at most:
- the BOOT pin, used to force entering the bootloader. Default is PB2/BOOT1 on the BP that has a jumper for it as well as for BOOT0, and the combination of BOOT0=HIGH + BOOT1=LOW was actually unused. We could hard-code the pin number for this function, but this may be useful to let it configurable for custom boards.
- the LED pin. Default is PC13 on the BP
- the DISC pin. Not needed on the BP, but used for the Maple board which has an external USB disconnect circuit. Default for the Maple is PB9
If we define a "pin" as a port name or number (ranging in theory from "A" to "G", but more realistically from "A" to "C" or 0 to 3) plus a bit number (from 0 to 15), this can be packed into 7 bits, with a reserved port (4) for unused pins.
There is often the need to define a pin as either ACTIVE_LOW or ACTIVE_HIGH, so the 8th bit could be used for this purpose.
Then, some pins may require to be set into a specific MODE/CNF in the sense of the Port bit configuration table. For the STM32F103, it is here:
https://www.st.com/content/ccc/resource ... f#page=161
For example, the BOOT pin may require an internal pull-up for the Maple board, whereas it is in floating input mode for the other boards having an external pull-up resistor. The LED pin is usually a push-pull output, but the DISC pin is an open-drain output.
This pin mode configuration requires 4 bits per pin, and the minimum required size to store the pin configuration is thus 3 * (8 + 4) = 36 bits = 4.5 bytes.
RAM_SIZE is not needed, and FLASH_SIZE is only required for the high-memory BL.
Most STM32s have "Reserved" vectors in their Vector Table, and addresses 0x0000001C - 0x0000002B (16 bytes) and 0x00000034 - 0x00000037 ( 4 bytes) seem to be the same for most chips.
In my high-memory PR, I used addresses 0x0000001C - 0x0000001F (4 bytes) to store the original user reset vector to jump to after running the BL, but I could have used the second area as well.
We could use the 0x0000001C - 0x0000002B to store the pin configuration and configure them at run time rather than fix them during compilation like today, this won't require much code in the BL.
But then, there is a need for a tool to flash this configuration: it can be by ST-Link or Serial BL, or using a specific sketch, but I don't know how practical this is for a user, any though on this subject is welcome!
: the Flash size can be determined at run time using the F_SIZE register (address 0x1FFFF7E0 on the STM32F103C8T6).