bootloader: enable RCC_AFIO before remapping pin

This commit is contained in:
King Kévin 2018-04-03 17:54:59 +02:00
parent 96f3458317
commit 61cc2491a6
2 changed files with 11 additions and 5 deletions

View File

@ -42,11 +42,17 @@ void main(void)
} else { // check if the force DFU mode input is set
// disable SWJ pin to use as GPIO
#if (GPIO(B)==GPIO(DFU_FORCE_PORT)) && (GPIO(4)==GPIO(DFU_FORCE_PIN))
gpio_primary_remap(AFIO_MAPR_SWJ_CFG_FULL_SWJ_NO_JNTRST, 0);
// JNTRST pin is used as DFU pin
rcc_periph_clock_enable(RCC_AFIO); // enable clock for alternate function domain
gpio_primary_remap(AFIO_MAPR_SWJ_CFG_FULL_SWJ_NO_JNTRST, 0); // keep SWJ enable bit don't use JNTRST
#elif ((GPIO(B)==GPIO(DFU_FORCE_PORT)) && (GPIO(3)==GPIO(DFU_FORCE_PIN))) || ((GPIO(A)==GPIO(DFU_FORCE_PORT)) && (GPIO(15)==GPIO(DFU_FORCE_PIN)))
gpio_primary_remap(AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON, 0);
// JTAG but not SWD pin used as DFU pin
rcc_periph_clock_enable(RCC_AFIO); // enable clock for alternate function domain
gpio_primary_remap(AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON, 0); // disable JTAG but keep SWD
#elif ((GPIO(A)==GPIO(DFU_FORCE_PORT)) && (GPIO(14)==GPIO(DFU_FORCE_PIN))) || ((GPIO(A)==GPIO(DFU_FORCE_PORT)) && (GPIO(13)==GPIO(DFU_FORCE_PIN)))
gpio_primary_remap(AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_OFF, 0);
// JTAG and SWD pin used as DFU pin
rcc_periph_clock_enable(RCC_AFIO); // enable clock for alternate function domain
gpio_primary_remap(AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_OFF, 0); // disable JTAG and SWD
#endif
rcc_periph_clock_enable(RCC_GPIO(DFU_FORCE_PORT)); // enable clock for GPIO domain
gpio_set_mode(GPIO(DFU_FORCE_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO(DFU_FORCE_PIN)); // set GPIO to input

View File

@ -412,10 +412,10 @@
#define DFU_FORCE_PIN 4 /**< GPIO pin (pin PC4) */
#define DFU_FORCE_VALUE 1 /**< pin floating, set high when shorted with nearby VCC */
#else
/* use the JNTRST pin as GPIO (this will disable the SWJ function, but we are not using it) */
/* use the JNTRST pin as GPIO (SWJ will still be working, minus NTRST) */
#define DFU_FORCE_PORT B /**< JNTRST port (needs to be remapped to become PB4) */
#define DFU_FORCE_PIN 4 /**< JNTRST pin (needs to be remapped to become PB4) */
#define DFU_FORCE_VALUE 1 /**< must be high to force DFU mode, since it's low after reset */
#define DFU_FORCE_VALUE 0 /**< must be low to force DFU mode (note: JNTRST is also pulled up after reset) */
#endif
/** @} */