Added detection of soft reset and swich of bind mode

after first hard reset (power on) if hardware bind plug is not
configured. Now completly tested.
This commit is contained in:
Michael Jakob 2014-12-06 17:43:26 +01:00 committed by Dominic Clifton
parent c09877e5b9
commit 1be3e8e550
4 changed files with 35 additions and 2 deletions

View File

@ -30,6 +30,7 @@ void failureMode(uint8_t mode);
// bootloader/IAP
void systemReset(void);
void systemResetToBootloader(void);
bool isMPUSoftReset(void);
void enableGPIOPowerUsageAndNoiseReductions(void);
// current crystal frequency - 8 or 12MHz

View File

@ -22,11 +22,19 @@
#include "platform.h"
#include "gpio.h"
#include "system.h"
#define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000)
#define BKP_SOFTRESET (0x50F7B007)
void systemReset(void)
{
// write magic value that we're doing a soft reset
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
PWR->CR |= PWR_CR_DBP;
*((uint16_t *)BKP_BASE + 0x04) = BKP_SOFTRESET & 0xffff;
*((uint16_t *)BKP_BASE + 0x08) = (BKP_SOFTRESET & 0xffff0000) >> 16;
// Generate system reset
SCB->AIRCR = AIRCR_VECTKEY_MASK | (uint32_t)0x04;
}
@ -52,3 +60,11 @@ void enableGPIOPowerUsageAndNoiseReductions(void)
gpioInit(GPIOB, &gpio);
gpioInit(GPIOC, &gpio);
}
bool isMPUSoftReset(void)
{
if ((*((uint16_t *)BKP_BASE + 0x04) | *((uint16_t *)BKP_BASE + 0x08) << 16) == BKP_SOFTRESET)
return true;
else
return false;
}

View File

@ -67,3 +67,9 @@ void enableGPIOPowerUsageAndNoiseReductions(void)
gpioInit(GPIOE, &gpio);
gpioInit(GPIOF, &gpio);
}
bool isMPUSoftReset(void)
{
// not implemented yet for STM32F3xx
return false;
}

View File

@ -175,8 +175,8 @@ void spektrumBind(rxConfig_t *rxConfig)
spekBindPort = BIND_PORT;
spekBindPin = BIND_PIN;
// don't try to bind if: bind flag is out of range
if (rxConfig->spektrum_sat_bind == 0 || rxConfig->spektrum_sat_bind > 10)
// don't try to bind if: here after soft reset or bind flag is out of range
if (isMPUSoftReset() || rxConfig->spektrum_sat_bind == 0 || rxConfig->spektrum_sat_bind > 10)
return;
gpio.speed = Speed_2MHz;
@ -196,5 +196,15 @@ void spektrumBind(rxConfig_t *rxConfig)
digitalHi(spekBindPort, spekBindPin);
delayMicroseconds(120);
}
#ifndef HARDWARE_BIND_PLUG
// If we came here as a result of hard reset (power up, with mcfg.spektrum_sat_bind set), then reset it back to zero and write config
// Don't reset if hardware bind plug is present
if (!isMPUSoftReset()) {
rxConfig->spektrum_sat_bind = 0;
writeEEPROM(1, true);
}
#endif
}
#endif