1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-15 04:15:44 +03:00

Switch to cleaner way of detecting a soft-reset on STM32F103 based targets using RCC->CSR register.

This commit is contained in:
Konstantin Sharlaimov 2015-03-13 23:42:12 +10:00 committed by Dominic Clifton
parent 11493cd01a
commit bd6297f0cc
4 changed files with 9 additions and 9 deletions

View file

@ -76,6 +76,8 @@ void EXTI15_10_IRQHandler(void)
static uint32_t usTicks = 0; static uint32_t usTicks = 0;
// current uptime for 1kHz systick timer. will rollover after 49 days. hopefully we won't care. // current uptime for 1kHz systick timer. will rollover after 49 days. hopefully we won't care.
static volatile uint32_t sysTickUptime = 0; static volatile uint32_t sysTickUptime = 0;
// cached value of RCC->CSR
uint32_t cachedRccCsrValue;
static void cycleCounterInit(void) static void cycleCounterInit(void)
{ {
@ -123,6 +125,8 @@ void systemInit(void)
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
#endif #endif
// cache RCC->CSR value to use it in isMPUSoftreset() and others
cachedRccCsrValue = RCC->CSR;
RCC_ClearFlag(); RCC_ClearFlag();

View file

@ -40,3 +40,5 @@ typedef void extiCallbackHandler(void);
void registerExti15_10_CallbackHandler(extiCallbackHandler *fn); void registerExti15_10_CallbackHandler(extiCallbackHandler *fn);
void unregisterExti15_10_CallbackHandler(extiCallbackHandler *fn); void unregisterExti15_10_CallbackHandler(extiCallbackHandler *fn);
extern uint32_t cachedRccCsrValue;

View file

@ -25,16 +25,9 @@
#include "system.h" #include "system.h"
#define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000) #define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000)
#define BKP_SOFTRESET (0x50F7B007)
void systemReset(void) 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 // Generate system reset
SCB->AIRCR = AIRCR_VECTKEY_MASK | (uint32_t)0x04; SCB->AIRCR = AIRCR_VECTKEY_MASK | (uint32_t)0x04;
} }
@ -63,7 +56,7 @@ void enableGPIOPowerUsageAndNoiseReductions(void)
bool isMPUSoftReset(void) bool isMPUSoftReset(void)
{ {
if ((*((uint16_t *)BKP_BASE + 0x04) | *((uint16_t *)BKP_BASE + 0x08) << 16) == BKP_SOFTRESET) if (cachedRccCsrValue & RCC_CSR_SFTRSTF)
return true; return true;
else else
return false; return false;

View file

@ -22,6 +22,7 @@
#include "platform.h" #include "platform.h"
#include "gpio.h" #include "gpio.h"
#include "system.h"
#define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000) #define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000)
@ -70,7 +71,7 @@ void enableGPIOPowerUsageAndNoiseReductions(void)
bool isMPUSoftReset(void) bool isMPUSoftReset(void)
{ {
if (RCC->CSR & RCC_CSR_SFTRSTF) if (cachedRccCsrValue & RCC_CSR_SFTRSTF)
return true; return true;
else else
return false; return false;