rogerclarkmelbourne / STM32duino-bootloader

Bootloader for STM32F103 boards, for use with the Arduino_STM32 repo and the Arduino IDE
962 stars 497 forks source link

Modified build_generic-pc13 to use PA14 (JTAG connector) to trigger DFU mode #89

Closed 3gyptian closed 4 years ago

3gyptian commented 4 years ago

I created an additional Bluepill bootloader to allow the use of a simple button switch placed between PA14 and 3.3V (Bluepill JTAG connector pins 2 and 4) to jump into DFU mode instead of BOOT1. The reason for this is those JTAG jumpers pins are soldered in and available on all BP boards and I hate fiddling with the Boot jumpers when I'm in a dev cycle where I need to force things into DFU that the usb reset isn't pulling it's weight (ie: having multiple USB classes configured)

So with this bootloader you can hook up a simple 2-wire switch between the two JTAG pins as follows and hold down button when powering up (or resetting) to force DFU:

image

A couple things:

Added following lines to Makefile:

build_generic-pc13-pa14: TARGETFLAGS= -DTARGET_GENERIC_F103_PC13_PA14 $(DEFINES)
# Set the linker script
build_generic-pc13-pa14: LDFLAGS +=-T$(ST_LIB)/c_only_md_high_density.ld
build_generic-pc13-pa14: elf bin lss sym
copy_generic-pc13-pa14:
    @echo
    @echo "Copying to binaries folder"
    @echo
    cp $(TARGET).bin bootloader_only_binaries/generic_boot20_pc13_pa14.bin
    @echo

And these lines to config.h

#elif defined TARGET_GENERIC_F103_PC13_PA14

    #define LED_BANK            GPIOC
    #define LED_PIN             13
    #define LED_ON_STATE        0

// Use Boot1 PB2 as the button, as hardly anyone uses this pin as GPIO
// Need to set the button input mode to just CR_INPUT and not CR_INPUT_PU_PD because the external pullup on the jumplink is very weak
    #define BUTTON_INPUT_MODE   CR_INPUT_PU_PD
    #define BUTTON_BANK GPIOA
    #define BUTTON_PIN 14
    #define BUTTON_PRESSED_STATE 1

Then $ make generic-pc13-pa14

I've only done a little testing but seems pretty solid. I'll update if I run into issues during the dev cycle.

cheers

rogerclarkmelbourne commented 4 years ago

I am not sure of the reason for this issue. It does not seem to be a be a bug.

If you want to add a new build target, please submit a PR