swlink: Handle force boot on bluepill.
This commit is contained in:
parent
b744d8b0c9
commit
530d1e5c28
|
@ -30,7 +30,7 @@ SRC += cdcacm.c \
|
||||||
|
|
||||||
all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex
|
all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex
|
||||||
|
|
||||||
blackmagic_dfu: usbdfu.o dfucore.o dfu_f1.o
|
blackmagic_dfu: usbdfu.o dfucore.o dfu_f1.o platform_common.o
|
||||||
@echo " LD $@"
|
@echo " LD $@"
|
||||||
$(Q)$(CC) $^ -o $@ $(LDFLAGS_BOOT)
|
$(Q)$(CC) $^ -o $@ $(LDFLAGS_BOOT)
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include <libopencm3/cm3/scb.h>
|
#include <libopencm3/cm3/scb.h>
|
||||||
|
|
||||||
#include "usbdfu.h"
|
#include "usbdfu.h"
|
||||||
|
#include "platform.h"
|
||||||
|
|
||||||
uint32_t app_address = 0x08002000;
|
uint32_t app_address = 0x08002000;
|
||||||
|
|
||||||
|
@ -43,20 +44,34 @@ void dfu_detach(void)
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
/* Check the force bootloader pin*/
|
/* Check the force bootloader pin*/
|
||||||
uint16_t pin_b;
|
bool normal_boot = 0;
|
||||||
rcc_periph_clock_enable(RCC_GPIOA);
|
int rev = detect_rev();
|
||||||
rcc_periph_clock_enable(RCC_GPIOB);
|
switch (rev) {
|
||||||
/* Switch PB5 (SWIM_RST_IN) up */
|
case 0:
|
||||||
gpio_set(GPIOB, GPIO5);
|
/* For Stlink on STM8S check that CN7 PIN 4 RESET# is
|
||||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
|
* forced to GND, Jumper CN7 PIN3/4 is plugged).
|
||||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO5);
|
* Switch PB5 high. Read PB6 low means jumper plugged.
|
||||||
gpio_set(GPIOB, GPIO5);
|
*/
|
||||||
pin_b = gpio_get(GPIOB, GPIO6);
|
gpio_set_mode(GPIOB, GPIO_MODE_INPUT,
|
||||||
/* Check state on PB6 ((SWIM_RST) and release PB5*/
|
GPIO_CNF_INPUT_PULL_UPDOWN, GPIO6);
|
||||||
pin_b = gpio_get(GPIOB, GPIO6);
|
gpio_set(GPIOB, GPIO6);
|
||||||
gpio_set_mode(GPIOB, GPIO_MODE_INPUT,
|
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
|
||||||
GPIO_CNF_INPUT_FLOAT, GPIO5);
|
GPIO_CNF_OUTPUT_PUSHPULL, GPIO5);
|
||||||
if(((GPIOA_CRL & 0x40) == 0x40) && pin_b)
|
while (gpio_get(GPIOB, GPIO5))
|
||||||
|
gpio_clear(GPIOB, GPIO5);
|
||||||
|
while (!gpio_get(GPIOB, GPIO5))
|
||||||
|
gpio_set(GPIOB, GPIO5);
|
||||||
|
normal_boot = (gpio_get(GPIOB, GPIO6));
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
/* Boot0/1 pins have 100k between Jumper and MCU
|
||||||
|
* and are jumperd to low by default.
|
||||||
|
* If we read PB2 high, force bootloader entry.*/
|
||||||
|
gpio_set_mode(GPIOB, GPIO_MODE_INPUT,
|
||||||
|
GPIO_CNF_INPUT_FLOAT, GPIO2);
|
||||||
|
normal_boot = !(gpio_get(GPIOB, GPIO2));
|
||||||
|
}
|
||||||
|
if(((GPIOA_CRL & 0x40) == 0x40) && normal_boot)
|
||||||
dfu_jump_app_if_valid();
|
dfu_jump_app_if_valid();
|
||||||
|
|
||||||
dfu_protect(DFU_MODE);
|
dfu_protect(DFU_MODE);
|
||||||
|
|
Loading…
Reference in New Issue