Skip to content

Commit

Permalink
Merge pull request cleanflight#658 from blckmn/usb_vcp_fix
Browse files Browse the repository at this point in the history
Fixed build issue for F1, and added dfu CLI command (for restart in D…
  • Loading branch information
blckmn committed Jul 2, 2016
2 parents 43276be + f499041 commit 6df812f
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 9 deletions.
2 changes: 0 additions & 2 deletions src/main/drivers/io.h
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions src/main/drivers/system.h
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/main/drivers/system_stm32f10x.c
Expand Up @@ -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

Expand Down Expand Up @@ -68,6 +69,8 @@ bool isMPUSoftReset(void)

void systemInit(void)
{
checkForBootLoaderRequest();

SetSysClock(false);

#ifdef CC3D
Expand Down Expand Up @@ -110,3 +113,6 @@ void systemInit(void)
SysTick_Config(SystemCoreClock / 1000);
}

void checkForBootLoaderRequest(void)
{
}
9 changes: 8 additions & 1 deletion src/main/drivers/system_stm32f30x.c
Expand Up @@ -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

Expand Down Expand Up @@ -82,6 +83,8 @@ bool isMPUSoftReset(void)

void systemInit(void)
{
checkForBootLoaderRequest();

// Enable FPU
SCB->CPACR = (0x3 << (10 * 2)) | (0x3 << (11 * 2));
SetSysClock();
Expand All @@ -102,3 +105,7 @@ void systemInit(void)
// SysTick
SysTick_Config(SystemCoreClock / 1000);
}

void checkForBootLoaderRequest(void)
{
}
17 changes: 17 additions & 0 deletions src/main/drivers/system_stm32f4xx.c
Expand Up @@ -169,6 +169,8 @@ bool isMPUSoftReset(void)

void systemInit(void)
{
checkForBootLoaderRequest();

SetSysClock();

// Configure NVIC preempt/priority groups
Expand All @@ -194,3 +196,18 @@ void systemInit(void)
SysTick_Config(SystemCoreClock / 1000);
}

void(*bootJump)(void);
void checkForBootLoaderRequest(void)
{
if (*((uint32_t *)0x2001FFFC) == 0xDEADBEEF) {

*((uint32_t *)0x2001FFFC) = 0x0;

__enable_irq();
__set_MSP(0x20001000);

bootJump = (void(*)(void))(*((uint32_t *) 0x1fff0004));
bootJump();
while (1);
}
}
4 changes: 2 additions & 2 deletions src/main/io/serial_4way.c
Expand Up @@ -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
Expand Down
24 changes: 21 additions & 3 deletions src/main/io/serial_cli.c
Expand Up @@ -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) ;
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6df812f

Please sign in to comment.