5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
22 #include "storage/rtc_backup.h"
26 GPIO_InitTypeDef GPIO_InitStructure
;
28 GPIO_InitStructure
.GPIO_Mode
= GPIO_Mode_OUT
;
29 GPIO_InitStructure
.GPIO_Speed
= GPIO_Speed_2MHz
;
30 GPIO_InitStructure
.GPIO_OType
= GPIO_OType_PP
;
31 GPIO_InitStructure
.GPIO_PuPd
= GPIO_PuPd_UP
;
33 // Internal module PWR
34 GPIO_ResetBits(INTMODULE_PWR_GPIO
, INTMODULE_PWR_GPIO_PIN
);
35 GPIO_InitStructure
.GPIO_Pin
= INTMODULE_PWR_GPIO_PIN
;
36 GPIO_Init(INTMODULE_PWR_GPIO
, &GPIO_InitStructure
);
38 // External module PWR
39 GPIO_ResetBits(EXTMODULE_PWR_GPIO
, EXTMODULE_PWR_GPIO_PIN
);
40 GPIO_InitStructure
.GPIO_Pin
= EXTMODULE_PWR_GPIO_PIN
;
41 GPIO_Init(EXTMODULE_PWR_GPIO
, &GPIO_InitStructure
);
43 #if defined(INTMODULE_BOOTCMD_GPIO)
44 GPIO_ResetBits(INTMODULE_BOOTCMD_GPIO
, INTMODULE_BOOTCMD_GPIO_PIN
);
45 GPIO_InitStructure
.GPIO_Pin
= INTMODULE_BOOTCMD_GPIO_PIN
;
46 GPIO_Init(INTMODULE_BOOTCMD_GPIO
, &GPIO_InitStructure
);
49 GPIO_InitStructure
.GPIO_Mode
= GPIO_Mode_IN
;
52 GPIO_InitStructure
.GPIO_Pin
= PWR_SWITCH_GPIO_PIN
;
53 GPIO_Init(PWR_SWITCH_GPIO
, &GPIO_InitStructure
);
56 #if defined(PCBREV_GPIO_PIN)
57 GPIO_InitStructure
.GPIO_Pin
= PCBREV_GPIO_PIN
;
58 GPIO_Init(PCBREV_GPIO
, &GPIO_InitStructure
);
59 hardwareOptions
.pcbrev
= PCBREV_VALUE();
63 GPIO_ResetBits(SD_PRESENT_GPIO
, SD_PRESENT_GPIO_PIN
);
64 GPIO_InitStructure
.GPIO_Pin
= SD_PRESENT_GPIO_PIN
;
65 GPIO_Init(SD_PRESENT_GPIO
, &GPIO_InitStructure
);
68 GPIO_InitStructure
.GPIO_Pin
= TRAINER_DETECT_GPIO_PIN
;
69 GPIO_Init(TRAINER_DETECT_GPIO
, &GPIO_InitStructure
);
74 // we keep the init of the PIN to have pwrOn as quick as possible
76 GPIO_InitTypeDef GPIO_InitStructure
;
77 GPIO_InitStructure
.GPIO_Pin
= PWR_ON_GPIO_PIN
;
78 GPIO_InitStructure
.GPIO_Mode
= GPIO_Mode_OUT
;
79 GPIO_InitStructure
.GPIO_Speed
= GPIO_Speed_2MHz
;
80 GPIO_InitStructure
.GPIO_OType
= GPIO_OType_PP
;
81 GPIO_InitStructure
.GPIO_PuPd
= GPIO_PuPd_UP
;
82 GPIO_Init(PWR_ON_GPIO
, &GPIO_InitStructure
);
84 GPIO_SetBits(PWR_ON_GPIO
, PWR_ON_GPIO_PIN
);
89 GPIO_ResetBits(PWR_ON_GPIO
, PWR_ON_GPIO_PIN
);
94 return GPIO_ReadInputDataBit(PWR_ON_GPIO
, PWR_SWITCH_GPIO_PIN
) == Bit_RESET
;
97 void pwrResetHandler()
99 RCC
->AHB1ENR
|= PWR_RCC_AHB1Periph
;
101 // these two NOPs are needed (see STM32F errata sheet) before the peripheral
102 // register can be written after the peripheral clock was enabled
103 __ASM
volatile ("nop");
104 __ASM
volatile ("nop");
106 if (WAS_RESET_BY_WATCHDOG_OR_SOFTWARE()) {