2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
24 #include "drivers/accgyro/accgyro_mpu.h"
25 #include "drivers/exti.h"
26 #include "drivers/nvic.h"
27 #include "drivers/system.h"
29 #include "target/system.h"
32 void SetSysClock(void);
34 void enableGPIOPowerUsageAndNoiseReductions(void)
37 RCC_AHB1PeriphClockCmd(
38 RCC_AHB1Periph_GPIOA
|
39 RCC_AHB1Periph_GPIOB
|
40 RCC_AHB1Periph_GPIOC
|
41 RCC_AHB1Periph_GPIOD
|
42 RCC_AHB1Periph_GPIOE
|
44 RCC_AHB1Periph_GPIOF
|
45 RCC_AHB1Periph_GPIOG
|
46 RCC_AHB1Periph_GPIOH
|
47 RCC_AHB1Periph_GPIOI
|
50 RCC_AHB1Periph_FLITF
|
51 RCC_AHB1Periph_SRAM1
|
52 RCC_AHB1Periph_SRAM2
|
53 RCC_AHB1Periph_BKPSRAM
|
59 RCC_AHB2PeriphClockCmd(0, ENABLE
);
61 RCC_AHB3PeriphClockCmd(0, ENABLE
);
63 RCC_APB1PeriphClockCmd(
70 RCC_APB1Periph_TIM12
|
71 RCC_APB1Periph_TIM13
|
72 RCC_APB1Periph_TIM14
|
76 RCC_APB1Periph_USART2
|
77 RCC_APB1Periph_USART3
|
78 RCC_APB1Periph_UART4
|
79 RCC_APB1Periph_UART5
|
83 // RCC_APB1Periph_CAN1 |
84 // RCC_APB1Periph_CAN2 |
86 // RCC_APB1Periph_DAC |
89 RCC_APB2PeriphClockCmd(
92 RCC_APB2Periph_USART1
|
93 RCC_APB2Periph_USART6
|
98 // RCC_APB2Periph_SDIO |
100 RCC_APB2Periph_SYSCFG
|
101 RCC_APB2Periph_TIM9
|
102 RCC_APB2Periph_TIM10
|
103 RCC_APB2Periph_TIM11
|
106 GPIO_InitTypeDef GPIO_InitStructure
;
107 GPIO_StructInit(&GPIO_InitStructure
);
108 GPIO_InitStructure
.GPIO_PuPd
= GPIO_PuPd_NOPULL
;
110 GPIO_InitStructure
.GPIO_Pin
= GPIO_Pin_All
;
111 GPIO_InitStructure
.GPIO_Pin
&= ~(GPIO_Pin_11
| GPIO_Pin_12
); // leave USB D+/D- alone
113 GPIO_InitStructure
.GPIO_Pin
&= ~(GPIO_Pin_13
| GPIO_Pin_14
); // leave JTAG pins alone
114 GPIO_Init(GPIOA
, &GPIO_InitStructure
);
116 GPIO_InitStructure
.GPIO_Pin
= GPIO_Pin_All
;
117 GPIO_Init(GPIOB
, &GPIO_InitStructure
);
119 GPIO_InitStructure
.GPIO_Pin
= GPIO_Pin_All
;
120 GPIO_Init(GPIOC
, &GPIO_InitStructure
);
121 GPIO_Init(GPIOD
, &GPIO_InitStructure
);
122 GPIO_Init(GPIOE
, &GPIO_InitStructure
);
124 #ifdef STM32F40_41xxx
125 GPIO_Init(GPIOF
, &GPIO_InitStructure
);
126 GPIO_Init(GPIOG
, &GPIO_InitStructure
);
127 GPIO_Init(GPIOH
, &GPIO_InitStructure
);
128 GPIO_Init(GPIOI
, &GPIO_InitStructure
);
133 bool isMPUSoftReset(void)
135 if (RCC
->CSR
& RCC_CSR_SFTRSTF
)
141 uint32_t systemBootloaderAddress(void)
146 void systemInit(void)
150 // Configure NVIC preempt/priority groups
151 NVIC_PriorityGroupConfig(NVIC_PRIORITY_GROUPING
);
153 // cache RCC->CSR value to use it in isMPUSoftreset() and others
154 cachedRccCsrValue
= RCC
->CSR
;
156 /* Accounts for OP Bootloader, set the Vector Table base address as specified in .ld file */
157 NVIC_SetVectorTable((uint32_t)&isr_vector_table_base
, 0x0);
158 RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS
, DISABLE
);
162 enableGPIOPowerUsageAndNoiseReductions();
164 // Init cycle counter
168 SysTick_Config(SystemCoreClock
/ 1000);