duplicate emptyline removal (#14027)
[betaflight.git] / src / platform / STM32 / system_stm32f7xx.c
blob8f6da10c70fd45dfc7b4ea9ecf4956de0c3fde69
1 /*
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)
8 * any later version.
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/>.
21 #include <string.h>
22 #include <stdbool.h>
23 #include <stdint.h>
24 #include <stdlib.h>
26 #include "platform.h"
28 #include "drivers/accgyro/accgyro_mpu.h"
29 #include "drivers/exti.h"
30 #include "drivers/nvic.h"
31 #include "drivers/system.h"
32 #include "drivers/persistent.h"
34 #include "stm32f7xx_ll_cortex.h"
36 #define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000)
38 #define DEFAULT_STACK_POINTER ((uint32_t *) 0x1FF00000)
39 #define SYSTEM_MEMORY_RESET_VECTOR ((uint32_t *) 0x1FF00004)
41 void SystemClock_Config(void);
43 void systemReset(void)
45 __disable_irq();
46 NVIC_SystemReset();
49 void systemResetToBootloader(bootloaderRequestType_e requestType)
51 switch (requestType) {
52 case BOOTLOADER_REQUEST_ROM:
53 default:
54 persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_BOOTLOADER_REQUEST_ROM);
56 break;
59 __disable_irq();
60 NVIC_SystemReset();
63 bool isMPUSoftReset(void)
65 if (cachedRccCsrValue & RCC_CSR_SFTRSTF)
66 return true;
67 else
68 return false;
71 static void checkForBootLoaderRequest(void)
73 uint32_t bootloaderRequest = persistentObjectRead(PERSISTENT_OBJECT_RESET_REASON);
75 if (bootloaderRequest != RESET_BOOTLOADER_REQUEST_ROM) {
76 return;
78 persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_BOOTLOADER_POST);
80 __SYSCFG_CLK_ENABLE();
81 SYSCFG->MEMRMP |= SYSCFG_MEM_BOOT_ADD0 ;
83 __set_MSP(*DEFAULT_STACK_POINTER);
85 ((void (*)(void))*SYSTEM_MEMORY_RESET_VECTOR)();
87 while (1);
90 void systemInit(void)
92 persistentObjectInit();
94 checkForBootLoaderRequest();
96 // Mark ITCM-RAM as read-only
97 LL_MPU_ConfigRegion(LL_MPU_REGION_NUMBER0, 0, RAMITCM_BASE, LL_MPU_REGION_SIZE_16KB | LL_MPU_REGION_PRIV_RO_URO);
98 LL_MPU_Enable(LL_MPU_CTRL_PRIVILEGED_DEFAULT);
100 //SystemClock_Config();
102 // Configure NVIC preempt/priority groups
103 HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITY_GROUPING);
105 // cache RCC->CSR value to use it in isMPUSoftReset() and others
106 cachedRccCsrValue = RCC->CSR;
108 /* Accounts for OP Bootloader, set the Vector Table base address as specified in .ld file */
109 //extern void *isr_vector_table_base;
110 //NVIC_SetVectorTable((uint32_t)&isr_vector_table_base, 0x0);
111 //__HAL_RCC_USB_OTG_FS_CLK_DISABLE;
113 //RCC_ClearFlag();
115 // Init cycle counter
116 cycleCounterInit();
118 // SysTick
119 //SysTick_Config(SystemCoreClock / 1000);
120 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
122 HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);