2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
26 #include "drivers/accgyro/accgyro_mpu.h"
27 #include "drivers/exti.h"
28 #include "drivers/nvic.h"
29 #include "drivers/system.h"
30 #include "drivers/persistent.h"
33 #define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000)
34 void SetSysClock(void);
36 void systemReset(void)
42 void systemResetToBootloader(bootloaderRequestType_e requestType
)
44 switch (requestType
) {
45 case BOOTLOADER_REQUEST_ROM
:
47 persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON
, RESET_BOOTLOADER_REQUEST_ROM
);
56 typedef void resetHandler_t(void);
58 typedef struct isrVector_s
{
59 __I
uint32_t stackEnd
;
60 resetHandler_t
*resetHandler
;
63 // Used in the startup files for F4
64 void checkForBootLoaderRequest(void)
66 uint32_t bootloaderRequest
= persistentObjectRead(PERSISTENT_OBJECT_RESET_REASON
);
68 if (bootloaderRequest
!= RESET_BOOTLOADER_REQUEST_ROM
) {
71 persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON
, RESET_NONE
);
73 extern isrVector_t system_isr_vector_table_base
;
75 __set_MSP(system_isr_vector_table_base
.stackEnd
);
76 system_isr_vector_table_base
.resetHandler();
80 void enableGPIOPowerUsageAndNoiseReductions(void)
83 RCC_AHB1PeriphClockCmd(
84 RCC_AHB1Periph_SRAM1
|
85 RCC_AHB1Periph_SRAM2
|
86 RCC_AHB1Periph_BKPSRAM
|
92 RCC_AHB2PeriphClockCmd(0, ENABLE
);
94 RCC_AHB3PeriphClockCmd(0, ENABLE
);
96 RCC_APB1PeriphClockCmd(
100 RCC_APB1Periph_TIM5
|
101 RCC_APB1Periph_TIM6
|
102 RCC_APB1Periph_TIM7
|
103 RCC_APB1Periph_TIM12
|
104 RCC_APB1Periph_TIM13
|
105 RCC_APB1Periph_TIM14
|
106 RCC_APB1Periph_WWDG
|
107 RCC_APB1Periph_SPI2
|
108 RCC_APB1Periph_SPI3
|
109 RCC_APB1Periph_USART2
|
110 RCC_APB1Periph_USART3
|
111 RCC_APB1Periph_UART4
|
112 RCC_APB1Periph_UART5
|
113 RCC_APB1Periph_I2C1
|
114 RCC_APB1Periph_I2C2
|
115 RCC_APB1Periph_I2C3
|
116 RCC_APB1Periph_CAN1
|
117 RCC_APB1Periph_CAN2
|
122 RCC_APB2PeriphClockCmd(
123 RCC_APB2Periph_TIM1
|
124 RCC_APB2Periph_TIM8
|
125 RCC_APB2Periph_USART1
|
126 RCC_APB2Periph_USART6
|
128 RCC_APB2Periph_ADC1
|
129 RCC_APB2Periph_ADC2
|
130 RCC_APB2Periph_ADC3
|
131 RCC_APB2Periph_SDIO
|
132 RCC_APB2Periph_SPI1
|
133 RCC_APB2Periph_SYSCFG
|
134 RCC_APB2Periph_TIM9
|
135 RCC_APB2Periph_TIM10
|
136 RCC_APB2Periph_TIM11
|
140 bool isMPUSoftReset(void)
142 if (cachedRccCsrValue
& RCC_CSR_SFTRSTF
)
148 void systemInit(void)
152 // Configure NVIC preempt/priority groups
153 NVIC_PriorityGroupConfig(NVIC_PRIORITY_GROUPING
);
155 // cache RCC->CSR value to use it in isMPUSoftReset() and others
156 cachedRccCsrValue
= RCC
->CSR
;
158 // Although VTOR is already loaded with a possible vector table in RAM,
159 // removing the call to NVIC_SetVectorTable causes USB not to become active,
161 extern uint8_t isr_vector_table_base
;
162 NVIC_SetVectorTable((uint32_t)&isr_vector_table_base
, 0x0);
164 RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS
, DISABLE
);
168 enableGPIOPowerUsageAndNoiseReductions();
170 // Init cycle counter
174 SysTick_Config(SystemCoreClock
/ 1000);