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"
28 #include "target/system.h"
29 #include "at32f435_437_clock.h"
31 void SetSysClock(void);
33 void enableGPIOPowerUsageAndNoiseReductions(void)
35 crm_periph_clock_enable(
36 CRM_GPIOA_PERIPH_CLOCK
|
37 CRM_GPIOB_PERIPH_CLOCK
|
38 CRM_GPIOC_PERIPH_CLOCK
|
39 CRM_GPIOD_PERIPH_CLOCK
|
40 CRM_GPIOE_PERIPH_CLOCK
|
41 CRM_DMA1_PERIPH_CLOCK
|
42 CRM_DMA2_PERIPH_CLOCK
|
45 crm_periph_clock_enable(
46 CRM_TMR2_PERIPH_CLOCK
|
47 CRM_TMR3_PERIPH_CLOCK
|
48 CRM_TMR4_PERIPH_CLOCK
|
49 CRM_TMR5_PERIPH_CLOCK
|
50 CRM_TMR6_PERIPH_CLOCK
|
51 CRM_TMR7_PERIPH_CLOCK
|
52 CRM_TMR12_PERIPH_CLOCK
|
53 CRM_TMR13_PERIPH_CLOCK
|
54 CRM_TMR14_PERIPH_CLOCK
|
55 CRM_SPI2_PERIPH_CLOCK
|
56 CRM_SPI3_PERIPH_CLOCK
|
57 CRM_USART2_PERIPH_CLOCK
|
58 CRM_USART3_PERIPH_CLOCK
|
59 CRM_UART4_PERIPH_CLOCK
|
60 CRM_UART5_PERIPH_CLOCK
|
61 CRM_I2C1_PERIPH_CLOCK
|
62 CRM_I2C2_PERIPH_CLOCK
|
63 CRM_I2C3_PERIPH_CLOCK
|
64 CRM_UART8_PERIPH_CLOCK
|
65 CRM_UART7_PERIPH_CLOCK
|
66 CRM_PWC_PERIPH_CLOCK
|
69 crm_periph_clock_enable(
70 CRM_TMR1_PERIPH_CLOCK
|
71 CRM_TMR8_PERIPH_CLOCK
|
72 CRM_USART1_PERIPH_CLOCK
|
73 CRM_USART6_PERIPH_CLOCK
|
74 CRM_ADC1_PERIPH_CLOCK
|
75 CRM_ADC2_PERIPH_CLOCK
|
76 CRM_ADC3_PERIPH_CLOCK
|
77 CRM_SPI1_PERIPH_CLOCK
|
78 CRM_SPI4_PERIPH_CLOCK
|
79 CRM_TMR9_PERIPH_CLOCK
|
80 CRM_TMR10_PERIPH_CLOCK
|
81 CRM_TMR11_PERIPH_CLOCK
|
82 CRM_TMR20_PERIPH_CLOCK
|
83 CRM_ACC_PERIPH_CLOCK
|
86 gpio_init_type gpio_init_struct
;
88 gpio_default_para_init(&gpio_init_struct
);
89 gpio_init_struct
.gpio_pull
= GPIO_PULL_NONE
;
90 gpio_init_struct
.gpio_pins
= GPIO_PINS_ALL
;
91 gpio_init_struct
.gpio_pins
&= ~(GPIO_PINS_12
|GPIO_PINS_11
|GPIO_PINS_9
); // leave USB D+/D- alone
92 gpio_init_struct
.gpio_pins
&= ~(GPIO_PINS_14
|GPIO_PINS_15
|GPIO_PINS_13
); // leave JTAG pins alone
93 gpio_init(GPIOA
, &gpio_init_struct
);
95 gpio_init_struct
.gpio_pins
= GPIO_PINS_ALL
;
96 gpio_init(GPIOB
, &gpio_init_struct
);
97 gpio_init(GPIOC
, &gpio_init_struct
);
98 gpio_init(GPIOD
, &gpio_init_struct
);
99 gpio_init(GPIOE
, &gpio_init_struct
);
100 gpio_init(GPIOF
, &gpio_init_struct
);
103 bool isMPUSoftReset(void)
105 if (cachedRccCsrValue
& CRM_SW_RESET_FLAG
)
110 //AT32 DIAGRAM2-1 AT32F435/437 DFU BOOTLOADER ADDR
111 uint32_t systemBootloaderAddress(void)
114 //return system_isr_vector_table_base;
117 void systemInit(void)
119 //config system clock to 288mhz usb 48mhz
120 system_clock_config();
121 // Configure NVIC preempt/priority groups
122 nvic_priority_group_config(NVIC_PRIORITY_GROUPING
);
124 // cache RCC->CSR value to use it in isMPUSoftReset() and others
125 cachedRccCsrValue
= CRM
->ctrlsts
;
127 // Although VTOR is already loaded with a possible vector table in RAM,
128 // removing the call to NVIC_SetVectorTable causes USB not to become active,
129 extern uint8_t isr_vector_table_base
;
130 nvic_vector_table_set((uint32_t)&isr_vector_table_base
, 0x0);
132 // disable usb otg fs1/2
133 crm_periph_clock_enable(CRM_OTGFS2_PERIPH_CLOCK
|CRM_OTGFS1_PERIPH_CLOCK
,FALSE
);
135 // clear all reset flags
136 CRM
->ctrlsts_bit
.rstfc
= TRUE
;
137 enableGPIOPowerUsageAndNoiseReductions();
138 // Init cycle counter
141 SysTick_Config(system_core_clock
/ 1000);