From 72a6e701eb2bb0af06931807d50a9081c85ab4a6 Mon Sep 17 00:00:00 2001 From: blckmn Date: Sun, 3 Jul 2016 07:44:35 +1000 Subject: [PATCH 1/2] Fixed build issue for F1, and added dfu CLI command (for restart in DFU mode) --- src/main/drivers/io.h | 2 -- src/main/drivers/system.h | 1 + src/main/drivers/system_stm32f10x.c | 8 +++++++- src/main/drivers/system_stm32f30x.c | 9 ++++++++- src/main/drivers/system_stm32f4xx.c | 15 +++++++++++++++ src/main/io/serial_4way.c | 4 ++-- src/main/io/serial_cli.c | 24 +++++++++++++++++++++--- 7 files changed, 54 insertions(+), 9 deletions(-) diff --git a/src/main/drivers/io.h b/src/main/drivers/io.h index 121e7a0e1..315560e43 100644 --- a/src/main/drivers/io.h +++ b/src/main/drivers/io.h @@ -40,14 +40,12 @@ typedef uint8_t ioConfig_t; // packed IO configuration #define IO_CONFIG(mode, speed) ((mode) | (speed)) #define IOCFG_OUT_PP IO_CONFIG(GPIO_Mode_Out_PP, GPIO_Speed_2MHz) -#define IOCFG_OUT_PP_25 IO_CONFIG(GPIO_Mode_Out_PP, GPIO_Speed_25MHz) #define IOCFG_OUT_OD IO_CONFIG(GPIO_Mode_Out_OD, GPIO_Speed_2MHz) #define IOCFG_AF_PP IO_CONFIG(GPIO_Mode_AF_PP, GPIO_Speed_2MHz) #define IOCFG_AF_OD IO_CONFIG(GPIO_Mode_AF_OD, GPIO_Speed_2MHz) #define IOCFG_IPD IO_CONFIG(GPIO_Mode_IPD, GPIO_Speed_2MHz) #define IOCFG_IPU IO_CONFIG(GPIO_Mode_IPU, GPIO_Speed_2MHz) #define IOCFG_IN_FLOATING IO_CONFIG(GPIO_Mode_IN_FLOATING, GPIO_Speed_2MHz) -#define IOCFG_IPU_25 IO_CONFIG(GPIO_Mode_IPU, GPIO_Speed_25MHz) #elif defined(STM32F3) || defined(STM32F4) diff --git a/src/main/drivers/system.h b/src/main/drivers/system.h index 92e17f8a8..c6d58aa74 100644 --- a/src/main/drivers/system.h +++ b/src/main/drivers/system.h @@ -42,6 +42,7 @@ void systemReset(void); void systemResetToBootloader(void); bool isMPUSoftReset(void); void cycleCounterInit(void); +void checkForBootLoaderRequest(void); void enableGPIOPowerUsageAndNoiseReductions(void); // current crystal frequency - 8 or 12MHz diff --git a/src/main/drivers/system_stm32f10x.c b/src/main/drivers/system_stm32f10x.c index 4ad526850..3e59fe734 100644 --- a/src/main/drivers/system_stm32f10x.c +++ b/src/main/drivers/system_stm32f10x.c @@ -37,7 +37,8 @@ void systemReset(void) SCB->AIRCR = AIRCR_VECTKEY_MASK | (uint32_t)0x04; } -void systemResetToBootloader(void) { +void systemResetToBootloader(void) +{ // 1FFFF000 -> 20000200 -> SP // 1FFFF004 -> 1FFFF021 -> PC @@ -68,6 +69,8 @@ bool isMPUSoftReset(void) void systemInit(void) { + checkForBootLoaderRequest(); + SetSysClock(false); #ifdef CC3D @@ -110,3 +113,6 @@ void systemInit(void) SysTick_Config(SystemCoreClock / 1000); } +void checkForBootLoaderRequest(void) +{ +} \ No newline at end of file diff --git a/src/main/drivers/system_stm32f30x.c b/src/main/drivers/system_stm32f30x.c index 7e58ab061..ee8aef1a0 100644 --- a/src/main/drivers/system_stm32f30x.c +++ b/src/main/drivers/system_stm32f30x.c @@ -35,7 +35,8 @@ void systemReset(void) SCB->AIRCR = AIRCR_VECTKEY_MASK | (uint32_t)0x04; } -void systemResetToBootloader(void) { +void systemResetToBootloader(void) +{ // 1FFFF000 -> 20000200 -> SP // 1FFFF004 -> 1FFFF021 -> PC @@ -82,6 +83,8 @@ bool isMPUSoftReset(void) void systemInit(void) { + checkForBootLoaderRequest(); + // Enable FPU SCB->CPACR = (0x3 << (10 * 2)) | (0x3 << (11 * 2)); SetSysClock(); @@ -102,3 +105,7 @@ void systemInit(void) // SysTick SysTick_Config(SystemCoreClock / 1000); } + +void checkForBootLoaderRequest(void) +{ +} diff --git a/src/main/drivers/system_stm32f4xx.c b/src/main/drivers/system_stm32f4xx.c index f0042026f..697b2b743 100644 --- a/src/main/drivers/system_stm32f4xx.c +++ b/src/main/drivers/system_stm32f4xx.c @@ -169,6 +169,8 @@ bool isMPUSoftReset(void) void systemInit(void) { + checkForBootLoaderRequest(); + SetSysClock(); // Configure NVIC preempt/priority groups @@ -194,3 +196,16 @@ void systemInit(void) SysTick_Config(SystemCoreClock / 1000); } +void(*bootJump)(void); +void checkForBootLoaderRequest(void) +{ + __enable_irq(); + if (*((uint32_t *)0x2001FFFC) == 0xDEADBEEF) { + *((uint32_t *)0x2001FFFC) = 0x0; + __set_MSP(0x20001000); + + bootJump = (void(*)(void))(*((uint32_t *) 0x1fff0004)); + bootJump(); + while (1); + } +} \ No newline at end of file diff --git a/src/main/io/serial_4way.c b/src/main/io/serial_4way.c index 49c580541..bcea2f8a1 100644 --- a/src/main/io/serial_4way.c +++ b/src/main/io/serial_4way.c @@ -120,12 +120,12 @@ void setEscLo(uint8_t selEsc) void setEscInput(uint8_t selEsc) { - IOConfigGPIO(escHardware[selEsc].io, IOCFG_IPU_25); + IOConfigGPIO(escHardware[selEsc].io, IOCFG_IPU); } void setEscOutput(uint8_t selEsc) { - IOConfigGPIO(escHardware[selEsc].io, IOCFG_OUT_PP_25); + IOConfigGPIO(escHardware[selEsc].io, IOCFG_OUT_PP); } // Initialize 4way ESC interface diff --git a/src/main/io/serial_cli.c b/src/main/io/serial_cli.c index a51f828ed..e160869df 100644 --- a/src/main/io/serial_cli.c +++ b/src/main/io/serial_cli.c @@ -112,6 +112,7 @@ static void cliRxFail(char *cmdline); static void cliAdjustmentRange(char *cmdline); static void cliMotorMix(char *cmdline); static void cliDefaults(char *cmdline); +void cliDfu(char *cmdLine); static void cliDump(char *cmdLine); void cliDumpProfile(uint8_t profileIndex); void cliDumpRateProfile(uint8_t rateProfileIndex) ; @@ -122,6 +123,7 @@ static void cliPlaySound(char *cmdline); static void cliProfile(char *cmdline); static void cliRateProfile(char *cmdline); static void cliReboot(void); +static void cliRebootEx(bool bootLoader); static void cliSave(char *cmdline); static void cliSerial(char *cmdline); #ifndef SKIP_SERIAL_PASSTHROUGH @@ -263,8 +265,8 @@ const clicmd_t cmdTable[] = { CLI_COMMAND_DEF("color", "configure colors", NULL, cliColor), #endif CLI_COMMAND_DEF("defaults", "reset to defaults and reboot", NULL, cliDefaults), - CLI_COMMAND_DEF("dump", "dump configuration", - "[master|profile]", cliDump), + CLI_COMMAND_DEF("dfu", "DFU mode on reboot", NULL, cliDfu), + CLI_COMMAND_DEF("dump", "dump configuration", "[master|profile]", cliDump), CLI_COMMAND_DEF("exit", NULL, NULL, cliExit), CLI_COMMAND_DEF("feature", "configure features", "list\r\n" @@ -2564,10 +2566,19 @@ static void cliRateProfile(char *cmdline) { static void cliReboot(void) { - cliPrint("\r\nRebooting"); + cliRebootEx(false); +} + +static void cliRebootEx(bool bootLoader) +{ + cliPrint("\r\nRebooting"); bufWriterFlush(cliWriter); waitForSerialPortToFinishTransmitting(cliPort); stopMotors(); + if (bootLoader) { + systemResetToBootloader(); + return; + } systemReset(); } @@ -3107,6 +3118,13 @@ static void cliResource(char *cmdline) } } +void cliDfu(char *cmdLine) +{ + UNUSED(cmdLine); + cliPrint("\r\nRestarting in DFU mode"); + cliRebootEx(true); +} + void cliInit(serialConfig_t *serialConfig) { UNUSED(serialConfig); From f499041c8e16476459a911902c8c046e6c17f355 Mon Sep 17 00:00:00 2001 From: blckmn Date: Sun, 3 Jul 2016 08:00:21 +1000 Subject: [PATCH 2/2] STM32F4: execute extra enable irq on startup only if rebooting into DFU --- src/main/drivers/system_stm32f4xx.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/drivers/system_stm32f4xx.c b/src/main/drivers/system_stm32f4xx.c index 697b2b743..53f3767a5 100644 --- a/src/main/drivers/system_stm32f4xx.c +++ b/src/main/drivers/system_stm32f4xx.c @@ -199,9 +199,11 @@ void systemInit(void) void(*bootJump)(void); void checkForBootLoaderRequest(void) { - __enable_irq(); if (*((uint32_t *)0x2001FFFC) == 0xDEADBEEF) { + *((uint32_t *)0x2001FFFC) = 0x0; + + __enable_irq(); __set_MSP(0x20001000); bootJump = (void(*)(void))(*((uint32_t *) 0x1fff0004));