|
11 | 11 | #include <board.h> |
12 | 12 | #include <drv_common.h> |
13 | 13 |
|
| 14 | +#ifdef RT_USING_MEM_PROTECTION |
| 15 | +#include "mprotect.h" |
| 16 | + |
| 17 | +rt_mem_region_t static_regions[NUM_STATIC_REGIONS] = { |
| 18 | + /* Flash region, read only */ |
| 19 | + { |
| 20 | + .start = (void *)STM32_FLASH_START_ADRESS, |
| 21 | + .size = (rt_size_t)STM32_FLASH_SIZE, |
| 22 | + .attr = RT_MEM_REGION_P_RX_U_RX, |
| 23 | + }, |
| 24 | +}; |
| 25 | +#endif |
| 26 | + |
14 | 27 | void SystemClock_Config(void) |
15 | 28 | { |
16 | | - RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
17 | | - RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
18 | | - RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; |
| 29 | + RCC_OscInitTypeDef RCC_OscInitStruct = { 0 }; |
| 30 | + RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 }; |
| 31 | + RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = { 0 }; |
19 | 32 |
|
20 | | - /**Configure the main internal regulator output voltage |
21 | | - */ |
22 | | - __HAL_RCC_PWR_CLK_ENABLE(); |
23 | | - __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); |
24 | | - /**Initializes the CPU, AHB and APB busses clocks |
25 | | - */ |
26 | | - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE |
27 | | - |RCC_OSCILLATORTYPE_LSE; |
28 | | - RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
29 | | - RCC_OscInitStruct.LSEState = RCC_LSE_ON; |
30 | | - RCC_OscInitStruct.LSIState = RCC_LSI_ON; |
31 | | - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
32 | | - RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
33 | | - RCC_OscInitStruct.PLL.PLLM = 4; |
34 | | - RCC_OscInitStruct.PLL.PLLN = 168; |
35 | | - RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; |
36 | | - RCC_OscInitStruct.PLL.PLLQ = 7; |
37 | | - if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
38 | | - { |
39 | | - Error_Handler(); |
40 | | - } |
41 | | - /**Initializes the CPU, AHB and APB busses clocks |
42 | | - */ |
43 | | - RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
44 | | - |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; |
45 | | - RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
46 | | - RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
47 | | - RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; |
48 | | - RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; |
| 33 | + /**Configure the main internal regulator output voltage |
| 34 | + */ |
| 35 | + __HAL_RCC_PWR_CLK_ENABLE(); |
| 36 | + __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); |
| 37 | + /**Initializes the CPU, AHB and APB busses clocks |
| 38 | + */ |
| 39 | + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_LSE; |
| 40 | + RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
| 41 | + RCC_OscInitStruct.LSEState = RCC_LSE_ON; |
| 42 | + RCC_OscInitStruct.LSIState = RCC_LSI_ON; |
| 43 | + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
| 44 | + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
| 45 | + RCC_OscInitStruct.PLL.PLLM = 4; |
| 46 | + RCC_OscInitStruct.PLL.PLLN = 168; |
| 47 | + RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; |
| 48 | + RCC_OscInitStruct.PLL.PLLQ = 7; |
| 49 | + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
| 50 | + { |
| 51 | + Error_Handler(); |
| 52 | + } |
| 53 | + /**Initializes the CPU, AHB and APB busses clocks |
| 54 | + */ |
| 55 | + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; |
| 56 | + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
| 57 | + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
| 58 | + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; |
| 59 | + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; |
49 | 60 |
|
50 | | - if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) |
51 | | - { |
52 | | - Error_Handler(); |
53 | | - } |
54 | | - PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC; |
55 | | - PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; |
56 | | - if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) |
57 | | - { |
58 | | - Error_Handler(); |
59 | | - } |
| 61 | + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) |
| 62 | + { |
| 63 | + Error_Handler(); |
| 64 | + } |
| 65 | + PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC; |
| 66 | + PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; |
| 67 | + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) |
| 68 | + { |
| 69 | + Error_Handler(); |
| 70 | + } |
60 | 71 | } |
0 commit comments