YJ пре 6 година
комит
04589f60c4
70 измењених фајлова са 74897 додато и 0 уклоњено
  1. 313 0
      .cproject
  2. 14 0
      .mxproject
  3. 76 0
      .project
  4. 11 0
      .settings/com.atollic.truestudio.debug.hardware_device.prefs
  5. 23 0
      .settings/language.settings.xml
  6. BIN
      BDA4601.pdf
  7. 11963 0
      Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xg.h
  8. 238 0
      Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h
  9. 116 0
      Drivers/CMSIS/Device/ST/STM32F1xx/Include/system_stm32f1xx.h
  10. 136 0
      Drivers/CMSIS/Include/arm_common_tables.h
  11. 79 0
      Drivers/CMSIS/Include/arm_const_structs.h
  12. 7154 0
      Drivers/CMSIS/Include/arm_math.h
  13. 734 0
      Drivers/CMSIS/Include/cmsis_armcc.h
  14. 1800 0
      Drivers/CMSIS/Include/cmsis_armcc_V6.h
  15. 1373 0
      Drivers/CMSIS/Include/cmsis_gcc.h
  16. 798 0
      Drivers/CMSIS/Include/core_cm0.h
  17. 914 0
      Drivers/CMSIS/Include/core_cm0plus.h
  18. 1763 0
      Drivers/CMSIS/Include/core_cm3.h
  19. 1937 0
      Drivers/CMSIS/Include/core_cm4.h
  20. 2512 0
      Drivers/CMSIS/Include/core_cm7.h
  21. 87 0
      Drivers/CMSIS/Include/core_cmFunc.h
  22. 87 0
      Drivers/CMSIS/Include/core_cmInstr.h
  23. 96 0
      Drivers/CMSIS/Include/core_cmSimd.h
  24. 926 0
      Drivers/CMSIS/Include/core_sc000.h
  25. 1745 0
      Drivers/CMSIS/Include/core_sc300.h
  26. 3219 0
      Drivers/STM32F1xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h
  27. 367 0
      Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal.h
  28. 965 0
      Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_adc.h
  29. 726 0
      Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_adc_ex.h
  30. 426 0
      Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_cortex.h
  31. 214 0
      Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_def.h
  32. 473 0
      Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma.h
  33. 293 0
      Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma_ex.h
  34. 344 0
      Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash.h
  35. 802 0
      Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash_ex.h
  36. 324 0
      Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio.h
  37. 910 0
      Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio_ex.h
  38. 404 0
      Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pwr.h
  39. 1393 0
      Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc.h
  40. 1924 0
      Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc_ex.h
  41. 1793 0
      Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h
  42. 343 0
      Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim_ex.h
  43. 785 0
      Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_uart.h
  44. 595 0
      Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c
  45. 2110 0
      Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc.c
  46. 1339 0
      Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.c
  47. 521 0
      Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c
  48. 902 0
      Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c
  49. 983 0
      Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c
  50. 1143 0
      Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c
  51. 595 0
      Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c
  52. 143 0
      Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c
  53. 637 0
      Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c
  54. 1416 0
      Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c
  55. 879 0
      Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c
  56. 5419 0
      Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c
  57. 1773 0
      Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c
  58. 2556 0
      Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c
  59. 209 0
      Inc/main.h
  60. 370 0
      Inc/stm32f1xx_hal_conf.h
  61. 69 0
      Inc/stm32f1xx_it.h
  62. 168 0
      STM32F103VG_FLASH.ld
  63. 46 0
      STM32F103_ATTEN_PLL_Zig.elf.launch
  64. 451 0
      STM32F103_ATTEN_PLL_Zig.ioc
  65. 378 0
      Src/main.c
  66. 258 0
      Src/stm32f1xx_hal_msp.c
  67. 203 0
      Src/stm32f1xx_it.c
  68. 204 0
      Src/syscalls.c
  69. 448 0
      Src/system_stm32f1xx.c
  70. 482 0
      startup/startup_stm32f103xg.s

Разлика између датотеке није приказан због своје велике величине
+ 313 - 0
.cproject


Разлика између датотеке није приказан због своје велике величине
+ 14 - 0
.mxproject


+ 76 - 0
.project

@@ -0,0 +1,76 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<projectDescription>
3
+	<name>STM32F103_ATTEN_PLL_Zig</name>
4
+	<comment />
5
+	<projects>
6
+	</projects>
7
+	<buildSpec>
8
+		<buildCommand>
9
+			<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
10
+			<triggers>clean,full,incremental,</triggers>
11
+			<arguments>
12
+				<dictionary>
13
+					<key>?children?</key>
14
+					<value>?name?=outputEntries\|?children?=?name?=entry\\\\\\\|\\\|\||</value>
15
+				</dictionary>
16
+				<dictionary>
17
+					<key>?name?</key>
18
+					<value />
19
+				</dictionary>
20
+				<dictionary>
21
+					<key>org.eclipse.cdt.make.core.append_environment</key>
22
+					<value>true</value>
23
+				</dictionary>
24
+				<dictionary>
25
+					<key>org.eclipse.cdt.make.core.buildArguments</key>
26
+					<value />
27
+				</dictionary>
28
+				<dictionary>
29
+					<key>org.eclipse.cdt.make.core.buildCommand</key>
30
+					<value>make</value>
31
+				</dictionary>
32
+				<dictionary>
33
+					<key>org.eclipse.cdt.make.core.buildLocation</key>
34
+					<value>${workspace_loc:/STM32100B-EVAL/Debug}</value>
35
+				</dictionary>
36
+				<dictionary>
37
+					<key>org.eclipse.cdt.make.core.contents</key>
38
+					<value>org.eclipse.cdt.make.core.activeConfigSettings</value>
39
+				</dictionary>
40
+				<dictionary>
41
+					<key>org.eclipse.cdt.make.core.enableAutoBuild</key>
42
+					<value>false</value>
43
+				</dictionary>
44
+				<dictionary>
45
+					<key>org.eclipse.cdt.make.core.enableCleanBuild</key>
46
+					<value>true</value>
47
+				</dictionary>
48
+				<dictionary>
49
+					<key>org.eclipse.cdt.make.core.enableFullBuild</key>
50
+					<value>true</value>
51
+				</dictionary>
52
+				<dictionary>
53
+					<key>org.eclipse.cdt.make.core.stopOnError</key>
54
+					<value>true</value>
55
+				</dictionary>
56
+				<dictionary>
57
+					<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
58
+					<value>true</value>
59
+				</dictionary>
60
+			</arguments>
61
+		</buildCommand>
62
+		<buildCommand>
63
+			<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
64
+			<arguments>
65
+			</arguments>
66
+		</buildCommand>
67
+	</buildSpec>
68
+	<natures>
69
+		<nature>org.eclipse.cdt.core.cnature</nature>
70
+		<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
71
+		<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
72
+	</natures>
73
+	<linkedResources>
74
+		
75
+	</linkedResources>
76
+</projectDescription>

+ 11 - 0
.settings/com.atollic.truestudio.debug.hardware_device.prefs

@@ -0,0 +1,11 @@
1
+BOARD=None
2
+CODE_LOCATION=FLASH
3
+ENDIAN=Little-endian
4
+MCU=STM32F103VG
5
+MCU_VENDOR=STMicroelectronics
6
+MODEL=Lite
7
+PROBE=ST-LINK
8
+PROJECT_FORMAT_VERSION=2
9
+TARGET=ARM\u00AE
10
+VERSION=4.1.0
11
+eclipse.preferences.version=1

+ 23 - 0
.settings/language.settings.xml

@@ -0,0 +1,23 @@
1
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+<project>
3
+	<configuration id="com.atollic.truestudio.exe.debug.1518366166" name="Debug">
4
+		<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
5
+			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
6
+			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
7
+			<provider class="com.atollic.truestudio.mbs.GCCSpecsDetectorAtollicArm" console="false" env-hash="1832218778156572642" id="com.atollic.truestudio.mbs.provider" keep-relative-paths="false" name="Atollic ARM Tools Language Settings" parameter="${COMMAND} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
8
+				<language-scope id="org.eclipse.cdt.core.gcc"/>
9
+				<language-scope id="org.eclipse.cdt.core.g++"/>
10
+			</provider>
11
+		</extension>
12
+	</configuration>
13
+	<configuration id="com.atollic.truestudio.configuration.release.1518366166" name="Release">
14
+		<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
15
+			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
16
+			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
17
+			<provider class="com.atollic.truestudio.mbs.GCCSpecsDetectorAtollicArm" console="false" env-hash="1832218778156572642" id="com.atollic.truestudio.mbs.provider" keep-relative-paths="false" name="Atollic ARM Tools Language Settings" parameter="${COMMAND} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
18
+				<language-scope id="org.eclipse.cdt.core.gcc"/>
19
+				<language-scope id="org.eclipse.cdt.core.g++"/>
20
+			</provider>
21
+		</extension>
22
+	</configuration>
23
+</project>


Разлика између датотеке није приказан због своје велике величине
+ 11963 - 0
Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xg.h


+ 238 - 0
Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h

@@ -0,0 +1,238 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx.h
4
+  * @author  MCD Application Team
5
+  * @version V4.2.0
6
+  * @date    31-March-2017
7
+  * @brief   CMSIS STM32F1xx Device Peripheral Access Layer Header File. 
8
+  *
9
+  *          The file is the unique include file that the application programmer
10
+  *          is using in the C source code, usually in main.c. This file contains:
11
+  *            - Configuration section that allows to select:
12
+  *              - The STM32F1xx device used in the target application
13
+  *              - To use or not the peripheral’s drivers in application code(i.e. 
14
+  *                code will be based on direct access to peripheral’s registers 
15
+  *                rather than drivers API), this option is controlled by 
16
+  *                "#define USE_HAL_DRIVER"
17
+  *  
18
+  ******************************************************************************
19
+  * @attention
20
+  *
21
+  * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
22
+  *
23
+  * Redistribution and use in source and binary forms, with or without modification,
24
+  * are permitted provided that the following conditions are met:
25
+  *   1. Redistributions of source code must retain the above copyright notice,
26
+  *      this list of conditions and the following disclaimer.
27
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
28
+  *      this list of conditions and the following disclaimer in the documentation
29
+  *      and/or other materials provided with the distribution.
30
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
31
+  *      may be used to endorse or promote products derived from this software
32
+  *      without specific prior written permission.
33
+  *
34
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
35
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
38
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
40
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
41
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
42
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
43
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44
+  *
45
+  ******************************************************************************
46
+  */
47
+
48
+/** @addtogroup CMSIS
49
+  * @{
50
+  */
51
+
52
+/** @addtogroup stm32f1xx
53
+  * @{
54
+  */
55
+    
56
+#ifndef __STM32F1XX_H
57
+#define __STM32F1XX_H
58
+
59
+#ifdef __cplusplus
60
+ extern "C" {
61
+#endif /* __cplusplus */
62
+  
63
+/** @addtogroup Library_configuration_section
64
+  * @{
65
+  */
66
+
67
+/**
68
+  * @brief STM32 Family
69
+  */
70
+#if !defined (STM32F1)
71
+#define STM32F1
72
+#endif /* STM32F1 */
73
+
74
+/* Uncomment the line below according to the target STM32L device used in your 
75
+   application 
76
+  */
77
+
78
+#if !defined (STM32F100xB) && !defined (STM32F100xE) && !defined (STM32F101x6) && \
79
+    !defined (STM32F101xB) && !defined (STM32F101xE) && !defined (STM32F101xG) && !defined (STM32F102x6) && !defined (STM32F102xB) && !defined (STM32F103x6) && \
80
+    !defined (STM32F103xB) && !defined (STM32F103xE) && !defined (STM32F103xG) && !defined (STM32F105xC) && !defined (STM32F107xC)
81
+  /* #define STM32F100xB  */   /*!< STM32F100C4, STM32F100R4, STM32F100C6, STM32F100R6, STM32F100C8, STM32F100R8, STM32F100V8, STM32F100CB, STM32F100RB and STM32F100VB */
82
+  /* #define STM32F100xE */    /*!< STM32F100RC, STM32F100VC, STM32F100ZC, STM32F100RD, STM32F100VD, STM32F100ZD, STM32F100RE, STM32F100VE and STM32F100ZE */
83
+  /* #define STM32F101x6  */   /*!< STM32F101C4, STM32F101R4, STM32F101T4, STM32F101C6, STM32F101R6 and STM32F101T6 Devices */
84
+  /* #define STM32F101xB  */   /*!< STM32F101C8, STM32F101R8, STM32F101T8, STM32F101V8, STM32F101CB, STM32F101RB, STM32F101TB and STM32F101VB */
85
+  /* #define STM32F101xE */    /*!< STM32F101RC, STM32F101VC, STM32F101ZC, STM32F101RD, STM32F101VD, STM32F101ZD, STM32F101RE, STM32F101VE and STM32F101ZE */ 
86
+  /* #define STM32F101xG  */   /*!< STM32F101RF, STM32F101VF, STM32F101ZF, STM32F101RG, STM32F101VG and STM32F101ZG */
87
+  /* #define STM32F102x6 */    /*!< STM32F102C4, STM32F102R4, STM32F102C6 and STM32F102R6 */
88
+  /* #define STM32F102xB  */   /*!< STM32F102C8, STM32F102R8, STM32F102CB and STM32F102RB */
89
+  /* #define STM32F103x6  */   /*!< STM32F103C4, STM32F103R4, STM32F103T4, STM32F103C6, STM32F103R6 and STM32F103T6 */
90
+  /* #define STM32F103xB  */   /*!< STM32F103C8, STM32F103R8, STM32F103T8, STM32F103V8, STM32F103CB, STM32F103RB, STM32F103TB and STM32F103VB */
91
+  /* #define STM32F103xE */    /*!< STM32F103RC, STM32F103VC, STM32F103ZC, STM32F103RD, STM32F103VD, STM32F103ZD, STM32F103RE, STM32F103VE and STM32F103ZE */
92
+  /* #define STM32F103xG  */   /*!< STM32F103RF, STM32F103VF, STM32F103ZF, STM32F103RG, STM32F103VG and STM32F103ZG */
93
+  /* #define STM32F105xC */    /*!< STM32F105R8, STM32F105V8, STM32F105RB, STM32F105VB, STM32F105RC and STM32F105VC */
94
+  /* #define STM32F107xC  */   /*!< STM32F107RB, STM32F107VB, STM32F107RC and STM32F107VC */  
95
+#endif
96
+
97
+/*  Tip: To avoid modifying this file each time you need to switch between these
98
+        devices, you can define the device in your toolchain compiler preprocessor.
99
+  */
100
+  
101
+#if !defined  (USE_HAL_DRIVER)
102
+/**
103
+ * @brief Comment the line below if you will not use the peripherals drivers.
104
+   In this case, these drivers will not be included and the application code will 
105
+   be based on direct access to peripherals registers 
106
+   */
107
+  /*#define USE_HAL_DRIVER */
108
+#endif /* USE_HAL_DRIVER */
109
+
110
+/**
111
+  * @brief CMSIS Device version number V4.2.0
112
+  */
113
+#define __STM32F1_CMSIS_VERSION_MAIN   (0x04) /*!< [31:24] main version */
114
+#define __STM32F1_CMSIS_VERSION_SUB1   (0x02) /*!< [23:16] sub1 version */
115
+#define __STM32F1_CMSIS_VERSION_SUB2   (0x00) /*!< [15:8]  sub2 version */
116
+#define __STM32F1_CMSIS_VERSION_RC     (0x00) /*!< [7:0]  release candidate */ 
117
+#define __STM32F1_CMSIS_VERSION        ((__STM32F1_CMSIS_VERSION_MAIN << 24)\
118
+                                       |(__STM32F1_CMSIS_VERSION_SUB1 << 16)\
119
+                                       |(__STM32F1_CMSIS_VERSION_SUB2 << 8 )\
120
+                                       |(__STM32F1_CMSIS_VERSION_RC))
121
+
122
+/**
123
+  * @}
124
+  */
125
+
126
+/** @addtogroup Device_Included
127
+  * @{
128
+  */
129
+
130
+#if defined(STM32F100xB)
131
+  #include "stm32f100xb.h"
132
+#elif defined(STM32F100xE)
133
+  #include "stm32f100xe.h"
134
+#elif defined(STM32F101x6)
135
+  #include "stm32f101x6.h"
136
+#elif defined(STM32F101xB)
137
+  #include "stm32f101xb.h"
138
+#elif defined(STM32F101xE)
139
+  #include "stm32f101xe.h"
140
+#elif defined(STM32F101xG)
141
+  #include "stm32f101xg.h"
142
+#elif defined(STM32F102x6)
143
+  #include "stm32f102x6.h"
144
+#elif defined(STM32F102xB)
145
+  #include "stm32f102xb.h"
146
+#elif defined(STM32F103x6)
147
+  #include "stm32f103x6.h"
148
+#elif defined(STM32F103xB)
149
+  #include "stm32f103xb.h"
150
+#elif defined(STM32F103xE)
151
+  #include "stm32f103xe.h"
152
+#elif defined(STM32F103xG)
153
+  #include "stm32f103xg.h"
154
+#elif defined(STM32F105xC)
155
+  #include "stm32f105xc.h"
156
+#elif defined(STM32F107xC)
157
+  #include "stm32f107xc.h"
158
+#else
159
+ #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)"
160
+#endif
161
+
162
+/**
163
+  * @}
164
+  */
165
+
166
+/** @addtogroup Exported_types
167
+  * @{
168
+  */  
169
+typedef enum 
170
+{
171
+  RESET = 0, 
172
+  SET = !RESET
173
+} FlagStatus, ITStatus;
174
+
175
+typedef enum 
176
+{
177
+  DISABLE = 0, 
178
+  ENABLE = !DISABLE
179
+} FunctionalState;
180
+#define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE))
181
+
182
+typedef enum 
183
+{
184
+  ERROR = 0, 
185
+  SUCCESS = !ERROR
186
+} ErrorStatus;
187
+
188
+/**
189
+  * @}
190
+  */
191
+
192
+
193
+/** @addtogroup Exported_macros
194
+  * @{
195
+  */
196
+#define SET_BIT(REG, BIT)     ((REG) |= (BIT))
197
+
198
+#define CLEAR_BIT(REG, BIT)   ((REG) &= ~(BIT))
199
+
200
+#define READ_BIT(REG, BIT)    ((REG) & (BIT))
201
+
202
+#define CLEAR_REG(REG)        ((REG) = (0x0))
203
+
204
+#define WRITE_REG(REG, VAL)   ((REG) = (VAL))
205
+
206
+#define READ_REG(REG)         ((REG))
207
+
208
+#define MODIFY_REG(REG, CLEARMASK, SETMASK)  WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))
209
+
210
+#define POSITION_VAL(VAL)     (__CLZ(__RBIT(VAL))) 
211
+
212
+
213
+/**
214
+  * @}
215
+  */
216
+
217
+#if defined (USE_HAL_DRIVER)
218
+ #include "stm32f1xx_hal.h"
219
+#endif /* USE_HAL_DRIVER */
220
+
221
+
222
+#ifdef __cplusplus
223
+}
224
+#endif /* __cplusplus */
225
+
226
+#endif /* __STM32F1xx_H */
227
+/**
228
+  * @}
229
+  */
230
+
231
+/**
232
+  * @}
233
+  */
234
+  
235
+
236
+
237
+
238
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 116 - 0
Drivers/CMSIS/Device/ST/STM32F1xx/Include/system_stm32f1xx.h

@@ -0,0 +1,116 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    system_stm32f10x.h
4
+  * @author  MCD Application Team
5
+  * @version V4.2.0
6
+  * @date    31-March-2017
7
+  * @brief   CMSIS Cortex-M3 Device Peripheral Access Layer System Header File.
8
+  ******************************************************************************
9
+  * @attention
10
+  *
11
+  * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
12
+  *
13
+  * Redistribution and use in source and binary forms, with or without modification,
14
+  * are permitted provided that the following conditions are met:
15
+  *   1. Redistributions of source code must retain the above copyright notice,
16
+  *      this list of conditions and the following disclaimer.
17
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
18
+  *      this list of conditions and the following disclaimer in the documentation
19
+  *      and/or other materials provided with the distribution.
20
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
21
+  *      may be used to endorse or promote products derived from this software
22
+  *      without specific prior written permission.
23
+  *
24
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+  *
35
+  ******************************************************************************
36
+  */
37
+
38
+/** @addtogroup CMSIS
39
+  * @{
40
+  */
41
+
42
+/** @addtogroup stm32f10x_system
43
+  * @{
44
+  */  
45
+  
46
+/**
47
+  * @brief Define to prevent recursive inclusion
48
+  */
49
+#ifndef __SYSTEM_STM32F10X_H
50
+#define __SYSTEM_STM32F10X_H
51
+
52
+#ifdef __cplusplus
53
+ extern "C" {
54
+#endif 
55
+
56
+/** @addtogroup STM32F10x_System_Includes
57
+  * @{
58
+  */
59
+
60
+/**
61
+  * @}
62
+  */
63
+
64
+
65
+/** @addtogroup STM32F10x_System_Exported_types
66
+  * @{
67
+  */
68
+
69
+extern uint32_t SystemCoreClock;          /*!< System Clock Frequency (Core Clock) */
70
+extern const uint8_t  AHBPrescTable[16U];  /*!< AHB prescalers table values */
71
+extern const uint8_t  APBPrescTable[8U];   /*!< APB prescalers table values */
72
+
73
+/**
74
+  * @}
75
+  */
76
+
77
+/** @addtogroup STM32F10x_System_Exported_Constants
78
+  * @{
79
+  */
80
+
81
+/**
82
+  * @}
83
+  */
84
+
85
+/** @addtogroup STM32F10x_System_Exported_Macros
86
+  * @{
87
+  */
88
+
89
+/**
90
+  * @}
91
+  */
92
+
93
+/** @addtogroup STM32F10x_System_Exported_Functions
94
+  * @{
95
+  */
96
+  
97
+extern void SystemInit(void);
98
+extern void SystemCoreClockUpdate(void);
99
+/**
100
+  * @}
101
+  */
102
+
103
+#ifdef __cplusplus
104
+}
105
+#endif
106
+
107
+#endif /*__SYSTEM_STM32F10X_H */
108
+
109
+/**
110
+  * @}
111
+  */
112
+  
113
+/**
114
+  * @}
115
+  */  
116
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 136 - 0
Drivers/CMSIS/Include/arm_common_tables.h

@@ -0,0 +1,136 @@
1
+/* ----------------------------------------------------------------------
2
+* Copyright (C) 2010-2014 ARM Limited. All rights reserved.
3
+*
4
+* $Date:        19. October 2015
5
+* $Revision: 	V.1.4.5 a
6
+*
7
+* Project: 	    CMSIS DSP Library
8
+* Title:	    arm_common_tables.h
9
+*
10
+* Description:	This file has extern declaration for common tables like Bitreverse, reciprocal etc which are used across different functions
11
+*
12
+* Target Processor: Cortex-M4/Cortex-M3
13
+*
14
+* Redistribution and use in source and binary forms, with or without
15
+* modification, are permitted provided that the following conditions
16
+* are met:
17
+*   - Redistributions of source code must retain the above copyright
18
+*     notice, this list of conditions and the following disclaimer.
19
+*   - Redistributions in binary form must reproduce the above copyright
20
+*     notice, this list of conditions and the following disclaimer in
21
+*     the documentation and/or other materials provided with the
22
+*     distribution.
23
+*   - Neither the name of ARM LIMITED nor the names of its contributors
24
+*     may be used to endorse or promote products derived from this
25
+*     software without specific prior written permission.
26
+*
27
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38
+* POSSIBILITY OF SUCH DAMAGE.
39
+* -------------------------------------------------------------------- */
40
+
41
+#ifndef _ARM_COMMON_TABLES_H
42
+#define _ARM_COMMON_TABLES_H
43
+
44
+#include "arm_math.h"
45
+
46
+extern const uint16_t armBitRevTable[1024];
47
+extern const q15_t armRecipTableQ15[64];
48
+extern const q31_t armRecipTableQ31[64];
49
+/* extern const q31_t realCoefAQ31[1024]; */
50
+/* extern const q31_t realCoefBQ31[1024]; */
51
+extern const float32_t twiddleCoef_16[32];
52
+extern const float32_t twiddleCoef_32[64];
53
+extern const float32_t twiddleCoef_64[128];
54
+extern const float32_t twiddleCoef_128[256];
55
+extern const float32_t twiddleCoef_256[512];
56
+extern const float32_t twiddleCoef_512[1024];
57
+extern const float32_t twiddleCoef_1024[2048];
58
+extern const float32_t twiddleCoef_2048[4096];
59
+extern const float32_t twiddleCoef_4096[8192];
60
+#define twiddleCoef twiddleCoef_4096
61
+extern const q31_t twiddleCoef_16_q31[24];
62
+extern const q31_t twiddleCoef_32_q31[48];
63
+extern const q31_t twiddleCoef_64_q31[96];
64
+extern const q31_t twiddleCoef_128_q31[192];
65
+extern const q31_t twiddleCoef_256_q31[384];
66
+extern const q31_t twiddleCoef_512_q31[768];
67
+extern const q31_t twiddleCoef_1024_q31[1536];
68
+extern const q31_t twiddleCoef_2048_q31[3072];
69
+extern const q31_t twiddleCoef_4096_q31[6144];
70
+extern const q15_t twiddleCoef_16_q15[24];
71
+extern const q15_t twiddleCoef_32_q15[48];
72
+extern const q15_t twiddleCoef_64_q15[96];
73
+extern const q15_t twiddleCoef_128_q15[192];
74
+extern const q15_t twiddleCoef_256_q15[384];
75
+extern const q15_t twiddleCoef_512_q15[768];
76
+extern const q15_t twiddleCoef_1024_q15[1536];
77
+extern const q15_t twiddleCoef_2048_q15[3072];
78
+extern const q15_t twiddleCoef_4096_q15[6144];
79
+extern const float32_t twiddleCoef_rfft_32[32];
80
+extern const float32_t twiddleCoef_rfft_64[64];
81
+extern const float32_t twiddleCoef_rfft_128[128];
82
+extern const float32_t twiddleCoef_rfft_256[256];
83
+extern const float32_t twiddleCoef_rfft_512[512];
84
+extern const float32_t twiddleCoef_rfft_1024[1024];
85
+extern const float32_t twiddleCoef_rfft_2048[2048];
86
+extern const float32_t twiddleCoef_rfft_4096[4096];
87
+
88
+
89
+/* floating-point bit reversal tables */
90
+#define ARMBITREVINDEXTABLE__16_TABLE_LENGTH ((uint16_t)20  )
91
+#define ARMBITREVINDEXTABLE__32_TABLE_LENGTH ((uint16_t)48  )
92
+#define ARMBITREVINDEXTABLE__64_TABLE_LENGTH ((uint16_t)56  )
93
+#define ARMBITREVINDEXTABLE_128_TABLE_LENGTH ((uint16_t)208 )
94
+#define ARMBITREVINDEXTABLE_256_TABLE_LENGTH ((uint16_t)440 )
95
+#define ARMBITREVINDEXTABLE_512_TABLE_LENGTH ((uint16_t)448 )
96
+#define ARMBITREVINDEXTABLE1024_TABLE_LENGTH ((uint16_t)1800)
97
+#define ARMBITREVINDEXTABLE2048_TABLE_LENGTH ((uint16_t)3808)
98
+#define ARMBITREVINDEXTABLE4096_TABLE_LENGTH ((uint16_t)4032)
99
+
100
+extern const uint16_t armBitRevIndexTable16[ARMBITREVINDEXTABLE__16_TABLE_LENGTH];
101
+extern const uint16_t armBitRevIndexTable32[ARMBITREVINDEXTABLE__32_TABLE_LENGTH];
102
+extern const uint16_t armBitRevIndexTable64[ARMBITREVINDEXTABLE__64_TABLE_LENGTH];
103
+extern const uint16_t armBitRevIndexTable128[ARMBITREVINDEXTABLE_128_TABLE_LENGTH];
104
+extern const uint16_t armBitRevIndexTable256[ARMBITREVINDEXTABLE_256_TABLE_LENGTH];
105
+extern const uint16_t armBitRevIndexTable512[ARMBITREVINDEXTABLE_512_TABLE_LENGTH];
106
+extern const uint16_t armBitRevIndexTable1024[ARMBITREVINDEXTABLE1024_TABLE_LENGTH];
107
+extern const uint16_t armBitRevIndexTable2048[ARMBITREVINDEXTABLE2048_TABLE_LENGTH];
108
+extern const uint16_t armBitRevIndexTable4096[ARMBITREVINDEXTABLE4096_TABLE_LENGTH];
109
+
110
+/* fixed-point bit reversal tables */
111
+#define ARMBITREVINDEXTABLE_FIXED___16_TABLE_LENGTH ((uint16_t)12  )
112
+#define ARMBITREVINDEXTABLE_FIXED___32_TABLE_LENGTH ((uint16_t)24  )
113
+#define ARMBITREVINDEXTABLE_FIXED___64_TABLE_LENGTH ((uint16_t)56  )
114
+#define ARMBITREVINDEXTABLE_FIXED__128_TABLE_LENGTH ((uint16_t)112 )
115
+#define ARMBITREVINDEXTABLE_FIXED__256_TABLE_LENGTH ((uint16_t)240 )
116
+#define ARMBITREVINDEXTABLE_FIXED__512_TABLE_LENGTH ((uint16_t)480 )
117
+#define ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH ((uint16_t)992 )
118
+#define ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH ((uint16_t)1984)
119
+#define ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH ((uint16_t)4032)
120
+
121
+extern const uint16_t armBitRevIndexTable_fixed_16[ARMBITREVINDEXTABLE_FIXED___16_TABLE_LENGTH];
122
+extern const uint16_t armBitRevIndexTable_fixed_32[ARMBITREVINDEXTABLE_FIXED___32_TABLE_LENGTH];
123
+extern const uint16_t armBitRevIndexTable_fixed_64[ARMBITREVINDEXTABLE_FIXED___64_TABLE_LENGTH];
124
+extern const uint16_t armBitRevIndexTable_fixed_128[ARMBITREVINDEXTABLE_FIXED__128_TABLE_LENGTH];
125
+extern const uint16_t armBitRevIndexTable_fixed_256[ARMBITREVINDEXTABLE_FIXED__256_TABLE_LENGTH];
126
+extern const uint16_t armBitRevIndexTable_fixed_512[ARMBITREVINDEXTABLE_FIXED__512_TABLE_LENGTH];
127
+extern const uint16_t armBitRevIndexTable_fixed_1024[ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH];
128
+extern const uint16_t armBitRevIndexTable_fixed_2048[ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH];
129
+extern const uint16_t armBitRevIndexTable_fixed_4096[ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH];
130
+
131
+/* Tables for Fast Math Sine and Cosine */
132
+extern const float32_t sinTable_f32[FAST_MATH_TABLE_SIZE + 1];
133
+extern const q31_t sinTable_q31[FAST_MATH_TABLE_SIZE + 1];
134
+extern const q15_t sinTable_q15[FAST_MATH_TABLE_SIZE + 1];
135
+
136
+#endif /*  ARM_COMMON_TABLES_H */

+ 79 - 0
Drivers/CMSIS/Include/arm_const_structs.h

@@ -0,0 +1,79 @@
1
+/* ----------------------------------------------------------------------
2
+* Copyright (C) 2010-2014 ARM Limited. All rights reserved.
3
+*
4
+* $Date:        19. March 2015
5
+* $Revision: 	V.1.4.5
6
+*
7
+* Project: 	    CMSIS DSP Library
8
+* Title:	    arm_const_structs.h
9
+*
10
+* Description:	This file has constant structs that are initialized for
11
+*              user convenience.  For example, some can be given as
12
+*              arguments to the arm_cfft_f32() function.
13
+*
14
+* Target Processor: Cortex-M4/Cortex-M3
15
+*
16
+* Redistribution and use in source and binary forms, with or without
17
+* modification, are permitted provided that the following conditions
18
+* are met:
19
+*   - Redistributions of source code must retain the above copyright
20
+*     notice, this list of conditions and the following disclaimer.
21
+*   - Redistributions in binary form must reproduce the above copyright
22
+*     notice, this list of conditions and the following disclaimer in
23
+*     the documentation and/or other materials provided with the
24
+*     distribution.
25
+*   - Neither the name of ARM LIMITED nor the names of its contributors
26
+*     may be used to endorse or promote products derived from this
27
+*     software without specific prior written permission.
28
+*
29
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
32
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
33
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
34
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
35
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
37
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
39
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40
+* POSSIBILITY OF SUCH DAMAGE.
41
+* -------------------------------------------------------------------- */
42
+
43
+#ifndef _ARM_CONST_STRUCTS_H
44
+#define _ARM_CONST_STRUCTS_H
45
+
46
+#include "arm_math.h"
47
+#include "arm_common_tables.h"
48
+
49
+   extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len16;
50
+   extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len32;
51
+   extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len64;
52
+   extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len128;
53
+   extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len256;
54
+   extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len512;
55
+   extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len1024;
56
+   extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len2048;
57
+   extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len4096;
58
+
59
+   extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len16;
60
+   extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len32;
61
+   extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len64;
62
+   extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len128;
63
+   extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len256;
64
+   extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len512;
65
+   extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len1024;
66
+   extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len2048;
67
+   extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len4096;
68
+
69
+   extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len16;
70
+   extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len32;
71
+   extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len64;
72
+   extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len128;
73
+   extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len256;
74
+   extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len512;
75
+   extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len1024;
76
+   extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len2048;
77
+   extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len4096;
78
+
79
+#endif

Разлика између датотеке није приказан због своје велике величине
+ 7154 - 0
Drivers/CMSIS/Include/arm_math.h


+ 734 - 0
Drivers/CMSIS/Include/cmsis_armcc.h

@@ -0,0 +1,734 @@
1
+/**************************************************************************//**
2
+ * @file     cmsis_armcc.h
3
+ * @brief    CMSIS Cortex-M Core Function/Instruction Header File
4
+ * @version  V4.30
5
+ * @date     20. October 2015
6
+ ******************************************************************************/
7
+/* Copyright (c) 2009 - 2015 ARM LIMITED
8
+
9
+   All rights reserved.
10
+   Redistribution and use in source and binary forms, with or without
11
+   modification, are permitted provided that the following conditions are met:
12
+   - Redistributions of source code must retain the above copyright
13
+     notice, this list of conditions and the following disclaimer.
14
+   - Redistributions in binary form must reproduce the above copyright
15
+     notice, this list of conditions and the following disclaimer in the
16
+     documentation and/or other materials provided with the distribution.
17
+   - Neither the name of ARM nor the names of its contributors may be used
18
+     to endorse or promote products derived from this software without
19
+     specific prior written permission.
20
+   *
21
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
+   ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
25
+   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26
+   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
+   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
+   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
+   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
+   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
+   POSSIBILITY OF SUCH DAMAGE.
32
+   ---------------------------------------------------------------------------*/
33
+
34
+
35
+#ifndef __CMSIS_ARMCC_H
36
+#define __CMSIS_ARMCC_H
37
+
38
+
39
+#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 400677)
40
+  #error "Please use ARM Compiler Toolchain V4.0.677 or later!"
41
+#endif
42
+
43
+/* ###########################  Core Function Access  ########################### */
44
+/** \ingroup  CMSIS_Core_FunctionInterface
45
+    \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
46
+  @{
47
+ */
48
+
49
+/* intrinsic void __enable_irq();     */
50
+/* intrinsic void __disable_irq();    */
51
+
52
+/**
53
+  \brief   Get Control Register
54
+  \details Returns the content of the Control Register.
55
+  \return               Control Register value
56
+ */
57
+__STATIC_INLINE uint32_t __get_CONTROL(void)
58
+{
59
+  register uint32_t __regControl         __ASM("control");
60
+  return(__regControl);
61
+}
62
+
63
+
64
+/**
65
+  \brief   Set Control Register
66
+  \details Writes the given value to the Control Register.
67
+  \param [in]    control  Control Register value to set
68
+ */
69
+__STATIC_INLINE void __set_CONTROL(uint32_t control)
70
+{
71
+  register uint32_t __regControl         __ASM("control");
72
+  __regControl = control;
73
+}
74
+
75
+
76
+/**
77
+  \brief   Get IPSR Register
78
+  \details Returns the content of the IPSR Register.
79
+  \return               IPSR Register value
80
+ */
81
+__STATIC_INLINE uint32_t __get_IPSR(void)
82
+{
83
+  register uint32_t __regIPSR          __ASM("ipsr");
84
+  return(__regIPSR);
85
+}
86
+
87
+
88
+/**
89
+  \brief   Get APSR Register
90
+  \details Returns the content of the APSR Register.
91
+  \return               APSR Register value
92
+ */
93
+__STATIC_INLINE uint32_t __get_APSR(void)
94
+{
95
+  register uint32_t __regAPSR          __ASM("apsr");
96
+  return(__regAPSR);
97
+}
98
+
99
+
100
+/**
101
+  \brief   Get xPSR Register
102
+  \details Returns the content of the xPSR Register.
103
+  \return               xPSR Register value
104
+ */
105
+__STATIC_INLINE uint32_t __get_xPSR(void)
106
+{
107
+  register uint32_t __regXPSR          __ASM("xpsr");
108
+  return(__regXPSR);
109
+}
110
+
111
+
112
+/**
113
+  \brief   Get Process Stack Pointer
114
+  \details Returns the current value of the Process Stack Pointer (PSP).
115
+  \return               PSP Register value
116
+ */
117
+__STATIC_INLINE uint32_t __get_PSP(void)
118
+{
119
+  register uint32_t __regProcessStackPointer  __ASM("psp");
120
+  return(__regProcessStackPointer);
121
+}
122
+
123
+
124
+/**
125
+  \brief   Set Process Stack Pointer
126
+  \details Assigns the given value to the Process Stack Pointer (PSP).
127
+  \param [in]    topOfProcStack  Process Stack Pointer value to set
128
+ */
129
+__STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
130
+{
131
+  register uint32_t __regProcessStackPointer  __ASM("psp");
132
+  __regProcessStackPointer = topOfProcStack;
133
+}
134
+
135
+
136
+/**
137
+  \brief   Get Main Stack Pointer
138
+  \details Returns the current value of the Main Stack Pointer (MSP).
139
+  \return               MSP Register value
140
+ */
141
+__STATIC_INLINE uint32_t __get_MSP(void)
142
+{
143
+  register uint32_t __regMainStackPointer     __ASM("msp");
144
+  return(__regMainStackPointer);
145
+}
146
+
147
+
148
+/**
149
+  \brief   Set Main Stack Pointer
150
+  \details Assigns the given value to the Main Stack Pointer (MSP).
151
+  \param [in]    topOfMainStack  Main Stack Pointer value to set
152
+ */
153
+__STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
154
+{
155
+  register uint32_t __regMainStackPointer     __ASM("msp");
156
+  __regMainStackPointer = topOfMainStack;
157
+}
158
+
159
+
160
+/**
161
+  \brief   Get Priority Mask
162
+  \details Returns the current state of the priority mask bit from the Priority Mask Register.
163
+  \return               Priority Mask value
164
+ */
165
+__STATIC_INLINE uint32_t __get_PRIMASK(void)
166
+{
167
+  register uint32_t __regPriMask         __ASM("primask");
168
+  return(__regPriMask);
169
+}
170
+
171
+
172
+/**
173
+  \brief   Set Priority Mask
174
+  \details Assigns the given value to the Priority Mask Register.
175
+  \param [in]    priMask  Priority Mask
176
+ */
177
+__STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
178
+{
179
+  register uint32_t __regPriMask         __ASM("primask");
180
+  __regPriMask = (priMask);
181
+}
182
+
183
+
184
+#if       (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U)
185
+
186
+/**
187
+  \brief   Enable FIQ
188
+  \details Enables FIQ interrupts by clearing the F-bit in the CPSR.
189
+           Can only be executed in Privileged modes.
190
+ */
191
+#define __enable_fault_irq                __enable_fiq
192
+
193
+
194
+/**
195
+  \brief   Disable FIQ
196
+  \details Disables FIQ interrupts by setting the F-bit in the CPSR.
197
+           Can only be executed in Privileged modes.
198
+ */
199
+#define __disable_fault_irq               __disable_fiq
200
+
201
+
202
+/**
203
+  \brief   Get Base Priority
204
+  \details Returns the current value of the Base Priority register.
205
+  \return               Base Priority register value
206
+ */
207
+__STATIC_INLINE uint32_t  __get_BASEPRI(void)
208
+{
209
+  register uint32_t __regBasePri         __ASM("basepri");
210
+  return(__regBasePri);
211
+}
212
+
213
+
214
+/**
215
+  \brief   Set Base Priority
216
+  \details Assigns the given value to the Base Priority register.
217
+  \param [in]    basePri  Base Priority value to set
218
+ */
219
+__STATIC_INLINE void __set_BASEPRI(uint32_t basePri)
220
+{
221
+  register uint32_t __regBasePri         __ASM("basepri");
222
+  __regBasePri = (basePri & 0xFFU);
223
+}
224
+
225
+
226
+/**
227
+  \brief   Set Base Priority with condition
228
+  \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
229
+           or the new value increases the BASEPRI priority level.
230
+  \param [in]    basePri  Base Priority value to set
231
+ */
232
+__STATIC_INLINE void __set_BASEPRI_MAX(uint32_t basePri)
233
+{
234
+  register uint32_t __regBasePriMax      __ASM("basepri_max");
235
+  __regBasePriMax = (basePri & 0xFFU);
236
+}
237
+
238
+
239
+/**
240
+  \brief   Get Fault Mask
241
+  \details Returns the current value of the Fault Mask register.
242
+  \return               Fault Mask register value
243
+ */
244
+__STATIC_INLINE uint32_t __get_FAULTMASK(void)
245
+{
246
+  register uint32_t __regFaultMask       __ASM("faultmask");
247
+  return(__regFaultMask);
248
+}
249
+
250
+
251
+/**
252
+  \brief   Set Fault Mask
253
+  \details Assigns the given value to the Fault Mask register.
254
+  \param [in]    faultMask  Fault Mask value to set
255
+ */
256
+__STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
257
+{
258
+  register uint32_t __regFaultMask       __ASM("faultmask");
259
+  __regFaultMask = (faultMask & (uint32_t)1);
260
+}
261
+
262
+#endif /* (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U) */
263
+
264
+
265
+#if       (__CORTEX_M == 0x04U) || (__CORTEX_M == 0x07U)
266
+
267
+/**
268
+  \brief   Get FPSCR
269
+  \details Returns the current value of the Floating Point Status/Control register.
270
+  \return               Floating Point Status/Control register value
271
+ */
272
+__STATIC_INLINE uint32_t __get_FPSCR(void)
273
+{
274
+#if (__FPU_PRESENT == 1U) && (__FPU_USED == 1U)
275
+  register uint32_t __regfpscr         __ASM("fpscr");
276
+  return(__regfpscr);
277
+#else
278
+   return(0U);
279
+#endif
280
+}
281
+
282
+
283
+/**
284
+  \brief   Set FPSCR
285
+  \details Assigns the given value to the Floating Point Status/Control register.
286
+  \param [in]    fpscr  Floating Point Status/Control value to set
287
+ */
288
+__STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
289
+{
290
+#if (__FPU_PRESENT == 1U) && (__FPU_USED == 1U)
291
+  register uint32_t __regfpscr         __ASM("fpscr");
292
+  __regfpscr = (fpscr);
293
+#endif
294
+}
295
+
296
+#endif /* (__CORTEX_M == 0x04U) || (__CORTEX_M == 0x07U) */
297
+
298
+
299
+
300
+/*@} end of CMSIS_Core_RegAccFunctions */
301
+
302
+
303
+/* ##########################  Core Instruction Access  ######################### */
304
+/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
305
+  Access to dedicated instructions
306
+  @{
307
+*/
308
+
309
+/**
310
+  \brief   No Operation
311
+  \details No Operation does nothing. This instruction can be used for code alignment purposes.
312
+ */
313
+#define __NOP                             __nop
314
+
315
+
316
+/**
317
+  \brief   Wait For Interrupt
318
+  \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
319
+ */
320
+#define __WFI                             __wfi
321
+
322
+
323
+/**
324
+  \brief   Wait For Event
325
+  \details Wait For Event is a hint instruction that permits the processor to enter
326
+           a low-power state until one of a number of events occurs.
327
+ */
328
+#define __WFE                             __wfe
329
+
330
+
331
+/**
332
+  \brief   Send Event
333
+  \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
334
+ */
335
+#define __SEV                             __sev
336
+
337
+
338
+/**
339
+  \brief   Instruction Synchronization Barrier
340
+  \details Instruction Synchronization Barrier flushes the pipeline in the processor,
341
+           so that all instructions following the ISB are fetched from cache or memory,
342
+           after the instruction has been completed.
343
+ */
344
+#define __ISB() do {\
345
+                   __schedule_barrier();\
346
+                   __isb(0xF);\
347
+                   __schedule_barrier();\
348
+                } while (0U)
349
+
350
+/**
351
+  \brief   Data Synchronization Barrier
352
+  \details Acts as a special kind of Data Memory Barrier.
353
+           It completes when all explicit memory accesses before this instruction complete.
354
+ */
355
+#define __DSB() do {\
356
+                   __schedule_barrier();\
357
+                   __dsb(0xF);\
358
+                   __schedule_barrier();\
359
+                } while (0U)
360
+
361
+/**
362
+  \brief   Data Memory Barrier
363
+  \details Ensures the apparent order of the explicit memory operations before
364
+           and after the instruction, without ensuring their completion.
365
+ */
366
+#define __DMB() do {\
367
+                   __schedule_barrier();\
368
+                   __dmb(0xF);\
369
+                   __schedule_barrier();\
370
+                } while (0U)
371
+
372
+/**
373
+  \brief   Reverse byte order (32 bit)
374
+  \details Reverses the byte order in integer value.
375
+  \param [in]    value  Value to reverse
376
+  \return               Reversed value
377
+ */
378
+#define __REV                             __rev
379
+
380
+
381
+/**
382
+  \brief   Reverse byte order (16 bit)
383
+  \details Reverses the byte order in two unsigned short values.
384
+  \param [in]    value  Value to reverse
385
+  \return               Reversed value
386
+ */
387
+#ifndef __NO_EMBEDDED_ASM
388
+__attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value)
389
+{
390
+  rev16 r0, r0
391
+  bx lr
392
+}
393
+#endif
394
+
395
+/**
396
+  \brief   Reverse byte order in signed short value
397
+  \details Reverses the byte order in a signed short value with sign extension to integer.
398
+  \param [in]    value  Value to reverse
399
+  \return               Reversed value
400
+ */
401
+#ifndef __NO_EMBEDDED_ASM
402
+__attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int32_t __REVSH(int32_t value)
403
+{
404
+  revsh r0, r0
405
+  bx lr
406
+}
407
+#endif
408
+
409
+
410
+/**
411
+  \brief   Rotate Right in unsigned value (32 bit)
412
+  \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
413
+  \param [in]    value  Value to rotate
414
+  \param [in]    value  Number of Bits to rotate
415
+  \return               Rotated value
416
+ */
417
+#define __ROR                             __ror
418
+
419
+
420
+/**
421
+  \brief   Breakpoint
422
+  \details Causes the processor to enter Debug state.
423
+           Debug tools can use this to investigate system state when the instruction at a particular address is reached.
424
+  \param [in]    value  is ignored by the processor.
425
+                 If required, a debugger can use it to store additional information about the breakpoint.
426
+ */
427
+#define __BKPT(value)                       __breakpoint(value)
428
+
429
+
430
+/**
431
+  \brief   Reverse bit order of value
432
+  \details Reverses the bit order of the given value.
433
+  \param [in]    value  Value to reverse
434
+  \return               Reversed value
435
+ */
436
+#if       (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U)
437
+  #define __RBIT                          __rbit
438
+#else
439
+__attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
440
+{
441
+  uint32_t result;
442
+  int32_t s = 4 /*sizeof(v)*/ * 8 - 1; /* extra shift needed at end */
443
+
444
+  result = value;                      /* r will be reversed bits of v; first get LSB of v */
445
+  for (value >>= 1U; value; value >>= 1U)
446
+  {
447
+    result <<= 1U;
448
+    result |= value & 1U;
449
+    s--;
450
+  }
451
+  result <<= s;                        /* shift when v's highest bits are zero */
452
+  return(result);
453
+}
454
+#endif
455
+
456
+
457
+/**
458
+  \brief   Count leading zeros
459
+  \details Counts the number of leading zeros of a data value.
460
+  \param [in]  value  Value to count the leading zeros
461
+  \return             number of leading zeros in value
462
+ */
463
+#define __CLZ                             __clz
464
+
465
+
466
+#if       (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U)
467
+
468
+/**
469
+  \brief   LDR Exclusive (8 bit)
470
+  \details Executes a exclusive LDR instruction for 8 bit value.
471
+  \param [in]    ptr  Pointer to data
472
+  \return             value of type uint8_t at (*ptr)
473
+ */
474
+#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
475
+  #define __LDREXB(ptr)                                                        ((uint8_t ) __ldrex(ptr))
476
+#else
477
+  #define __LDREXB(ptr)          _Pragma("push") _Pragma("diag_suppress 3731") ((uint8_t ) __ldrex(ptr))  _Pragma("pop")
478
+#endif
479
+
480
+
481
+/**
482
+  \brief   LDR Exclusive (16 bit)
483
+  \details Executes a exclusive LDR instruction for 16 bit values.
484
+  \param [in]    ptr  Pointer to data
485
+  \return        value of type uint16_t at (*ptr)
486
+ */
487
+#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
488
+  #define __LDREXH(ptr)                                                        ((uint16_t) __ldrex(ptr))
489
+#else
490
+  #define __LDREXH(ptr)          _Pragma("push") _Pragma("diag_suppress 3731") ((uint16_t) __ldrex(ptr))  _Pragma("pop")
491
+#endif
492
+
493
+
494
+/**
495
+  \brief   LDR Exclusive (32 bit)
496
+  \details Executes a exclusive LDR instruction for 32 bit values.
497
+  \param [in]    ptr  Pointer to data
498
+  \return        value of type uint32_t at (*ptr)
499
+ */
500
+#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
501
+  #define __LDREXW(ptr)                                                        ((uint32_t ) __ldrex(ptr))
502
+#else
503
+  #define __LDREXW(ptr)          _Pragma("push") _Pragma("diag_suppress 3731") ((uint32_t ) __ldrex(ptr))  _Pragma("pop")
504
+#endif
505
+
506
+
507
+/**
508
+  \brief   STR Exclusive (8 bit)
509
+  \details Executes a exclusive STR instruction for 8 bit values.
510
+  \param [in]  value  Value to store
511
+  \param [in]    ptr  Pointer to location
512
+  \return          0  Function succeeded
513
+  \return          1  Function failed
514
+ */
515
+#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
516
+  #define __STREXB(value, ptr)                                                 __strex(value, ptr)
517
+#else
518
+  #define __STREXB(value, ptr)   _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr)        _Pragma("pop")
519
+#endif
520
+
521
+
522
+/**
523
+  \brief   STR Exclusive (16 bit)
524
+  \details Executes a exclusive STR instruction for 16 bit values.
525
+  \param [in]  value  Value to store
526
+  \param [in]    ptr  Pointer to location
527
+  \return          0  Function succeeded
528
+  \return          1  Function failed
529
+ */
530
+#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
531
+  #define __STREXH(value, ptr)                                                 __strex(value, ptr)
532
+#else
533
+  #define __STREXH(value, ptr)   _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr)        _Pragma("pop")
534
+#endif
535
+
536
+
537
+/**
538
+  \brief   STR Exclusive (32 bit)
539
+  \details Executes a exclusive STR instruction for 32 bit values.
540
+  \param [in]  value  Value to store
541
+  \param [in]    ptr  Pointer to location
542
+  \return          0  Function succeeded
543
+  \return          1  Function failed
544
+ */
545
+#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
546
+  #define __STREXW(value, ptr)                                                 __strex(value, ptr)
547
+#else
548
+  #define __STREXW(value, ptr)   _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr)        _Pragma("pop")
549
+#endif
550
+
551
+
552
+/**
553
+  \brief   Remove the exclusive lock
554
+  \details Removes the exclusive lock which is created by LDREX.
555
+ */
556
+#define __CLREX                           __clrex
557
+
558
+
559
+/**
560
+  \brief   Signed Saturate
561
+  \details Saturates a signed value.
562
+  \param [in]  value  Value to be saturated
563
+  \param [in]    sat  Bit position to saturate to (1..32)
564
+  \return             Saturated value
565
+ */
566
+#define __SSAT                            __ssat
567
+
568
+
569
+/**
570
+  \brief   Unsigned Saturate
571
+  \details Saturates an unsigned value.
572
+  \param [in]  value  Value to be saturated
573
+  \param [in]    sat  Bit position to saturate to (0..31)
574
+  \return             Saturated value
575
+ */
576
+#define __USAT                            __usat
577
+
578
+
579
+/**
580
+  \brief   Rotate Right with Extend (32 bit)
581
+  \details Moves each bit of a bitstring right by one bit.
582
+           The carry input is shifted in at the left end of the bitstring.
583
+  \param [in]    value  Value to rotate
584
+  \return               Rotated value
585
+ */
586
+#ifndef __NO_EMBEDDED_ASM
587
+__attribute__((section(".rrx_text"))) __STATIC_INLINE __ASM uint32_t __RRX(uint32_t value)
588
+{
589
+  rrx r0, r0
590
+  bx lr
591
+}
592
+#endif
593
+
594
+
595
+/**
596
+  \brief   LDRT Unprivileged (8 bit)
597
+  \details Executes a Unprivileged LDRT instruction for 8 bit value.
598
+  \param [in]    ptr  Pointer to data
599
+  \return             value of type uint8_t at (*ptr)
600
+ */
601
+#define __LDRBT(ptr)                      ((uint8_t )  __ldrt(ptr))
602
+
603
+
604
+/**
605
+  \brief   LDRT Unprivileged (16 bit)
606
+  \details Executes a Unprivileged LDRT instruction for 16 bit values.
607
+  \param [in]    ptr  Pointer to data
608
+  \return        value of type uint16_t at (*ptr)
609
+ */
610
+#define __LDRHT(ptr)                      ((uint16_t)  __ldrt(ptr))
611
+
612
+
613
+/**
614
+  \brief   LDRT Unprivileged (32 bit)
615
+  \details Executes a Unprivileged LDRT instruction for 32 bit values.
616
+  \param [in]    ptr  Pointer to data
617
+  \return        value of type uint32_t at (*ptr)
618
+ */
619
+#define __LDRT(ptr)                       ((uint32_t ) __ldrt(ptr))
620
+
621
+
622
+/**
623
+  \brief   STRT Unprivileged (8 bit)
624
+  \details Executes a Unprivileged STRT instruction for 8 bit values.
625
+  \param [in]  value  Value to store
626
+  \param [in]    ptr  Pointer to location
627
+ */
628
+#define __STRBT(value, ptr)               __strt(value, ptr)
629
+
630
+
631
+/**
632
+  \brief   STRT Unprivileged (16 bit)
633
+  \details Executes a Unprivileged STRT instruction for 16 bit values.
634
+  \param [in]  value  Value to store
635
+  \param [in]    ptr  Pointer to location
636
+ */
637
+#define __STRHT(value, ptr)               __strt(value, ptr)
638
+
639
+
640
+/**
641
+  \brief   STRT Unprivileged (32 bit)
642
+  \details Executes a Unprivileged STRT instruction for 32 bit values.
643
+  \param [in]  value  Value to store
644
+  \param [in]    ptr  Pointer to location
645
+ */
646
+#define __STRT(value, ptr)                __strt(value, ptr)
647
+
648
+#endif /* (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U) */
649
+
650
+/*@}*/ /* end of group CMSIS_Core_InstructionInterface */
651
+
652
+
653
+/* ###################  Compiler specific Intrinsics  ########################### */
654
+/** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
655
+  Access to dedicated SIMD instructions
656
+  @{
657
+*/
658
+
659
+#if (__CORTEX_M >= 0x04U)  /* only for Cortex-M4 and above */
660
+
661
+#define __SADD8                           __sadd8
662
+#define __QADD8                           __qadd8
663
+#define __SHADD8                          __shadd8
664
+#define __UADD8                           __uadd8
665
+#define __UQADD8                          __uqadd8
666
+#define __UHADD8                          __uhadd8
667
+#define __SSUB8                           __ssub8
668
+#define __QSUB8                           __qsub8
669
+#define __SHSUB8                          __shsub8
670
+#define __USUB8                           __usub8
671
+#define __UQSUB8                          __uqsub8
672
+#define __UHSUB8                          __uhsub8
673
+#define __SADD16                          __sadd16
674
+#define __QADD16                          __qadd16
675
+#define __SHADD16                         __shadd16
676
+#define __UADD16                          __uadd16
677
+#define __UQADD16                         __uqadd16
678
+#define __UHADD16                         __uhadd16
679
+#define __SSUB16                          __ssub16
680
+#define __QSUB16                          __qsub16
681
+#define __SHSUB16                         __shsub16
682
+#define __USUB16                          __usub16
683
+#define __UQSUB16                         __uqsub16
684
+#define __UHSUB16                         __uhsub16
685
+#define __SASX                            __sasx
686
+#define __QASX                            __qasx
687
+#define __SHASX                           __shasx
688
+#define __UASX                            __uasx
689
+#define __UQASX                           __uqasx
690
+#define __UHASX                           __uhasx
691
+#define __SSAX                            __ssax
692
+#define __QSAX                            __qsax
693
+#define __SHSAX                           __shsax
694
+#define __USAX                            __usax
695
+#define __UQSAX                           __uqsax
696
+#define __UHSAX                           __uhsax
697
+#define __USAD8                           __usad8
698
+#define __USADA8                          __usada8
699
+#define __SSAT16                          __ssat16
700
+#define __USAT16                          __usat16
701
+#define __UXTB16                          __uxtb16
702
+#define __UXTAB16                         __uxtab16
703
+#define __SXTB16                          __sxtb16
704
+#define __SXTAB16                         __sxtab16
705
+#define __SMUAD                           __smuad
706
+#define __SMUADX                          __smuadx
707
+#define __SMLAD                           __smlad
708
+#define __SMLADX                          __smladx
709
+#define __SMLALD                          __smlald
710
+#define __SMLALDX                         __smlaldx
711
+#define __SMUSD                           __smusd
712
+#define __SMUSDX                          __smusdx
713
+#define __SMLSD                           __smlsd
714
+#define __SMLSDX                          __smlsdx
715
+#define __SMLSLD                          __smlsld
716
+#define __SMLSLDX                         __smlsldx
717
+#define __SEL                             __sel
718
+#define __QADD                            __qadd
719
+#define __QSUB                            __qsub
720
+
721
+#define __PKHBT(ARG1,ARG2,ARG3)          ( ((((uint32_t)(ARG1))          ) & 0x0000FFFFUL) |  \
722
+                                           ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL)  )
723
+
724
+#define __PKHTB(ARG1,ARG2,ARG3)          ( ((((uint32_t)(ARG1))          ) & 0xFFFF0000UL) |  \
725
+                                           ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL)  )
726
+
727
+#define __SMMLA(ARG1,ARG2,ARG3)          ( (int32_t)((((int64_t)(ARG1) * (ARG2)) + \
728
+                                                      ((int64_t)(ARG3) << 32U)     ) >> 32U))
729
+
730
+#endif /* (__CORTEX_M >= 0x04) */
731
+/*@} end of group CMSIS_SIMD_intrinsics */
732
+
733
+
734
+#endif /* __CMSIS_ARMCC_H */

Разлика између датотеке није приказан због своје велике величине
+ 1800 - 0
Drivers/CMSIS/Include/cmsis_armcc_V6.h


Разлика између датотеке није приказан због своје велике величине
+ 1373 - 0
Drivers/CMSIS/Include/cmsis_gcc.h


+ 798 - 0
Drivers/CMSIS/Include/core_cm0.h

@@ -0,0 +1,798 @@
1
+/**************************************************************************//**
2
+ * @file     core_cm0.h
3
+ * @brief    CMSIS Cortex-M0 Core Peripheral Access Layer Header File
4
+ * @version  V4.30
5
+ * @date     20. October 2015
6
+ ******************************************************************************/
7
+/* Copyright (c) 2009 - 2015 ARM LIMITED
8
+
9
+   All rights reserved.
10
+   Redistribution and use in source and binary forms, with or without
11
+   modification, are permitted provided that the following conditions are met:
12
+   - Redistributions of source code must retain the above copyright
13
+     notice, this list of conditions and the following disclaimer.
14
+   - Redistributions in binary form must reproduce the above copyright
15
+     notice, this list of conditions and the following disclaimer in the
16
+     documentation and/or other materials provided with the distribution.
17
+   - Neither the name of ARM nor the names of its contributors may be used
18
+     to endorse or promote products derived from this software without
19
+     specific prior written permission.
20
+   *
21
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
+   ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
25
+   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26
+   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
+   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
+   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
+   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
+   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
+   POSSIBILITY OF SUCH DAMAGE.
32
+   ---------------------------------------------------------------------------*/
33
+
34
+
35
+#if   defined ( __ICCARM__ )
36
+ #pragma system_include         /* treat file as system include file for MISRA check */
37
+#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
38
+  #pragma clang system_header   /* treat file as system include file */
39
+#endif
40
+
41
+#ifndef __CORE_CM0_H_GENERIC
42
+#define __CORE_CM0_H_GENERIC
43
+
44
+#include <stdint.h>
45
+
46
+#ifdef __cplusplus
47
+ extern "C" {
48
+#endif
49
+
50
+/**
51
+  \page CMSIS_MISRA_Exceptions  MISRA-C:2004 Compliance Exceptions
52
+  CMSIS violates the following MISRA-C:2004 rules:
53
+
54
+   \li Required Rule 8.5, object/function definition in header file.<br>
55
+     Function definitions in header files are used to allow 'inlining'.
56
+
57
+   \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br>
58
+     Unions are used for effective representation of core registers.
59
+
60
+   \li Advisory Rule 19.7, Function-like macro defined.<br>
61
+     Function-like macros are used to allow more efficient code.
62
+ */
63
+
64
+
65
+/*******************************************************************************
66
+ *                 CMSIS definitions
67
+ ******************************************************************************/
68
+/**
69
+  \ingroup Cortex_M0
70
+  @{
71
+ */
72
+
73
+/*  CMSIS CM0 definitions */
74
+#define __CM0_CMSIS_VERSION_MAIN  (0x04U)                                      /*!< [31:16] CMSIS HAL main version */
75
+#define __CM0_CMSIS_VERSION_SUB   (0x1EU)                                      /*!< [15:0]  CMSIS HAL sub version */
76
+#define __CM0_CMSIS_VERSION       ((__CM0_CMSIS_VERSION_MAIN << 16U) | \
77
+                                    __CM0_CMSIS_VERSION_SUB           )        /*!< CMSIS HAL version number */
78
+
79
+#define __CORTEX_M                (0x00U)                                      /*!< Cortex-M Core */
80
+
81
+
82
+#if   defined ( __CC_ARM )
83
+  #define __ASM            __asm                                      /*!< asm keyword for ARM Compiler */
84
+  #define __INLINE         __inline                                   /*!< inline keyword for ARM Compiler */
85
+  #define __STATIC_INLINE  static __inline
86
+
87
+#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
88
+  #define __ASM            __asm                                      /*!< asm keyword for ARM Compiler */
89
+  #define __INLINE         __inline                                   /*!< inline keyword for ARM Compiler */
90
+  #define __STATIC_INLINE  static __inline
91
+
92
+#elif defined ( __GNUC__ )
93
+  #define __ASM            __asm                                      /*!< asm keyword for GNU Compiler */
94
+  #define __INLINE         inline                                     /*!< inline keyword for GNU Compiler */
95
+  #define __STATIC_INLINE  static inline
96
+
97
+#elif defined ( __ICCARM__ )
98
+  #define __ASM            __asm                                      /*!< asm keyword for IAR Compiler */
99
+  #define __INLINE         inline                                     /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */
100
+  #define __STATIC_INLINE  static inline
101
+
102
+#elif defined ( __TMS470__ )
103
+  #define __ASM            __asm                                      /*!< asm keyword for TI CCS Compiler */
104
+  #define __STATIC_INLINE  static inline
105
+
106
+#elif defined ( __TASKING__ )
107
+  #define __ASM            __asm                                      /*!< asm keyword for TASKING Compiler */
108
+  #define __INLINE         inline                                     /*!< inline keyword for TASKING Compiler */
109
+  #define __STATIC_INLINE  static inline
110
+
111
+#elif defined ( __CSMC__ )
112
+  #define __packed
113
+  #define __ASM            _asm                                      /*!< asm keyword for COSMIC Compiler */
114
+  #define __INLINE         inline                                    /*!< inline keyword for COSMIC Compiler. Use -pc99 on compile line */
115
+  #define __STATIC_INLINE  static inline
116
+
117
+#else
118
+  #error Unknown compiler
119
+#endif
120
+
121
+/** __FPU_USED indicates whether an FPU is used or not.
122
+    This core does not support an FPU at all
123
+*/
124
+#define __FPU_USED       0U
125
+
126
+#if defined ( __CC_ARM )
127
+  #if defined __TARGET_FPU_VFP
128
+    #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
129
+  #endif
130
+
131
+#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
132
+  #if defined __ARM_PCS_VFP
133
+    #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
134
+  #endif
135
+
136
+#elif defined ( __GNUC__ )
137
+  #if defined (__VFP_FP__) && !defined(__SOFTFP__)
138
+    #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
139
+  #endif
140
+
141
+#elif defined ( __ICCARM__ )
142
+  #if defined __ARMVFP__
143
+    #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
144
+  #endif
145
+
146
+#elif defined ( __TMS470__ )
147
+  #if defined __TI_VFP_SUPPORT__
148
+    #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
149
+  #endif
150
+
151
+#elif defined ( __TASKING__ )
152
+  #if defined __FPU_VFP__
153
+    #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
154
+  #endif
155
+
156
+#elif defined ( __CSMC__ )
157
+  #if ( __CSMC__ & 0x400U)
158
+    #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
159
+  #endif
160
+
161
+#endif
162
+
163
+#include "core_cmInstr.h"                /* Core Instruction Access */
164
+#include "core_cmFunc.h"                 /* Core Function Access */
165
+
166
+#ifdef __cplusplus
167
+}
168
+#endif
169
+
170
+#endif /* __CORE_CM0_H_GENERIC */
171
+
172
+#ifndef __CMSIS_GENERIC
173
+
174
+#ifndef __CORE_CM0_H_DEPENDANT
175
+#define __CORE_CM0_H_DEPENDANT
176
+
177
+#ifdef __cplusplus
178
+ extern "C" {
179
+#endif
180
+
181
+/* check device defines and use defaults */
182
+#if defined __CHECK_DEVICE_DEFINES
183
+  #ifndef __CM0_REV
184
+    #define __CM0_REV               0x0000U
185
+    #warning "__CM0_REV not defined in device header file; using default!"
186
+  #endif
187
+
188
+  #ifndef __NVIC_PRIO_BITS
189
+    #define __NVIC_PRIO_BITS          2U
190
+    #warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
191
+  #endif
192
+
193
+  #ifndef __Vendor_SysTickConfig
194
+    #define __Vendor_SysTickConfig    0U
195
+    #warning "__Vendor_SysTickConfig not defined in device header file; using default!"
196
+  #endif
197
+#endif
198
+
199
+/* IO definitions (access restrictions to peripheral registers) */
200
+/**
201
+    \defgroup CMSIS_glob_defs CMSIS Global Defines
202
+
203
+    <strong>IO Type Qualifiers</strong> are used
204
+    \li to specify the access to peripheral variables.
205
+    \li for automatic generation of peripheral register debug information.
206
+*/
207
+#ifdef __cplusplus
208
+  #define   __I     volatile             /*!< Defines 'read only' permissions */
209
+#else
210
+  #define   __I     volatile const       /*!< Defines 'read only' permissions */
211
+#endif
212
+#define     __O     volatile             /*!< Defines 'write only' permissions */
213
+#define     __IO    volatile             /*!< Defines 'read / write' permissions */
214
+
215
+/* following defines should be used for structure members */
216
+#define     __IM     volatile const      /*! Defines 'read only' structure member permissions */
217
+#define     __OM     volatile            /*! Defines 'write only' structure member permissions */
218
+#define     __IOM    volatile            /*! Defines 'read / write' structure member permissions */
219
+
220
+/*@} end of group Cortex_M0 */
221
+
222
+
223
+
224
+/*******************************************************************************
225
+ *                 Register Abstraction
226
+  Core Register contain:
227
+  - Core Register
228
+  - Core NVIC Register
229
+  - Core SCB Register
230
+  - Core SysTick Register
231
+ ******************************************************************************/
232
+/**
233
+  \defgroup CMSIS_core_register Defines and Type Definitions
234
+  \brief Type definitions and defines for Cortex-M processor based devices.
235
+*/
236
+
237
+/**
238
+  \ingroup    CMSIS_core_register
239
+  \defgroup   CMSIS_CORE  Status and Control Registers
240
+  \brief      Core Register type definitions.
241
+  @{
242
+ */
243
+
244
+/**
245
+  \brief  Union type to access the Application Program Status Register (APSR).
246
+ */
247
+typedef union
248
+{
249
+  struct
250
+  {
251
+    uint32_t _reserved0:28;              /*!< bit:  0..27  Reserved */
252
+    uint32_t V:1;                        /*!< bit:     28  Overflow condition code flag */
253
+    uint32_t C:1;                        /*!< bit:     29  Carry condition code flag */
254
+    uint32_t Z:1;                        /*!< bit:     30  Zero condition code flag */
255
+    uint32_t N:1;                        /*!< bit:     31  Negative condition code flag */
256
+  } b;                                   /*!< Structure used for bit  access */
257
+  uint32_t w;                            /*!< Type      used for word access */
258
+} APSR_Type;
259
+
260
+/* APSR Register Definitions */
261
+#define APSR_N_Pos                         31U                                            /*!< APSR: N Position */
262
+#define APSR_N_Msk                         (1UL << APSR_N_Pos)                            /*!< APSR: N Mask */
263
+
264
+#define APSR_Z_Pos                         30U                                            /*!< APSR: Z Position */
265
+#define APSR_Z_Msk                         (1UL << APSR_Z_Pos)                            /*!< APSR: Z Mask */
266
+
267
+#define APSR_C_Pos                         29U                                            /*!< APSR: C Position */
268
+#define APSR_C_Msk                         (1UL << APSR_C_Pos)                            /*!< APSR: C Mask */
269
+
270
+#define APSR_V_Pos                         28U                                            /*!< APSR: V Position */
271
+#define APSR_V_Msk                         (1UL << APSR_V_Pos)                            /*!< APSR: V Mask */
272
+
273
+
274
+/**
275
+  \brief  Union type to access the Interrupt Program Status Register (IPSR).
276
+ */
277
+typedef union
278
+{
279
+  struct
280
+  {
281
+    uint32_t ISR:9;                      /*!< bit:  0.. 8  Exception number */
282
+    uint32_t _reserved0:23;              /*!< bit:  9..31  Reserved */
283
+  } b;                                   /*!< Structure used for bit  access */
284
+  uint32_t w;                            /*!< Type      used for word access */
285
+} IPSR_Type;
286
+
287
+/* IPSR Register Definitions */
288
+#define IPSR_ISR_Pos                        0U                                            /*!< IPSR: ISR Position */
289
+#define IPSR_ISR_Msk                       (0x1FFUL /*<< IPSR_ISR_Pos*/)                  /*!< IPSR: ISR Mask */
290
+
291
+
292
+/**
293
+  \brief  Union type to access the Special-Purpose Program Status Registers (xPSR).
294
+ */
295
+typedef union
296
+{
297
+  struct
298
+  {
299
+    uint32_t ISR:9;                      /*!< bit:  0.. 8  Exception number */
300
+    uint32_t _reserved0:15;              /*!< bit:  9..23  Reserved */
301
+    uint32_t T:1;                        /*!< bit:     24  Thumb bit        (read 0) */
302
+    uint32_t _reserved1:3;               /*!< bit: 25..27  Reserved */
303
+    uint32_t V:1;                        /*!< bit:     28  Overflow condition code flag */
304
+    uint32_t C:1;                        /*!< bit:     29  Carry condition code flag */
305
+    uint32_t Z:1;                        /*!< bit:     30  Zero condition code flag */
306
+    uint32_t N:1;                        /*!< bit:     31  Negative condition code flag */
307
+  } b;                                   /*!< Structure used for bit  access */
308
+  uint32_t w;                            /*!< Type      used for word access */
309
+} xPSR_Type;
310
+
311
+/* xPSR Register Definitions */
312
+#define xPSR_N_Pos                         31U                                            /*!< xPSR: N Position */
313
+#define xPSR_N_Msk                         (1UL << xPSR_N_Pos)                            /*!< xPSR: N Mask */
314
+
315
+#define xPSR_Z_Pos                         30U                                            /*!< xPSR: Z Position */
316
+#define xPSR_Z_Msk                         (1UL << xPSR_Z_Pos)                            /*!< xPSR: Z Mask */
317
+
318
+#define xPSR_C_Pos                         29U                                            /*!< xPSR: C Position */
319
+#define xPSR_C_Msk                         (1UL << xPSR_C_Pos)                            /*!< xPSR: C Mask */
320
+
321
+#define xPSR_V_Pos                         28U                                            /*!< xPSR: V Position */
322
+#define xPSR_V_Msk                         (1UL << xPSR_V_Pos)                            /*!< xPSR: V Mask */
323
+
324
+#define xPSR_T_Pos                         24U                                            /*!< xPSR: T Position */
325
+#define xPSR_T_Msk                         (1UL << xPSR_T_Pos)                            /*!< xPSR: T Mask */
326
+
327
+#define xPSR_ISR_Pos                        0U                                            /*!< xPSR: ISR Position */
328
+#define xPSR_ISR_Msk                       (0x1FFUL /*<< xPSR_ISR_Pos*/)                  /*!< xPSR: ISR Mask */
329
+
330
+
331
+/**
332
+  \brief  Union type to access the Control Registers (CONTROL).
333
+ */
334
+typedef union
335
+{
336
+  struct
337
+  {
338
+    uint32_t _reserved0:1;               /*!< bit:      0  Reserved */
339
+    uint32_t SPSEL:1;                    /*!< bit:      1  Stack to be used */
340
+    uint32_t _reserved1:30;              /*!< bit:  2..31  Reserved */
341
+  } b;                                   /*!< Structure used for bit  access */
342
+  uint32_t w;                            /*!< Type      used for word access */
343
+} CONTROL_Type;
344
+
345
+/* CONTROL Register Definitions */
346
+#define CONTROL_SPSEL_Pos                   1U                                            /*!< CONTROL: SPSEL Position */
347
+#define CONTROL_SPSEL_Msk                  (1UL << CONTROL_SPSEL_Pos)                     /*!< CONTROL: SPSEL Mask */
348
+
349
+/*@} end of group CMSIS_CORE */
350
+
351
+
352
+/**
353
+  \ingroup    CMSIS_core_register
354
+  \defgroup   CMSIS_NVIC  Nested Vectored Interrupt Controller (NVIC)
355
+  \brief      Type definitions for the NVIC Registers
356
+  @{
357
+ */
358
+
359
+/**
360
+  \brief  Structure type to access the Nested Vectored Interrupt Controller (NVIC).
361
+ */
362
+typedef struct
363
+{
364
+  __IOM uint32_t ISER[1U];               /*!< Offset: 0x000 (R/W)  Interrupt Set Enable Register */
365
+        uint32_t RESERVED0[31U];
366
+  __IOM uint32_t ICER[1U];               /*!< Offset: 0x080 (R/W)  Interrupt Clear Enable Register */
367
+        uint32_t RSERVED1[31U];
368
+  __IOM uint32_t ISPR[1U];               /*!< Offset: 0x100 (R/W)  Interrupt Set Pending Register */
369
+        uint32_t RESERVED2[31U];
370
+  __IOM uint32_t ICPR[1U];               /*!< Offset: 0x180 (R/W)  Interrupt Clear Pending Register */
371
+        uint32_t RESERVED3[31U];
372
+        uint32_t RESERVED4[64U];
373
+  __IOM uint32_t IP[8U];                 /*!< Offset: 0x300 (R/W)  Interrupt Priority Register */
374
+}  NVIC_Type;
375
+
376
+/*@} end of group CMSIS_NVIC */
377
+
378
+
379
+/**
380
+  \ingroup  CMSIS_core_register
381
+  \defgroup CMSIS_SCB     System Control Block (SCB)
382
+  \brief    Type definitions for the System Control Block Registers
383
+  @{
384
+ */
385
+
386
+/**
387
+  \brief  Structure type to access the System Control Block (SCB).
388
+ */
389
+typedef struct
390
+{
391
+  __IM  uint32_t CPUID;                  /*!< Offset: 0x000 (R/ )  CPUID Base Register */
392
+  __IOM uint32_t ICSR;                   /*!< Offset: 0x004 (R/W)  Interrupt Control and State Register */
393
+        uint32_t RESERVED0;
394
+  __IOM uint32_t AIRCR;                  /*!< Offset: 0x00C (R/W)  Application Interrupt and Reset Control Register */
395
+  __IOM uint32_t SCR;                    /*!< Offset: 0x010 (R/W)  System Control Register */
396
+  __IOM uint32_t CCR;                    /*!< Offset: 0x014 (R/W)  Configuration Control Register */
397
+        uint32_t RESERVED1;
398
+  __IOM uint32_t SHP[2U];                /*!< Offset: 0x01C (R/W)  System Handlers Priority Registers. [0] is RESERVED */
399
+  __IOM uint32_t SHCSR;                  /*!< Offset: 0x024 (R/W)  System Handler Control and State Register */
400
+} SCB_Type;
401
+
402
+/* SCB CPUID Register Definitions */
403
+#define SCB_CPUID_IMPLEMENTER_Pos          24U                                            /*!< SCB CPUID: IMPLEMENTER Position */
404
+#define SCB_CPUID_IMPLEMENTER_Msk          (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos)          /*!< SCB CPUID: IMPLEMENTER Mask */
405
+
406
+#define SCB_CPUID_VARIANT_Pos              20U                                            /*!< SCB CPUID: VARIANT Position */
407
+#define SCB_CPUID_VARIANT_Msk              (0xFUL << SCB_CPUID_VARIANT_Pos)               /*!< SCB CPUID: VARIANT Mask */
408
+
409
+#define SCB_CPUID_ARCHITECTURE_Pos         16U                                            /*!< SCB CPUID: ARCHITECTURE Position */
410
+#define SCB_CPUID_ARCHITECTURE_Msk         (0xFUL << SCB_CPUID_ARCHITECTURE_Pos)          /*!< SCB CPUID: ARCHITECTURE Mask */
411
+
412
+#define SCB_CPUID_PARTNO_Pos                4U                                            /*!< SCB CPUID: PARTNO Position */
413
+#define SCB_CPUID_PARTNO_Msk               (0xFFFUL << SCB_CPUID_PARTNO_Pos)              /*!< SCB CPUID: PARTNO Mask */
414
+
415
+#define SCB_CPUID_REVISION_Pos              0U                                            /*!< SCB CPUID: REVISION Position */
416
+#define SCB_CPUID_REVISION_Msk             (0xFUL /*<< SCB_CPUID_REVISION_Pos*/)          /*!< SCB CPUID: REVISION Mask */
417
+
418
+/* SCB Interrupt Control State Register Definitions */
419
+#define SCB_ICSR_NMIPENDSET_Pos            31U                                            /*!< SCB ICSR: NMIPENDSET Position */
420
+#define SCB_ICSR_NMIPENDSET_Msk            (1UL << SCB_ICSR_NMIPENDSET_Pos)               /*!< SCB ICSR: NMIPENDSET Mask */
421
+
422
+#define SCB_ICSR_PENDSVSET_Pos             28U                                            /*!< SCB ICSR: PENDSVSET Position */
423
+#define SCB_ICSR_PENDSVSET_Msk             (1UL << SCB_ICSR_PENDSVSET_Pos)                /*!< SCB ICSR: PENDSVSET Mask */
424
+
425
+#define SCB_ICSR_PENDSVCLR_Pos             27U                                            /*!< SCB ICSR: PENDSVCLR Position */
426
+#define SCB_ICSR_PENDSVCLR_Msk             (1UL << SCB_ICSR_PENDSVCLR_Pos)                /*!< SCB ICSR: PENDSVCLR Mask */
427
+
428
+#define SCB_ICSR_PENDSTSET_Pos             26U                                            /*!< SCB ICSR: PENDSTSET Position */
429
+#define SCB_ICSR_PENDSTSET_Msk             (1UL << SCB_ICSR_PENDSTSET_Pos)                /*!< SCB ICSR: PENDSTSET Mask */
430
+
431
+#define SCB_ICSR_PENDSTCLR_Pos             25U                                            /*!< SCB ICSR: PENDSTCLR Position */
432
+#define SCB_ICSR_PENDSTCLR_Msk             (1UL << SCB_ICSR_PENDSTCLR_Pos)                /*!< SCB ICSR: PENDSTCLR Mask */
433
+
434
+#define SCB_ICSR_ISRPREEMPT_Pos            23U                                            /*!< SCB ICSR: ISRPREEMPT Position */
435
+#define SCB_ICSR_ISRPREEMPT_Msk            (1UL << SCB_ICSR_ISRPREEMPT_Pos)               /*!< SCB ICSR: ISRPREEMPT Mask */
436
+
437
+#define SCB_ICSR_ISRPENDING_Pos            22U                                            /*!< SCB ICSR: ISRPENDING Position */
438
+#define SCB_ICSR_ISRPENDING_Msk            (1UL << SCB_ICSR_ISRPENDING_Pos)               /*!< SCB ICSR: ISRPENDING Mask */
439
+
440
+#define SCB_ICSR_VECTPENDING_Pos           12U                                            /*!< SCB ICSR: VECTPENDING Position */
441
+#define SCB_ICSR_VECTPENDING_Msk           (0x1FFUL << SCB_ICSR_VECTPENDING_Pos)          /*!< SCB ICSR: VECTPENDING Mask */
442
+
443
+#define SCB_ICSR_VECTACTIVE_Pos             0U                                            /*!< SCB ICSR: VECTACTIVE Position */
444
+#define SCB_ICSR_VECTACTIVE_Msk            (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/)       /*!< SCB ICSR: VECTACTIVE Mask */
445
+
446
+/* SCB Application Interrupt and Reset Control Register Definitions */
447
+#define SCB_AIRCR_VECTKEY_Pos              16U                                            /*!< SCB AIRCR: VECTKEY Position */
448
+#define SCB_AIRCR_VECTKEY_Msk              (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos)            /*!< SCB AIRCR: VECTKEY Mask */
449
+
450
+#define SCB_AIRCR_VECTKEYSTAT_Pos          16U                                            /*!< SCB AIRCR: VECTKEYSTAT Position */
451
+#define SCB_AIRCR_VECTKEYSTAT_Msk          (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos)        /*!< SCB AIRCR: VECTKEYSTAT Mask */
452
+
453
+#define SCB_AIRCR_ENDIANESS_Pos            15U                                            /*!< SCB AIRCR: ENDIANESS Position */
454
+#define SCB_AIRCR_ENDIANESS_Msk            (1UL << SCB_AIRCR_ENDIANESS_Pos)               /*!< SCB AIRCR: ENDIANESS Mask */
455
+
456
+#define SCB_AIRCR_SYSRESETREQ_Pos           2U                                            /*!< SCB AIRCR: SYSRESETREQ Position */
457
+#define SCB_AIRCR_SYSRESETREQ_Msk          (1UL << SCB_AIRCR_SYSRESETREQ_Pos)             /*!< SCB AIRCR: SYSRESETREQ Mask */
458
+
459
+#define SCB_AIRCR_VECTCLRACTIVE_Pos         1U                                            /*!< SCB AIRCR: VECTCLRACTIVE Position */
460
+#define SCB_AIRCR_VECTCLRACTIVE_Msk        (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos)           /*!< SCB AIRCR: VECTCLRACTIVE Mask */
461
+
462
+/* SCB System Control Register Definitions */
463
+#define SCB_SCR_SEVONPEND_Pos               4U                                            /*!< SCB SCR: SEVONPEND Position */
464
+#define SCB_SCR_SEVONPEND_Msk              (1UL << SCB_SCR_SEVONPEND_Pos)                 /*!< SCB SCR: SEVONPEND Mask */
465
+
466
+#define SCB_SCR_SLEEPDEEP_Pos               2U                                            /*!< SCB SCR: SLEEPDEEP Position */
467
+#define SCB_SCR_SLEEPDEEP_Msk              (1UL << SCB_SCR_SLEEPDEEP_Pos)                 /*!< SCB SCR: SLEEPDEEP Mask */
468
+
469
+#define SCB_SCR_SLEEPONEXIT_Pos             1U                                            /*!< SCB SCR: SLEEPONEXIT Position */
470
+#define SCB_SCR_SLEEPONEXIT_Msk            (1UL << SCB_SCR_SLEEPONEXIT_Pos)               /*!< SCB SCR: SLEEPONEXIT Mask */
471
+
472
+/* SCB Configuration Control Register Definitions */
473
+#define SCB_CCR_STKALIGN_Pos                9U                                            /*!< SCB CCR: STKALIGN Position */
474
+#define SCB_CCR_STKALIGN_Msk               (1UL << SCB_CCR_STKALIGN_Pos)                  /*!< SCB CCR: STKALIGN Mask */
475
+
476
+#define SCB_CCR_UNALIGN_TRP_Pos             3U                                            /*!< SCB CCR: UNALIGN_TRP Position */
477
+#define SCB_CCR_UNALIGN_TRP_Msk            (1UL << SCB_CCR_UNALIGN_TRP_Pos)               /*!< SCB CCR: UNALIGN_TRP Mask */
478
+
479
+/* SCB System Handler Control and State Register Definitions */
480
+#define SCB_SHCSR_SVCALLPENDED_Pos         15U                                            /*!< SCB SHCSR: SVCALLPENDED Position */
481
+#define SCB_SHCSR_SVCALLPENDED_Msk         (1UL << SCB_SHCSR_SVCALLPENDED_Pos)            /*!< SCB SHCSR: SVCALLPENDED Mask */
482
+
483
+/*@} end of group CMSIS_SCB */
484
+
485
+
486
+/**
487
+  \ingroup  CMSIS_core_register
488
+  \defgroup CMSIS_SysTick     System Tick Timer (SysTick)
489
+  \brief    Type definitions for the System Timer Registers.
490
+  @{
491
+ */
492
+
493
+/**
494
+  \brief  Structure type to access the System Timer (SysTick).
495
+ */
496
+typedef struct
497
+{
498
+  __IOM uint32_t CTRL;                   /*!< Offset: 0x000 (R/W)  SysTick Control and Status Register */
499
+  __IOM uint32_t LOAD;                   /*!< Offset: 0x004 (R/W)  SysTick Reload Value Register */
500
+  __IOM uint32_t VAL;                    /*!< Offset: 0x008 (R/W)  SysTick Current Value Register */
501
+  __IM  uint32_t CALIB;                  /*!< Offset: 0x00C (R/ )  SysTick Calibration Register */
502
+} SysTick_Type;
503
+
504
+/* SysTick Control / Status Register Definitions */
505
+#define SysTick_CTRL_COUNTFLAG_Pos         16U                                            /*!< SysTick CTRL: COUNTFLAG Position */
506
+#define SysTick_CTRL_COUNTFLAG_Msk         (1UL << SysTick_CTRL_COUNTFLAG_Pos)            /*!< SysTick CTRL: COUNTFLAG Mask */
507
+
508
+#define SysTick_CTRL_CLKSOURCE_Pos          2U                                            /*!< SysTick CTRL: CLKSOURCE Position */
509
+#define SysTick_CTRL_CLKSOURCE_Msk         (1UL << SysTick_CTRL_CLKSOURCE_Pos)            /*!< SysTick CTRL: CLKSOURCE Mask */
510
+
511
+#define SysTick_CTRL_TICKINT_Pos            1U                                            /*!< SysTick CTRL: TICKINT Position */
512
+#define SysTick_CTRL_TICKINT_Msk           (1UL << SysTick_CTRL_TICKINT_Pos)              /*!< SysTick CTRL: TICKINT Mask */
513
+
514
+#define SysTick_CTRL_ENABLE_Pos             0U                                            /*!< SysTick CTRL: ENABLE Position */
515
+#define SysTick_CTRL_ENABLE_Msk            (1UL /*<< SysTick_CTRL_ENABLE_Pos*/)           /*!< SysTick CTRL: ENABLE Mask */
516
+
517
+/* SysTick Reload Register Definitions */
518
+#define SysTick_LOAD_RELOAD_Pos             0U                                            /*!< SysTick LOAD: RELOAD Position */
519
+#define SysTick_LOAD_RELOAD_Msk            (0xFFFFFFUL /*<< SysTick_LOAD_RELOAD_Pos*/)    /*!< SysTick LOAD: RELOAD Mask */
520
+
521
+/* SysTick Current Register Definitions */
522
+#define SysTick_VAL_CURRENT_Pos             0U                                            /*!< SysTick VAL: CURRENT Position */
523
+#define SysTick_VAL_CURRENT_Msk            (0xFFFFFFUL /*<< SysTick_VAL_CURRENT_Pos*/)    /*!< SysTick VAL: CURRENT Mask */
524
+
525
+/* SysTick Calibration Register Definitions */
526
+#define SysTick_CALIB_NOREF_Pos            31U                                            /*!< SysTick CALIB: NOREF Position */
527
+#define SysTick_CALIB_NOREF_Msk            (1UL << SysTick_CALIB_NOREF_Pos)               /*!< SysTick CALIB: NOREF Mask */
528
+
529
+#define SysTick_CALIB_SKEW_Pos             30U                                            /*!< SysTick CALIB: SKEW Position */
530
+#define SysTick_CALIB_SKEW_Msk             (1UL << SysTick_CALIB_SKEW_Pos)                /*!< SysTick CALIB: SKEW Mask */
531
+
532
+#define SysTick_CALIB_TENMS_Pos             0U                                            /*!< SysTick CALIB: TENMS Position */
533
+#define SysTick_CALIB_TENMS_Msk            (0xFFFFFFUL /*<< SysTick_CALIB_TENMS_Pos*/)    /*!< SysTick CALIB: TENMS Mask */
534
+
535
+/*@} end of group CMSIS_SysTick */
536
+
537
+
538
+/**
539
+  \ingroup  CMSIS_core_register
540
+  \defgroup CMSIS_CoreDebug       Core Debug Registers (CoreDebug)
541
+  \brief    Cortex-M0 Core Debug Registers (DCB registers, SHCSR, and DFSR) are only accessible over DAP and not via processor.
542
+            Therefore they are not covered by the Cortex-M0 header file.
543
+  @{
544
+ */
545
+/*@} end of group CMSIS_CoreDebug */
546
+
547
+
548
+/**
549
+  \ingroup    CMSIS_core_register
550
+  \defgroup   CMSIS_core_bitfield     Core register bit field macros
551
+  \brief      Macros for use with bit field definitions (xxx_Pos, xxx_Msk).
552
+  @{
553
+ */
554
+
555
+/**
556
+  \brief   Mask and shift a bit field value for use in a register bit range.
557
+  \param[in] field  Name of the register bit field.
558
+  \param[in] value  Value of the bit field.
559
+  \return           Masked and shifted value.
560
+*/
561
+#define _VAL2FLD(field, value)    ((value << field ## _Pos) & field ## _Msk)
562
+
563
+/**
564
+  \brief     Mask and shift a register value to extract a bit filed value.
565
+  \param[in] field  Name of the register bit field.
566
+  \param[in] value  Value of register.
567
+  \return           Masked and shifted bit field value.
568
+*/
569
+#define _FLD2VAL(field, value)    ((value & field ## _Msk) >> field ## _Pos)
570
+
571
+/*@} end of group CMSIS_core_bitfield */
572
+
573
+
574
+/**
575
+  \ingroup    CMSIS_core_register
576
+  \defgroup   CMSIS_core_base     Core Definitions
577
+  \brief      Definitions for base addresses, unions, and structures.
578
+  @{
579
+ */
580
+
581
+/* Memory mapping of Cortex-M0 Hardware */
582
+#define SCS_BASE            (0xE000E000UL)                            /*!< System Control Space Base Address */
583
+#define SysTick_BASE        (SCS_BASE +  0x0010UL)                    /*!< SysTick Base Address */
584
+#define NVIC_BASE           (SCS_BASE +  0x0100UL)                    /*!< NVIC Base Address */
585
+#define SCB_BASE            (SCS_BASE +  0x0D00UL)                    /*!< System Control Block Base Address */
586
+
587
+#define SCB                 ((SCB_Type       *)     SCB_BASE      )   /*!< SCB configuration struct */
588
+#define SysTick             ((SysTick_Type   *)     SysTick_BASE  )   /*!< SysTick configuration struct */
589
+#define NVIC                ((NVIC_Type      *)     NVIC_BASE     )   /*!< NVIC configuration struct */
590
+
591
+
592
+/*@} */
593
+
594
+
595
+
596
+/*******************************************************************************
597
+ *                Hardware Abstraction Layer
598
+  Core Function Interface contains:
599
+  - Core NVIC Functions
600
+  - Core SysTick Functions
601
+  - Core Register Access Functions
602
+ ******************************************************************************/
603
+/**
604
+  \defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference
605
+*/
606
+
607
+
608
+
609
+/* ##########################   NVIC functions  #################################### */
610
+/**
611
+  \ingroup  CMSIS_Core_FunctionInterface
612
+  \defgroup CMSIS_Core_NVICFunctions NVIC Functions
613
+  \brief    Functions that manage interrupts and exceptions via the NVIC.
614
+  @{
615
+ */
616
+
617
+/* Interrupt Priorities are WORD accessible only under ARMv6M                   */
618
+/* The following MACROS handle generation of the register offset and byte masks */
619
+#define _BIT_SHIFT(IRQn)         (  ((((uint32_t)(int32_t)(IRQn))         )      &  0x03UL) * 8UL)
620
+#define _SHP_IDX(IRQn)           ( (((((uint32_t)(int32_t)(IRQn)) & 0x0FUL)-8UL) >>    2UL)      )
621
+#define _IP_IDX(IRQn)            (   (((uint32_t)(int32_t)(IRQn))                >>    2UL)      )
622
+
623
+
624
+/**
625
+  \brief   Enable External Interrupt
626
+  \details Enables a device-specific interrupt in the NVIC interrupt controller.
627
+  \param [in]      IRQn  External interrupt number. Value cannot be negative.
628
+ */
629
+__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
630
+{
631
+  NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
632
+}
633
+
634
+
635
+/**
636
+  \brief   Disable External Interrupt
637
+  \details Disables a device-specific interrupt in the NVIC interrupt controller.
638
+  \param [in]      IRQn  External interrupt number. Value cannot be negative.
639
+ */
640
+__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
641
+{
642
+  NVIC->ICER[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
643
+}
644
+
645
+
646
+/**
647
+  \brief   Get Pending Interrupt
648
+  \details Reads the pending register in the NVIC and returns the pending bit for the specified interrupt.
649
+  \param [in]      IRQn  Interrupt number.
650
+  \return             0  Interrupt status is not pending.
651
+  \return             1  Interrupt status is pending.
652
+ */
653
+__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
654
+{
655
+  return((uint32_t)(((NVIC->ISPR[0U] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
656
+}
657
+
658
+
659
+/**
660
+  \brief   Set Pending Interrupt
661
+  \details Sets the pending bit of an external interrupt.
662
+  \param [in]      IRQn  Interrupt number. Value cannot be negative.
663
+ */
664
+__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
665
+{
666
+  NVIC->ISPR[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
667
+}
668
+
669
+
670
+/**
671
+  \brief   Clear Pending Interrupt
672
+  \details Clears the pending bit of an external interrupt.
673
+  \param [in]      IRQn  External interrupt number. Value cannot be negative.
674
+ */
675
+__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
676
+{
677
+  NVIC->ICPR[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
678
+}
679
+
680
+
681
+/**
682
+  \brief   Set Interrupt Priority
683
+  \details Sets the priority of an interrupt.
684
+  \note    The priority cannot be set for every core interrupt.
685
+  \param [in]      IRQn  Interrupt number.
686
+  \param [in]  priority  Priority to set.
687
+ */
688
+__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
689
+{
690
+  if ((int32_t)(IRQn) < 0)
691
+  {
692
+    SCB->SHP[_SHP_IDX(IRQn)] = ((uint32_t)(SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
693
+       (((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
694
+  }
695
+  else
696
+  {
697
+    NVIC->IP[_IP_IDX(IRQn)]  = ((uint32_t)(NVIC->IP[_IP_IDX(IRQn)]  & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
698
+       (((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
699
+  }
700
+}
701
+
702
+
703
+/**
704
+  \brief   Get Interrupt Priority
705
+  \details Reads the priority of an interrupt.
706
+           The interrupt number can be positive to specify an external (device specific) interrupt,
707
+           or negative to specify an internal (core) interrupt.
708
+  \param [in]   IRQn  Interrupt number.
709
+  \return             Interrupt Priority.
710
+                      Value is aligned automatically to the implemented priority bits of the microcontroller.
711
+ */
712
+__STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
713
+{
714
+
715
+  if ((int32_t)(IRQn) < 0)
716
+  {
717
+    return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
718
+  }
719
+  else
720
+  {
721
+    return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
722
+  }
723
+}
724
+
725
+
726
+/**
727
+  \brief   System Reset
728
+  \details Initiates a system reset request to reset the MCU.
729
+ */
730
+__STATIC_INLINE void NVIC_SystemReset(void)
731
+{
732
+  __DSB();                                                          /* Ensure all outstanding memory accesses included
733
+                                                                       buffered write are completed before reset */
734
+  SCB->AIRCR  = ((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) |
735
+                 SCB_AIRCR_SYSRESETREQ_Msk);
736
+  __DSB();                                                          /* Ensure completion of memory access */
737
+
738
+  for(;;)                                                           /* wait until reset */
739
+  {
740
+    __NOP();
741
+  }
742
+}
743
+
744
+/*@} end of CMSIS_Core_NVICFunctions */
745
+
746
+
747
+
748
+/* ##################################    SysTick function  ############################################ */
749
+/**
750
+  \ingroup  CMSIS_Core_FunctionInterface
751
+  \defgroup CMSIS_Core_SysTickFunctions SysTick Functions
752
+  \brief    Functions that configure the System.
753
+  @{
754
+ */
755
+
756
+#if (__Vendor_SysTickConfig == 0U)
757
+
758
+/**
759
+  \brief   System Tick Configuration
760
+  \details Initializes the System Timer and its interrupt, and starts the System Tick Timer.
761
+           Counter is in free running mode to generate periodic interrupts.
762
+  \param [in]  ticks  Number of ticks between two interrupts.
763
+  \return          0  Function succeeded.
764
+  \return          1  Function failed.
765
+  \note    When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then the
766
+           function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b>
767
+           must contain a vendor-specific implementation of this function.
768
+ */
769
+__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
770
+{
771
+  if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk)
772
+  {
773
+    return (1UL);                                                   /* Reload value impossible */
774
+  }
775
+
776
+  SysTick->LOAD  = (uint32_t)(ticks - 1UL);                         /* set reload register */
777
+  NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */
778
+  SysTick->VAL   = 0UL;                                             /* Load the SysTick Counter Value */
779
+  SysTick->CTRL  = SysTick_CTRL_CLKSOURCE_Msk |
780
+                   SysTick_CTRL_TICKINT_Msk   |
781
+                   SysTick_CTRL_ENABLE_Msk;                         /* Enable SysTick IRQ and SysTick Timer */
782
+  return (0UL);                                                     /* Function successful */
783
+}
784
+
785
+#endif
786
+
787
+/*@} end of CMSIS_Core_SysTickFunctions */
788
+
789
+
790
+
791
+
792
+#ifdef __cplusplus
793
+}
794
+#endif
795
+
796
+#endif /* __CORE_CM0_H_DEPENDANT */
797
+
798
+#endif /* __CMSIS_GENERIC */

+ 914 - 0
Drivers/CMSIS/Include/core_cm0plus.h

@@ -0,0 +1,914 @@
1
+/**************************************************************************//**
2
+ * @file     core_cm0plus.h
3
+ * @brief    CMSIS Cortex-M0+ Core Peripheral Access Layer Header File
4
+ * @version  V4.30
5
+ * @date     20. October 2015
6
+ ******************************************************************************/
7
+/* Copyright (c) 2009 - 2015 ARM LIMITED
8
+
9
+   All rights reserved.
10
+   Redistribution and use in source and binary forms, with or without
11
+   modification, are permitted provided that the following conditions are met:
12
+   - Redistributions of source code must retain the above copyright
13
+     notice, this list of conditions and the following disclaimer.
14
+   - Redistributions in binary form must reproduce the above copyright
15
+     notice, this list of conditions and the following disclaimer in the
16
+     documentation and/or other materials provided with the distribution.
17
+   - Neither the name of ARM nor the names of its contributors may be used
18
+     to endorse or promote products derived from this software without
19
+     specific prior written permission.
20
+   *
21
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
+   ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
25
+   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26
+   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
+   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
+   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
+   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
+   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
+   POSSIBILITY OF SUCH DAMAGE.
32
+   ---------------------------------------------------------------------------*/
33
+
34
+
35
+#if   defined ( __ICCARM__ )
36
+ #pragma system_include         /* treat file as system include file for MISRA check */
37
+#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
38
+  #pragma clang system_header   /* treat file as system include file */
39
+#endif
40
+
41
+#ifndef __CORE_CM0PLUS_H_GENERIC
42
+#define __CORE_CM0PLUS_H_GENERIC
43
+
44
+#include <stdint.h>
45
+
46
+#ifdef __cplusplus
47
+ extern "C" {
48
+#endif
49
+
50
+/**
51
+  \page CMSIS_MISRA_Exceptions  MISRA-C:2004 Compliance Exceptions
52
+  CMSIS violates the following MISRA-C:2004 rules:
53
+
54
+   \li Required Rule 8.5, object/function definition in header file.<br>
55
+     Function definitions in header files are used to allow 'inlining'.
56
+
57
+   \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br>
58
+     Unions are used for effective representation of core registers.
59
+
60
+   \li Advisory Rule 19.7, Function-like macro defined.<br>
61
+     Function-like macros are used to allow more efficient code.
62
+ */
63
+
64
+
65
+/*******************************************************************************
66
+ *                 CMSIS definitions
67
+ ******************************************************************************/
68
+/**
69
+  \ingroup Cortex-M0+
70
+  @{
71
+ */
72
+
73
+/*  CMSIS CM0+ definitions */
74
+#define __CM0PLUS_CMSIS_VERSION_MAIN (0x04U)                                   /*!< [31:16] CMSIS HAL main version */
75
+#define __CM0PLUS_CMSIS_VERSION_SUB  (0x1EU)                                   /*!< [15:0]  CMSIS HAL sub version */
76
+#define __CM0PLUS_CMSIS_VERSION      ((__CM0PLUS_CMSIS_VERSION_MAIN << 16U) | \
77
+                                       __CM0PLUS_CMSIS_VERSION_SUB           ) /*!< CMSIS HAL version number */
78
+
79
+#define __CORTEX_M                (0x00U)                                      /*!< Cortex-M Core */
80
+
81
+
82
+#if   defined ( __CC_ARM )
83
+  #define __ASM            __asm                                      /*!< asm keyword for ARM Compiler */
84
+  #define __INLINE         __inline                                   /*!< inline keyword for ARM Compiler */
85
+  #define __STATIC_INLINE  static __inline
86
+
87
+#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
88
+  #define __ASM            __asm                                      /*!< asm keyword for ARM Compiler */
89
+  #define __INLINE         __inline                                   /*!< inline keyword for ARM Compiler */
90
+  #define __STATIC_INLINE  static __inline
91
+
92
+#elif defined ( __GNUC__ )
93
+  #define __ASM            __asm                                      /*!< asm keyword for GNU Compiler */
94
+  #define __INLINE         inline                                     /*!< inline keyword for GNU Compiler */
95
+  #define __STATIC_INLINE  static inline
96
+
97
+#elif defined ( __ICCARM__ )
98
+  #define __ASM            __asm                                      /*!< asm keyword for IAR Compiler */
99
+  #define __INLINE         inline                                     /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */
100
+  #define __STATIC_INLINE  static inline
101
+
102
+#elif defined ( __TMS470__ )
103
+  #define __ASM            __asm                                      /*!< asm keyword for TI CCS Compiler */
104
+  #define __STATIC_INLINE  static inline
105
+
106
+#elif defined ( __TASKING__ )
107
+  #define __ASM            __asm                                      /*!< asm keyword for TASKING Compiler */
108
+  #define __INLINE         inline                                     /*!< inline keyword for TASKING Compiler */
109
+  #define __STATIC_INLINE  static inline
110
+
111
+#elif defined ( __CSMC__ )
112
+  #define __packed
113
+  #define __ASM            _asm                                      /*!< asm keyword for COSMIC Compiler */
114
+  #define __INLINE         inline                                    /*!< inline keyword for COSMIC Compiler. Use -pc99 on compile line */
115
+  #define __STATIC_INLINE  static inline
116
+
117
+#else
118
+  #error Unknown compiler
119
+#endif
120
+
121
+/** __FPU_USED indicates whether an FPU is used or not.
122
+    This core does not support an FPU at all
123
+*/
124
+#define __FPU_USED       0U
125
+
126
+#if defined ( __CC_ARM )
127
+  #if defined __TARGET_FPU_VFP
128
+    #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
129
+  #endif
130
+
131
+#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
132
+  #if defined __ARM_PCS_VFP
133
+    #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
134
+  #endif
135
+
136
+#elif defined ( __GNUC__ )
137
+  #if defined (__VFP_FP__) && !defined(__SOFTFP__)
138
+    #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
139
+  #endif
140
+
141
+#elif defined ( __ICCARM__ )
142
+  #if defined __ARMVFP__
143
+    #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
144
+  #endif
145
+
146
+#elif defined ( __TMS470__ )
147
+  #if defined __TI_VFP_SUPPORT__
148
+    #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
149
+  #endif
150
+
151
+#elif defined ( __TASKING__ )
152
+  #if defined __FPU_VFP__
153
+    #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
154
+  #endif
155
+
156
+#elif defined ( __CSMC__ )
157
+  #if ( __CSMC__ & 0x400U)
158
+    #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
159
+  #endif
160
+
161
+#endif
162
+
163
+#include "core_cmInstr.h"                /* Core Instruction Access */
164
+#include "core_cmFunc.h"                 /* Core Function Access */
165
+
166
+#ifdef __cplusplus
167
+}
168
+#endif
169
+
170
+#endif /* __CORE_CM0PLUS_H_GENERIC */
171
+
172
+#ifndef __CMSIS_GENERIC
173
+
174
+#ifndef __CORE_CM0PLUS_H_DEPENDANT
175
+#define __CORE_CM0PLUS_H_DEPENDANT
176
+
177
+#ifdef __cplusplus
178
+ extern "C" {
179
+#endif
180
+
181
+/* check device defines and use defaults */
182
+#if defined __CHECK_DEVICE_DEFINES
183
+  #ifndef __CM0PLUS_REV
184
+    #define __CM0PLUS_REV             0x0000U
185
+    #warning "__CM0PLUS_REV not defined in device header file; using default!"
186
+  #endif
187
+
188
+  #ifndef __MPU_PRESENT
189
+    #define __MPU_PRESENT             0U
190
+    #warning "__MPU_PRESENT not defined in device header file; using default!"
191
+  #endif
192
+
193
+  #ifndef __VTOR_PRESENT
194
+    #define __VTOR_PRESENT            0U
195
+    #warning "__VTOR_PRESENT not defined in device header file; using default!"
196
+  #endif
197
+
198
+  #ifndef __NVIC_PRIO_BITS
199
+    #define __NVIC_PRIO_BITS          2U
200
+    #warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
201
+  #endif
202
+
203
+  #ifndef __Vendor_SysTickConfig
204
+    #define __Vendor_SysTickConfig    0U
205
+    #warning "__Vendor_SysTickConfig not defined in device header file; using default!"
206
+  #endif
207
+#endif
208
+
209
+/* IO definitions (access restrictions to peripheral registers) */
210
+/**
211
+    \defgroup CMSIS_glob_defs CMSIS Global Defines
212
+
213
+    <strong>IO Type Qualifiers</strong> are used
214
+    \li to specify the access to peripheral variables.
215
+    \li for automatic generation of peripheral register debug information.
216
+*/
217
+#ifdef __cplusplus
218
+  #define   __I     volatile             /*!< Defines 'read only' permissions */
219
+#else
220
+  #define   __I     volatile const       /*!< Defines 'read only' permissions */
221
+#endif
222
+#define     __O     volatile             /*!< Defines 'write only' permissions */
223
+#define     __IO    volatile             /*!< Defines 'read / write' permissions */
224
+
225
+/* following defines should be used for structure members */
226
+#define     __IM     volatile const      /*! Defines 'read only' structure member permissions */
227
+#define     __OM     volatile            /*! Defines 'write only' structure member permissions */
228
+#define     __IOM    volatile            /*! Defines 'read / write' structure member permissions */
229
+
230
+/*@} end of group Cortex-M0+ */
231
+
232
+
233
+
234
+/*******************************************************************************
235
+ *                 Register Abstraction
236
+  Core Register contain:
237
+  - Core Register
238
+  - Core NVIC Register
239
+  - Core SCB Register
240
+  - Core SysTick Register
241
+  - Core MPU Register
242
+ ******************************************************************************/
243
+/**
244
+  \defgroup CMSIS_core_register Defines and Type Definitions
245
+  \brief Type definitions and defines for Cortex-M processor based devices.
246
+*/
247
+
248
+/**
249
+  \ingroup    CMSIS_core_register
250
+  \defgroup   CMSIS_CORE  Status and Control Registers
251
+  \brief      Core Register type definitions.
252
+  @{
253
+ */
254
+
255
+/**
256
+  \brief  Union type to access the Application Program Status Register (APSR).
257
+ */
258
+typedef union
259
+{
260
+  struct
261
+  {
262
+    uint32_t _reserved0:28;              /*!< bit:  0..27  Reserved */
263
+    uint32_t V:1;                        /*!< bit:     28  Overflow condition code flag */
264
+    uint32_t C:1;                        /*!< bit:     29  Carry condition code flag */
265
+    uint32_t Z:1;                        /*!< bit:     30  Zero condition code flag */
266
+    uint32_t N:1;                        /*!< bit:     31  Negative condition code flag */
267
+  } b;                                   /*!< Structure used for bit  access */
268
+  uint32_t w;                            /*!< Type      used for word access */
269
+} APSR_Type;
270
+
271
+/* APSR Register Definitions */
272
+#define APSR_N_Pos                         31U                                            /*!< APSR: N Position */
273
+#define APSR_N_Msk                         (1UL << APSR_N_Pos)                            /*!< APSR: N Mask */
274
+
275
+#define APSR_Z_Pos                         30U                                            /*!< APSR: Z Position */
276
+#define APSR_Z_Msk                         (1UL << APSR_Z_Pos)                            /*!< APSR: Z Mask */
277
+
278
+#define APSR_C_Pos                         29U                                            /*!< APSR: C Position */
279
+#define APSR_C_Msk                         (1UL << APSR_C_Pos)                            /*!< APSR: C Mask */
280
+
281
+#define APSR_V_Pos                         28U                                            /*!< APSR: V Position */
282
+#define APSR_V_Msk                         (1UL << APSR_V_Pos)                            /*!< APSR: V Mask */
283
+
284
+
285
+/**
286
+  \brief  Union type to access the Interrupt Program Status Register (IPSR).
287
+ */
288
+typedef union
289
+{
290
+  struct
291
+  {
292
+    uint32_t ISR:9;                      /*!< bit:  0.. 8  Exception number */
293
+    uint32_t _reserved0:23;              /*!< bit:  9..31  Reserved */
294
+  } b;                                   /*!< Structure used for bit  access */
295
+  uint32_t w;                            /*!< Type      used for word access */
296
+} IPSR_Type;
297
+
298
+/* IPSR Register Definitions */
299
+#define IPSR_ISR_Pos                        0U                                            /*!< IPSR: ISR Position */
300
+#define IPSR_ISR_Msk                       (0x1FFUL /*<< IPSR_ISR_Pos*/)                  /*!< IPSR: ISR Mask */
301
+
302
+
303
+/**
304
+  \brief  Union type to access the Special-Purpose Program Status Registers (xPSR).
305
+ */
306
+typedef union
307
+{
308
+  struct
309
+  {
310
+    uint32_t ISR:9;                      /*!< bit:  0.. 8  Exception number */
311
+    uint32_t _reserved0:15;              /*!< bit:  9..23  Reserved */
312
+    uint32_t T:1;                        /*!< bit:     24  Thumb bit        (read 0) */
313
+    uint32_t _reserved1:3;               /*!< bit: 25..27  Reserved */
314
+    uint32_t V:1;                        /*!< bit:     28  Overflow condition code flag */
315
+    uint32_t C:1;                        /*!< bit:     29  Carry condition code flag */
316
+    uint32_t Z:1;                        /*!< bit:     30  Zero condition code flag */
317
+    uint32_t N:1;                        /*!< bit:     31  Negative condition code flag */
318
+  } b;                                   /*!< Structure used for bit  access */
319
+  uint32_t w;                            /*!< Type      used for word access */
320
+} xPSR_Type;
321
+
322
+/* xPSR Register Definitions */
323
+#define xPSR_N_Pos                         31U                                            /*!< xPSR: N Position */
324
+#define xPSR_N_Msk                         (1UL << xPSR_N_Pos)                            /*!< xPSR: N Mask */
325
+
326
+#define xPSR_Z_Pos                         30U                                            /*!< xPSR: Z Position */
327
+#define xPSR_Z_Msk                         (1UL << xPSR_Z_Pos)                            /*!< xPSR: Z Mask */
328
+
329
+#define xPSR_C_Pos                         29U                                            /*!< xPSR: C Position */
330
+#define xPSR_C_Msk                         (1UL << xPSR_C_Pos)                            /*!< xPSR: C Mask */
331
+
332
+#define xPSR_V_Pos                         28U                                            /*!< xPSR: V Position */
333
+#define xPSR_V_Msk                         (1UL << xPSR_V_Pos)                            /*!< xPSR: V Mask */
334
+
335
+#define xPSR_T_Pos                         24U                                            /*!< xPSR: T Position */
336
+#define xPSR_T_Msk                         (1UL << xPSR_T_Pos)                            /*!< xPSR: T Mask */
337
+
338
+#define xPSR_ISR_Pos                        0U                                            /*!< xPSR: ISR Position */
339
+#define xPSR_ISR_Msk                       (0x1FFUL /*<< xPSR_ISR_Pos*/)                  /*!< xPSR: ISR Mask */
340
+
341
+
342
+/**
343
+  \brief  Union type to access the Control Registers (CONTROL).
344
+ */
345
+typedef union
346
+{
347
+  struct
348
+  {
349
+    uint32_t nPRIV:1;                    /*!< bit:      0  Execution privilege in Thread mode */
350
+    uint32_t SPSEL:1;                    /*!< bit:      1  Stack to be used */
351
+    uint32_t _reserved1:30;              /*!< bit:  2..31  Reserved */
352
+  } b;                                   /*!< Structure used for bit  access */
353
+  uint32_t w;                            /*!< Type      used for word access */
354
+} CONTROL_Type;
355
+
356
+/* CONTROL Register Definitions */
357
+#define CONTROL_SPSEL_Pos                   1U                                            /*!< CONTROL: SPSEL Position */
358
+#define CONTROL_SPSEL_Msk                  (1UL << CONTROL_SPSEL_Pos)                     /*!< CONTROL: SPSEL Mask */
359
+
360
+#define CONTROL_nPRIV_Pos                   0U                                            /*!< CONTROL: nPRIV Position */
361
+#define CONTROL_nPRIV_Msk                  (1UL /*<< CONTROL_nPRIV_Pos*/)                 /*!< CONTROL: nPRIV Mask */
362
+
363
+/*@} end of group CMSIS_CORE */
364
+
365
+
366
+/**
367
+  \ingroup    CMSIS_core_register
368
+  \defgroup   CMSIS_NVIC  Nested Vectored Interrupt Controller (NVIC)
369
+  \brief      Type definitions for the NVIC Registers
370
+  @{
371
+ */
372
+
373
+/**
374
+  \brief  Structure type to access the Nested Vectored Interrupt Controller (NVIC).
375
+ */
376
+typedef struct
377
+{
378
+  __IOM uint32_t ISER[1U];               /*!< Offset: 0x000 (R/W)  Interrupt Set Enable Register */
379
+        uint32_t RESERVED0[31U];
380
+  __IOM uint32_t ICER[1U];               /*!< Offset: 0x080 (R/W)  Interrupt Clear Enable Register */
381
+        uint32_t RSERVED1[31U];
382
+  __IOM uint32_t ISPR[1U];               /*!< Offset: 0x100 (R/W)  Interrupt Set Pending Register */
383
+        uint32_t RESERVED2[31U];
384
+  __IOM uint32_t ICPR[1U];               /*!< Offset: 0x180 (R/W)  Interrupt Clear Pending Register */
385
+        uint32_t RESERVED3[31U];
386
+        uint32_t RESERVED4[64U];
387
+  __IOM uint32_t IP[8U];                 /*!< Offset: 0x300 (R/W)  Interrupt Priority Register */
388
+}  NVIC_Type;
389
+
390
+/*@} end of group CMSIS_NVIC */
391
+
392
+
393
+/**
394
+  \ingroup  CMSIS_core_register
395
+  \defgroup CMSIS_SCB     System Control Block (SCB)
396
+  \brief    Type definitions for the System Control Block Registers
397
+  @{
398
+ */
399
+
400
+/**
401
+  \brief  Structure type to access the System Control Block (SCB).
402
+ */
403
+typedef struct
404
+{
405
+  __IM  uint32_t CPUID;                  /*!< Offset: 0x000 (R/ )  CPUID Base Register */
406
+  __IOM uint32_t ICSR;                   /*!< Offset: 0x004 (R/W)  Interrupt Control and State Register */
407
+#if (__VTOR_PRESENT == 1U)
408
+  __IOM uint32_t VTOR;                   /*!< Offset: 0x008 (R/W)  Vector Table Offset Register */
409
+#else
410
+        uint32_t RESERVED0;
411
+#endif
412
+  __IOM uint32_t AIRCR;                  /*!< Offset: 0x00C (R/W)  Application Interrupt and Reset Control Register */
413
+  __IOM uint32_t SCR;                    /*!< Offset: 0x010 (R/W)  System Control Register */
414
+  __IOM uint32_t CCR;                    /*!< Offset: 0x014 (R/W)  Configuration Control Register */
415
+        uint32_t RESERVED1;
416
+  __IOM uint32_t SHP[2U];                /*!< Offset: 0x01C (R/W)  System Handlers Priority Registers. [0] is RESERVED */
417
+  __IOM uint32_t SHCSR;                  /*!< Offset: 0x024 (R/W)  System Handler Control and State Register */
418
+} SCB_Type;
419
+
420
+/* SCB CPUID Register Definitions */
421
+#define SCB_CPUID_IMPLEMENTER_Pos          24U                                            /*!< SCB CPUID: IMPLEMENTER Position */
422
+#define SCB_CPUID_IMPLEMENTER_Msk          (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos)          /*!< SCB CPUID: IMPLEMENTER Mask */
423
+
424
+#define SCB_CPUID_VARIANT_Pos              20U                                            /*!< SCB CPUID: VARIANT Position */
425
+#define SCB_CPUID_VARIANT_Msk              (0xFUL << SCB_CPUID_VARIANT_Pos)               /*!< SCB CPUID: VARIANT Mask */
426
+
427
+#define SCB_CPUID_ARCHITECTURE_Pos         16U                                            /*!< SCB CPUID: ARCHITECTURE Position */
428
+#define SCB_CPUID_ARCHITECTURE_Msk         (0xFUL << SCB_CPUID_ARCHITECTURE_Pos)          /*!< SCB CPUID: ARCHITECTURE Mask */
429
+
430
+#define SCB_CPUID_PARTNO_Pos                4U                                            /*!< SCB CPUID: PARTNO Position */
431
+#define SCB_CPUID_PARTNO_Msk               (0xFFFUL << SCB_CPUID_PARTNO_Pos)              /*!< SCB CPUID: PARTNO Mask */
432
+
433
+#define SCB_CPUID_REVISION_Pos              0U                                            /*!< SCB CPUID: REVISION Position */
434
+#define SCB_CPUID_REVISION_Msk             (0xFUL /*<< SCB_CPUID_REVISION_Pos*/)          /*!< SCB CPUID: REVISION Mask */
435
+
436
+/* SCB Interrupt Control State Register Definitions */
437
+#define SCB_ICSR_NMIPENDSET_Pos            31U                                            /*!< SCB ICSR: NMIPENDSET Position */
438
+#define SCB_ICSR_NMIPENDSET_Msk            (1UL << SCB_ICSR_NMIPENDSET_Pos)               /*!< SCB ICSR: NMIPENDSET Mask */
439
+
440
+#define SCB_ICSR_PENDSVSET_Pos             28U                                            /*!< SCB ICSR: PENDSVSET Position */
441
+#define SCB_ICSR_PENDSVSET_Msk             (1UL << SCB_ICSR_PENDSVSET_Pos)                /*!< SCB ICSR: PENDSVSET Mask */
442
+
443
+#define SCB_ICSR_PENDSVCLR_Pos             27U                                            /*!< SCB ICSR: PENDSVCLR Position */
444
+#define SCB_ICSR_PENDSVCLR_Msk             (1UL << SCB_ICSR_PENDSVCLR_Pos)                /*!< SCB ICSR: PENDSVCLR Mask */
445
+
446
+#define SCB_ICSR_PENDSTSET_Pos             26U                                            /*!< SCB ICSR: PENDSTSET Position */
447
+#define SCB_ICSR_PENDSTSET_Msk             (1UL << SCB_ICSR_PENDSTSET_Pos)                /*!< SCB ICSR: PENDSTSET Mask */
448
+
449
+#define SCB_ICSR_PENDSTCLR_Pos             25U                                            /*!< SCB ICSR: PENDSTCLR Position */
450
+#define SCB_ICSR_PENDSTCLR_Msk             (1UL << SCB_ICSR_PENDSTCLR_Pos)                /*!< SCB ICSR: PENDSTCLR Mask */
451
+
452
+#define SCB_ICSR_ISRPREEMPT_Pos            23U                                            /*!< SCB ICSR: ISRPREEMPT Position */
453
+#define SCB_ICSR_ISRPREEMPT_Msk            (1UL << SCB_ICSR_ISRPREEMPT_Pos)               /*!< SCB ICSR: ISRPREEMPT Mask */
454
+
455
+#define SCB_ICSR_ISRPENDING_Pos            22U                                            /*!< SCB ICSR: ISRPENDING Position */
456
+#define SCB_ICSR_ISRPENDING_Msk            (1UL << SCB_ICSR_ISRPENDING_Pos)               /*!< SCB ICSR: ISRPENDING Mask */
457
+
458
+#define SCB_ICSR_VECTPENDING_Pos           12U                                            /*!< SCB ICSR: VECTPENDING Position */
459
+#define SCB_ICSR_VECTPENDING_Msk           (0x1FFUL << SCB_ICSR_VECTPENDING_Pos)          /*!< SCB ICSR: VECTPENDING Mask */
460
+
461
+#define SCB_ICSR_VECTACTIVE_Pos             0U                                            /*!< SCB ICSR: VECTACTIVE Position */
462
+#define SCB_ICSR_VECTACTIVE_Msk            (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/)       /*!< SCB ICSR: VECTACTIVE Mask */
463
+
464
+#if (__VTOR_PRESENT == 1U)
465
+/* SCB Interrupt Control State Register Definitions */
466
+#define SCB_VTOR_TBLOFF_Pos                 8U                                            /*!< SCB VTOR: TBLOFF Position */
467
+#define SCB_VTOR_TBLOFF_Msk                (0xFFFFFFUL << SCB_VTOR_TBLOFF_Pos)            /*!< SCB VTOR: TBLOFF Mask */
468
+#endif
469
+
470
+/* SCB Application Interrupt and Reset Control Register Definitions */
471
+#define SCB_AIRCR_VECTKEY_Pos              16U                                            /*!< SCB AIRCR: VECTKEY Position */
472
+#define SCB_AIRCR_VECTKEY_Msk              (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos)            /*!< SCB AIRCR: VECTKEY Mask */
473
+
474
+#define SCB_AIRCR_VECTKEYSTAT_Pos          16U                                            /*!< SCB AIRCR: VECTKEYSTAT Position */
475
+#define SCB_AIRCR_VECTKEYSTAT_Msk          (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos)        /*!< SCB AIRCR: VECTKEYSTAT Mask */
476
+
477
+#define SCB_AIRCR_ENDIANESS_Pos            15U                                            /*!< SCB AIRCR: ENDIANESS Position */
478
+#define SCB_AIRCR_ENDIANESS_Msk            (1UL << SCB_AIRCR_ENDIANESS_Pos)               /*!< SCB AIRCR: ENDIANESS Mask */
479
+
480
+#define SCB_AIRCR_SYSRESETREQ_Pos           2U                                            /*!< SCB AIRCR: SYSRESETREQ Position */
481
+#define SCB_AIRCR_SYSRESETREQ_Msk          (1UL << SCB_AIRCR_SYSRESETREQ_Pos)             /*!< SCB AIRCR: SYSRESETREQ Mask */
482
+
483
+#define SCB_AIRCR_VECTCLRACTIVE_Pos         1U                                            /*!< SCB AIRCR: VECTCLRACTIVE Position */
484
+#define SCB_AIRCR_VECTCLRACTIVE_Msk        (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos)           /*!< SCB AIRCR: VECTCLRACTIVE Mask */
485
+
486
+/* SCB System Control Register Definitions */
487
+#define SCB_SCR_SEVONPEND_Pos               4U                                            /*!< SCB SCR: SEVONPEND Position */
488
+#define SCB_SCR_SEVONPEND_Msk              (1UL << SCB_SCR_SEVONPEND_Pos)                 /*!< SCB SCR: SEVONPEND Mask */
489
+
490
+#define SCB_SCR_SLEEPDEEP_Pos               2U                                            /*!< SCB SCR: SLEEPDEEP Position */
491
+#define SCB_SCR_SLEEPDEEP_Msk              (1UL << SCB_SCR_SLEEPDEEP_Pos)                 /*!< SCB SCR: SLEEPDEEP Mask */
492
+
493
+#define SCB_SCR_SLEEPONEXIT_Pos             1U                                            /*!< SCB SCR: SLEEPONEXIT Position */
494
+#define SCB_SCR_SLEEPONEXIT_Msk            (1UL << SCB_SCR_SLEEPONEXIT_Pos)               /*!< SCB SCR: SLEEPONEXIT Mask */
495
+
496
+/* SCB Configuration Control Register Definitions */
497
+#define SCB_CCR_STKALIGN_Pos                9U                                            /*!< SCB CCR: STKALIGN Position */
498
+#define SCB_CCR_STKALIGN_Msk               (1UL << SCB_CCR_STKALIGN_Pos)                  /*!< SCB CCR: STKALIGN Mask */
499
+
500
+#define SCB_CCR_UNALIGN_TRP_Pos             3U                                            /*!< SCB CCR: UNALIGN_TRP Position */
501
+#define SCB_CCR_UNALIGN_TRP_Msk            (1UL << SCB_CCR_UNALIGN_TRP_Pos)               /*!< SCB CCR: UNALIGN_TRP Mask */
502
+
503
+/* SCB System Handler Control and State Register Definitions */
504
+#define SCB_SHCSR_SVCALLPENDED_Pos         15U                                            /*!< SCB SHCSR: SVCALLPENDED Position */
505
+#define SCB_SHCSR_SVCALLPENDED_Msk         (1UL << SCB_SHCSR_SVCALLPENDED_Pos)            /*!< SCB SHCSR: SVCALLPENDED Mask */
506
+
507
+/*@} end of group CMSIS_SCB */
508
+
509
+
510
+/**
511
+  \ingroup  CMSIS_core_register
512
+  \defgroup CMSIS_SysTick     System Tick Timer (SysTick)
513
+  \brief    Type definitions for the System Timer Registers.
514
+  @{
515
+ */
516
+
517
+/**
518
+  \brief  Structure type to access the System Timer (SysTick).
519
+ */
520
+typedef struct
521
+{
522
+  __IOM uint32_t CTRL;                   /*!< Offset: 0x000 (R/W)  SysTick Control and Status Register */
523
+  __IOM uint32_t LOAD;                   /*!< Offset: 0x004 (R/W)  SysTick Reload Value Register */
524
+  __IOM uint32_t VAL;                    /*!< Offset: 0x008 (R/W)  SysTick Current Value Register */
525
+  __IM  uint32_t CALIB;                  /*!< Offset: 0x00C (R/ )  SysTick Calibration Register */
526
+} SysTick_Type;
527
+
528
+/* SysTick Control / Status Register Definitions */
529
+#define SysTick_CTRL_COUNTFLAG_Pos         16U                                            /*!< SysTick CTRL: COUNTFLAG Position */
530
+#define SysTick_CTRL_COUNTFLAG_Msk         (1UL << SysTick_CTRL_COUNTFLAG_Pos)            /*!< SysTick CTRL: COUNTFLAG Mask */
531
+
532
+#define SysTick_CTRL_CLKSOURCE_Pos          2U                                            /*!< SysTick CTRL: CLKSOURCE Position */
533
+#define SysTick_CTRL_CLKSOURCE_Msk         (1UL << SysTick_CTRL_CLKSOURCE_Pos)            /*!< SysTick CTRL: CLKSOURCE Mask */
534
+
535
+#define SysTick_CTRL_TICKINT_Pos            1U                                            /*!< SysTick CTRL: TICKINT Position */
536
+#define SysTick_CTRL_TICKINT_Msk           (1UL << SysTick_CTRL_TICKINT_Pos)              /*!< SysTick CTRL: TICKINT Mask */
537
+
538
+#define SysTick_CTRL_ENABLE_Pos             0U                                            /*!< SysTick CTRL: ENABLE Position */
539
+#define SysTick_CTRL_ENABLE_Msk            (1UL /*<< SysTick_CTRL_ENABLE_Pos*/)           /*!< SysTick CTRL: ENABLE Mask */
540
+
541
+/* SysTick Reload Register Definitions */
542
+#define SysTick_LOAD_RELOAD_Pos             0U                                            /*!< SysTick LOAD: RELOAD Position */
543
+#define SysTick_LOAD_RELOAD_Msk            (0xFFFFFFUL /*<< SysTick_LOAD_RELOAD_Pos*/)    /*!< SysTick LOAD: RELOAD Mask */
544
+
545
+/* SysTick Current Register Definitions */
546
+#define SysTick_VAL_CURRENT_Pos             0U                                            /*!< SysTick VAL: CURRENT Position */
547
+#define SysTick_VAL_CURRENT_Msk            (0xFFFFFFUL /*<< SysTick_VAL_CURRENT_Pos*/)    /*!< SysTick VAL: CURRENT Mask */
548
+
549
+/* SysTick Calibration Register Definitions */
550
+#define SysTick_CALIB_NOREF_Pos            31U                                            /*!< SysTick CALIB: NOREF Position */
551
+#define SysTick_CALIB_NOREF_Msk            (1UL << SysTick_CALIB_NOREF_Pos)               /*!< SysTick CALIB: NOREF Mask */
552
+
553
+#define SysTick_CALIB_SKEW_Pos             30U                                            /*!< SysTick CALIB: SKEW Position */
554
+#define SysTick_CALIB_SKEW_Msk             (1UL << SysTick_CALIB_SKEW_Pos)                /*!< SysTick CALIB: SKEW Mask */
555
+
556
+#define SysTick_CALIB_TENMS_Pos             0U                                            /*!< SysTick CALIB: TENMS Position */
557
+#define SysTick_CALIB_TENMS_Msk            (0xFFFFFFUL /*<< SysTick_CALIB_TENMS_Pos*/)    /*!< SysTick CALIB: TENMS Mask */
558
+
559
+/*@} end of group CMSIS_SysTick */
560
+
561
+#if (__MPU_PRESENT == 1U)
562
+/**
563
+  \ingroup  CMSIS_core_register
564
+  \defgroup CMSIS_MPU     Memory Protection Unit (MPU)
565
+  \brief    Type definitions for the Memory Protection Unit (MPU)
566
+  @{
567
+ */
568
+
569
+/**
570
+  \brief  Structure type to access the Memory Protection Unit (MPU).
571
+ */
572
+typedef struct
573
+{
574
+  __IM  uint32_t TYPE;                   /*!< Offset: 0x000 (R/ )  MPU Type Register */
575
+  __IOM uint32_t CTRL;                   /*!< Offset: 0x004 (R/W)  MPU Control Register */
576
+  __IOM uint32_t RNR;                    /*!< Offset: 0x008 (R/W)  MPU Region RNRber Register */
577
+  __IOM uint32_t RBAR;                   /*!< Offset: 0x00C (R/W)  MPU Region Base Address Register */
578
+  __IOM uint32_t RASR;                   /*!< Offset: 0x010 (R/W)  MPU Region Attribute and Size Register */
579
+} MPU_Type;
580
+
581
+/* MPU Type Register Definitions */
582
+#define MPU_TYPE_IREGION_Pos               16U                                            /*!< MPU TYPE: IREGION Position */
583
+#define MPU_TYPE_IREGION_Msk               (0xFFUL << MPU_TYPE_IREGION_Pos)               /*!< MPU TYPE: IREGION Mask */
584
+
585
+#define MPU_TYPE_DREGION_Pos                8U                                            /*!< MPU TYPE: DREGION Position */
586
+#define MPU_TYPE_DREGION_Msk               (0xFFUL << MPU_TYPE_DREGION_Pos)               /*!< MPU TYPE: DREGION Mask */
587
+
588
+#define MPU_TYPE_SEPARATE_Pos               0U                                            /*!< MPU TYPE: SEPARATE Position */
589
+#define MPU_TYPE_SEPARATE_Msk              (1UL /*<< MPU_TYPE_SEPARATE_Pos*/)             /*!< MPU TYPE: SEPARATE Mask */
590
+
591
+/* MPU Control Register Definitions */
592
+#define MPU_CTRL_PRIVDEFENA_Pos             2U                                            /*!< MPU CTRL: PRIVDEFENA Position */
593
+#define MPU_CTRL_PRIVDEFENA_Msk            (1UL << MPU_CTRL_PRIVDEFENA_Pos)               /*!< MPU CTRL: PRIVDEFENA Mask */
594
+
595
+#define MPU_CTRL_HFNMIENA_Pos               1U                                            /*!< MPU CTRL: HFNMIENA Position */
596
+#define MPU_CTRL_HFNMIENA_Msk              (1UL << MPU_CTRL_HFNMIENA_Pos)                 /*!< MPU CTRL: HFNMIENA Mask */
597
+
598
+#define MPU_CTRL_ENABLE_Pos                 0U                                            /*!< MPU CTRL: ENABLE Position */
599
+#define MPU_CTRL_ENABLE_Msk                (1UL /*<< MPU_CTRL_ENABLE_Pos*/)               /*!< MPU CTRL: ENABLE Mask */
600
+
601
+/* MPU Region Number Register Definitions */
602
+#define MPU_RNR_REGION_Pos                  0U                                            /*!< MPU RNR: REGION Position */
603
+#define MPU_RNR_REGION_Msk                 (0xFFUL /*<< MPU_RNR_REGION_Pos*/)             /*!< MPU RNR: REGION Mask */
604
+
605
+/* MPU Region Base Address Register Definitions */
606
+#define MPU_RBAR_ADDR_Pos                   8U                                            /*!< MPU RBAR: ADDR Position */
607
+#define MPU_RBAR_ADDR_Msk                  (0xFFFFFFUL << MPU_RBAR_ADDR_Pos)              /*!< MPU RBAR: ADDR Mask */
608
+
609
+#define MPU_RBAR_VALID_Pos                  4U                                            /*!< MPU RBAR: VALID Position */
610
+#define MPU_RBAR_VALID_Msk                 (1UL << MPU_RBAR_VALID_Pos)                    /*!< MPU RBAR: VALID Mask */
611
+
612
+#define MPU_RBAR_REGION_Pos                 0U                                            /*!< MPU RBAR: REGION Position */
613
+#define MPU_RBAR_REGION_Msk                (0xFUL /*<< MPU_RBAR_REGION_Pos*/)             /*!< MPU RBAR: REGION Mask */
614
+
615
+/* MPU Region Attribute and Size Register Definitions */
616
+#define MPU_RASR_ATTRS_Pos                 16U                                            /*!< MPU RASR: MPU Region Attribute field Position */
617
+#define MPU_RASR_ATTRS_Msk                 (0xFFFFUL << MPU_RASR_ATTRS_Pos)               /*!< MPU RASR: MPU Region Attribute field Mask */
618
+
619
+#define MPU_RASR_XN_Pos                    28U                                            /*!< MPU RASR: ATTRS.XN Position */
620
+#define MPU_RASR_XN_Msk                    (1UL << MPU_RASR_XN_Pos)                       /*!< MPU RASR: ATTRS.XN Mask */
621
+
622
+#define MPU_RASR_AP_Pos                    24U                                            /*!< MPU RASR: ATTRS.AP Position */
623
+#define MPU_RASR_AP_Msk                    (0x7UL << MPU_RASR_AP_Pos)                     /*!< MPU RASR: ATTRS.AP Mask */
624
+
625
+#define MPU_RASR_TEX_Pos                   19U                                            /*!< MPU RASR: ATTRS.TEX Position */
626
+#define MPU_RASR_TEX_Msk                   (0x7UL << MPU_RASR_TEX_Pos)                    /*!< MPU RASR: ATTRS.TEX Mask */
627
+
628
+#define MPU_RASR_S_Pos                     18U                                            /*!< MPU RASR: ATTRS.S Position */
629
+#define MPU_RASR_S_Msk                     (1UL << MPU_RASR_S_Pos)                        /*!< MPU RASR: ATTRS.S Mask */
630
+
631
+#define MPU_RASR_C_Pos                     17U                                            /*!< MPU RASR: ATTRS.C Position */
632
+#define MPU_RASR_C_Msk                     (1UL << MPU_RASR_C_Pos)                        /*!< MPU RASR: ATTRS.C Mask */
633
+
634
+#define MPU_RASR_B_Pos                     16U                                            /*!< MPU RASR: ATTRS.B Position */
635
+#define MPU_RASR_B_Msk                     (1UL << MPU_RASR_B_Pos)                        /*!< MPU RASR: ATTRS.B Mask */
636
+
637
+#define MPU_RASR_SRD_Pos                    8U                                            /*!< MPU RASR: Sub-Region Disable Position */
638
+#define MPU_RASR_SRD_Msk                   (0xFFUL << MPU_RASR_SRD_Pos)                   /*!< MPU RASR: Sub-Region Disable Mask */
639
+
640
+#define MPU_RASR_SIZE_Pos                   1U                                            /*!< MPU RASR: Region Size Field Position */
641
+#define MPU_RASR_SIZE_Msk                  (0x1FUL << MPU_RASR_SIZE_Pos)                  /*!< MPU RASR: Region Size Field Mask */
642
+
643
+#define MPU_RASR_ENABLE_Pos                 0U                                            /*!< MPU RASR: Region enable bit Position */
644
+#define MPU_RASR_ENABLE_Msk                (1UL /*<< MPU_RASR_ENABLE_Pos*/)               /*!< MPU RASR: Region enable bit Disable Mask */
645
+
646
+/*@} end of group CMSIS_MPU */
647
+#endif
648
+
649
+
650
+/**
651
+  \ingroup  CMSIS_core_register
652
+  \defgroup CMSIS_CoreDebug       Core Debug Registers (CoreDebug)
653
+  \brief    Cortex-M0+ Core Debug Registers (DCB registers, SHCSR, and DFSR) are only accessible over DAP and not via processor.
654
+            Therefore they are not covered by the Cortex-M0+ header file.
655
+  @{
656
+ */
657
+/*@} end of group CMSIS_CoreDebug */
658
+
659
+
660
+/**
661
+  \ingroup    CMSIS_core_register
662
+  \defgroup   CMSIS_core_bitfield     Core register bit field macros
663
+  \brief      Macros for use with bit field definitions (xxx_Pos, xxx_Msk).
664
+  @{
665
+ */
666
+
667
+/**
668
+  \brief   Mask and shift a bit field value for use in a register bit range.
669
+  \param[in] field  Name of the register bit field.
670
+  \param[in] value  Value of the bit field.
671
+  \return           Masked and shifted value.
672
+*/
673
+#define _VAL2FLD(field, value)    ((value << field ## _Pos) & field ## _Msk)
674
+
675
+/**
676
+  \brief     Mask and shift a register value to extract a bit filed value.
677
+  \param[in] field  Name of the register bit field.
678
+  \param[in] value  Value of register.
679
+  \return           Masked and shifted bit field value.
680
+*/
681
+#define _FLD2VAL(field, value)    ((value & field ## _Msk) >> field ## _Pos)
682
+
683
+/*@} end of group CMSIS_core_bitfield */
684
+
685
+
686
+/**
687
+  \ingroup    CMSIS_core_register
688
+  \defgroup   CMSIS_core_base     Core Definitions
689
+  \brief      Definitions for base addresses, unions, and structures.
690
+  @{
691
+ */
692
+
693
+/* Memory mapping of Cortex-M0+ Hardware */
694
+#define SCS_BASE            (0xE000E000UL)                            /*!< System Control Space Base Address */
695
+#define SysTick_BASE        (SCS_BASE +  0x0010UL)                    /*!< SysTick Base Address */
696
+#define NVIC_BASE           (SCS_BASE +  0x0100UL)                    /*!< NVIC Base Address */
697
+#define SCB_BASE            (SCS_BASE +  0x0D00UL)                    /*!< System Control Block Base Address */
698
+
699
+#define SCB                 ((SCB_Type       *)     SCB_BASE      )   /*!< SCB configuration struct */
700
+#define SysTick             ((SysTick_Type   *)     SysTick_BASE  )   /*!< SysTick configuration struct */
701
+#define NVIC                ((NVIC_Type      *)     NVIC_BASE     )   /*!< NVIC configuration struct */
702
+
703
+#if (__MPU_PRESENT == 1U)
704
+  #define MPU_BASE          (SCS_BASE +  0x0D90UL)                    /*!< Memory Protection Unit */
705
+  #define MPU               ((MPU_Type       *)     MPU_BASE      )   /*!< Memory Protection Unit */
706
+#endif
707
+
708
+/*@} */
709
+
710
+
711
+
712
+/*******************************************************************************
713
+ *                Hardware Abstraction Layer
714
+  Core Function Interface contains:
715
+  - Core NVIC Functions
716
+  - Core SysTick Functions
717
+  - Core Register Access Functions
718
+ ******************************************************************************/
719
+/**
720
+  \defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference
721
+*/
722
+
723
+
724
+
725
+/* ##########################   NVIC functions  #################################### */
726
+/**
727
+  \ingroup  CMSIS_Core_FunctionInterface
728
+  \defgroup CMSIS_Core_NVICFunctions NVIC Functions
729
+  \brief    Functions that manage interrupts and exceptions via the NVIC.
730
+  @{
731
+ */
732
+
733
+/* Interrupt Priorities are WORD accessible only under ARMv6M                   */
734
+/* The following MACROS handle generation of the register offset and byte masks */
735
+#define _BIT_SHIFT(IRQn)         (  ((((uint32_t)(int32_t)(IRQn))         )      &  0x03UL) * 8UL)
736
+#define _SHP_IDX(IRQn)           ( (((((uint32_t)(int32_t)(IRQn)) & 0x0FUL)-8UL) >>    2UL)      )
737
+#define _IP_IDX(IRQn)            (   (((uint32_t)(int32_t)(IRQn))                >>    2UL)      )
738
+
739
+
740
+/**
741
+  \brief   Enable External Interrupt
742
+  \details Enables a device-specific interrupt in the NVIC interrupt controller.
743
+  \param [in]      IRQn  External interrupt number. Value cannot be negative.
744
+ */
745
+__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
746
+{
747
+  NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
748
+}
749
+
750
+
751
+/**
752
+  \brief   Disable External Interrupt
753
+  \details Disables a device-specific interrupt in the NVIC interrupt controller.
754
+  \param [in]      IRQn  External interrupt number. Value cannot be negative.
755
+ */
756
+__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
757
+{
758
+  NVIC->ICER[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
759
+}
760
+
761
+
762
+/**
763
+  \brief   Get Pending Interrupt
764
+  \details Reads the pending register in the NVIC and returns the pending bit for the specified interrupt.
765
+  \param [in]      IRQn  Interrupt number.
766
+  \return             0  Interrupt status is not pending.
767
+  \return             1  Interrupt status is pending.
768
+ */
769
+__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
770
+{
771
+  return((uint32_t)(((NVIC->ISPR[0U] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
772
+}
773
+
774
+
775
+/**
776
+  \brief   Set Pending Interrupt
777
+  \details Sets the pending bit of an external interrupt.
778
+  \param [in]      IRQn  Interrupt number. Value cannot be negative.
779
+ */
780
+__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
781
+{
782
+  NVIC->ISPR[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
783
+}
784
+
785
+
786
+/**
787
+  \brief   Clear Pending Interrupt
788
+  \details Clears the pending bit of an external interrupt.
789
+  \param [in]      IRQn  External interrupt number. Value cannot be negative.
790
+ */
791
+__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
792
+{
793
+  NVIC->ICPR[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
794
+}
795
+
796
+
797
+/**
798
+  \brief   Set Interrupt Priority
799
+  \details Sets the priority of an interrupt.
800
+  \note    The priority cannot be set for every core interrupt.
801
+  \param [in]      IRQn  Interrupt number.
802
+  \param [in]  priority  Priority to set.
803
+ */
804
+__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
805
+{
806
+  if ((int32_t)(IRQn) < 0)
807
+  {
808
+    SCB->SHP[_SHP_IDX(IRQn)] = ((uint32_t)(SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
809
+       (((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
810
+  }
811
+  else
812
+  {
813
+    NVIC->IP[_IP_IDX(IRQn)]  = ((uint32_t)(NVIC->IP[_IP_IDX(IRQn)]  & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
814
+       (((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
815
+  }
816
+}
817
+
818
+
819
+/**
820
+  \brief   Get Interrupt Priority
821
+  \details Reads the priority of an interrupt.
822
+           The interrupt number can be positive to specify an external (device specific) interrupt,
823
+           or negative to specify an internal (core) interrupt.
824
+  \param [in]   IRQn  Interrupt number.
825
+  \return             Interrupt Priority.
826
+                      Value is aligned automatically to the implemented priority bits of the microcontroller.
827
+ */
828
+__STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
829
+{
830
+
831
+  if ((int32_t)(IRQn) < 0)
832
+  {
833
+    return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
834
+  }
835
+  else
836
+  {
837
+    return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
838
+  }
839
+}
840
+
841
+
842
+/**
843
+  \brief   System Reset
844
+  \details Initiates a system reset request to reset the MCU.
845
+ */
846
+__STATIC_INLINE void NVIC_SystemReset(void)
847
+{
848
+  __DSB();                                                          /* Ensure all outstanding memory accesses included
849
+                                                                       buffered write are completed before reset */
850
+  SCB->AIRCR  = ((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) |
851
+                 SCB_AIRCR_SYSRESETREQ_Msk);
852
+  __DSB();                                                          /* Ensure completion of memory access */
853
+
854
+  for(;;)                                                           /* wait until reset */
855
+  {
856
+    __NOP();
857
+  }
858
+}
859
+
860
+/*@} end of CMSIS_Core_NVICFunctions */
861
+
862
+
863
+
864
+/* ##################################    SysTick function  ############################################ */
865
+/**
866
+  \ingroup  CMSIS_Core_FunctionInterface
867
+  \defgroup CMSIS_Core_SysTickFunctions SysTick Functions
868
+  \brief    Functions that configure the System.
869
+  @{
870
+ */
871
+
872
+#if (__Vendor_SysTickConfig == 0U)
873
+
874
+/**
875
+  \brief   System Tick Configuration
876
+  \details Initializes the System Timer and its interrupt, and starts the System Tick Timer.
877
+           Counter is in free running mode to generate periodic interrupts.
878
+  \param [in]  ticks  Number of ticks between two interrupts.
879
+  \return          0  Function succeeded.
880
+  \return          1  Function failed.
881
+  \note    When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then the
882
+           function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b>
883
+           must contain a vendor-specific implementation of this function.
884
+ */
885
+__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
886
+{
887
+  if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk)
888
+  {
889
+    return (1UL);                                                   /* Reload value impossible */
890
+  }
891
+
892
+  SysTick->LOAD  = (uint32_t)(ticks - 1UL);                         /* set reload register */
893
+  NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */
894
+  SysTick->VAL   = 0UL;                                             /* Load the SysTick Counter Value */
895
+  SysTick->CTRL  = SysTick_CTRL_CLKSOURCE_Msk |
896
+                   SysTick_CTRL_TICKINT_Msk   |
897
+                   SysTick_CTRL_ENABLE_Msk;                         /* Enable SysTick IRQ and SysTick Timer */
898
+  return (0UL);                                                     /* Function successful */
899
+}
900
+
901
+#endif
902
+
903
+/*@} end of CMSIS_Core_SysTickFunctions */
904
+
905
+
906
+
907
+
908
+#ifdef __cplusplus
909
+}
910
+#endif
911
+
912
+#endif /* __CORE_CM0PLUS_H_DEPENDANT */
913
+
914
+#endif /* __CMSIS_GENERIC */

Разлика између датотеке није приказан због своје велике величине
+ 1763 - 0
Drivers/CMSIS/Include/core_cm3.h


Разлика између датотеке није приказан због своје велике величине
+ 1937 - 0
Drivers/CMSIS/Include/core_cm4.h


Разлика између датотеке није приказан због своје велике величине
+ 2512 - 0
Drivers/CMSIS/Include/core_cm7.h


+ 87 - 0
Drivers/CMSIS/Include/core_cmFunc.h

@@ -0,0 +1,87 @@
1
+/**************************************************************************//**
2
+ * @file     core_cmFunc.h
3
+ * @brief    CMSIS Cortex-M Core Function Access Header File
4
+ * @version  V4.30
5
+ * @date     20. October 2015
6
+ ******************************************************************************/
7
+/* Copyright (c) 2009 - 2015 ARM LIMITED
8
+
9
+   All rights reserved.
10
+   Redistribution and use in source and binary forms, with or without
11
+   modification, are permitted provided that the following conditions are met:
12
+   - Redistributions of source code must retain the above copyright
13
+     notice, this list of conditions and the following disclaimer.
14
+   - Redistributions in binary form must reproduce the above copyright
15
+     notice, this list of conditions and the following disclaimer in the
16
+     documentation and/or other materials provided with the distribution.
17
+   - Neither the name of ARM nor the names of its contributors may be used
18
+     to endorse or promote products derived from this software without
19
+     specific prior written permission.
20
+   *
21
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
+   ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
25
+   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26
+   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
+   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
+   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
+   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
+   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
+   POSSIBILITY OF SUCH DAMAGE.
32
+   ---------------------------------------------------------------------------*/
33
+
34
+
35
+#if   defined ( __ICCARM__ )
36
+ #pragma system_include         /* treat file as system include file for MISRA check */
37
+#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
38
+  #pragma clang system_header   /* treat file as system include file */
39
+#endif
40
+
41
+#ifndef __CORE_CMFUNC_H
42
+#define __CORE_CMFUNC_H
43
+
44
+
45
+/* ###########################  Core Function Access  ########################### */
46
+/** \ingroup  CMSIS_Core_FunctionInterface
47
+    \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
48
+  @{
49
+*/
50
+
51
+/*------------------ RealView Compiler -----------------*/
52
+#if   defined ( __CC_ARM )
53
+  #include "cmsis_armcc.h"
54
+
55
+/*------------------ ARM Compiler V6 -------------------*/
56
+#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
57
+  #include "cmsis_armcc_V6.h"
58
+
59
+/*------------------ GNU Compiler ----------------------*/
60
+#elif defined ( __GNUC__ )
61
+  #include "cmsis_gcc.h"
62
+
63
+/*------------------ ICC Compiler ----------------------*/
64
+#elif defined ( __ICCARM__ )
65
+  #include <cmsis_iar.h>
66
+
67
+/*------------------ TI CCS Compiler -------------------*/
68
+#elif defined ( __TMS470__ )
69
+  #include <cmsis_ccs.h>
70
+
71
+/*------------------ TASKING Compiler ------------------*/
72
+#elif defined ( __TASKING__ )
73
+  /*
74
+   * The CMSIS functions have been implemented as intrinsics in the compiler.
75
+   * Please use "carm -?i" to get an up to date list of all intrinsics,
76
+   * Including the CMSIS ones.
77
+   */
78
+
79
+/*------------------ COSMIC Compiler -------------------*/
80
+#elif defined ( __CSMC__ )
81
+  #include <cmsis_csm.h>
82
+
83
+#endif
84
+
85
+/*@} end of CMSIS_Core_RegAccFunctions */
86
+
87
+#endif /* __CORE_CMFUNC_H */

+ 87 - 0
Drivers/CMSIS/Include/core_cmInstr.h

@@ -0,0 +1,87 @@
1
+/**************************************************************************//**
2
+ * @file     core_cmInstr.h
3
+ * @brief    CMSIS Cortex-M Core Instruction Access Header File
4
+ * @version  V4.30
5
+ * @date     20. October 2015
6
+ ******************************************************************************/
7
+/* Copyright (c) 2009 - 2015 ARM LIMITED
8
+
9
+   All rights reserved.
10
+   Redistribution and use in source and binary forms, with or without
11
+   modification, are permitted provided that the following conditions are met:
12
+   - Redistributions of source code must retain the above copyright
13
+     notice, this list of conditions and the following disclaimer.
14
+   - Redistributions in binary form must reproduce the above copyright
15
+     notice, this list of conditions and the following disclaimer in the
16
+     documentation and/or other materials provided with the distribution.
17
+   - Neither the name of ARM nor the names of its contributors may be used
18
+     to endorse or promote products derived from this software without
19
+     specific prior written permission.
20
+   *
21
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
+   ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
25
+   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26
+   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
+   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
+   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
+   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
+   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
+   POSSIBILITY OF SUCH DAMAGE.
32
+   ---------------------------------------------------------------------------*/
33
+
34
+
35
+#if   defined ( __ICCARM__ )
36
+ #pragma system_include         /* treat file as system include file for MISRA check */
37
+#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
38
+  #pragma clang system_header   /* treat file as system include file */
39
+#endif
40
+
41
+#ifndef __CORE_CMINSTR_H
42
+#define __CORE_CMINSTR_H
43
+
44
+
45
+/* ##########################  Core Instruction Access  ######################### */
46
+/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
47
+  Access to dedicated instructions
48
+  @{
49
+*/
50
+
51
+/*------------------ RealView Compiler -----------------*/
52
+#if   defined ( __CC_ARM )
53
+  #include "cmsis_armcc.h"
54
+
55
+/*------------------ ARM Compiler V6 -------------------*/
56
+#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
57
+  #include "cmsis_armcc_V6.h"
58
+
59
+/*------------------ GNU Compiler ----------------------*/
60
+#elif defined ( __GNUC__ )
61
+  #include "cmsis_gcc.h"
62
+
63
+/*------------------ ICC Compiler ----------------------*/
64
+#elif defined ( __ICCARM__ )
65
+  #include <cmsis_iar.h>
66
+
67
+/*------------------ TI CCS Compiler -------------------*/
68
+#elif defined ( __TMS470__ )
69
+  #include <cmsis_ccs.h>
70
+
71
+/*------------------ TASKING Compiler ------------------*/
72
+#elif defined ( __TASKING__ )
73
+  /*
74
+   * The CMSIS functions have been implemented as intrinsics in the compiler.
75
+   * Please use "carm -?i" to get an up to date list of all intrinsics,
76
+   * Including the CMSIS ones.
77
+   */
78
+
79
+/*------------------ COSMIC Compiler -------------------*/
80
+#elif defined ( __CSMC__ )
81
+  #include <cmsis_csm.h>
82
+
83
+#endif
84
+
85
+/*@}*/ /* end of group CMSIS_Core_InstructionInterface */
86
+
87
+#endif /* __CORE_CMINSTR_H */

+ 96 - 0
Drivers/CMSIS/Include/core_cmSimd.h

@@ -0,0 +1,96 @@
1
+/**************************************************************************//**
2
+ * @file     core_cmSimd.h
3
+ * @brief    CMSIS Cortex-M SIMD Header File
4
+ * @version  V4.30
5
+ * @date     20. October 2015
6
+ ******************************************************************************/
7
+/* Copyright (c) 2009 - 2015 ARM LIMITED
8
+
9
+   All rights reserved.
10
+   Redistribution and use in source and binary forms, with or without
11
+   modification, are permitted provided that the following conditions are met:
12
+   - Redistributions of source code must retain the above copyright
13
+     notice, this list of conditions and the following disclaimer.
14
+   - Redistributions in binary form must reproduce the above copyright
15
+     notice, this list of conditions and the following disclaimer in the
16
+     documentation and/or other materials provided with the distribution.
17
+   - Neither the name of ARM nor the names of its contributors may be used
18
+     to endorse or promote products derived from this software without
19
+     specific prior written permission.
20
+   *
21
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
+   ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
25
+   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26
+   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
+   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
+   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
+   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
+   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
+   POSSIBILITY OF SUCH DAMAGE.
32
+   ---------------------------------------------------------------------------*/
33
+
34
+
35
+#if   defined ( __ICCARM__ )
36
+ #pragma system_include         /* treat file as system include file for MISRA check */
37
+#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
38
+  #pragma clang system_header   /* treat file as system include file */
39
+#endif
40
+
41
+#ifndef __CORE_CMSIMD_H
42
+#define __CORE_CMSIMD_H
43
+
44
+#ifdef __cplusplus
45
+ extern "C" {
46
+#endif
47
+
48
+
49
+/* ###################  Compiler specific Intrinsics  ########################### */
50
+/** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
51
+  Access to dedicated SIMD instructions
52
+  @{
53
+*/
54
+
55
+/*------------------ RealView Compiler -----------------*/
56
+#if   defined ( __CC_ARM )
57
+  #include "cmsis_armcc.h"
58
+
59
+/*------------------ ARM Compiler V6 -------------------*/
60
+#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
61
+  #include "cmsis_armcc_V6.h"
62
+
63
+/*------------------ GNU Compiler ----------------------*/
64
+#elif defined ( __GNUC__ )
65
+  #include "cmsis_gcc.h"
66
+
67
+/*------------------ ICC Compiler ----------------------*/
68
+#elif defined ( __ICCARM__ )
69
+  #include <cmsis_iar.h>
70
+
71
+/*------------------ TI CCS Compiler -------------------*/
72
+#elif defined ( __TMS470__ )
73
+  #include <cmsis_ccs.h>
74
+
75
+/*------------------ TASKING Compiler ------------------*/
76
+#elif defined ( __TASKING__ )
77
+  /*
78
+   * The CMSIS functions have been implemented as intrinsics in the compiler.
79
+   * Please use "carm -?i" to get an up to date list of all intrinsics,
80
+   * Including the CMSIS ones.
81
+   */
82
+
83
+/*------------------ COSMIC Compiler -------------------*/
84
+#elif defined ( __CSMC__ )
85
+  #include <cmsis_csm.h>
86
+
87
+#endif
88
+
89
+/*@} end of group CMSIS_SIMD_intrinsics */
90
+
91
+
92
+#ifdef __cplusplus
93
+}
94
+#endif
95
+
96
+#endif /* __CORE_CMSIMD_H */

+ 926 - 0
Drivers/CMSIS/Include/core_sc000.h

@@ -0,0 +1,926 @@
1
+/**************************************************************************//**
2
+ * @file     core_sc000.h
3
+ * @brief    CMSIS SC000 Core Peripheral Access Layer Header File
4
+ * @version  V4.30
5
+ * @date     20. October 2015
6
+ ******************************************************************************/
7
+/* Copyright (c) 2009 - 2015 ARM LIMITED
8
+
9
+   All rights reserved.
10
+   Redistribution and use in source and binary forms, with or without
11
+   modification, are permitted provided that the following conditions are met:
12
+   - Redistributions of source code must retain the above copyright
13
+     notice, this list of conditions and the following disclaimer.
14
+   - Redistributions in binary form must reproduce the above copyright
15
+     notice, this list of conditions and the following disclaimer in the
16
+     documentation and/or other materials provided with the distribution.
17
+   - Neither the name of ARM nor the names of its contributors may be used
18
+     to endorse or promote products derived from this software without
19
+     specific prior written permission.
20
+   *
21
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
+   ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
25
+   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26
+   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
+   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
+   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
+   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
+   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
+   POSSIBILITY OF SUCH DAMAGE.
32
+   ---------------------------------------------------------------------------*/
33
+
34
+
35
+#if   defined ( __ICCARM__ )
36
+ #pragma system_include         /* treat file as system include file for MISRA check */
37
+#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
38
+  #pragma clang system_header   /* treat file as system include file */
39
+#endif
40
+
41
+#ifndef __CORE_SC000_H_GENERIC
42
+#define __CORE_SC000_H_GENERIC
43
+
44
+#include <stdint.h>
45
+
46
+#ifdef __cplusplus
47
+ extern "C" {
48
+#endif
49
+
50
+/**
51
+  \page CMSIS_MISRA_Exceptions  MISRA-C:2004 Compliance Exceptions
52
+  CMSIS violates the following MISRA-C:2004 rules:
53
+
54
+   \li Required Rule 8.5, object/function definition in header file.<br>
55
+     Function definitions in header files are used to allow 'inlining'.
56
+
57
+   \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br>
58
+     Unions are used for effective representation of core registers.
59
+
60
+   \li Advisory Rule 19.7, Function-like macro defined.<br>
61
+     Function-like macros are used to allow more efficient code.
62
+ */
63
+
64
+
65
+/*******************************************************************************
66
+ *                 CMSIS definitions
67
+ ******************************************************************************/
68
+/**
69
+  \ingroup SC000
70
+  @{
71
+ */
72
+
73
+/*  CMSIS SC000 definitions */
74
+#define __SC000_CMSIS_VERSION_MAIN  (0x04U)                                    /*!< [31:16] CMSIS HAL main version */
75
+#define __SC000_CMSIS_VERSION_SUB   (0x1EU)                                    /*!< [15:0]  CMSIS HAL sub version */
76
+#define __SC000_CMSIS_VERSION       ((__SC000_CMSIS_VERSION_MAIN << 16U) | \
77
+                                      __SC000_CMSIS_VERSION_SUB           )    /*!< CMSIS HAL version number */
78
+
79
+#define __CORTEX_SC                 (000U)                                     /*!< Cortex secure core */
80
+
81
+
82
+#if   defined ( __CC_ARM )
83
+  #define __ASM            __asm                                      /*!< asm keyword for ARM Compiler */
84
+  #define __INLINE         __inline                                   /*!< inline keyword for ARM Compiler */
85
+  #define __STATIC_INLINE  static __inline
86
+
87
+#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
88
+  #define __ASM            __asm                                      /*!< asm keyword for ARM Compiler */
89
+  #define __INLINE         __inline                                   /*!< inline keyword for ARM Compiler */
90
+  #define __STATIC_INLINE  static __inline
91
+
92
+#elif defined ( __GNUC__ )
93
+  #define __ASM            __asm                                      /*!< asm keyword for GNU Compiler */
94
+  #define __INLINE         inline                                     /*!< inline keyword for GNU Compiler */
95
+  #define __STATIC_INLINE  static inline
96
+
97
+#elif defined ( __ICCARM__ )
98
+  #define __ASM            __asm                                      /*!< asm keyword for IAR Compiler */
99
+  #define __INLINE         inline                                     /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */
100
+  #define __STATIC_INLINE  static inline
101
+
102
+#elif defined ( __TMS470__ )
103
+  #define __ASM            __asm                                      /*!< asm keyword for TI CCS Compiler */
104
+  #define __STATIC_INLINE  static inline
105
+
106
+#elif defined ( __TASKING__ )
107
+  #define __ASM            __asm                                      /*!< asm keyword for TASKING Compiler */
108
+  #define __INLINE         inline                                     /*!< inline keyword for TASKING Compiler */
109
+  #define __STATIC_INLINE  static inline
110
+
111
+#elif defined ( __CSMC__ )
112
+  #define __packed
113
+  #define __ASM            _asm                                      /*!< asm keyword for COSMIC Compiler */
114
+  #define __INLINE         inline                                    /*!< inline keyword for COSMIC Compiler. Use -pc99 on compile line */
115
+  #define __STATIC_INLINE  static inline
116
+
117
+#else
118
+  #error Unknown compiler
119
+#endif
120
+
121
+/** __FPU_USED indicates whether an FPU is used or not.
122
+    This core does not support an FPU at all
123
+*/
124
+#define __FPU_USED       0U
125
+
126
+#if defined ( __CC_ARM )
127
+  #if defined __TARGET_FPU_VFP
128
+    #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
129
+  #endif
130
+
131
+#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
132
+  #if defined __ARM_PCS_VFP
133
+    #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
134
+  #endif
135
+
136
+#elif defined ( __GNUC__ )
137
+  #if defined (__VFP_FP__) && !defined(__SOFTFP__)
138
+    #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
139
+  #endif
140
+
141
+#elif defined ( __ICCARM__ )
142
+  #if defined __ARMVFP__
143
+    #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
144
+  #endif
145
+
146
+#elif defined ( __TMS470__ )
147
+  #if defined __TI_VFP_SUPPORT__
148
+    #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
149
+  #endif
150
+
151
+#elif defined ( __TASKING__ )
152
+  #if defined __FPU_VFP__
153
+    #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
154
+  #endif
155
+
156
+#elif defined ( __CSMC__ )
157
+  #if ( __CSMC__ & 0x400U)
158
+    #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
159
+  #endif
160
+
161
+#endif
162
+
163
+#include "core_cmInstr.h"                /* Core Instruction Access */
164
+#include "core_cmFunc.h"                 /* Core Function Access */
165
+
166
+#ifdef __cplusplus
167
+}
168
+#endif
169
+
170
+#endif /* __CORE_SC000_H_GENERIC */
171
+
172
+#ifndef __CMSIS_GENERIC
173
+
174
+#ifndef __CORE_SC000_H_DEPENDANT
175
+#define __CORE_SC000_H_DEPENDANT
176
+
177
+#ifdef __cplusplus
178
+ extern "C" {
179
+#endif
180
+
181
+/* check device defines and use defaults */
182
+#if defined __CHECK_DEVICE_DEFINES
183
+  #ifndef __SC000_REV
184
+    #define __SC000_REV             0x0000U
185
+    #warning "__SC000_REV not defined in device header file; using default!"
186
+  #endif
187
+
188
+  #ifndef __MPU_PRESENT
189
+    #define __MPU_PRESENT             0U
190
+    #warning "__MPU_PRESENT not defined in device header file; using default!"
191
+  #endif
192
+
193
+  #ifndef __NVIC_PRIO_BITS
194
+    #define __NVIC_PRIO_BITS          2U
195
+    #warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
196
+  #endif
197
+
198
+  #ifndef __Vendor_SysTickConfig
199
+    #define __Vendor_SysTickConfig    0U
200
+    #warning "__Vendor_SysTickConfig not defined in device header file; using default!"
201
+  #endif
202
+#endif
203
+
204
+/* IO definitions (access restrictions to peripheral registers) */
205
+/**
206
+    \defgroup CMSIS_glob_defs CMSIS Global Defines
207
+
208
+    <strong>IO Type Qualifiers</strong> are used
209
+    \li to specify the access to peripheral variables.
210
+    \li for automatic generation of peripheral register debug information.
211
+*/
212
+#ifdef __cplusplus
213
+  #define   __I     volatile             /*!< Defines 'read only' permissions */
214
+#else
215
+  #define   __I     volatile const       /*!< Defines 'read only' permissions */
216
+#endif
217
+#define     __O     volatile             /*!< Defines 'write only' permissions */
218
+#define     __IO    volatile             /*!< Defines 'read / write' permissions */
219
+
220
+/* following defines should be used for structure members */
221
+#define     __IM     volatile const      /*! Defines 'read only' structure member permissions */
222
+#define     __OM     volatile            /*! Defines 'write only' structure member permissions */
223
+#define     __IOM    volatile            /*! Defines 'read / write' structure member permissions */
224
+
225
+/*@} end of group SC000 */
226
+
227
+
228
+
229
+/*******************************************************************************
230
+ *                 Register Abstraction
231
+  Core Register contain:
232
+  - Core Register
233
+  - Core NVIC Register
234
+  - Core SCB Register
235
+  - Core SysTick Register
236
+  - Core MPU Register
237
+ ******************************************************************************/
238
+/**
239
+  \defgroup CMSIS_core_register Defines and Type Definitions
240
+  \brief Type definitions and defines for Cortex-M processor based devices.
241
+*/
242
+
243
+/**
244
+  \ingroup    CMSIS_core_register
245
+  \defgroup   CMSIS_CORE  Status and Control Registers
246
+  \brief      Core Register type definitions.
247
+  @{
248
+ */
249
+
250
+/**
251
+  \brief  Union type to access the Application Program Status Register (APSR).
252
+ */
253
+typedef union
254
+{
255
+  struct
256
+  {
257
+    uint32_t _reserved0:28;              /*!< bit:  0..27  Reserved */
258
+    uint32_t V:1;                        /*!< bit:     28  Overflow condition code flag */
259
+    uint32_t C:1;                        /*!< bit:     29  Carry condition code flag */
260
+    uint32_t Z:1;                        /*!< bit:     30  Zero condition code flag */
261
+    uint32_t N:1;                        /*!< bit:     31  Negative condition code flag */
262
+  } b;                                   /*!< Structure used for bit  access */
263
+  uint32_t w;                            /*!< Type      used for word access */
264
+} APSR_Type;
265
+
266
+/* APSR Register Definitions */
267
+#define APSR_N_Pos                         31U                                            /*!< APSR: N Position */
268
+#define APSR_N_Msk                         (1UL << APSR_N_Pos)                            /*!< APSR: N Mask */
269
+
270
+#define APSR_Z_Pos                         30U                                            /*!< APSR: Z Position */
271
+#define APSR_Z_Msk                         (1UL << APSR_Z_Pos)                            /*!< APSR: Z Mask */
272
+
273
+#define APSR_C_Pos                         29U                                            /*!< APSR: C Position */
274
+#define APSR_C_Msk                         (1UL << APSR_C_Pos)                            /*!< APSR: C Mask */
275
+
276
+#define APSR_V_Pos                         28U                                            /*!< APSR: V Position */
277
+#define APSR_V_Msk                         (1UL << APSR_V_Pos)                            /*!< APSR: V Mask */
278
+
279
+
280
+/**
281
+  \brief  Union type to access the Interrupt Program Status Register (IPSR).
282
+ */
283
+typedef union
284
+{
285
+  struct
286
+  {
287
+    uint32_t ISR:9;                      /*!< bit:  0.. 8  Exception number */
288
+    uint32_t _reserved0:23;              /*!< bit:  9..31  Reserved */
289
+  } b;                                   /*!< Structure used for bit  access */
290
+  uint32_t w;                            /*!< Type      used for word access */
291
+} IPSR_Type;
292
+
293
+/* IPSR Register Definitions */
294
+#define IPSR_ISR_Pos                        0U                                            /*!< IPSR: ISR Position */
295
+#define IPSR_ISR_Msk                       (0x1FFUL /*<< IPSR_ISR_Pos*/)                  /*!< IPSR: ISR Mask */
296
+
297
+
298
+/**
299
+  \brief  Union type to access the Special-Purpose Program Status Registers (xPSR).
300
+ */
301
+typedef union
302
+{
303
+  struct
304
+  {
305
+    uint32_t ISR:9;                      /*!< bit:  0.. 8  Exception number */
306
+    uint32_t _reserved0:15;              /*!< bit:  9..23  Reserved */
307
+    uint32_t T:1;                        /*!< bit:     24  Thumb bit        (read 0) */
308
+    uint32_t _reserved1:3;               /*!< bit: 25..27  Reserved */
309
+    uint32_t V:1;                        /*!< bit:     28  Overflow condition code flag */
310
+    uint32_t C:1;                        /*!< bit:     29  Carry condition code flag */
311
+    uint32_t Z:1;                        /*!< bit:     30  Zero condition code flag */
312
+    uint32_t N:1;                        /*!< bit:     31  Negative condition code flag */
313
+  } b;                                   /*!< Structure used for bit  access */
314
+  uint32_t w;                            /*!< Type      used for word access */
315
+} xPSR_Type;
316
+
317
+/* xPSR Register Definitions */
318
+#define xPSR_N_Pos                         31U                                            /*!< xPSR: N Position */
319
+#define xPSR_N_Msk                         (1UL << xPSR_N_Pos)                            /*!< xPSR: N Mask */
320
+
321
+#define xPSR_Z_Pos                         30U                                            /*!< xPSR: Z Position */
322
+#define xPSR_Z_Msk                         (1UL << xPSR_Z_Pos)                            /*!< xPSR: Z Mask */
323
+
324
+#define xPSR_C_Pos                         29U                                            /*!< xPSR: C Position */
325
+#define xPSR_C_Msk                         (1UL << xPSR_C_Pos)                            /*!< xPSR: C Mask */
326
+
327
+#define xPSR_V_Pos                         28U                                            /*!< xPSR: V Position */
328
+#define xPSR_V_Msk                         (1UL << xPSR_V_Pos)                            /*!< xPSR: V Mask */
329
+
330
+#define xPSR_T_Pos                         24U                                            /*!< xPSR: T Position */
331
+#define xPSR_T_Msk                         (1UL << xPSR_T_Pos)                            /*!< xPSR: T Mask */
332
+
333
+#define xPSR_ISR_Pos                        0U                                            /*!< xPSR: ISR Position */
334
+#define xPSR_ISR_Msk                       (0x1FFUL /*<< xPSR_ISR_Pos*/)                  /*!< xPSR: ISR Mask */
335
+
336
+
337
+/**
338
+  \brief  Union type to access the Control Registers (CONTROL).
339
+ */
340
+typedef union
341
+{
342
+  struct
343
+  {
344
+    uint32_t _reserved0:1;               /*!< bit:      0  Reserved */
345
+    uint32_t SPSEL:1;                    /*!< bit:      1  Stack to be used */
346
+    uint32_t _reserved1:30;              /*!< bit:  2..31  Reserved */
347
+  } b;                                   /*!< Structure used for bit  access */
348
+  uint32_t w;                            /*!< Type      used for word access */
349
+} CONTROL_Type;
350
+
351
+/* CONTROL Register Definitions */
352
+#define CONTROL_SPSEL_Pos                   1U                                            /*!< CONTROL: SPSEL Position */
353
+#define CONTROL_SPSEL_Msk                  (1UL << CONTROL_SPSEL_Pos)                     /*!< CONTROL: SPSEL Mask */
354
+
355
+/*@} end of group CMSIS_CORE */
356
+
357
+
358
+/**
359
+  \ingroup    CMSIS_core_register
360
+  \defgroup   CMSIS_NVIC  Nested Vectored Interrupt Controller (NVIC)
361
+  \brief      Type definitions for the NVIC Registers
362
+  @{
363
+ */
364
+
365
+/**
366
+  \brief  Structure type to access the Nested Vectored Interrupt Controller (NVIC).
367
+ */
368
+typedef struct
369
+{
370
+  __IOM uint32_t ISER[1U];               /*!< Offset: 0x000 (R/W)  Interrupt Set Enable Register */
371
+        uint32_t RESERVED0[31U];
372
+  __IOM uint32_t ICER[1U];               /*!< Offset: 0x080 (R/W)  Interrupt Clear Enable Register */
373
+        uint32_t RSERVED1[31U];
374
+  __IOM uint32_t ISPR[1U];               /*!< Offset: 0x100 (R/W)  Interrupt Set Pending Register */
375
+        uint32_t RESERVED2[31U];
376
+  __IOM uint32_t ICPR[1U];               /*!< Offset: 0x180 (R/W)  Interrupt Clear Pending Register */
377
+        uint32_t RESERVED3[31U];
378
+        uint32_t RESERVED4[64U];
379
+  __IOM uint32_t IP[8U];                 /*!< Offset: 0x300 (R/W)  Interrupt Priority Register */
380
+}  NVIC_Type;
381
+
382
+/*@} end of group CMSIS_NVIC */
383
+
384
+
385
+/**
386
+  \ingroup  CMSIS_core_register
387
+  \defgroup CMSIS_SCB     System Control Block (SCB)
388
+  \brief    Type definitions for the System Control Block Registers
389
+  @{
390
+ */
391
+
392
+/**
393
+  \brief  Structure type to access the System Control Block (SCB).
394
+ */
395
+typedef struct
396
+{
397
+  __IM  uint32_t CPUID;                  /*!< Offset: 0x000 (R/ )  CPUID Base Register */
398
+  __IOM uint32_t ICSR;                   /*!< Offset: 0x004 (R/W)  Interrupt Control and State Register */
399
+  __IOM uint32_t VTOR;                   /*!< Offset: 0x008 (R/W)  Vector Table Offset Register */
400
+  __IOM uint32_t AIRCR;                  /*!< Offset: 0x00C (R/W)  Application Interrupt and Reset Control Register */
401
+  __IOM uint32_t SCR;                    /*!< Offset: 0x010 (R/W)  System Control Register */
402
+  __IOM uint32_t CCR;                    /*!< Offset: 0x014 (R/W)  Configuration Control Register */
403
+        uint32_t RESERVED0[1U];
404
+  __IOM uint32_t SHP[2U];                /*!< Offset: 0x01C (R/W)  System Handlers Priority Registers. [0] is RESERVED */
405
+  __IOM uint32_t SHCSR;                  /*!< Offset: 0x024 (R/W)  System Handler Control and State Register */
406
+        uint32_t RESERVED1[154U];
407
+  __IOM uint32_t SFCR;                   /*!< Offset: 0x290 (R/W)  Security Features Control Register */
408
+} SCB_Type;
409
+
410
+/* SCB CPUID Register Definitions */
411
+#define SCB_CPUID_IMPLEMENTER_Pos          24U                                            /*!< SCB CPUID: IMPLEMENTER Position */
412
+#define SCB_CPUID_IMPLEMENTER_Msk          (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos)          /*!< SCB CPUID: IMPLEMENTER Mask */
413
+
414
+#define SCB_CPUID_VARIANT_Pos              20U                                            /*!< SCB CPUID: VARIANT Position */
415
+#define SCB_CPUID_VARIANT_Msk              (0xFUL << SCB_CPUID_VARIANT_Pos)               /*!< SCB CPUID: VARIANT Mask */
416
+
417
+#define SCB_CPUID_ARCHITECTURE_Pos         16U                                            /*!< SCB CPUID: ARCHITECTURE Position */
418
+#define SCB_CPUID_ARCHITECTURE_Msk         (0xFUL << SCB_CPUID_ARCHITECTURE_Pos)          /*!< SCB CPUID: ARCHITECTURE Mask */
419
+
420
+#define SCB_CPUID_PARTNO_Pos                4U                                            /*!< SCB CPUID: PARTNO Position */
421
+#define SCB_CPUID_PARTNO_Msk               (0xFFFUL << SCB_CPUID_PARTNO_Pos)              /*!< SCB CPUID: PARTNO Mask */
422
+
423
+#define SCB_CPUID_REVISION_Pos              0U                                            /*!< SCB CPUID: REVISION Position */
424
+#define SCB_CPUID_REVISION_Msk             (0xFUL /*<< SCB_CPUID_REVISION_Pos*/)          /*!< SCB CPUID: REVISION Mask */
425
+
426
+/* SCB Interrupt Control State Register Definitions */
427
+#define SCB_ICSR_NMIPENDSET_Pos            31U                                            /*!< SCB ICSR: NMIPENDSET Position */
428
+#define SCB_ICSR_NMIPENDSET_Msk            (1UL << SCB_ICSR_NMIPENDSET_Pos)               /*!< SCB ICSR: NMIPENDSET Mask */
429
+
430
+#define SCB_ICSR_PENDSVSET_Pos             28U                                            /*!< SCB ICSR: PENDSVSET Position */
431
+#define SCB_ICSR_PENDSVSET_Msk             (1UL << SCB_ICSR_PENDSVSET_Pos)                /*!< SCB ICSR: PENDSVSET Mask */
432
+
433
+#define SCB_ICSR_PENDSVCLR_Pos             27U                                            /*!< SCB ICSR: PENDSVCLR Position */
434
+#define SCB_ICSR_PENDSVCLR_Msk             (1UL << SCB_ICSR_PENDSVCLR_Pos)                /*!< SCB ICSR: PENDSVCLR Mask */
435
+
436
+#define SCB_ICSR_PENDSTSET_Pos             26U                                            /*!< SCB ICSR: PENDSTSET Position */
437
+#define SCB_ICSR_PENDSTSET_Msk             (1UL << SCB_ICSR_PENDSTSET_Pos)                /*!< SCB ICSR: PENDSTSET Mask */
438
+
439
+#define SCB_ICSR_PENDSTCLR_Pos             25U                                            /*!< SCB ICSR: PENDSTCLR Position */
440
+#define SCB_ICSR_PENDSTCLR_Msk             (1UL << SCB_ICSR_PENDSTCLR_Pos)                /*!< SCB ICSR: PENDSTCLR Mask */
441
+
442
+#define SCB_ICSR_ISRPREEMPT_Pos            23U                                            /*!< SCB ICSR: ISRPREEMPT Position */
443
+#define SCB_ICSR_ISRPREEMPT_Msk            (1UL << SCB_ICSR_ISRPREEMPT_Pos)               /*!< SCB ICSR: ISRPREEMPT Mask */
444
+
445
+#define SCB_ICSR_ISRPENDING_Pos            22U                                            /*!< SCB ICSR: ISRPENDING Position */
446
+#define SCB_ICSR_ISRPENDING_Msk            (1UL << SCB_ICSR_ISRPENDING_Pos)               /*!< SCB ICSR: ISRPENDING Mask */
447
+
448
+#define SCB_ICSR_VECTPENDING_Pos           12U                                            /*!< SCB ICSR: VECTPENDING Position */
449
+#define SCB_ICSR_VECTPENDING_Msk           (0x1FFUL << SCB_ICSR_VECTPENDING_Pos)          /*!< SCB ICSR: VECTPENDING Mask */
450
+
451
+#define SCB_ICSR_VECTACTIVE_Pos             0U                                            /*!< SCB ICSR: VECTACTIVE Position */
452
+#define SCB_ICSR_VECTACTIVE_Msk            (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/)       /*!< SCB ICSR: VECTACTIVE Mask */
453
+
454
+/* SCB Interrupt Control State Register Definitions */
455
+#define SCB_VTOR_TBLOFF_Pos                 7U                                            /*!< SCB VTOR: TBLOFF Position */
456
+#define SCB_VTOR_TBLOFF_Msk                (0x1FFFFFFUL << SCB_VTOR_TBLOFF_Pos)           /*!< SCB VTOR: TBLOFF Mask */
457
+
458
+/* SCB Application Interrupt and Reset Control Register Definitions */
459
+#define SCB_AIRCR_VECTKEY_Pos              16U                                            /*!< SCB AIRCR: VECTKEY Position */
460
+#define SCB_AIRCR_VECTKEY_Msk              (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos)            /*!< SCB AIRCR: VECTKEY Mask */
461
+
462
+#define SCB_AIRCR_VECTKEYSTAT_Pos          16U                                            /*!< SCB AIRCR: VECTKEYSTAT Position */
463
+#define SCB_AIRCR_VECTKEYSTAT_Msk          (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos)        /*!< SCB AIRCR: VECTKEYSTAT Mask */
464
+
465
+#define SCB_AIRCR_ENDIANESS_Pos            15U                                            /*!< SCB AIRCR: ENDIANESS Position */
466
+#define SCB_AIRCR_ENDIANESS_Msk            (1UL << SCB_AIRCR_ENDIANESS_Pos)               /*!< SCB AIRCR: ENDIANESS Mask */
467
+
468
+#define SCB_AIRCR_SYSRESETREQ_Pos           2U                                            /*!< SCB AIRCR: SYSRESETREQ Position */
469
+#define SCB_AIRCR_SYSRESETREQ_Msk          (1UL << SCB_AIRCR_SYSRESETREQ_Pos)             /*!< SCB AIRCR: SYSRESETREQ Mask */
470
+
471
+#define SCB_AIRCR_VECTCLRACTIVE_Pos         1U                                            /*!< SCB AIRCR: VECTCLRACTIVE Position */
472
+#define SCB_AIRCR_VECTCLRACTIVE_Msk        (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos)           /*!< SCB AIRCR: VECTCLRACTIVE Mask */
473
+
474
+/* SCB System Control Register Definitions */
475
+#define SCB_SCR_SEVONPEND_Pos               4U                                            /*!< SCB SCR: SEVONPEND Position */
476
+#define SCB_SCR_SEVONPEND_Msk              (1UL << SCB_SCR_SEVONPEND_Pos)                 /*!< SCB SCR: SEVONPEND Mask */
477
+
478
+#define SCB_SCR_SLEEPDEEP_Pos               2U                                            /*!< SCB SCR: SLEEPDEEP Position */
479
+#define SCB_SCR_SLEEPDEEP_Msk              (1UL << SCB_SCR_SLEEPDEEP_Pos)                 /*!< SCB SCR: SLEEPDEEP Mask */
480
+
481
+#define SCB_SCR_SLEEPONEXIT_Pos             1U                                            /*!< SCB SCR: SLEEPONEXIT Position */
482
+#define SCB_SCR_SLEEPONEXIT_Msk            (1UL << SCB_SCR_SLEEPONEXIT_Pos)               /*!< SCB SCR: SLEEPONEXIT Mask */
483
+
484
+/* SCB Configuration Control Register Definitions */
485
+#define SCB_CCR_STKALIGN_Pos                9U                                            /*!< SCB CCR: STKALIGN Position */
486
+#define SCB_CCR_STKALIGN_Msk               (1UL << SCB_CCR_STKALIGN_Pos)                  /*!< SCB CCR: STKALIGN Mask */
487
+
488
+#define SCB_CCR_UNALIGN_TRP_Pos             3U                                            /*!< SCB CCR: UNALIGN_TRP Position */
489
+#define SCB_CCR_UNALIGN_TRP_Msk            (1UL << SCB_CCR_UNALIGN_TRP_Pos)               /*!< SCB CCR: UNALIGN_TRP Mask */
490
+
491
+/* SCB System Handler Control and State Register Definitions */
492
+#define SCB_SHCSR_SVCALLPENDED_Pos         15U                                            /*!< SCB SHCSR: SVCALLPENDED Position */
493
+#define SCB_SHCSR_SVCALLPENDED_Msk         (1UL << SCB_SHCSR_SVCALLPENDED_Pos)            /*!< SCB SHCSR: SVCALLPENDED Mask */
494
+
495
+/*@} end of group CMSIS_SCB */
496
+
497
+
498
+/**
499
+  \ingroup  CMSIS_core_register
500
+  \defgroup CMSIS_SCnSCB System Controls not in SCB (SCnSCB)
501
+  \brief    Type definitions for the System Control and ID Register not in the SCB
502
+  @{
503
+ */
504
+
505
+/**
506
+  \brief  Structure type to access the System Control and ID Register not in the SCB.
507
+ */
508
+typedef struct
509
+{
510
+        uint32_t RESERVED0[2U];
511
+  __IOM uint32_t ACTLR;                  /*!< Offset: 0x008 (R/W)  Auxiliary Control Register */
512
+} SCnSCB_Type;
513
+
514
+/* Auxiliary Control Register Definitions */
515
+#define SCnSCB_ACTLR_DISMCYCINT_Pos         0U                                         /*!< ACTLR: DISMCYCINT Position */
516
+#define SCnSCB_ACTLR_DISMCYCINT_Msk        (1UL /*<< SCnSCB_ACTLR_DISMCYCINT_Pos*/)    /*!< ACTLR: DISMCYCINT Mask */
517
+
518
+/*@} end of group CMSIS_SCnotSCB */
519
+
520
+
521
+/**
522
+  \ingroup  CMSIS_core_register
523
+  \defgroup CMSIS_SysTick     System Tick Timer (SysTick)
524
+  \brief    Type definitions for the System Timer Registers.
525
+  @{
526
+ */
527
+
528
+/**
529
+  \brief  Structure type to access the System Timer (SysTick).
530
+ */
531
+typedef struct
532
+{
533
+  __IOM uint32_t CTRL;                   /*!< Offset: 0x000 (R/W)  SysTick Control and Status Register */
534
+  __IOM uint32_t LOAD;                   /*!< Offset: 0x004 (R/W)  SysTick Reload Value Register */
535
+  __IOM uint32_t VAL;                    /*!< Offset: 0x008 (R/W)  SysTick Current Value Register */
536
+  __IM  uint32_t CALIB;                  /*!< Offset: 0x00C (R/ )  SysTick Calibration Register */
537
+} SysTick_Type;
538
+
539
+/* SysTick Control / Status Register Definitions */
540
+#define SysTick_CTRL_COUNTFLAG_Pos         16U                                            /*!< SysTick CTRL: COUNTFLAG Position */
541
+#define SysTick_CTRL_COUNTFLAG_Msk         (1UL << SysTick_CTRL_COUNTFLAG_Pos)            /*!< SysTick CTRL: COUNTFLAG Mask */
542
+
543
+#define SysTick_CTRL_CLKSOURCE_Pos          2U                                            /*!< SysTick CTRL: CLKSOURCE Position */
544
+#define SysTick_CTRL_CLKSOURCE_Msk         (1UL << SysTick_CTRL_CLKSOURCE_Pos)            /*!< SysTick CTRL: CLKSOURCE Mask */
545
+
546
+#define SysTick_CTRL_TICKINT_Pos            1U                                            /*!< SysTick CTRL: TICKINT Position */
547
+#define SysTick_CTRL_TICKINT_Msk           (1UL << SysTick_CTRL_TICKINT_Pos)              /*!< SysTick CTRL: TICKINT Mask */
548
+
549
+#define SysTick_CTRL_ENABLE_Pos             0U                                            /*!< SysTick CTRL: ENABLE Position */
550
+#define SysTick_CTRL_ENABLE_Msk            (1UL /*<< SysTick_CTRL_ENABLE_Pos*/)           /*!< SysTick CTRL: ENABLE Mask */
551
+
552
+/* SysTick Reload Register Definitions */
553
+#define SysTick_LOAD_RELOAD_Pos             0U                                            /*!< SysTick LOAD: RELOAD Position */
554
+#define SysTick_LOAD_RELOAD_Msk            (0xFFFFFFUL /*<< SysTick_LOAD_RELOAD_Pos*/)    /*!< SysTick LOAD: RELOAD Mask */
555
+
556
+/* SysTick Current Register Definitions */
557
+#define SysTick_VAL_CURRENT_Pos             0U                                            /*!< SysTick VAL: CURRENT Position */
558
+#define SysTick_VAL_CURRENT_Msk            (0xFFFFFFUL /*<< SysTick_VAL_CURRENT_Pos*/)    /*!< SysTick VAL: CURRENT Mask */
559
+
560
+/* SysTick Calibration Register Definitions */
561
+#define SysTick_CALIB_NOREF_Pos            31U                                            /*!< SysTick CALIB: NOREF Position */
562
+#define SysTick_CALIB_NOREF_Msk            (1UL << SysTick_CALIB_NOREF_Pos)               /*!< SysTick CALIB: NOREF Mask */
563
+
564
+#define SysTick_CALIB_SKEW_Pos             30U                                            /*!< SysTick CALIB: SKEW Position */
565
+#define SysTick_CALIB_SKEW_Msk             (1UL << SysTick_CALIB_SKEW_Pos)                /*!< SysTick CALIB: SKEW Mask */
566
+
567
+#define SysTick_CALIB_TENMS_Pos             0U                                            /*!< SysTick CALIB: TENMS Position */
568
+#define SysTick_CALIB_TENMS_Msk            (0xFFFFFFUL /*<< SysTick_CALIB_TENMS_Pos*/)    /*!< SysTick CALIB: TENMS Mask */
569
+
570
+/*@} end of group CMSIS_SysTick */
571
+
572
+#if (__MPU_PRESENT == 1U)
573
+/**
574
+  \ingroup  CMSIS_core_register
575
+  \defgroup CMSIS_MPU     Memory Protection Unit (MPU)
576
+  \brief    Type definitions for the Memory Protection Unit (MPU)
577
+  @{
578
+ */
579
+
580
+/**
581
+  \brief  Structure type to access the Memory Protection Unit (MPU).
582
+ */
583
+typedef struct
584
+{
585
+  __IM  uint32_t TYPE;                   /*!< Offset: 0x000 (R/ )  MPU Type Register */
586
+  __IOM uint32_t CTRL;                   /*!< Offset: 0x004 (R/W)  MPU Control Register */
587
+  __IOM uint32_t RNR;                    /*!< Offset: 0x008 (R/W)  MPU Region RNRber Register */
588
+  __IOM uint32_t RBAR;                   /*!< Offset: 0x00C (R/W)  MPU Region Base Address Register */
589
+  __IOM uint32_t RASR;                   /*!< Offset: 0x010 (R/W)  MPU Region Attribute and Size Register */
590
+} MPU_Type;
591
+
592
+/* MPU Type Register Definitions */
593
+#define MPU_TYPE_IREGION_Pos               16U                                            /*!< MPU TYPE: IREGION Position */
594
+#define MPU_TYPE_IREGION_Msk               (0xFFUL << MPU_TYPE_IREGION_Pos)               /*!< MPU TYPE: IREGION Mask */
595
+
596
+#define MPU_TYPE_DREGION_Pos                8U                                            /*!< MPU TYPE: DREGION Position */
597
+#define MPU_TYPE_DREGION_Msk               (0xFFUL << MPU_TYPE_DREGION_Pos)               /*!< MPU TYPE: DREGION Mask */
598
+
599
+#define MPU_TYPE_SEPARATE_Pos               0U                                            /*!< MPU TYPE: SEPARATE Position */
600
+#define MPU_TYPE_SEPARATE_Msk              (1UL /*<< MPU_TYPE_SEPARATE_Pos*/)             /*!< MPU TYPE: SEPARATE Mask */
601
+
602
+/* MPU Control Register Definitions */
603
+#define MPU_CTRL_PRIVDEFENA_Pos             2U                                            /*!< MPU CTRL: PRIVDEFENA Position */
604
+#define MPU_CTRL_PRIVDEFENA_Msk            (1UL << MPU_CTRL_PRIVDEFENA_Pos)               /*!< MPU CTRL: PRIVDEFENA Mask */
605
+
606
+#define MPU_CTRL_HFNMIENA_Pos               1U                                            /*!< MPU CTRL: HFNMIENA Position */
607
+#define MPU_CTRL_HFNMIENA_Msk              (1UL << MPU_CTRL_HFNMIENA_Pos)                 /*!< MPU CTRL: HFNMIENA Mask */
608
+
609
+#define MPU_CTRL_ENABLE_Pos                 0U                                            /*!< MPU CTRL: ENABLE Position */
610
+#define MPU_CTRL_ENABLE_Msk                (1UL /*<< MPU_CTRL_ENABLE_Pos*/)               /*!< MPU CTRL: ENABLE Mask */
611
+
612
+/* MPU Region Number Register Definitions */
613
+#define MPU_RNR_REGION_Pos                  0U                                            /*!< MPU RNR: REGION Position */
614
+#define MPU_RNR_REGION_Msk                 (0xFFUL /*<< MPU_RNR_REGION_Pos*/)             /*!< MPU RNR: REGION Mask */
615
+
616
+/* MPU Region Base Address Register Definitions */
617
+#define MPU_RBAR_ADDR_Pos                   8U                                            /*!< MPU RBAR: ADDR Position */
618
+#define MPU_RBAR_ADDR_Msk                  (0xFFFFFFUL << MPU_RBAR_ADDR_Pos)              /*!< MPU RBAR: ADDR Mask */
619
+
620
+#define MPU_RBAR_VALID_Pos                  4U                                            /*!< MPU RBAR: VALID Position */
621
+#define MPU_RBAR_VALID_Msk                 (1UL << MPU_RBAR_VALID_Pos)                    /*!< MPU RBAR: VALID Mask */
622
+
623
+#define MPU_RBAR_REGION_Pos                 0U                                            /*!< MPU RBAR: REGION Position */
624
+#define MPU_RBAR_REGION_Msk                (0xFUL /*<< MPU_RBAR_REGION_Pos*/)             /*!< MPU RBAR: REGION Mask */
625
+
626
+/* MPU Region Attribute and Size Register Definitions */
627
+#define MPU_RASR_ATTRS_Pos                 16U                                            /*!< MPU RASR: MPU Region Attribute field Position */
628
+#define MPU_RASR_ATTRS_Msk                 (0xFFFFUL << MPU_RASR_ATTRS_Pos)               /*!< MPU RASR: MPU Region Attribute field Mask */
629
+
630
+#define MPU_RASR_XN_Pos                    28U                                            /*!< MPU RASR: ATTRS.XN Position */
631
+#define MPU_RASR_XN_Msk                    (1UL << MPU_RASR_XN_Pos)                       /*!< MPU RASR: ATTRS.XN Mask */
632
+
633
+#define MPU_RASR_AP_Pos                    24U                                            /*!< MPU RASR: ATTRS.AP Position */
634
+#define MPU_RASR_AP_Msk                    (0x7UL << MPU_RASR_AP_Pos)                     /*!< MPU RASR: ATTRS.AP Mask */
635
+
636
+#define MPU_RASR_TEX_Pos                   19U                                            /*!< MPU RASR: ATTRS.TEX Position */
637
+#define MPU_RASR_TEX_Msk                   (0x7UL << MPU_RASR_TEX_Pos)                    /*!< MPU RASR: ATTRS.TEX Mask */
638
+
639
+#define MPU_RASR_S_Pos                     18U                                            /*!< MPU RASR: ATTRS.S Position */
640
+#define MPU_RASR_S_Msk                     (1UL << MPU_RASR_S_Pos)                        /*!< MPU RASR: ATTRS.S Mask */
641
+
642
+#define MPU_RASR_C_Pos                     17U                                            /*!< MPU RASR: ATTRS.C Position */
643
+#define MPU_RASR_C_Msk                     (1UL << MPU_RASR_C_Pos)                        /*!< MPU RASR: ATTRS.C Mask */
644
+
645
+#define MPU_RASR_B_Pos                     16U                                            /*!< MPU RASR: ATTRS.B Position */
646
+#define MPU_RASR_B_Msk                     (1UL << MPU_RASR_B_Pos)                        /*!< MPU RASR: ATTRS.B Mask */
647
+
648
+#define MPU_RASR_SRD_Pos                    8U                                            /*!< MPU RASR: Sub-Region Disable Position */
649
+#define MPU_RASR_SRD_Msk                   (0xFFUL << MPU_RASR_SRD_Pos)                   /*!< MPU RASR: Sub-Region Disable Mask */
650
+
651
+#define MPU_RASR_SIZE_Pos                   1U                                            /*!< MPU RASR: Region Size Field Position */
652
+#define MPU_RASR_SIZE_Msk                  (0x1FUL << MPU_RASR_SIZE_Pos)                  /*!< MPU RASR: Region Size Field Mask */
653
+
654
+#define MPU_RASR_ENABLE_Pos                 0U                                            /*!< MPU RASR: Region enable bit Position */
655
+#define MPU_RASR_ENABLE_Msk                (1UL /*<< MPU_RASR_ENABLE_Pos*/)               /*!< MPU RASR: Region enable bit Disable Mask */
656
+
657
+/*@} end of group CMSIS_MPU */
658
+#endif
659
+
660
+
661
+/**
662
+  \ingroup  CMSIS_core_register
663
+  \defgroup CMSIS_CoreDebug       Core Debug Registers (CoreDebug)
664
+  \brief    SC000 Core Debug Registers (DCB registers, SHCSR, and DFSR) are only accessible over DAP and not via processor.
665
+            Therefore they are not covered by the SC000 header file.
666
+  @{
667
+ */
668
+/*@} end of group CMSIS_CoreDebug */
669
+
670
+
671
+/**
672
+  \ingroup    CMSIS_core_register
673
+  \defgroup   CMSIS_core_bitfield     Core register bit field macros
674
+  \brief      Macros for use with bit field definitions (xxx_Pos, xxx_Msk).
675
+  @{
676
+ */
677
+
678
+/**
679
+  \brief   Mask and shift a bit field value for use in a register bit range.
680
+  \param[in] field  Name of the register bit field.
681
+  \param[in] value  Value of the bit field.
682
+  \return           Masked and shifted value.
683
+*/
684
+#define _VAL2FLD(field, value)    ((value << field ## _Pos) & field ## _Msk)
685
+
686
+/**
687
+  \brief     Mask and shift a register value to extract a bit filed value.
688
+  \param[in] field  Name of the register bit field.
689
+  \param[in] value  Value of register.
690
+  \return           Masked and shifted bit field value.
691
+*/
692
+#define _FLD2VAL(field, value)    ((value & field ## _Msk) >> field ## _Pos)
693
+
694
+/*@} end of group CMSIS_core_bitfield */
695
+
696
+
697
+/**
698
+  \ingroup    CMSIS_core_register
699
+  \defgroup   CMSIS_core_base     Core Definitions
700
+  \brief      Definitions for base addresses, unions, and structures.
701
+  @{
702
+ */
703
+
704
+/* Memory mapping of SC000 Hardware */
705
+#define SCS_BASE            (0xE000E000UL)                            /*!< System Control Space Base Address */
706
+#define SysTick_BASE        (SCS_BASE +  0x0010UL)                    /*!< SysTick Base Address */
707
+#define NVIC_BASE           (SCS_BASE +  0x0100UL)                    /*!< NVIC Base Address */
708
+#define SCB_BASE            (SCS_BASE +  0x0D00UL)                    /*!< System Control Block Base Address */
709
+
710
+#define SCnSCB              ((SCnSCB_Type    *)     SCS_BASE      )   /*!< System control Register not in SCB */
711
+#define SCB                 ((SCB_Type       *)     SCB_BASE      )   /*!< SCB configuration struct */
712
+#define SysTick             ((SysTick_Type   *)     SysTick_BASE  )   /*!< SysTick configuration struct */
713
+#define NVIC                ((NVIC_Type      *)     NVIC_BASE     )   /*!< NVIC configuration struct */
714
+
715
+#if (__MPU_PRESENT == 1U)
716
+  #define MPU_BASE          (SCS_BASE +  0x0D90UL)                    /*!< Memory Protection Unit */
717
+  #define MPU               ((MPU_Type       *)     MPU_BASE      )   /*!< Memory Protection Unit */
718
+#endif
719
+
720
+/*@} */
721
+
722
+
723
+
724
+/*******************************************************************************
725
+ *                Hardware Abstraction Layer
726
+  Core Function Interface contains:
727
+  - Core NVIC Functions
728
+  - Core SysTick Functions
729
+  - Core Register Access Functions
730
+ ******************************************************************************/
731
+/**
732
+  \defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference
733
+*/
734
+
735
+
736
+
737
+/* ##########################   NVIC functions  #################################### */
738
+/**
739
+  \ingroup  CMSIS_Core_FunctionInterface
740
+  \defgroup CMSIS_Core_NVICFunctions NVIC Functions
741
+  \brief    Functions that manage interrupts and exceptions via the NVIC.
742
+  @{
743
+ */
744
+
745
+/* Interrupt Priorities are WORD accessible only under ARMv6M                   */
746
+/* The following MACROS handle generation of the register offset and byte masks */
747
+#define _BIT_SHIFT(IRQn)         (  ((((uint32_t)(int32_t)(IRQn))         )      &  0x03UL) * 8UL)
748
+#define _SHP_IDX(IRQn)           ( (((((uint32_t)(int32_t)(IRQn)) & 0x0FUL)-8UL) >>    2UL)      )
749
+#define _IP_IDX(IRQn)            (   (((uint32_t)(int32_t)(IRQn))                >>    2UL)      )
750
+
751
+
752
+/**
753
+  \brief   Enable External Interrupt
754
+  \details Enables a device-specific interrupt in the NVIC interrupt controller.
755
+  \param [in]      IRQn  External interrupt number. Value cannot be negative.
756
+ */
757
+__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
758
+{
759
+  NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
760
+}
761
+
762
+
763
+/**
764
+  \brief   Disable External Interrupt
765
+  \details Disables a device-specific interrupt in the NVIC interrupt controller.
766
+  \param [in]      IRQn  External interrupt number. Value cannot be negative.
767
+ */
768
+__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
769
+{
770
+  NVIC->ICER[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
771
+}
772
+
773
+
774
+/**
775
+  \brief   Get Pending Interrupt
776
+  \details Reads the pending register in the NVIC and returns the pending bit for the specified interrupt.
777
+  \param [in]      IRQn  Interrupt number.
778
+  \return             0  Interrupt status is not pending.
779
+  \return             1  Interrupt status is pending.
780
+ */
781
+__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
782
+{
783
+  return((uint32_t)(((NVIC->ISPR[0U] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
784
+}
785
+
786
+
787
+/**
788
+  \brief   Set Pending Interrupt
789
+  \details Sets the pending bit of an external interrupt.
790
+  \param [in]      IRQn  Interrupt number. Value cannot be negative.
791
+ */
792
+__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
793
+{
794
+  NVIC->ISPR[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
795
+}
796
+
797
+
798
+/**
799
+  \brief   Clear Pending Interrupt
800
+  \details Clears the pending bit of an external interrupt.
801
+  \param [in]      IRQn  External interrupt number. Value cannot be negative.
802
+ */
803
+__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
804
+{
805
+  NVIC->ICPR[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
806
+}
807
+
808
+
809
+/**
810
+  \brief   Set Interrupt Priority
811
+  \details Sets the priority of an interrupt.
812
+  \note    The priority cannot be set for every core interrupt.
813
+  \param [in]      IRQn  Interrupt number.
814
+  \param [in]  priority  Priority to set.
815
+ */
816
+__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
817
+{
818
+  if ((int32_t)(IRQn) < 0)
819
+  {
820
+    SCB->SHP[_SHP_IDX(IRQn)] = ((uint32_t)(SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
821
+       (((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
822
+  }
823
+  else
824
+  {
825
+    NVIC->IP[_IP_IDX(IRQn)]  = ((uint32_t)(NVIC->IP[_IP_IDX(IRQn)]  & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
826
+       (((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
827
+  }
828
+}
829
+
830
+
831
+/**
832
+  \brief   Get Interrupt Priority
833
+  \details Reads the priority of an interrupt.
834
+           The interrupt number can be positive to specify an external (device specific) interrupt,
835
+           or negative to specify an internal (core) interrupt.
836
+  \param [in]   IRQn  Interrupt number.
837
+  \return             Interrupt Priority.
838
+                      Value is aligned automatically to the implemented priority bits of the microcontroller.
839
+ */
840
+__STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
841
+{
842
+
843
+  if ((int32_t)(IRQn) < 0)
844
+  {
845
+    return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
846
+  }
847
+  else
848
+  {
849
+    return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
850
+  }
851
+}
852
+
853
+
854
+/**
855
+  \brief   System Reset
856
+  \details Initiates a system reset request to reset the MCU.
857
+ */
858
+__STATIC_INLINE void NVIC_SystemReset(void)
859
+{
860
+  __DSB();                                                          /* Ensure all outstanding memory accesses included
861
+                                                                       buffered write are completed before reset */
862
+  SCB->AIRCR  = ((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) |
863
+                 SCB_AIRCR_SYSRESETREQ_Msk);
864
+  __DSB();                                                          /* Ensure completion of memory access */
865
+
866
+  for(;;)                                                           /* wait until reset */
867
+  {
868
+    __NOP();
869
+  }
870
+}
871
+
872
+/*@} end of CMSIS_Core_NVICFunctions */
873
+
874
+
875
+
876
+/* ##################################    SysTick function  ############################################ */
877
+/**
878
+  \ingroup  CMSIS_Core_FunctionInterface
879
+  \defgroup CMSIS_Core_SysTickFunctions SysTick Functions
880
+  \brief    Functions that configure the System.
881
+  @{
882
+ */
883
+
884
+#if (__Vendor_SysTickConfig == 0U)
885
+
886
+/**
887
+  \brief   System Tick Configuration
888
+  \details Initializes the System Timer and its interrupt, and starts the System Tick Timer.
889
+           Counter is in free running mode to generate periodic interrupts.
890
+  \param [in]  ticks  Number of ticks between two interrupts.
891
+  \return          0  Function succeeded.
892
+  \return          1  Function failed.
893
+  \note    When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then the
894
+           function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b>
895
+           must contain a vendor-specific implementation of this function.
896
+ */
897
+__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
898
+{
899
+  if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk)
900
+  {
901
+    return (1UL);                                                   /* Reload value impossible */
902
+  }
903
+
904
+  SysTick->LOAD  = (uint32_t)(ticks - 1UL);                         /* set reload register */
905
+  NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */
906
+  SysTick->VAL   = 0UL;                                             /* Load the SysTick Counter Value */
907
+  SysTick->CTRL  = SysTick_CTRL_CLKSOURCE_Msk |
908
+                   SysTick_CTRL_TICKINT_Msk   |
909
+                   SysTick_CTRL_ENABLE_Msk;                         /* Enable SysTick IRQ and SysTick Timer */
910
+  return (0UL);                                                     /* Function successful */
911
+}
912
+
913
+#endif
914
+
915
+/*@} end of CMSIS_Core_SysTickFunctions */
916
+
917
+
918
+
919
+
920
+#ifdef __cplusplus
921
+}
922
+#endif
923
+
924
+#endif /* __CORE_SC000_H_DEPENDANT */
925
+
926
+#endif /* __CMSIS_GENERIC */

Разлика између датотеке није приказан због своје велике величине
+ 1745 - 0
Drivers/CMSIS/Include/core_sc300.h


Разлика између датотеке није приказан због своје велике величине
+ 3219 - 0
Drivers/STM32F1xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h


+ 367 - 0
Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal.h

@@ -0,0 +1,367 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal.h
4
+  * @author  MCD Application Team
5
+  * @brief   This file contains all the functions prototypes for the HAL
6
+  *          module driver.
7
+  ******************************************************************************
8
+  * @attention
9
+  *
10
+  * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
11
+  *
12
+  * Redistribution and use in source and binary forms, with or without modification,
13
+  * are permitted provided that the following conditions are met:
14
+  *   1. Redistributions of source code must retain the above copyright notice,
15
+  *      this list of conditions and the following disclaimer.
16
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
17
+  *      this list of conditions and the following disclaimer in the documentation
18
+  *      and/or other materials provided with the distribution.
19
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
20
+  *      may be used to endorse or promote products derived from this software
21
+  *      without specific prior written permission.
22
+  *
23
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
27
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
+  *
34
+  ******************************************************************************
35
+  */
36
+
37
+/* Define to prevent recursive inclusion -------------------------------------*/
38
+#ifndef __STM32F1xx_HAL_H
39
+#define __STM32F1xx_HAL_H
40
+
41
+#ifdef __cplusplus
42
+extern "C" {
43
+#endif
44
+
45
+/* Includes ------------------------------------------------------------------*/
46
+#include "stm32f1xx_hal_conf.h"
47
+
48
+/** @addtogroup STM32F1xx_HAL_Driver
49
+  * @{
50
+  */
51
+
52
+/** @addtogroup HAL
53
+  * @{
54
+  */
55
+
56
+/* Exported constants --------------------------------------------------------*/
57
+
58
+/** @defgroup HAL_Exported_Constants HAL Exported Constants
59
+  * @{
60
+  */
61
+
62
+/** @defgroup HAL_TICK_FREQ Tick Frequency
63
+  * @{
64
+  */
65
+typedef enum
66
+{
67
+  HAL_TICK_FREQ_10HZ         = 100U,
68
+  HAL_TICK_FREQ_100HZ        = 10U,
69
+  HAL_TICK_FREQ_1KHZ         = 1U,
70
+  HAL_TICK_FREQ_DEFAULT      = HAL_TICK_FREQ_1KHZ
71
+} HAL_TickFreqTypeDef;
72
+/**
73
+  * @}
74
+  */
75
+/* Exported types ------------------------------------------------------------*/
76
+extern uint32_t uwTickPrio;
77
+extern HAL_TickFreqTypeDef uwTickFreq;
78
+
79
+/**
80
+  * @}
81
+  */
82
+/* Exported macro ------------------------------------------------------------*/
83
+/** @defgroup HAL_Exported_Macros HAL Exported Macros
84
+  * @{
85
+  */
86
+
87
+/** @defgroup DBGMCU_Freeze_Unfreeze Freeze Unfreeze Peripherals in Debug mode
88
+  * @brief   Freeze/Unfreeze Peripherals in Debug mode
89
+  * Note: On devices STM32F10xx8 and STM32F10xxB,
90
+  *                  STM32F101xC/D/E and STM32F103xC/D/E,
91
+  *                  STM32F101xF/G and STM32F103xF/G
92
+  *                  STM32F10xx4 and STM32F10xx6
93
+  *       Debug registers DBGMCU_IDCODE and DBGMCU_CR are accessible only in
94
+  *       debug mode (not accessible by the user software in normal mode).
95
+  *       Refer to errata sheet of these devices for more details.
96
+  * @{
97
+  */
98
+
99
+/* Peripherals on APB1 */
100
+/**
101
+  * @brief  TIM2 Peripherals Debug mode
102
+  */
103
+#define __HAL_DBGMCU_FREEZE_TIM2()            SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM2_STOP)
104
+#define __HAL_DBGMCU_UNFREEZE_TIM2()          CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM2_STOP)
105
+
106
+/**
107
+  * @brief  TIM3 Peripherals Debug mode
108
+  */
109
+#define __HAL_DBGMCU_FREEZE_TIM3()            SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM3_STOP)
110
+#define __HAL_DBGMCU_UNFREEZE_TIM3()          CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM3_STOP)
111
+
112
+#if defined (DBGMCU_CR_DBG_TIM4_STOP)
113
+/**
114
+  * @brief  TIM4 Peripherals Debug mode
115
+  */
116
+#define __HAL_DBGMCU_FREEZE_TIM4()            SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM4_STOP)
117
+#define __HAL_DBGMCU_UNFREEZE_TIM4()          CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM4_STOP)
118
+#endif
119
+
120
+#if defined (DBGMCU_CR_DBG_TIM5_STOP)
121
+/**
122
+  * @brief  TIM5 Peripherals Debug mode
123
+  */
124
+#define __HAL_DBGMCU_FREEZE_TIM5()            SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM5_STOP)
125
+#define __HAL_DBGMCU_UNFREEZE_TIM5()          CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM5_STOP)
126
+#endif
127
+
128
+#if defined (DBGMCU_CR_DBG_TIM6_STOP)
129
+/**
130
+  * @brief  TIM6 Peripherals Debug mode
131
+  */
132
+#define __HAL_DBGMCU_FREEZE_TIM6()            SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM6_STOP)
133
+#define __HAL_DBGMCU_UNFREEZE_TIM6()          CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM6_STOP)
134
+#endif
135
+
136
+#if defined (DBGMCU_CR_DBG_TIM7_STOP)
137
+/**
138
+  * @brief  TIM7 Peripherals Debug mode
139
+  */
140
+#define __HAL_DBGMCU_FREEZE_TIM7()            SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM7_STOP)
141
+#define __HAL_DBGMCU_UNFREEZE_TIM7()          CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM7_STOP)
142
+#endif
143
+
144
+#if defined (DBGMCU_CR_DBG_TIM12_STOP)
145
+/**
146
+  * @brief  TIM12 Peripherals Debug mode
147
+  */
148
+#define __HAL_DBGMCU_FREEZE_TIM12()            SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM12_STOP)
149
+#define __HAL_DBGMCU_UNFREEZE_TIM12()          CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM12_STOP)
150
+#endif
151
+
152
+#if defined (DBGMCU_CR_DBG_TIM13_STOP)
153
+/**
154
+  * @brief  TIM13 Peripherals Debug mode
155
+  */
156
+#define __HAL_DBGMCU_FREEZE_TIM13()            SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM13_STOP)
157
+#define __HAL_DBGMCU_UNFREEZE_TIM13()          CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM13_STOP)
158
+#endif
159
+
160
+#if defined (DBGMCU_CR_DBG_TIM14_STOP)
161
+/**
162
+  * @brief  TIM14 Peripherals Debug mode
163
+  */
164
+#define __HAL_DBGMCU_FREEZE_TIM14()            SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM14_STOP)
165
+#define __HAL_DBGMCU_UNFREEZE_TIM14()          CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM14_STOP)
166
+#endif
167
+
168
+/**
169
+  * @brief  WWDG Peripherals Debug mode
170
+  */
171
+#define __HAL_DBGMCU_FREEZE_WWDG()            SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_WWDG_STOP)
172
+#define __HAL_DBGMCU_UNFREEZE_WWDG()          CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_WWDG_STOP)
173
+
174
+/**
175
+  * @brief  IWDG Peripherals Debug mode
176
+  */
177
+#define __HAL_DBGMCU_FREEZE_IWDG()            SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_IWDG_STOP)
178
+#define __HAL_DBGMCU_UNFREEZE_IWDG()          CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_IWDG_STOP)
179
+
180
+/**
181
+  * @brief  I2C1 Peripherals Debug mode
182
+  */
183
+#define __HAL_DBGMCU_FREEZE_I2C1_TIMEOUT()    SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_I2C1_SMBUS_TIMEOUT)
184
+#define __HAL_DBGMCU_UNFREEZE_I2C1_TIMEOUT()  CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_I2C1_SMBUS_TIMEOUT)
185
+
186
+#if defined (DBGMCU_CR_DBG_I2C2_SMBUS_TIMEOUT)
187
+/**
188
+  * @brief  I2C2 Peripherals Debug mode
189
+  */
190
+#define __HAL_DBGMCU_FREEZE_I2C2_TIMEOUT()    SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_I2C2_SMBUS_TIMEOUT)
191
+#define __HAL_DBGMCU_UNFREEZE_I2C2_TIMEOUT()  CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_I2C2_SMBUS_TIMEOUT)
192
+#endif
193
+
194
+#if defined (DBGMCU_CR_DBG_CAN1_STOP)
195
+/**
196
+  * @brief  CAN1 Peripherals Debug mode
197
+  */
198
+#define __HAL_DBGMCU_FREEZE_CAN1()            SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_CAN1_STOP)
199
+#define __HAL_DBGMCU_UNFREEZE_CAN1()          CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_CAN1_STOP)
200
+#endif
201
+
202
+#if defined (DBGMCU_CR_DBG_CAN2_STOP)
203
+/**
204
+  * @brief  CAN2 Peripherals Debug mode
205
+  */
206
+#define __HAL_DBGMCU_FREEZE_CAN2()            SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_CAN2_STOP)
207
+#define __HAL_DBGMCU_UNFREEZE_CAN2()          CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_CAN2_STOP)
208
+#endif
209
+
210
+/* Peripherals on APB2 */
211
+#if defined (DBGMCU_CR_DBG_TIM1_STOP)
212
+/**
213
+  * @brief  TIM1 Peripherals Debug mode
214
+  */
215
+#define __HAL_DBGMCU_FREEZE_TIM1()            SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM1_STOP)
216
+#define __HAL_DBGMCU_UNFREEZE_TIM1()          CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM1_STOP)
217
+#endif
218
+
219
+#if defined (DBGMCU_CR_DBG_TIM8_STOP)
220
+/**
221
+  * @brief  TIM8 Peripherals Debug mode
222
+  */
223
+#define __HAL_DBGMCU_FREEZE_TIM8()            SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM8_STOP)
224
+#define __HAL_DBGMCU_UNFREEZE_TIM8()          CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM8_STOP)
225
+#endif
226
+
227
+#if defined (DBGMCU_CR_DBG_TIM9_STOP)
228
+/**
229
+  * @brief  TIM9 Peripherals Debug mode
230
+  */
231
+#define __HAL_DBGMCU_FREEZE_TIM9()            SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM9_STOP)
232
+#define __HAL_DBGMCU_UNFREEZE_TIM9()          CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM9_STOP)
233
+#endif
234
+
235
+#if defined (DBGMCU_CR_DBG_TIM10_STOP)
236
+/**
237
+  * @brief  TIM10 Peripherals Debug mode
238
+  */
239
+#define __HAL_DBGMCU_FREEZE_TIM10()            SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM10_STOP)
240
+#define __HAL_DBGMCU_UNFREEZE_TIM10()          CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM10_STOP)
241
+#endif
242
+
243
+#if defined (DBGMCU_CR_DBG_TIM11_STOP)
244
+/**
245
+  * @brief  TIM11 Peripherals Debug mode
246
+  */
247
+#define __HAL_DBGMCU_FREEZE_TIM11()            SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM11_STOP)
248
+#define __HAL_DBGMCU_UNFREEZE_TIM11()          CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM11_STOP)
249
+#endif
250
+
251
+
252
+#if defined (DBGMCU_CR_DBG_TIM15_STOP)
253
+/**
254
+  * @brief  TIM15 Peripherals Debug mode
255
+  */
256
+#define __HAL_DBGMCU_FREEZE_TIM15()            SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM15_STOP)
257
+#define __HAL_DBGMCU_UNFREEZE_TIM15()          CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM15_STOP)
258
+#endif
259
+
260
+#if defined (DBGMCU_CR_DBG_TIM16_STOP)
261
+/**
262
+  * @brief  TIM16 Peripherals Debug mode
263
+  */
264
+#define __HAL_DBGMCU_FREEZE_TIM16()            SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM16_STOP)
265
+#define __HAL_DBGMCU_UNFREEZE_TIM16()          CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM16_STOP)
266
+#endif
267
+
268
+#if defined (DBGMCU_CR_DBG_TIM17_STOP)
269
+/**
270
+  * @brief  TIM17 Peripherals Debug mode
271
+  */
272
+#define __HAL_DBGMCU_FREEZE_TIM17()            SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM17_STOP)
273
+#define __HAL_DBGMCU_UNFREEZE_TIM17()          CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_TIM17_STOP)
274
+#endif
275
+
276
+/**
277
+  * @}
278
+  */
279
+
280
+/** @defgroup HAL_Private_Macros HAL Private Macros
281
+  * @{
282
+  */
283
+#define IS_TICKFREQ(FREQ) (((FREQ) == HAL_TICK_FREQ_10HZ)  || \
284
+                           ((FREQ) == HAL_TICK_FREQ_100HZ) || \
285
+                           ((FREQ) == HAL_TICK_FREQ_1KHZ))
286
+/**
287
+  * @}
288
+  */
289
+
290
+/* Exported functions --------------------------------------------------------*/
291
+/** @addtogroup HAL_Exported_Functions
292
+  * @{
293
+  */
294
+/** @addtogroup HAL_Exported_Functions_Group1
295
+  * @{
296
+  */
297
+/* Initialization and de-initialization functions  ******************************/
298
+HAL_StatusTypeDef HAL_Init(void);
299
+HAL_StatusTypeDef HAL_DeInit(void);
300
+void HAL_MspInit(void);
301
+void HAL_MspDeInit(void);
302
+HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority);
303
+/**
304
+  * @}
305
+  */
306
+
307
+/** @addtogroup HAL_Exported_Functions_Group2
308
+  * @{
309
+  */
310
+/* Peripheral Control functions  ************************************************/
311
+void HAL_IncTick(void);
312
+void HAL_Delay(uint32_t Delay);
313
+uint32_t HAL_GetTick(void);
314
+uint32_t HAL_GetTickPrio(void);
315
+HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq);
316
+HAL_TickFreqTypeDef HAL_GetTickFreq(void);
317
+void HAL_SuspendTick(void);
318
+void HAL_ResumeTick(void);
319
+uint32_t HAL_GetHalVersion(void);
320
+uint32_t HAL_GetREVID(void);
321
+uint32_t HAL_GetDEVID(void);
322
+void HAL_DBGMCU_EnableDBGSleepMode(void);
323
+void HAL_DBGMCU_DisableDBGSleepMode(void);
324
+void HAL_DBGMCU_EnableDBGStopMode(void);
325
+void HAL_DBGMCU_DisableDBGStopMode(void);
326
+void HAL_DBGMCU_EnableDBGStandbyMode(void);
327
+void HAL_DBGMCU_DisableDBGStandbyMode(void);
328
+void HAL_GetUID(uint32_t *UID);
329
+/**
330
+  * @}
331
+  */
332
+
333
+/**
334
+  * @}
335
+  */
336
+/* Private types -------------------------------------------------------------*/
337
+/* Private variables ---------------------------------------------------------*/
338
+/** @defgroup HAL_Private_Variables HAL Private Variables
339
+  * @{
340
+  */
341
+/**
342
+  * @}
343
+  */
344
+/* Private constants ---------------------------------------------------------*/
345
+/** @defgroup HAL_Private_Constants HAL Private Constants
346
+  * @{
347
+  */
348
+/**
349
+  * @}
350
+  */
351
+/* Private macros ------------------------------------------------------------*/
352
+/* Private functions ---------------------------------------------------------*/
353
+/**
354
+  * @}
355
+  */
356
+
357
+/**
358
+  * @}
359
+  */
360
+
361
+#ifdef __cplusplus
362
+}
363
+#endif
364
+
365
+#endif /* __STM32F1xx_HAL_H */
366
+
367
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 965 - 0
Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_adc.h

@@ -0,0 +1,965 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_adc.h
4
+  * @author  MCD Application Team
5
+  * @brief   Header file containing functions prototypes of ADC HAL library.
6
+  ******************************************************************************
7
+  * @attention
8
+  *
9
+  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
10
+  *
11
+  * Redistribution and use in source and binary forms, with or without modification,
12
+  * are permitted provided that the following conditions are met:
13
+  *   1. Redistributions of source code must retain the above copyright notice,
14
+  *      this list of conditions and the following disclaimer.
15
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
16
+  *      this list of conditions and the following disclaimer in the documentation
17
+  *      and/or other materials provided with the distribution.
18
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
19
+  *      may be used to endorse or promote products derived from this software
20
+  *      without specific prior written permission.
21
+  *
22
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+  *
33
+  ******************************************************************************
34
+  */
35
+
36
+/* Define to prevent recursive inclusion -------------------------------------*/
37
+#ifndef __STM32F1xx_HAL_ADC_H
38
+#define __STM32F1xx_HAL_ADC_H
39
+
40
+#ifdef __cplusplus
41
+ extern "C" {
42
+#endif
43
+
44
+/* Includes ------------------------------------------------------------------*/
45
+#include "stm32f1xx_hal_def.h"  
46
+/** @addtogroup STM32F1xx_HAL_Driver
47
+  * @{
48
+  */
49
+
50
+/** @addtogroup ADC
51
+  * @{
52
+  */ 
53
+
54
+/* Exported types ------------------------------------------------------------*/ 
55
+/** @defgroup ADC_Exported_Types ADC Exported Types
56
+  * @{
57
+  */
58
+
59
+/** 
60
+  * @brief  Structure definition of ADC and regular group initialization 
61
+  * @note   Parameters of this structure are shared within 2 scopes:
62
+  *          - Scope entire ADC (affects regular and injected groups): DataAlign, ScanConvMode.
63
+  *          - Scope regular group: ContinuousConvMode, NbrOfConversion, DiscontinuousConvMode, NbrOfDiscConversion, ExternalTrigConvEdge, ExternalTrigConv.
64
+  * @note   The setting of these parameters with function HAL_ADC_Init() is conditioned to ADC state.
65
+  *         ADC can be either disabled or enabled without conversion on going on regular group.
66
+  */
67
+typedef struct
68
+{
69
+  uint32_t DataAlign;             /*!< Specifies ADC data alignment to right (MSB on register bit 11 and LSB on register bit 0) (default setting)
70
+                                       or to left (if regular group: MSB on register bit 15 and LSB on register bit 4, if injected group (MSB kept as signed value due to potential negative value after offset application): MSB on register bit 14 and LSB on register bit 3).
71
+                                       This parameter can be a value of @ref ADC_Data_align */
72
+  uint32_t ScanConvMode;          /*!< Configures the sequencer of regular and injected groups.
73
+                                       This parameter can be associated to parameter 'DiscontinuousConvMode' to have main sequence subdivided in successive parts.
74
+                                       If disabled: Conversion is performed in single mode (one channel converted, the one defined in rank 1).
75
+                                                    Parameters 'NbrOfConversion' and 'InjectedNbrOfConversion' are discarded (equivalent to set to 1).
76
+                                       If enabled:  Conversions are performed in sequence mode (multiple ranks defined by 'NbrOfConversion'/'InjectedNbrOfConversion' and each channel rank).
77
+                                                    Scan direction is upward: from rank1 to rank 'n'.
78
+                                       This parameter can be a value of @ref ADC_Scan_mode
79
+                                       Note: For regular group, this parameter should be enabled in conversion either by polling (HAL_ADC_Start with Discontinuous mode and NbrOfDiscConversion=1)
80
+                                             or by DMA (HAL_ADC_Start_DMA), but not by interruption (HAL_ADC_Start_IT): in scan mode, interruption is triggered only on the
81
+                                             the last conversion of the sequence. All previous conversions would be overwritten by the last one.
82
+                                             Injected group used with scan mode has not this constraint: each rank has its own result register, no data is overwritten. */
83
+  uint32_t ContinuousConvMode;    /*!< Specifies whether the conversion is performed in single mode (one conversion) or continuous mode for regular group,
84
+                                       after the selected trigger occurred (software start or external trigger).
85
+                                       This parameter can be set to ENABLE or DISABLE. */
86
+  uint32_t NbrOfConversion;       /*!< Specifies the number of ranks that will be converted within the regular group sequencer.
87
+                                       To use regular group sequencer and convert several ranks, parameter 'ScanConvMode' must be enabled.
88
+                                       This parameter must be a number between Min_Data = 1 and Max_Data = 16. */
89
+  uint32_t DiscontinuousConvMode; /*!< Specifies whether the conversions sequence of regular group is performed in Complete-sequence/Discontinuous-sequence (main sequence subdivided in successive parts).
90
+                                       Discontinuous mode is used only if sequencer is enabled (parameter 'ScanConvMode'). If sequencer is disabled, this parameter is discarded.
91
+                                       Discontinuous mode can be enabled only if continuous mode is disabled. If continuous mode is enabled, this parameter setting is discarded.
92
+                                       This parameter can be set to ENABLE or DISABLE. */
93
+  uint32_t NbrOfDiscConversion;   /*!< Specifies the number of discontinuous conversions in which the  main sequence of regular group (parameter NbrOfConversion) will be subdivided.
94
+                                       If parameter 'DiscontinuousConvMode' is disabled, this parameter is discarded.
95
+                                       This parameter must be a number between Min_Data = 1 and Max_Data = 8. */
96
+  uint32_t ExternalTrigConv;      /*!< Selects the external event used to trigger the conversion start of regular group.
97
+                                       If set to ADC_SOFTWARE_START, external triggers are disabled.
98
+                                       If set to external trigger source, triggering is on event rising edge.
99
+                                       This parameter can be a value of @ref ADC_External_trigger_source_Regular */
100
+}ADC_InitTypeDef;
101
+
102
+/** 
103
+  * @brief  Structure definition of ADC channel for regular group   
104
+  * @note   The setting of these parameters with function HAL_ADC_ConfigChannel() is conditioned to ADC state.
105
+  *         ADC can be either disabled or enabled without conversion on going on regular group.
106
+  */ 
107
+typedef struct 
108
+{
109
+  uint32_t Channel;                /*!< Specifies the channel to configure into ADC regular group.
110
+                                        This parameter can be a value of @ref ADC_channels
111
+                                        Note: Depending on devices, some channels may not be available on package pins. Refer to device datasheet for channels availability.
112
+                                        Note: On STM32F1 devices with several ADC: Only ADC1 can access internal measurement channels (VrefInt/TempSensor) 
113
+                                        Note: On STM32F10xx8 and STM32F10xxB devices: A low-amplitude voltage glitch may be generated (on ADC input 0) on the PA0 pin, when the ADC is converting with injection trigger.
114
+                                              It is advised to distribute the analog channels so that Channel 0 is configured as an injected channel.
115
+                                              Refer to errata sheet of these devices for more details. */
116
+  uint32_t Rank;                   /*!< Specifies the rank in the regular group sequencer 
117
+                                        This parameter can be a value of @ref ADC_regular_rank
118
+                                        Note: In case of need to disable a channel or change order of conversion sequencer, rank containing a previous channel setting can be overwritten by the new channel setting (or parameter number of conversions can be adjusted) */
119
+  uint32_t SamplingTime;           /*!< Sampling time value to be set for the selected channel.
120
+                                        Unit: ADC clock cycles
121
+                                        Conversion time is the addition of sampling time and processing time (12.5 ADC clock cycles at ADC resolution 12 bits).
122
+                                        This parameter can be a value of @ref ADC_sampling_times
123
+                                        Caution: This parameter updates the parameter property of the channel, that can be used into regular and/or injected groups.
124
+                                                 If this same channel has been previously configured in the other group (regular/injected), it will be updated to last setting.
125
+                                        Note: In case of usage of internal measurement channels (VrefInt/TempSensor),
126
+                                              sampling time constraints must be respected (sampling time can be adjusted in function of ADC clock frequency and sampling time setting)
127
+                                              Refer to device datasheet for timings values, parameters TS_vrefint, TS_temp (values rough order: 5us to 17.1us min). */
128
+}ADC_ChannelConfTypeDef;
129
+
130
+/**
131
+  * @brief  ADC Configuration analog watchdog definition
132
+  * @note   The setting of these parameters with function is conditioned to ADC state.
133
+  *         ADC state can be either disabled or enabled without conversion on going on regular and injected groups.
134
+  */
135
+typedef struct
136
+{
137
+  uint32_t WatchdogMode;      /*!< Configures the ADC analog watchdog mode: single/all channels, regular/injected group.
138
+                                   This parameter can be a value of @ref ADC_analog_watchdog_mode. */
139
+  uint32_t Channel;           /*!< Selects which ADC channel to monitor by analog watchdog.
140
+                                   This parameter has an effect only if watchdog mode is configured on single channel (parameter WatchdogMode)
141
+                                   This parameter can be a value of @ref ADC_channels. */
142
+  uint32_t ITMode;            /*!< Specifies whether the analog watchdog is configured in interrupt or polling mode.
143
+                                   This parameter can be set to ENABLE or DISABLE */
144
+  uint32_t HighThreshold;     /*!< Configures the ADC analog watchdog High threshold value.
145
+                                   This parameter must be a number between Min_Data = 0x000 and Max_Data = 0xFFF. */
146
+  uint32_t LowThreshold;      /*!< Configures the ADC analog watchdog High threshold value.
147
+                                   This parameter must be a number between Min_Data = 0x000 and Max_Data = 0xFFF. */
148
+  uint32_t WatchdogNumber;    /*!< Reserved for future use, can be set to 0 */
149
+}ADC_AnalogWDGConfTypeDef;
150
+
151
+/** 
152
+  * @brief  HAL ADC state machine: ADC states definition (bitfields)
153
+  */ 
154
+/* States of ADC global scope */
155
+#define HAL_ADC_STATE_RESET             0x00000000U    /*!< ADC not yet initialized or disabled */
156
+#define HAL_ADC_STATE_READY             0x00000001U    /*!< ADC peripheral ready for use */
157
+#define HAL_ADC_STATE_BUSY_INTERNAL     0x00000002U    /*!< ADC is busy to internal process (initialization, calibration) */
158
+#define HAL_ADC_STATE_TIMEOUT           0x00000004U    /*!< TimeOut occurrence */
159
+
160
+/* States of ADC errors */
161
+#define HAL_ADC_STATE_ERROR_INTERNAL    0x00000010U    /*!< Internal error occurrence */
162
+#define HAL_ADC_STATE_ERROR_CONFIG      0x00000020U    /*!< Configuration error occurrence */
163
+#define HAL_ADC_STATE_ERROR_DMA         0x00000040U    /*!< DMA error occurrence */
164
+
165
+/* States of ADC group regular */
166
+#define HAL_ADC_STATE_REG_BUSY          0x00000100U    /*!< A conversion on group regular is ongoing or can occur (either by continuous mode,
167
+                                                           external trigger, low power auto power-on, multimode ADC master control) */
168
+#define HAL_ADC_STATE_REG_EOC           0x00000200U    /*!< Conversion data available on group regular */
169
+#define HAL_ADC_STATE_REG_OVR           0x00000400U    /*!< Not available on STM32F1 device: Overrun occurrence */
170
+#define HAL_ADC_STATE_REG_EOSMP         0x00000800U    /*!< Not available on STM32F1 device: End Of Sampling flag raised  */
171
+
172
+/* States of ADC group injected */
173
+#define HAL_ADC_STATE_INJ_BUSY          0x00001000U    /*!< A conversion on group injected is ongoing or can occur (either by auto-injection mode,
174
+                                                           external trigger, low power auto power-on, multimode ADC master control) */
175
+#define HAL_ADC_STATE_INJ_EOC           0x00002000U    /*!< Conversion data available on group injected */
176
+#define HAL_ADC_STATE_INJ_JQOVF         0x00004000U    /*!< Not available on STM32F1 device: Injected queue overflow occurrence */
177
+
178
+/* States of ADC analog watchdogs */
179
+#define HAL_ADC_STATE_AWD1              0x00010000U    /*!< Out-of-window occurrence of analog watchdog 1 */
180
+#define HAL_ADC_STATE_AWD2              0x00020000U    /*!< Not available on STM32F1 device: Out-of-window occurrence of analog watchdog 2 */
181
+#define HAL_ADC_STATE_AWD3              0x00040000U    /*!< Not available on STM32F1 device: Out-of-window occurrence of analog watchdog 3 */
182
+
183
+/* States of ADC multi-mode */
184
+#define HAL_ADC_STATE_MULTIMODE_SLAVE   0x00100000U    /*!< ADC in multimode slave state, controlled by another ADC master ( */
185
+
186
+
187
+/** 
188
+  * @brief  ADC handle Structure definition  
189
+  */ 
190
+typedef struct
191
+{
192
+  ADC_TypeDef                   *Instance;              /*!< Register base address */
193
+
194
+  ADC_InitTypeDef               Init;                   /*!< ADC required parameters */
195
+
196
+  DMA_HandleTypeDef             *DMA_Handle;            /*!< Pointer DMA Handler */
197
+
198
+  HAL_LockTypeDef               Lock;                   /*!< ADC locking object */
199
+  
200
+  __IO uint32_t                 State;                  /*!< ADC communication state (bitmap of ADC states) */
201
+
202
+  __IO uint32_t                 ErrorCode;              /*!< ADC Error code */
203
+}ADC_HandleTypeDef;
204
+/**
205
+  * @}
206
+  */
207
+
208
+
209
+
210
+/* Exported constants --------------------------------------------------------*/
211
+
212
+/** @defgroup ADC_Exported_Constants ADC Exported Constants
213
+  * @{
214
+  */
215
+
216
+/** @defgroup ADC_Error_Code ADC Error Code
217
+  * @{
218
+  */
219
+#define HAL_ADC_ERROR_NONE                0x00U   /*!< No error                                              */
220
+#define HAL_ADC_ERROR_INTERNAL            0x01U   /*!< ADC IP internal error: if problem of clocking, 
221
+                                                       enable/disable, erroneous state                       */
222
+#define HAL_ADC_ERROR_OVR                 0x02U   /*!< Overrun error                                         */
223
+#define HAL_ADC_ERROR_DMA                 0x04U   /*!< DMA transfer error                                    */
224
+
225
+/**
226
+  * @}
227
+  */
228
+
229
+
230
+/** @defgroup ADC_Data_align ADC data alignment
231
+  * @{
232
+  */
233
+#define ADC_DATAALIGN_RIGHT      0x00000000U
234
+#define ADC_DATAALIGN_LEFT       ((uint32_t)ADC_CR2_ALIGN)
235
+/**
236
+  * @}
237
+  */
238
+
239
+/** @defgroup ADC_Scan_mode ADC scan mode
240
+  * @{
241
+  */
242
+/* Note: Scan mode values are not among binary choices ENABLE/DISABLE for     */
243
+/*       compatibility with other STM32 devices having a sequencer with       */
244
+/*       additional options.                                                  */
245
+#define ADC_SCAN_DISABLE         0x00000000U
246
+#define ADC_SCAN_ENABLE          ((uint32_t)ADC_CR1_SCAN)
247
+/**
248
+  * @}
249
+  */
250
+
251
+/** @defgroup ADC_External_trigger_edge_Regular ADC external trigger enable for regular group
252
+  * @{
253
+  */
254
+#define ADC_EXTERNALTRIGCONVEDGE_NONE           0x00000000U
255
+#define ADC_EXTERNALTRIGCONVEDGE_RISING         ((uint32_t)ADC_CR2_EXTTRIG)
256
+/**
257
+  * @}
258
+  */
259
+
260
+/** @defgroup ADC_channels ADC channels
261
+  * @{
262
+  */
263
+/* Note: Depending on devices, some channels may not be available on package  */
264
+/*       pins. Refer to device datasheet for channels availability.           */
265
+#define ADC_CHANNEL_0                       0x00000000U
266
+#define ADC_CHANNEL_1           ((uint32_t)(                                                                    ADC_SQR3_SQ1_0))
267
+#define ADC_CHANNEL_2           ((uint32_t)(                                                   ADC_SQR3_SQ1_1                 ))
268
+#define ADC_CHANNEL_3           ((uint32_t)(                                                   ADC_SQR3_SQ1_1 | ADC_SQR3_SQ1_0))
269
+#define ADC_CHANNEL_4           ((uint32_t)(                                  ADC_SQR3_SQ1_2                                  ))
270
+#define ADC_CHANNEL_5           ((uint32_t)(                                  ADC_SQR3_SQ1_2                  | ADC_SQR3_SQ1_0))
271
+#define ADC_CHANNEL_6           ((uint32_t)(                                  ADC_SQR3_SQ1_2 | ADC_SQR3_SQ1_1                 ))
272
+#define ADC_CHANNEL_7           ((uint32_t)(                                  ADC_SQR3_SQ1_2 | ADC_SQR3_SQ1_1 | ADC_SQR3_SQ1_0))
273
+#define ADC_CHANNEL_8           ((uint32_t)(                 ADC_SQR3_SQ1_3                                                   ))
274
+#define ADC_CHANNEL_9           ((uint32_t)(                 ADC_SQR3_SQ1_3                                   | ADC_SQR3_SQ1_0))
275
+#define ADC_CHANNEL_10          ((uint32_t)(                 ADC_SQR3_SQ1_3                  | ADC_SQR3_SQ1_1                 ))
276
+#define ADC_CHANNEL_11          ((uint32_t)(                 ADC_SQR3_SQ1_3                  | ADC_SQR3_SQ1_1 | ADC_SQR3_SQ1_0))
277
+#define ADC_CHANNEL_12          ((uint32_t)(                 ADC_SQR3_SQ1_3 | ADC_SQR3_SQ1_2                                  ))
278
+#define ADC_CHANNEL_13          ((uint32_t)(                 ADC_SQR3_SQ1_3 | ADC_SQR3_SQ1_2                  | ADC_SQR3_SQ1_0))
279
+#define ADC_CHANNEL_14          ((uint32_t)(                 ADC_SQR3_SQ1_3 | ADC_SQR3_SQ1_2 | ADC_SQR3_SQ1_1                 ))
280
+#define ADC_CHANNEL_15          ((uint32_t)(                 ADC_SQR3_SQ1_3 | ADC_SQR3_SQ1_2 | ADC_SQR3_SQ1_1 | ADC_SQR3_SQ1_0))
281
+#define ADC_CHANNEL_16          ((uint32_t)(ADC_SQR3_SQ1_4                                                                    ))
282
+#define ADC_CHANNEL_17          ((uint32_t)(ADC_SQR3_SQ1_4                                                    | ADC_SQR3_SQ1_0))
283
+
284
+#define ADC_CHANNEL_TEMPSENSOR  ADC_CHANNEL_16  /* ADC internal channel (no connection on device pin) */
285
+#define ADC_CHANNEL_VREFINT     ADC_CHANNEL_17  /* ADC internal channel (no connection on device pin) */
286
+/**
287
+  * @}
288
+  */
289
+
290
+/** @defgroup ADC_sampling_times ADC sampling times
291
+  * @{
292
+  */
293
+#define ADC_SAMPLETIME_1CYCLE_5                   0x00000000U                                              /*!< Sampling time 1.5 ADC clock cycle */
294
+#define ADC_SAMPLETIME_7CYCLES_5      ((uint32_t)(                                      ADC_SMPR2_SMP0_0)) /*!< Sampling time 7.5 ADC clock cycles */
295
+#define ADC_SAMPLETIME_13CYCLES_5     ((uint32_t)(                   ADC_SMPR2_SMP0_1                   )) /*!< Sampling time 13.5 ADC clock cycles */
296
+#define ADC_SAMPLETIME_28CYCLES_5     ((uint32_t)(                   ADC_SMPR2_SMP0_1 | ADC_SMPR2_SMP0_0)) /*!< Sampling time 28.5 ADC clock cycles */
297
+#define ADC_SAMPLETIME_41CYCLES_5     ((uint32_t)(ADC_SMPR2_SMP0_2                                      )) /*!< Sampling time 41.5 ADC clock cycles */
298
+#define ADC_SAMPLETIME_55CYCLES_5     ((uint32_t)(ADC_SMPR2_SMP0_2                    | ADC_SMPR2_SMP0_0)) /*!< Sampling time 55.5 ADC clock cycles */
299
+#define ADC_SAMPLETIME_71CYCLES_5     ((uint32_t)(ADC_SMPR2_SMP0_2 | ADC_SMPR2_SMP0_1                   )) /*!< Sampling time 71.5 ADC clock cycles */
300
+#define ADC_SAMPLETIME_239CYCLES_5    ((uint32_t)(ADC_SMPR2_SMP0_2 | ADC_SMPR2_SMP0_1 | ADC_SMPR2_SMP0_0)) /*!< Sampling time 239.5 ADC clock cycles */
301
+/**
302
+  * @}
303
+  */
304
+
305
+/** @defgroup ADC_regular_rank ADC rank into regular group
306
+  * @{
307
+  */
308
+#define ADC_REGULAR_RANK_1                 0x00000001U
309
+#define ADC_REGULAR_RANK_2                 0x00000002U
310
+#define ADC_REGULAR_RANK_3                 0x00000003U
311
+#define ADC_REGULAR_RANK_4                 0x00000004U
312
+#define ADC_REGULAR_RANK_5                 0x00000005U
313
+#define ADC_REGULAR_RANK_6                 0x00000006U
314
+#define ADC_REGULAR_RANK_7                 0x00000007U
315
+#define ADC_REGULAR_RANK_8                 0x00000008U
316
+#define ADC_REGULAR_RANK_9                 0x00000009U
317
+#define ADC_REGULAR_RANK_10                0x0000000AU
318
+#define ADC_REGULAR_RANK_11                0x0000000BU
319
+#define ADC_REGULAR_RANK_12                0x0000000CU
320
+#define ADC_REGULAR_RANK_13                0x0000000DU
321
+#define ADC_REGULAR_RANK_14                0x0000000EU
322
+#define ADC_REGULAR_RANK_15                0x0000000FU
323
+#define ADC_REGULAR_RANK_16                0x00000010U
324
+/**
325
+  * @}
326
+  */
327
+
328
+/** @defgroup ADC_analog_watchdog_mode ADC analog watchdog mode
329
+  * @{
330
+  */
331
+#define ADC_ANALOGWATCHDOG_NONE                             0x00000000U
332
+#define ADC_ANALOGWATCHDOG_SINGLE_REG           ((uint32_t)(ADC_CR1_AWDSGL | ADC_CR1_AWDEN))
333
+#define ADC_ANALOGWATCHDOG_SINGLE_INJEC         ((uint32_t)(ADC_CR1_AWDSGL | ADC_CR1_JAWDEN))
334
+#define ADC_ANALOGWATCHDOG_SINGLE_REGINJEC      ((uint32_t)(ADC_CR1_AWDSGL | ADC_CR1_AWDEN | ADC_CR1_JAWDEN))
335
+#define ADC_ANALOGWATCHDOG_ALL_REG              ((uint32_t)ADC_CR1_AWDEN)
336
+#define ADC_ANALOGWATCHDOG_ALL_INJEC            ((uint32_t)ADC_CR1_JAWDEN)
337
+#define ADC_ANALOGWATCHDOG_ALL_REGINJEC         ((uint32_t)(ADC_CR1_AWDEN | ADC_CR1_JAWDEN))
338
+/**
339
+  * @}
340
+  */
341
+
342
+/** @defgroup ADC_conversion_group ADC conversion group
343
+  * @{
344
+  */
345
+#define ADC_REGULAR_GROUP             ((uint32_t)(ADC_FLAG_EOC))
346
+#define ADC_INJECTED_GROUP            ((uint32_t)(ADC_FLAG_JEOC))
347
+#define ADC_REGULAR_INJECTED_GROUP    ((uint32_t)(ADC_FLAG_EOC | ADC_FLAG_JEOC))
348
+/**
349
+  * @}
350
+  */
351
+
352
+/** @defgroup ADC_Event_type ADC Event type
353
+  * @{
354
+  */
355
+#define ADC_AWD_EVENT               ((uint32_t)ADC_FLAG_AWD)   /*!< ADC Analog watchdog event */
356
+
357
+#define ADC_AWD1_EVENT              ADC_AWD_EVENT              /*!< ADC Analog watchdog 1 event: Alternate naming for compatibility with other STM32 devices having several analog watchdogs */
358
+/**
359
+  * @}
360
+  */
361
+
362
+/** @defgroup ADC_interrupts_definition ADC interrupts definition
363
+  * @{
364
+  */
365
+#define ADC_IT_EOC           ADC_CR1_EOCIE        /*!< ADC End of Regular Conversion interrupt source */
366
+#define ADC_IT_JEOC          ADC_CR1_JEOCIE       /*!< ADC End of Injected Conversion interrupt source */
367
+#define ADC_IT_AWD           ADC_CR1_AWDIE        /*!< ADC Analog watchdog interrupt source */
368
+/**
369
+  * @}
370
+  */
371
+
372
+/** @defgroup ADC_flags_definition ADC flags definition
373
+  * @{
374
+  */
375
+#define ADC_FLAG_STRT          ADC_SR_STRT     /*!< ADC Regular group start flag */
376
+#define ADC_FLAG_JSTRT         ADC_SR_JSTRT    /*!< ADC Injected group start flag */
377
+#define ADC_FLAG_EOC           ADC_SR_EOC      /*!< ADC End of Regular conversion flag */
378
+#define ADC_FLAG_JEOC          ADC_SR_JEOC     /*!< ADC End of Injected conversion flag */
379
+#define ADC_FLAG_AWD           ADC_SR_AWD      /*!< ADC Analog watchdog flag */
380
+/**
381
+  * @}
382
+  */
383
+
384
+
385
+/**
386
+  * @}
387
+  */ 
388
+
389
+/* Private constants ---------------------------------------------------------*/
390
+
391
+/** @addtogroup ADC_Private_Constants ADC Private Constants
392
+  * @{
393
+  */
394
+
395
+/** @defgroup ADC_conversion_cycles ADC conversion cycles
396
+  * @{
397
+  */
398
+/* ADC conversion cycles (unit: ADC clock cycles)                           */
399
+/* (selected sampling time + conversion time of 12.5 ADC clock cycles, with */
400
+/* resolution 12 bits)                                                      */
401
+#define ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_1CYCLE5                  14U
402
+#define ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_7CYCLES5                 20U
403
+#define ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_13CYCLES5                26U
404
+#define ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_28CYCLES5                41U
405
+#define ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_41CYCLES5                54U
406
+#define ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_55CYCLES5                68U
407
+#define ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_71CYCLES5                84U
408
+#define ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_239CYCLES5              252U
409
+/**
410
+  * @}
411
+  */
412
+
413
+/** @defgroup ADC_sampling_times_all_channels ADC sampling times all channels
414
+  * @{
415
+  */
416
+#define ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT2                                          \
417
+     (ADC_SMPR2_SMP9_2 | ADC_SMPR2_SMP8_2 | ADC_SMPR2_SMP7_2 | ADC_SMPR2_SMP6_2 |     \
418
+      ADC_SMPR2_SMP5_2 | ADC_SMPR2_SMP4_2 | ADC_SMPR2_SMP3_2 | ADC_SMPR2_SMP2_2 |     \
419
+      ADC_SMPR2_SMP1_2 | ADC_SMPR2_SMP0_2)
420
+#define ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT2                                          \
421
+     (ADC_SMPR1_SMP17_2 | ADC_SMPR1_SMP16_2 | ADC_SMPR1_SMP15_2 | ADC_SMPR1_SMP14_2 | \
422
+      ADC_SMPR1_SMP13_2 | ADC_SMPR1_SMP12_2 | ADC_SMPR1_SMP11_2 | ADC_SMPR1_SMP10_2 )
423
+
424
+#define ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT1                                          \
425
+     (ADC_SMPR2_SMP9_1 | ADC_SMPR2_SMP8_1 | ADC_SMPR2_SMP7_1 | ADC_SMPR2_SMP6_1 |     \
426
+      ADC_SMPR2_SMP5_1 | ADC_SMPR2_SMP4_1 | ADC_SMPR2_SMP3_1 | ADC_SMPR2_SMP2_1 |     \
427
+      ADC_SMPR2_SMP1_1 | ADC_SMPR2_SMP0_1)
428
+#define ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT1                                          \
429
+     (ADC_SMPR1_SMP17_1 | ADC_SMPR1_SMP16_1 | ADC_SMPR1_SMP15_1 | ADC_SMPR1_SMP14_1 | \
430
+      ADC_SMPR1_SMP13_1 | ADC_SMPR1_SMP12_1 | ADC_SMPR1_SMP11_1 | ADC_SMPR1_SMP10_1 )
431
+
432
+#define ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT0                                          \
433
+     (ADC_SMPR2_SMP9_0 | ADC_SMPR2_SMP8_0 | ADC_SMPR2_SMP7_0 | ADC_SMPR2_SMP6_0 |     \
434
+      ADC_SMPR2_SMP5_0 | ADC_SMPR2_SMP4_0 | ADC_SMPR2_SMP3_0 | ADC_SMPR2_SMP2_0 |     \
435
+      ADC_SMPR2_SMP1_0 | ADC_SMPR2_SMP0_0)
436
+#define ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT0                                          \
437
+     (ADC_SMPR1_SMP17_0 | ADC_SMPR1_SMP16_0 | ADC_SMPR1_SMP15_0 | ADC_SMPR1_SMP14_0 | \
438
+      ADC_SMPR1_SMP13_0 | ADC_SMPR1_SMP12_0 | ADC_SMPR1_SMP11_0 | ADC_SMPR1_SMP10_0 )
439
+
440
+#define ADC_SAMPLETIME_1CYCLE5_SMPR2ALLCHANNELS    0x00000000U
441
+#define ADC_SAMPLETIME_7CYCLES5_SMPR2ALLCHANNELS   (ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT0)
442
+#define ADC_SAMPLETIME_13CYCLES5_SMPR2ALLCHANNELS  (ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT1)
443
+#define ADC_SAMPLETIME_28CYCLES5_SMPR2ALLCHANNELS  (ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT1 | ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT0)
444
+#define ADC_SAMPLETIME_41CYCLES5_SMPR2ALLCHANNELS  (ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT2)
445
+#define ADC_SAMPLETIME_55CYCLES5_SMPR2ALLCHANNELS  (ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT2 | ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT0)
446
+#define ADC_SAMPLETIME_71CYCLES5_SMPR2ALLCHANNELS  (ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT2 | ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT1)
447
+#define ADC_SAMPLETIME_239CYCLES5_SMPR2ALLCHANNELS (ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT2 | ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT1 | ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT0)
448
+
449
+#define ADC_SAMPLETIME_1CYCLE5_SMPR1ALLCHANNELS    0x00000000U
450
+#define ADC_SAMPLETIME_7CYCLES5_SMPR1ALLCHANNELS   (ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT0)
451
+#define ADC_SAMPLETIME_13CYCLES5_SMPR1ALLCHANNELS  (ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT1)
452
+#define ADC_SAMPLETIME_28CYCLES5_SMPR1ALLCHANNELS  (ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT1 | ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT0)
453
+#define ADC_SAMPLETIME_41CYCLES5_SMPR1ALLCHANNELS  (ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT2)
454
+#define ADC_SAMPLETIME_55CYCLES5_SMPR1ALLCHANNELS  (ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT2 | ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT0)
455
+#define ADC_SAMPLETIME_71CYCLES5_SMPR1ALLCHANNELS  (ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT2 | ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT1)
456
+#define ADC_SAMPLETIME_239CYCLES5_SMPR1ALLCHANNELS (ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT2 | ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT1 | ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT0)
457
+/**
458
+  * @}
459
+  */
460
+
461
+/* Combination of all post-conversion flags bits: EOC/EOS, JEOC/JEOS, OVR, AWDx */
462
+#define ADC_FLAG_POSTCONV_ALL   (ADC_FLAG_EOC | ADC_FLAG_JEOC | ADC_FLAG_AWD )
463
+
464
+/**
465
+  * @}
466
+  */
467
+
468
+
469
+/* Exported macro ------------------------------------------------------------*/
470
+
471
+/** @defgroup ADC_Exported_Macros ADC Exported Macros
472
+  * @{
473
+  */
474
+/* Macro for internal HAL driver usage, and possibly can be used into code of */
475
+/* final user.                                                                */    
476
+
477
+/**
478
+  * @brief Enable the ADC peripheral
479
+  * @note ADC enable requires a delay for ADC stabilization time
480
+  *       (refer to device datasheet, parameter tSTAB)
481
+  * @note On STM32F1, if ADC is already enabled this macro trigs a conversion 
482
+  *       SW start on regular group.
483
+  * @param __HANDLE__: ADC handle
484
+  * @retval None
485
+  */
486
+#define __HAL_ADC_ENABLE(__HANDLE__)                                           \
487
+  (SET_BIT((__HANDLE__)->Instance->CR2, (ADC_CR2_ADON)))
488
+    
489
+/**
490
+  * @brief Disable the ADC peripheral
491
+  * @param __HANDLE__: ADC handle
492
+  * @retval None
493
+  */
494
+#define __HAL_ADC_DISABLE(__HANDLE__)                                          \
495
+  (CLEAR_BIT((__HANDLE__)->Instance->CR2, (ADC_CR2_ADON)))
496
+    
497
+/** @brief Enable the ADC end of conversion interrupt.
498
+  * @param __HANDLE__: ADC handle
499
+  * @param __INTERRUPT__: ADC Interrupt
500
+  *          This parameter can be any combination of the following values:
501
+  *            @arg ADC_IT_EOC: ADC End of Regular Conversion interrupt source
502
+  *            @arg ADC_IT_JEOC: ADC End of Injected Conversion interrupt source
503
+  *            @arg ADC_IT_AWD: ADC Analog watchdog interrupt source
504
+  * @retval None
505
+  */
506
+#define __HAL_ADC_ENABLE_IT(__HANDLE__, __INTERRUPT__)                         \
507
+  (SET_BIT((__HANDLE__)->Instance->CR1, (__INTERRUPT__)))
508
+    
509
+/** @brief Disable the ADC end of conversion interrupt.
510
+  * @param __HANDLE__: ADC handle
511
+  * @param __INTERRUPT__: ADC Interrupt
512
+  *          This parameter can be any combination of the following values:
513
+  *            @arg ADC_IT_EOC: ADC End of Regular Conversion interrupt source
514
+  *            @arg ADC_IT_JEOC: ADC End of Injected Conversion interrupt source
515
+  *            @arg ADC_IT_AWD: ADC Analog watchdog interrupt source
516
+  * @retval None
517
+  */
518
+#define __HAL_ADC_DISABLE_IT(__HANDLE__, __INTERRUPT__)                        \
519
+  (CLEAR_BIT((__HANDLE__)->Instance->CR1, (__INTERRUPT__)))
520
+
521
+/** @brief  Checks if the specified ADC interrupt source is enabled or disabled.
522
+  * @param __HANDLE__: ADC handle
523
+  * @param __INTERRUPT__: ADC interrupt source to check
524
+  *          This parameter can be any combination of the following values:
525
+  *            @arg ADC_IT_EOC: ADC End of Regular Conversion interrupt source
526
+  *            @arg ADC_IT_JEOC: ADC End of Injected Conversion interrupt source
527
+  *            @arg ADC_IT_AWD: ADC Analog watchdog interrupt source
528
+  * @retval None
529
+  */
530
+#define __HAL_ADC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)                     \
531
+  (((__HANDLE__)->Instance->CR1 & (__INTERRUPT__)) == (__INTERRUPT__))
532
+
533
+/** @brief Get the selected ADC's flag status.
534
+  * @param __HANDLE__: ADC handle
535
+  * @param __FLAG__: ADC flag
536
+  *          This parameter can be any combination of the following values:
537
+  *            @arg ADC_FLAG_STRT: ADC Regular group start flag
538
+  *            @arg ADC_FLAG_JSTRT: ADC Injected group start flag
539
+  *            @arg ADC_FLAG_EOC: ADC End of Regular conversion flag
540
+  *            @arg ADC_FLAG_JEOC: ADC End of Injected conversion flag
541
+  *            @arg ADC_FLAG_AWD: ADC Analog watchdog flag
542
+  * @retval None
543
+  */
544
+#define __HAL_ADC_GET_FLAG(__HANDLE__, __FLAG__)                               \
545
+  ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
546
+    
547
+/** @brief Clear the ADC's pending flags
548
+  * @param __HANDLE__: ADC handle
549
+  * @param __FLAG__: ADC flag
550
+  *          This parameter can be any combination of the following values:
551
+  *            @arg ADC_FLAG_STRT: ADC Regular group start flag
552
+  *            @arg ADC_FLAG_JSTRT: ADC Injected group start flag
553
+  *            @arg ADC_FLAG_EOC: ADC End of Regular conversion flag
554
+  *            @arg ADC_FLAG_JEOC: ADC End of Injected conversion flag
555
+  *            @arg ADC_FLAG_AWD: ADC Analog watchdog flag
556
+  * @retval None
557
+  */
558
+#define __HAL_ADC_CLEAR_FLAG(__HANDLE__, __FLAG__)                             \
559
+  (WRITE_REG((__HANDLE__)->Instance->SR, ~(__FLAG__)))
560
+
561
+/** @brief  Reset ADC handle state
562
+  * @param  __HANDLE__: ADC handle
563
+  * @retval None
564
+  */
565
+#define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__)                               \
566
+  ((__HANDLE__)->State = HAL_ADC_STATE_RESET)
567
+
568
+/**
569
+  * @}
570
+  */
571
+
572
+/* Private macro ------------------------------------------------------------*/
573
+
574
+/** @defgroup ADC_Private_Macros ADC Private Macros
575
+  * @{
576
+  */
577
+/* Macro reserved for internal HAL driver usage, not intended to be used in   */
578
+/* code of final user.                                                        */
579
+
580
+/**
581
+  * @brief Verification of ADC state: enabled or disabled
582
+  * @param __HANDLE__: ADC handle
583
+  * @retval SET (ADC enabled) or RESET (ADC disabled)
584
+  */
585
+#define ADC_IS_ENABLE(__HANDLE__)                                              \
586
+  ((( ((__HANDLE__)->Instance->CR2 & ADC_CR2_ADON) == ADC_CR2_ADON )           \
587
+   ) ? SET : RESET)
588
+
589
+/**
590
+  * @brief Test if conversion trigger of regular group is software start
591
+  *        or external trigger.
592
+  * @param __HANDLE__: ADC handle
593
+  * @retval SET (software start) or RESET (external trigger)
594
+  */
595
+#define ADC_IS_SOFTWARE_START_REGULAR(__HANDLE__)                              \
596
+  (READ_BIT((__HANDLE__)->Instance->CR2, ADC_CR2_EXTSEL) == ADC_SOFTWARE_START)
597
+
598
+/**
599
+  * @brief Test if conversion trigger of injected group is software start
600
+  *        or external trigger.
601
+  * @param __HANDLE__: ADC handle
602
+  * @retval SET (software start) or RESET (external trigger)
603
+  */
604
+#define ADC_IS_SOFTWARE_START_INJECTED(__HANDLE__)                             \
605
+  (READ_BIT((__HANDLE__)->Instance->CR2, ADC_CR2_JEXTSEL) == ADC_INJECTED_SOFTWARE_START)
606
+
607
+/**
608
+  * @brief Simultaneously clears and sets specific bits of the handle State
609
+  * @note: ADC_STATE_CLR_SET() macro is merely aliased to generic macro MODIFY_REG(),
610
+  *        the first parameter is the ADC handle State, the second parameter is the
611
+  *        bit field to clear, the third and last parameter is the bit field to set.
612
+  * @retval None
613
+  */
614
+#define ADC_STATE_CLR_SET MODIFY_REG
615
+
616
+/**
617
+  * @brief Clear ADC error code (set it to error code: "no error")
618
+  * @param __HANDLE__: ADC handle
619
+  * @retval None
620
+  */
621
+#define ADC_CLEAR_ERRORCODE(__HANDLE__)                                        \
622
+  ((__HANDLE__)->ErrorCode = HAL_ADC_ERROR_NONE)
623
+
624
+/**
625
+  * @brief Set ADC number of conversions into regular channel sequence length.
626
+  * @param _NbrOfConversion_: Regular channel sequence length 
627
+  * @retval None
628
+  */
629
+#define ADC_SQR1_L_SHIFT(_NbrOfConversion_)                                    \
630
+  (((_NbrOfConversion_) - (uint8_t)1) << ADC_SQR1_L_Pos)
631
+
632
+/**
633
+  * @brief Set the ADC's sample time for channel numbers between 10 and 18.
634
+  * @param _SAMPLETIME_: Sample time parameter.
635
+  * @param _CHANNELNB_: Channel number.  
636
+  * @retval None
637
+  */
638
+#define ADC_SMPR1(_SAMPLETIME_, _CHANNELNB_)                                   \
639
+  ((_SAMPLETIME_) << (ADC_SMPR1_SMP11_Pos * ((_CHANNELNB_) - 10)))
640
+
641
+/**
642
+  * @brief Set the ADC's sample time for channel numbers between 0 and 9.
643
+  * @param _SAMPLETIME_: Sample time parameter.
644
+  * @param _CHANNELNB_: Channel number.  
645
+  * @retval None
646
+  */
647
+#define ADC_SMPR2(_SAMPLETIME_, _CHANNELNB_)                                   \
648
+  ((_SAMPLETIME_) << (ADC_SMPR2_SMP1_Pos * (_CHANNELNB_)))
649
+
650
+/**
651
+  * @brief Set the selected regular channel rank for rank between 1 and 6.
652
+  * @param _CHANNELNB_: Channel number.
653
+  * @param _RANKNB_: Rank number.    
654
+  * @retval None
655
+  */
656
+#define ADC_SQR3_RK(_CHANNELNB_, _RANKNB_)                                     \
657
+  ((_CHANNELNB_) << (ADC_SQR3_SQ2_Pos * ((_RANKNB_) - 1)))
658
+
659
+/**
660
+  * @brief Set the selected regular channel rank for rank between 7 and 12.
661
+  * @param _CHANNELNB_: Channel number.
662
+  * @param _RANKNB_: Rank number.    
663
+  * @retval None
664
+  */
665
+#define ADC_SQR2_RK(_CHANNELNB_, _RANKNB_)                                     \
666
+  ((_CHANNELNB_) << (ADC_SQR2_SQ8_Pos * ((_RANKNB_) - 7)))
667
+
668
+/**
669
+  * @brief Set the selected regular channel rank for rank between 13 and 16.
670
+  * @param _CHANNELNB_: Channel number.
671
+  * @param _RANKNB_: Rank number.    
672
+  * @retval None
673
+  */
674
+#define ADC_SQR1_RK(_CHANNELNB_, _RANKNB_)                                     \
675
+  ((_CHANNELNB_) << (ADC_SQR1_SQ14_Pos * ((_RANKNB_) - 13)))
676
+
677
+/**
678
+  * @brief Set the injected sequence length.
679
+  * @param _JSQR_JL_: Sequence length.
680
+  * @retval None
681
+  */
682
+#define ADC_JSQR_JL_SHIFT(_JSQR_JL_)                                           \
683
+  (((_JSQR_JL_) -1) << ADC_JSQR_JL_Pos)
684
+
685
+/**
686
+  * @brief Set the selected injected channel rank
687
+  *        Note: on STM32F1 devices, channel rank position in JSQR register
688
+  *              is depending on total number of ranks selected into
689
+  *              injected sequencer (ranks sequence starting from 4-JL)
690
+  * @param _CHANNELNB_: Channel number.
691
+  * @param _RANKNB_: Rank number.
692
+  * @param _JSQR_JL_: Sequence length.
693
+  * @retval None
694
+  */
695
+#define ADC_JSQR_RK_JL(_CHANNELNB_, _RANKNB_, _JSQR_JL_)                       \
696
+  ((_CHANNELNB_) << (ADC_JSQR_JSQ2_Pos * ((4 - ((_JSQR_JL_) - (_RANKNB_))) - 1)))
697
+
698
+/**
699
+  * @brief Enable ADC continuous conversion mode.
700
+  * @param _CONTINUOUS_MODE_: Continuous mode.
701
+  * @retval None
702
+  */
703
+#define ADC_CR2_CONTINUOUS(_CONTINUOUS_MODE_)                                  \
704
+  ((_CONTINUOUS_MODE_) << ADC_CR2_CONT_Pos)
705
+
706
+/**
707
+  * @brief Configures the number of discontinuous conversions for the regular group channels.
708
+  * @param _NBR_DISCONTINUOUS_CONV_: Number of discontinuous conversions.
709
+  * @retval None
710
+  */
711
+#define ADC_CR1_DISCONTINUOUS_NUM(_NBR_DISCONTINUOUS_CONV_)                    \
712
+  (((_NBR_DISCONTINUOUS_CONV_) - 1) << ADC_CR1_DISCNUM_Pos)
713
+
714
+/**
715
+  * @brief Enable ADC scan mode to convert multiple ranks with sequencer.
716
+  * @param _SCAN_MODE_: Scan conversion mode.
717
+  * @retval None
718
+  */
719
+/* Note: Scan mode is compared to ENABLE for legacy purpose, this parameter   */
720
+/*       is equivalent to ADC_SCAN_ENABLE.                                    */
721
+#define ADC_CR1_SCAN_SET(_SCAN_MODE_)                                          \
722
+  (( ((_SCAN_MODE_) == ADC_SCAN_ENABLE) || ((_SCAN_MODE_) == ENABLE)           \
723
+   )? (ADC_SCAN_ENABLE) : (ADC_SCAN_DISABLE)                                   \
724
+  )
725
+
726
+/**
727
+  * @brief Get the maximum ADC conversion cycles on all channels.
728
+  * Returns the selected sampling time + conversion time (12.5 ADC clock cycles)
729
+  * Approximation of sampling time within 4 ranges, returns the highest value:
730
+  *   below 7.5 cycles {1.5 cycle; 7.5 cycles},
731
+  *   between 13.5 cycles and 28.5 cycles {13.5 cycles; 28.5 cycles}
732
+  *   between 41.5 cycles and 71.5 cycles {41.5 cycles; 55.5 cycles; 71.5cycles}
733
+  *   equal to 239.5 cycles
734
+  * Unit: ADC clock cycles
735
+  * @param __HANDLE__: ADC handle
736
+  * @retval ADC conversion cycles on all channels
737
+  */   
738
+#define ADC_CONVCYCLES_MAX_RANGE(__HANDLE__)                                                                     \
739
+    (( (((__HANDLE__)->Instance->SMPR2 & ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT2) == RESET)  &&                     \
740
+       (((__HANDLE__)->Instance->SMPR1 & ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT2) == RESET) ) ?                     \
741
+                                                                                                                 \
742
+          (( (((__HANDLE__)->Instance->SMPR2 & ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT1) == RESET)  &&               \
743
+             (((__HANDLE__)->Instance->SMPR1 & ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT1) == RESET) ) ?               \
744
+               ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_7CYCLES5 : ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_28CYCLES5)   \
745
+          :                                                                                                      \
746
+          ((((((__HANDLE__)->Instance->SMPR2 & ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT1) == RESET)  &&               \
747
+             (((__HANDLE__)->Instance->SMPR1 & ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT1) == RESET)) ||               \
748
+            ((((__HANDLE__)->Instance->SMPR2 & ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT0) == RESET)  &&               \
749
+             (((__HANDLE__)->Instance->SMPR1 & ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT0) == RESET))) ?               \
750
+               ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_71CYCLES5 : ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_239CYCLES5) \
751
+     )
752
+
753
+#define IS_ADC_DATA_ALIGN(ALIGN) (((ALIGN) == ADC_DATAALIGN_RIGHT) || \
754
+                                  ((ALIGN) == ADC_DATAALIGN_LEFT)    )
755
+
756
+#define IS_ADC_SCAN_MODE(SCAN_MODE) (((SCAN_MODE) == ADC_SCAN_DISABLE) || \
757
+                                     ((SCAN_MODE) == ADC_SCAN_ENABLE)    )
758
+
759
+#define IS_ADC_EXTTRIG_EDGE(EDGE) (((EDGE) == ADC_EXTERNALTRIGCONVEDGE_NONE)  || \
760
+                                   ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_RISING)  )
761
+
762
+#define IS_ADC_CHANNEL(CHANNEL) (((CHANNEL) == ADC_CHANNEL_0)           || \
763
+                                 ((CHANNEL) == ADC_CHANNEL_1)           || \
764
+                                 ((CHANNEL) == ADC_CHANNEL_2)           || \
765
+                                 ((CHANNEL) == ADC_CHANNEL_3)           || \
766
+                                 ((CHANNEL) == ADC_CHANNEL_4)           || \
767
+                                 ((CHANNEL) == ADC_CHANNEL_5)           || \
768
+                                 ((CHANNEL) == ADC_CHANNEL_6)           || \
769
+                                 ((CHANNEL) == ADC_CHANNEL_7)           || \
770
+                                 ((CHANNEL) == ADC_CHANNEL_8)           || \
771
+                                 ((CHANNEL) == ADC_CHANNEL_9)           || \
772
+                                 ((CHANNEL) == ADC_CHANNEL_10)          || \
773
+                                 ((CHANNEL) == ADC_CHANNEL_11)          || \
774
+                                 ((CHANNEL) == ADC_CHANNEL_12)          || \
775
+                                 ((CHANNEL) == ADC_CHANNEL_13)          || \
776
+                                 ((CHANNEL) == ADC_CHANNEL_14)          || \
777
+                                 ((CHANNEL) == ADC_CHANNEL_15)          || \
778
+                                 ((CHANNEL) == ADC_CHANNEL_16)          || \
779
+                                 ((CHANNEL) == ADC_CHANNEL_17)            )
780
+
781
+#define IS_ADC_SAMPLE_TIME(TIME) (((TIME) == ADC_SAMPLETIME_1CYCLE_5)    || \
782
+                                  ((TIME) == ADC_SAMPLETIME_7CYCLES_5)   || \
783
+                                  ((TIME) == ADC_SAMPLETIME_13CYCLES_5)  || \
784
+                                  ((TIME) == ADC_SAMPLETIME_28CYCLES_5)  || \
785
+                                  ((TIME) == ADC_SAMPLETIME_41CYCLES_5)  || \
786
+                                  ((TIME) == ADC_SAMPLETIME_55CYCLES_5)  || \
787
+                                  ((TIME) == ADC_SAMPLETIME_71CYCLES_5)  || \
788
+                                  ((TIME) == ADC_SAMPLETIME_239CYCLES_5)   )
789
+
790
+#define IS_ADC_REGULAR_RANK(CHANNEL) (((CHANNEL) == ADC_REGULAR_RANK_1 ) || \
791
+                                      ((CHANNEL) == ADC_REGULAR_RANK_2 ) || \
792
+                                      ((CHANNEL) == ADC_REGULAR_RANK_3 ) || \
793
+                                      ((CHANNEL) == ADC_REGULAR_RANK_4 ) || \
794
+                                      ((CHANNEL) == ADC_REGULAR_RANK_5 ) || \
795
+                                      ((CHANNEL) == ADC_REGULAR_RANK_6 ) || \
796
+                                      ((CHANNEL) == ADC_REGULAR_RANK_7 ) || \
797
+                                      ((CHANNEL) == ADC_REGULAR_RANK_8 ) || \
798
+                                      ((CHANNEL) == ADC_REGULAR_RANK_9 ) || \
799
+                                      ((CHANNEL) == ADC_REGULAR_RANK_10) || \
800
+                                      ((CHANNEL) == ADC_REGULAR_RANK_11) || \
801
+                                      ((CHANNEL) == ADC_REGULAR_RANK_12) || \
802
+                                      ((CHANNEL) == ADC_REGULAR_RANK_13) || \
803
+                                      ((CHANNEL) == ADC_REGULAR_RANK_14) || \
804
+                                      ((CHANNEL) == ADC_REGULAR_RANK_15) || \
805
+                                      ((CHANNEL) == ADC_REGULAR_RANK_16)   )
806
+
807
+#define IS_ADC_ANALOG_WATCHDOG_MODE(WATCHDOG) (((WATCHDOG) == ADC_ANALOGWATCHDOG_NONE)             || \
808
+                                               ((WATCHDOG) == ADC_ANALOGWATCHDOG_SINGLE_REG)       || \
809
+                                               ((WATCHDOG) == ADC_ANALOGWATCHDOG_SINGLE_INJEC)     || \
810
+                                               ((WATCHDOG) == ADC_ANALOGWATCHDOG_SINGLE_REGINJEC)  || \
811
+                                               ((WATCHDOG) == ADC_ANALOGWATCHDOG_ALL_REG)          || \
812
+                                               ((WATCHDOG) == ADC_ANALOGWATCHDOG_ALL_INJEC)        || \
813
+                                               ((WATCHDOG) == ADC_ANALOGWATCHDOG_ALL_REGINJEC)       )
814
+
815
+#define IS_ADC_CONVERSION_GROUP(CONVERSION) (((CONVERSION) == ADC_REGULAR_GROUP)         || \
816
+                                             ((CONVERSION) == ADC_INJECTED_GROUP)        || \
817
+                                             ((CONVERSION) == ADC_REGULAR_INJECTED_GROUP)  )
818
+
819
+#define IS_ADC_EVENT_TYPE(EVENT) ((EVENT) == ADC_AWD_EVENT)
820
+
821
+
822
+/** @defgroup ADC_range_verification ADC range verification
823
+  * For a unique ADC resolution: 12 bits
824
+  * @{
825
+  */
826
+#define IS_ADC_RANGE(ADC_VALUE) ((ADC_VALUE) <= 0x0FFFU)
827
+/**
828
+  * @}
829
+  */
830
+
831
+/** @defgroup ADC_regular_nb_conv_verification ADC regular nb conv verification
832
+  * @{
833
+  */
834
+#define IS_ADC_REGULAR_NB_CONV(LENGTH) (((LENGTH) >= 1U) && ((LENGTH) <= 16U))
835
+/**
836
+  * @}
837
+  */
838
+
839
+/** @defgroup ADC_regular_discontinuous_mode_number_verification ADC regular discontinuous mode number verification
840
+  * @{
841
+  */
842
+#define IS_ADC_REGULAR_DISCONT_NUMBER(NUMBER) (((NUMBER) >= 1U) && ((NUMBER) <= 8U))
843
+/**
844
+  * @}
845
+  */
846
+      
847
+/**
848
+  * @}
849
+  */
850
+    
851
+/* Include ADC HAL Extension module */
852
+#include "stm32f1xx_hal_adc_ex.h"
853
+
854
+/* Exported functions --------------------------------------------------------*/
855
+/** @addtogroup ADC_Exported_Functions
856
+  * @{
857
+  */
858
+
859
+/** @addtogroup ADC_Exported_Functions_Group1
860
+  * @{
861
+  */
862
+
863
+
864
+/* Initialization and de-initialization functions  **********************************/
865
+HAL_StatusTypeDef       HAL_ADC_Init(ADC_HandleTypeDef* hadc);
866
+HAL_StatusTypeDef       HAL_ADC_DeInit(ADC_HandleTypeDef *hadc);
867
+void                    HAL_ADC_MspInit(ADC_HandleTypeDef* hadc);
868
+void                    HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc);
869
+/**
870
+  * @}
871
+  */
872
+
873
+/* IO operation functions  *****************************************************/
874
+
875
+/** @addtogroup ADC_Exported_Functions_Group2
876
+  * @{
877
+  */
878
+
879
+
880
+/* Blocking mode: Polling */
881
+HAL_StatusTypeDef       HAL_ADC_Start(ADC_HandleTypeDef* hadc);
882
+HAL_StatusTypeDef       HAL_ADC_Stop(ADC_HandleTypeDef* hadc);
883
+HAL_StatusTypeDef       HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout);
884
+HAL_StatusTypeDef       HAL_ADC_PollForEvent(ADC_HandleTypeDef* hadc, uint32_t EventType, uint32_t Timeout);
885
+
886
+/* Non-blocking mode: Interruption */
887
+HAL_StatusTypeDef       HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc);
888
+HAL_StatusTypeDef       HAL_ADC_Stop_IT(ADC_HandleTypeDef* hadc);
889
+
890
+/* Non-blocking mode: DMA */
891
+HAL_StatusTypeDef       HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length);
892
+HAL_StatusTypeDef       HAL_ADC_Stop_DMA(ADC_HandleTypeDef* hadc);
893
+
894
+/* ADC retrieve conversion value intended to be used with polling or interruption */
895
+uint32_t                HAL_ADC_GetValue(ADC_HandleTypeDef* hadc);
896
+
897
+/* ADC IRQHandler and Callbacks used in non-blocking modes (Interruption and DMA) */
898
+void                    HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc);
899
+void                    HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc);
900
+void                    HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc);
901
+void                    HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc);
902
+void                    HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc);
903
+/**
904
+  * @}
905
+  */
906
+
907
+
908
+/* Peripheral Control functions ***********************************************/
909
+/** @addtogroup ADC_Exported_Functions_Group3
910
+  * @{
911
+  */
912
+HAL_StatusTypeDef       HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConfTypeDef* sConfig);
913
+HAL_StatusTypeDef       HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDGConfTypeDef* AnalogWDGConfig);
914
+/**
915
+  * @}
916
+  */
917
+
918
+
919
+/* Peripheral State functions *************************************************/
920
+/** @addtogroup ADC_Exported_Functions_Group4
921
+  * @{
922
+  */
923
+uint32_t                HAL_ADC_GetState(ADC_HandleTypeDef* hadc);
924
+uint32_t                HAL_ADC_GetError(ADC_HandleTypeDef *hadc);
925
+/**
926
+  * @}
927
+  */
928
+
929
+
930
+/**
931
+  * @}
932
+  */
933
+
934
+
935
+/* Internal HAL driver functions **********************************************/
936
+/** @addtogroup ADC_Private_Functions
937
+  * @{
938
+  */
939
+HAL_StatusTypeDef ADC_Enable(ADC_HandleTypeDef* hadc);
940
+HAL_StatusTypeDef ADC_ConversionStop_Disable(ADC_HandleTypeDef* hadc);
941
+void              ADC_StabilizationTime(uint32_t DelayUs);
942
+void              ADC_DMAConvCplt(DMA_HandleTypeDef *hdma);
943
+void              ADC_DMAHalfConvCplt(DMA_HandleTypeDef *hdma);
944
+void              ADC_DMAError(DMA_HandleTypeDef *hdma);
945
+/**
946
+  * @}
947
+  */ 
948
+
949
+
950
+/**
951
+  * @}
952
+  */ 
953
+
954
+/**
955
+  * @}
956
+  */
957
+
958
+#ifdef __cplusplus
959
+}
960
+#endif
961
+
962
+
963
+#endif /* __STM32F1xx_HAL_ADC_H */
964
+
965
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 726 - 0
Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_adc_ex.h

@@ -0,0 +1,726 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_adc_ex.h
4
+  * @author  MCD Application Team
5
+  * @brief   Header file of ADC HAL extension module.
6
+  ******************************************************************************
7
+  * @attention
8
+  *
9
+  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
10
+  *
11
+  * Redistribution and use in source and binary forms, with or without modification,
12
+  * are permitted provided that the following conditions are met:
13
+  *   1. Redistributions of source code must retain the above copyright notice,
14
+  *      this list of conditions and the following disclaimer.
15
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
16
+  *      this list of conditions and the following disclaimer in the documentation
17
+  *      and/or other materials provided with the distribution.
18
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
19
+  *      may be used to endorse or promote products derived from this software
20
+  *      without specific prior written permission.
21
+  *
22
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+  *
33
+  ******************************************************************************
34
+  */
35
+
36
+/* Define to prevent recursive inclusion -------------------------------------*/
37
+#ifndef __STM32F1xx_HAL_ADC_EX_H
38
+#define __STM32F1xx_HAL_ADC_EX_H
39
+
40
+#ifdef __cplusplus
41
+ extern "C" {
42
+#endif
43
+
44
+/* Includes ------------------------------------------------------------------*/
45
+#include "stm32f1xx_hal_def.h"  
46
+
47
+/** @addtogroup STM32F1xx_HAL_Driver
48
+  * @{
49
+  */
50
+
51
+/** @addtogroup ADCEx
52
+  * @{
53
+  */ 
54
+
55
+/* Exported types ------------------------------------------------------------*/ 
56
+/** @defgroup ADCEx_Exported_Types ADCEx Exported Types
57
+  * @{
58
+  */
59
+
60
+/** 
61
+  * @brief  ADC Configuration injected Channel structure definition
62
+  * @note   Parameters of this structure are shared within 2 scopes:
63
+  *          - Scope channel: InjectedChannel, InjectedRank, InjectedSamplingTime, InjectedOffset
64
+  *          - Scope injected group (affects all channels of injected group): InjectedNbrOfConversion, InjectedDiscontinuousConvMode,
65
+  *            AutoInjectedConv, ExternalTrigInjecConvEdge, ExternalTrigInjecConv.
66
+  * @note   The setting of these parameters with function HAL_ADCEx_InjectedConfigChannel() is conditioned to ADC state.
67
+  *         ADC state can be either:
68
+  *          - For all parameters: ADC disabled (this is the only possible ADC state to modify parameter 'ExternalTrigInjecConv')
69
+  *          - For all except parameters 'ExternalTrigInjecConv': ADC enabled without conversion on going on injected group.
70
+  */
71
+typedef struct 
72
+{
73
+  uint32_t InjectedChannel;               /*!< Selection of ADC channel to configure
74
+                                               This parameter can be a value of @ref ADC_channels
75
+                                               Note: Depending on devices, some channels may not be available on package pins. Refer to device datasheet for channels availability.
76
+                                               Note: On STM32F1 devices with several ADC: Only ADC1 can access internal measurement channels (VrefInt/TempSensor) 
77
+                                               Note: On STM32F10xx8 and STM32F10xxB devices: A low-amplitude voltage glitch may be generated (on ADC input 0) on the PA0 pin, when the ADC is converting with injection trigger.
78
+                                                     It is advised to distribute the analog channels so that Channel 0 is configured as an injected channel.
79
+                                                     Refer to errata sheet of these devices for more details. */
80
+  uint32_t InjectedRank;                  /*!< Rank in the injected group sequencer
81
+                                               This parameter must be a value of @ref ADCEx_injected_rank
82
+                                               Note: In case of need to disable a channel or change order of conversion sequencer, rank containing a previous channel setting can be overwritten by the new channel setting (or parameter number of conversions can be adjusted) */
83
+  uint32_t InjectedSamplingTime;          /*!< Sampling time value to be set for the selected channel.
84
+                                               Unit: ADC clock cycles
85
+                                               Conversion time is the addition of sampling time and processing time (12.5 ADC clock cycles at ADC resolution 12 bits).
86
+                                               This parameter can be a value of @ref ADC_sampling_times
87
+                                               Caution: This parameter updates the parameter property of the channel, that can be used into regular and/or injected groups.
88
+                                                        If this same channel has been previously configured in the other group (regular/injected), it will be updated to last setting.
89
+                                               Note: In case of usage of internal measurement channels (VrefInt/TempSensor),
90
+                                                     sampling time constraints must be respected (sampling time can be adjusted in function of ADC clock frequency and sampling time setting)
91
+                                                     Refer to device datasheet for timings values, parameters TS_vrefint, TS_temp (values rough order: 5us to 17.1us min). */
92
+  uint32_t InjectedOffset;                /*!< Defines the offset to be subtracted from the raw converted data (for channels set on injected group only).
93
+                                               Offset value must be a positive number.
94
+                                               Depending of ADC resolution selected (12, 10, 8 or 6 bits),
95
+                                               this parameter must be a number between Min_Data = 0x000 and Max_Data = 0xFFF, 0x3FF, 0xFF or 0x3F respectively. */
96
+  uint32_t InjectedNbrOfConversion;       /*!< Specifies the number of ranks that will be converted within the injected group sequencer.
97
+                                               To use the injected group sequencer and convert several ranks, parameter 'ScanConvMode' must be enabled.
98
+                                               This parameter must be a number between Min_Data = 1 and Max_Data = 4.
99
+                                               Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to 
100
+                                                        configure a channel on injected group can impact the configuration of other channels previously set. */
101
+  uint32_t InjectedDiscontinuousConvMode; /*!< Specifies whether the conversions sequence of injected group is performed in Complete-sequence/Discontinuous-sequence (main sequence subdivided in successive parts).
102
+                                               Discontinuous mode is used only if sequencer is enabled (parameter 'ScanConvMode'). If sequencer is disabled, this parameter is discarded.
103
+                                               Discontinuous mode can be enabled only if continuous mode is disabled. If continuous mode is enabled, this parameter setting is discarded.
104
+                                               This parameter can be set to ENABLE or DISABLE.
105
+                                               Note: For injected group, number of discontinuous ranks increment is fixed to one-by-one.
106
+                                               Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to 
107
+                                                        configure a channel on injected group can impact the configuration of other channels previously set. */
108
+  uint32_t AutoInjectedConv;              /*!< Enables or disables the selected ADC automatic injected group conversion after regular one
109
+                                               This parameter can be set to ENABLE or DISABLE.      
110
+                                               Note: To use Automatic injected conversion, discontinuous mode must be disabled ('DiscontinuousConvMode' and 'InjectedDiscontinuousConvMode' set to DISABLE)
111
+                                               Note: To use Automatic injected conversion, injected group external triggers must be disabled ('ExternalTrigInjecConv' set to ADC_SOFTWARE_START)
112
+                                               Note: In case of DMA used with regular group: if DMA configured in normal mode (single shot) JAUTO will be stopped upon DMA transfer complete.
113
+                                                     To maintain JAUTO always enabled, DMA must be configured in circular mode.
114
+                                               Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to
115
+                                                        configure a channel on injected group can impact the configuration of other channels previously set. */
116
+  uint32_t ExternalTrigInjecConv;         /*!< Selects the external event used to trigger the conversion start of injected group.
117
+                                               If set to ADC_INJECTED_SOFTWARE_START, external triggers are disabled.
118
+                                               If set to external trigger source, triggering is on event rising edge.
119
+                                               This parameter can be a value of @ref ADCEx_External_trigger_source_Injected
120
+                                               Note: This parameter must be modified when ADC is disabled (before ADC start conversion or after ADC stop conversion).
121
+                                                     If ADC is enabled, this parameter setting is bypassed without error reporting (as it can be the expected behaviour in case of another parameter update on the fly)
122
+                                               Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to
123
+                                                        configure a channel on injected group can impact the configuration of other channels previously set. */
124
+}ADC_InjectionConfTypeDef;
125
+
126
+#if defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
127
+/** 
128
+  * @brief  Structure definition of ADC multimode
129
+  * @note   The setting of these parameters with function HAL_ADCEx_MultiModeConfigChannel() is conditioned to ADCs state (both ADCs of the common group).
130
+  *         State of ADCs of the common group must be: disabled.
131
+  */
132
+typedef struct
133
+{
134
+  uint32_t Mode;              /*!< Configures the ADC to operate in independent or multi mode. 
135
+                                   This parameter can be a value of @ref ADCEx_Common_mode
136
+                                   Note: In dual mode, a change of channel configuration generates a restart that can produce a loss of synchronization. It is recommended to disable dual mode before any configuration change.
137
+                                   Note: In case of simultaneous mode used: Exactly the same sampling time should be configured for the 2 channels that will be sampled simultaneously by ACD1 and ADC2.
138
+                                   Note: In case of interleaved mode used: To avoid overlap between conversions, maximum sampling time allowed is 7 ADC clock cycles for fast interleaved mode and 14 ADC clock cycles for slow interleaved mode.
139
+                                   Note: Some multimode parameters are fixed on STM32F1 and can be configured on other STM32 devices with several ADC (multimode configuration structure can have additional parameters).
140
+                                         The equivalences are:
141
+                                           - Parameter 'DMAAccessMode': On STM32F1, this parameter is fixed to 1 DMA channel (one DMA channel for both ADC, DMA of ADC master). On other STM32 devices with several ADC, this is equivalent to parameter 'ADC_DMAACCESSMODE_12_10_BITS'.
142
+                                           - Parameter 'TwoSamplingDelay': On STM32F1, this parameter is fixed to 7 or 14 ADC clock cycles depending on fast or slow interleaved mode selected. On other STM32 devices with several ADC, this is equivalent to parameter 'ADC_TWOSAMPLINGDELAY_7CYCLES' (for fast interleaved mode). */
143
+
144
+  
145
+}ADC_MultiModeTypeDef;                                                          
146
+#endif /* defined STM32F103x6 || defined STM32F103xB || defined STM32F105xC || defined STM32F107xC || defined STM32F103xE || defined STM32F103xG */
147
+
148
+/**
149
+  * @}
150
+  */
151
+
152
+
153
+/* Exported constants --------------------------------------------------------*/
154
+   
155
+/** @defgroup ADCEx_Exported_Constants ADCEx Exported Constants
156
+  * @{
157
+  */
158
+
159
+/** @defgroup ADCEx_injected_rank ADCEx rank into injected group
160
+  * @{
161
+  */
162
+#define ADC_INJECTED_RANK_1                           0x00000001U
163
+#define ADC_INJECTED_RANK_2                           0x00000002U
164
+#define ADC_INJECTED_RANK_3                           0x00000003U
165
+#define ADC_INJECTED_RANK_4                           0x00000004U
166
+/**
167
+  * @}
168
+  */
169
+
170
+/** @defgroup ADCEx_External_trigger_edge_Injected ADCEx external trigger enable for injected group
171
+  * @{
172
+  */
173
+#define ADC_EXTERNALTRIGINJECCONV_EDGE_NONE           0x00000000U
174
+#define ADC_EXTERNALTRIGINJECCONV_EDGE_RISING         ((uint32_t)ADC_CR2_JEXTTRIG)
175
+/**
176
+  * @}
177
+  */
178
+    
179
+/** @defgroup ADC_External_trigger_source_Regular ADC External trigger selection for regular group
180
+  * @{
181
+  */
182
+/*!< List of external triggers with generic trigger name, independently of    */
183
+/* ADC target, sorted by trigger name:                                        */
184
+
185
+/*!< External triggers of regular group for ADC1&ADC2 only */
186
+#define ADC_EXTERNALTRIGCONV_T1_CC1         ADC1_2_EXTERNALTRIG_T1_CC1
187
+#define ADC_EXTERNALTRIGCONV_T1_CC2         ADC1_2_EXTERNALTRIG_T1_CC2
188
+#define ADC_EXTERNALTRIGCONV_T2_CC2         ADC1_2_EXTERNALTRIG_T2_CC2
189
+#define ADC_EXTERNALTRIGCONV_T3_TRGO        ADC1_2_EXTERNALTRIG_T3_TRGO
190
+#define ADC_EXTERNALTRIGCONV_T4_CC4         ADC1_2_EXTERNALTRIG_T4_CC4
191
+#define ADC_EXTERNALTRIGCONV_EXT_IT11       ADC1_2_EXTERNALTRIG_EXT_IT11
192
+
193
+#if defined (STM32F103xE) || defined (STM32F103xG)
194
+/*!< External triggers of regular group for ADC3 only */
195
+#define ADC_EXTERNALTRIGCONV_T2_CC3         ADC3_EXTERNALTRIG_T2_CC3
196
+#define ADC_EXTERNALTRIGCONV_T3_CC1         ADC3_EXTERNALTRIG_T3_CC1
197
+#define ADC_EXTERNALTRIGCONV_T5_CC1         ADC3_EXTERNALTRIG_T5_CC1
198
+#define ADC_EXTERNALTRIGCONV_T5_CC3         ADC3_EXTERNALTRIG_T5_CC3
199
+#define ADC_EXTERNALTRIGCONV_T8_CC1         ADC3_EXTERNALTRIG_T8_CC1
200
+#endif /* STM32F103xE || defined STM32F103xG */
201
+
202
+/*!< External triggers of regular group for all ADC instances */
203
+#define ADC_EXTERNALTRIGCONV_T1_CC3         ADC1_2_3_EXTERNALTRIG_T1_CC3
204
+
205
+#if defined (STM32F101xE) || defined (STM32F103xE) || defined (STM32F103xG) || defined (STM32F105xC) || defined (STM32F107xC)
206
+/*!< Note: TIM8_TRGO is available on ADC1 and ADC2 only in high-density and   */
207
+/*         XL-density devices.                                                */
208
+/*         To use it on ADC or ADC2, a remap of trigger must be done from     */
209
+/*         EXTI line 11 to TIM8_TRGO with macro:                              */
210
+/*           __HAL_AFIO_REMAP_ADC1_ETRGREG_ENABLE()                           */
211
+/*           __HAL_AFIO_REMAP_ADC2_ETRGREG_ENABLE()                           */
212
+
213
+/* Note for internal constant value management: If TIM8_TRGO is available,    */
214
+/* its definition is set to value for ADC1&ADC2 by default and changed to     */
215
+/* value for ADC3 by HAL ADC driver if ADC3 is selected.                      */
216
+#define ADC_EXTERNALTRIGCONV_T8_TRGO        ADC1_2_EXTERNALTRIG_T8_TRGO
217
+#endif /* STM32F101xE || STM32F103xE || STM32F103xG || STM32F105xC || STM32F107xC */
218
+
219
+#define ADC_SOFTWARE_START                  ADC1_2_3_SWSTART
220
+/**
221
+  * @}
222
+  */
223
+
224
+/** @defgroup ADCEx_External_trigger_source_Injected ADCEx External trigger selection for injected group
225
+  * @{
226
+  */
227
+/*!< List of external triggers with generic trigger name, independently of    */
228
+/* ADC target, sorted by trigger name:                                        */
229
+
230
+/*!< External triggers of injected group for ADC1&ADC2 only */
231
+#define ADC_EXTERNALTRIGINJECCONV_T2_TRGO        ADC1_2_EXTERNALTRIGINJEC_T2_TRGO
232
+#define ADC_EXTERNALTRIGINJECCONV_T2_CC1         ADC1_2_EXTERNALTRIGINJEC_T2_CC1
233
+#define ADC_EXTERNALTRIGINJECCONV_T3_CC4         ADC1_2_EXTERNALTRIGINJEC_T3_CC4
234
+#define ADC_EXTERNALTRIGINJECCONV_T4_TRGO        ADC1_2_EXTERNALTRIGINJEC_T4_TRGO 
235
+#define ADC_EXTERNALTRIGINJECCONV_EXT_IT15       ADC1_2_EXTERNALTRIGINJEC_EXT_IT15
236
+
237
+#if defined (STM32F103xE) || defined (STM32F103xG)
238
+/*!< External triggers of injected group for ADC3 only */
239
+#define ADC_EXTERNALTRIGINJECCONV_T4_CC3         ADC3_EXTERNALTRIGINJEC_T4_CC3
240
+#define ADC_EXTERNALTRIGINJECCONV_T8_CC2         ADC3_EXTERNALTRIGINJEC_T8_CC2
241
+#define ADC_EXTERNALTRIGINJECCONV_T5_TRGO        ADC3_EXTERNALTRIGINJEC_T5_TRGO
242
+#define ADC_EXTERNALTRIGINJECCONV_T5_CC4         ADC3_EXTERNALTRIGINJEC_T5_CC4
243
+#endif /* STM32F103xE || defined STM32F103xG */
244
+
245
+/*!< External triggers of injected group for all ADC instances */
246
+#define ADC_EXTERNALTRIGINJECCONV_T1_CC4         ADC1_2_3_EXTERNALTRIGINJEC_T1_CC4
247
+#define ADC_EXTERNALTRIGINJECCONV_T1_TRGO        ADC1_2_3_EXTERNALTRIGINJEC_T1_TRGO
248
+
249
+#if defined (STM32F101xE) || defined (STM32F103xE) || defined (STM32F103xG) || defined (STM32F105xC) || defined (STM32F107xC)
250
+/*!< Note: TIM8_CC4 is available on ADC1 and ADC2 only in high-density and    */
251
+/*         XL-density devices.                                                */
252
+/*         To use it on ADC1 or ADC2, a remap of trigger must be done from    */
253
+/*         EXTI line 11 to TIM8_CC4 with macro:                               */
254
+/*           __HAL_AFIO_REMAP_ADC1_ETRGINJ_ENABLE()                           */
255
+/*           __HAL_AFIO_REMAP_ADC2_ETRGINJ_ENABLE()                           */
256
+
257
+/* Note for internal constant value management: If TIM8_CC4 is available,     */
258
+/* its definition is set to value for ADC1&ADC2 by default and changed to     */
259
+/* value for ADC3 by HAL ADC driver if ADC3 is selected.                      */
260
+#define ADC_EXTERNALTRIGINJECCONV_T8_CC4         ADC1_2_EXTERNALTRIGINJEC_T8_CC4
261
+#endif /* STM32F101xE || STM32F103xE || STM32F103xG || STM32F105xC || STM32F107xC */
262
+
263
+#define ADC_INJECTED_SOFTWARE_START              ADC1_2_3_JSWSTART
264
+/**
265
+  * @}
266
+  */
267
+
268
+#if defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
269
+/** @defgroup ADCEx_Common_mode ADC Extended Dual ADC Mode
270
+  * @{
271
+  */
272
+#define ADC_MODE_INDEPENDENT                              0x00000000U                                                                     /*!< ADC dual mode disabled (ADC independent mode) */
273
+#define ADC_DUALMODE_REGSIMULT_INJECSIMULT    ((uint32_t)(                                                            ADC_CR1_DUALMOD_0)) /*!< ADC dual mode enabled: Combined regular simultaneous + injected simultaneous mode, on groups regular and injected */
274
+#define ADC_DUALMODE_REGSIMULT_ALTERTRIG      ((uint32_t)(                                        ADC_CR1_DUALMOD_1                    )) /*!< ADC dual mode enabled: Combined regular simultaneous + alternate trigger mode, on groups regular and injected */
275
+#define ADC_DUALMODE_INJECSIMULT_INTERLFAST   ((uint32_t)(                                        ADC_CR1_DUALMOD_1 | ADC_CR1_DUALMOD_0)) /*!< ADC dual mode enabled: Combined injected simultaneous + fast interleaved mode, on groups regular and injected (delay between ADC sampling phases: 7 ADC clock cycles (equivalent to parameter "TwoSamplingDelay" set to "ADC_TWOSAMPLINGDELAY_7CYCLES" on other STM32 devices)) */
276
+#define ADC_DUALMODE_INJECSIMULT_INTERLSLOW   ((uint32_t)(                    ADC_CR1_DUALMOD_2                                        )) /*!< ADC dual mode enabled: Combined injected simultaneous + slow Interleaved mode, on groups regular and injected (delay between ADC sampling phases: 14 ADC clock cycles (equivalent to parameter "TwoSamplingDelay" set to "ADC_TWOSAMPLINGDELAY_7CYCLES" on other STM32 devices)) */
277
+#define ADC_DUALMODE_INJECSIMULT              ((uint32_t)(                    ADC_CR1_DUALMOD_2 |                     ADC_CR1_DUALMOD_0)) /*!< ADC dual mode enabled: Injected simultaneous mode, on group injected */
278
+#define ADC_DUALMODE_REGSIMULT                ((uint32_t)(                    ADC_CR1_DUALMOD_2 | ADC_CR1_DUALMOD_1                    )) /*!< ADC dual mode enabled: Regular simultaneous mode, on group regular */
279
+#define ADC_DUALMODE_INTERLFAST               ((uint32_t)(                    ADC_CR1_DUALMOD_2 | ADC_CR1_DUALMOD_1 | ADC_CR1_DUALMOD_0)) /*!< ADC dual mode enabled: Fast interleaved mode, on group regular (delay between ADC sampling phases: 7 ADC clock cycles (equivalent to parameter "TwoSamplingDelay" set to "ADC_TWOSAMPLINGDELAY_7CYCLES" on other STM32 devices)) */
280
+#define ADC_DUALMODE_INTERLSLOW               ((uint32_t)(ADC_CR1_DUALMOD_3                                                            )) /*!< ADC dual mode enabled: Slow interleaved mode, on group regular (delay between ADC sampling phases: 14 ADC clock cycles (equivalent to parameter "TwoSamplingDelay" set to "ADC_TWOSAMPLINGDELAY_7CYCLES" on other STM32 devices)) */
281
+#define ADC_DUALMODE_ALTERTRIG                ((uint32_t)(ADC_CR1_DUALMOD_3 |                                         ADC_CR1_DUALMOD_0)) /*!< ADC dual mode enabled: Alternate trigger mode, on group injected */
282
+/**
283
+  * @}
284
+  */
285
+#endif /* defined STM32F103x6 || defined STM32F103xB || defined STM32F105xC || defined STM32F107xC || defined STM32F103xE || defined STM32F103xG */
286
+
287
+/**
288
+  * @}
289
+  */
290
+
291
+
292
+/* Private constants ---------------------------------------------------------*/
293
+
294
+/** @addtogroup ADCEx_Private_Constants ADCEx Private Constants
295
+  * @{
296
+  */
297
+
298
+/** @defgroup ADCEx_Internal_HAL_driver_Ext_trig_src_Regular ADC Extended Internal HAL driver trigger selection for regular group
299
+  * @{
300
+  */
301
+/* List of external triggers of regular group for ADC1, ADC2, ADC3 (if ADC    */
302
+/* instance is available on the selected device).                             */
303
+/* (used internally by HAL driver. To not use into HAL structure parameters)  */
304
+
305
+/* External triggers of regular group for ADC1&ADC2 (if ADCx available) */
306
+#define ADC1_2_EXTERNALTRIG_T1_CC1                       0x00000000U
307
+#define ADC1_2_EXTERNALTRIG_T1_CC2           ((uint32_t)(                                      ADC_CR2_EXTSEL_0))
308
+#define ADC1_2_EXTERNALTRIG_T2_CC2           ((uint32_t)(                   ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_0))
309
+#define ADC1_2_EXTERNALTRIG_T3_TRGO          ((uint32_t)(ADC_CR2_EXTSEL_2                                      ))
310
+#define ADC1_2_EXTERNALTRIG_T4_CC4           ((uint32_t)(ADC_CR2_EXTSEL_2 |                    ADC_CR2_EXTSEL_0))
311
+#define ADC1_2_EXTERNALTRIG_EXT_IT11         ((uint32_t)(ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_1                   ))
312
+#if defined (STM32F101xE) || defined (STM32F103xE) || defined (STM32F103xG)
313
+/* Note: TIM8_TRGO is available on ADC1 and ADC2 only in high-density and     */
314
+/* XL-density devices.                                                        */
315
+#define ADC1_2_EXTERNALTRIG_T8_TRGO          ADC1_2_EXTERNALTRIG_EXT_IT11
316
+#endif
317
+
318
+#if defined (STM32F103xE) || defined (STM32F103xG)
319
+/* External triggers of regular group for ADC3 */
320
+#define ADC3_EXTERNALTRIG_T3_CC1             ADC1_2_EXTERNALTRIG_T1_CC1
321
+#define ADC3_EXTERNALTRIG_T2_CC3             ADC1_2_EXTERNALTRIG_T1_CC2
322
+#define ADC3_EXTERNALTRIG_T8_CC1             ADC1_2_EXTERNALTRIG_T2_CC2
323
+#define ADC3_EXTERNALTRIG_T8_TRGO            ADC1_2_EXTERNALTRIG_T3_TRGO
324
+#define ADC3_EXTERNALTRIG_T5_CC1             ADC1_2_EXTERNALTRIG_T4_CC4
325
+#define ADC3_EXTERNALTRIG_T5_CC3             ADC1_2_EXTERNALTRIG_EXT_IT11
326
+#endif
327
+
328
+/* External triggers of regular group for ADC1&ADC2&ADC3 (if ADCx available) */
329
+#define ADC1_2_3_EXTERNALTRIG_T1_CC3         ((uint32_t)(                   ADC_CR2_EXTSEL_1                   ))
330
+#define ADC1_2_3_SWSTART                     ((uint32_t)(ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_0))
331
+/**
332
+  * @}
333
+  */
334
+
335
+/** @defgroup ADCEx_Internal_HAL_driver_Ext_trig_src_Injected ADC Extended Internal HAL driver trigger selection for injected group
336
+  * @{
337
+  */
338
+/* List of external triggers of injected group for ADC1, ADC2, ADC3 (if ADC    */
339
+/* instance is available on the selected device).                             */
340
+/* (used internally by HAL driver. To not use into HAL structure parameters)  */
341
+
342
+/* External triggers of injected group for ADC1&ADC2 (if ADCx available) */
343
+#define ADC1_2_EXTERNALTRIGINJEC_T2_TRGO          ((uint32_t)(                    ADC_CR2_JEXTSEL_1                    ))
344
+#define ADC1_2_EXTERNALTRIGINJEC_T2_CC1           ((uint32_t)(                    ADC_CR2_JEXTSEL_1 | ADC_CR2_JEXTSEL_0))
345
+#define ADC1_2_EXTERNALTRIGINJEC_T3_CC4           ((uint32_t)(ADC_CR2_JEXTSEL_2                                        ))
346
+#define ADC1_2_EXTERNALTRIGINJEC_T4_TRGO          ((uint32_t)(ADC_CR2_JEXTSEL_2 |                     ADC_CR2_JEXTSEL_0))
347
+#define ADC1_2_EXTERNALTRIGINJEC_EXT_IT15         ((uint32_t)(ADC_CR2_JEXTSEL_2 | ADC_CR2_JEXTSEL_1                    ))
348
+#if defined (STM32F101xE) || defined (STM32F103xE) || defined (STM32F103xG)
349
+/* Note: TIM8_CC4 is available on ADC1 and ADC2 only in high-density and      */
350
+/* XL-density devices.                                                        */
351
+#define ADC1_2_EXTERNALTRIGINJEC_T8_CC4           ADC1_2_EXTERNALTRIGINJEC_EXT_IT15
352
+#endif
353
+
354
+#if defined (STM32F103xE) || defined (STM32F103xG)
355
+/* External triggers of injected group for ADC3 */
356
+#define ADC3_EXTERNALTRIGINJEC_T4_CC3             ADC1_2_EXTERNALTRIGINJEC_T2_TRGO
357
+#define ADC3_EXTERNALTRIGINJEC_T8_CC2             ADC1_2_EXTERNALTRIGINJEC_T2_CC1
358
+#define ADC3_EXTERNALTRIGINJEC_T8_CC4             ADC1_2_EXTERNALTRIGINJEC_T3_CC4
359
+#define ADC3_EXTERNALTRIGINJEC_T5_TRGO            ADC1_2_EXTERNALTRIGINJEC_T4_TRGO
360
+#define ADC3_EXTERNALTRIGINJEC_T5_CC4             ADC1_2_EXTERNALTRIGINJEC_EXT_IT15
361
+#endif /* STM32F103xE || defined STM32F103xG */
362
+
363
+/* External triggers of injected group for ADC1&ADC2&ADC3 (if ADCx available) */
364
+#define ADC1_2_3_EXTERNALTRIGINJEC_T1_TRGO                    0x00000000U
365
+#define ADC1_2_3_EXTERNALTRIGINJEC_T1_CC4         ((uint32_t)(                                        ADC_CR2_JEXTSEL_0))
366
+#define ADC1_2_3_JSWSTART                         ((uint32_t)(ADC_CR2_JEXTSEL_2 | ADC_CR2_JEXTSEL_1 | ADC_CR2_JEXTSEL_0))
367
+/**
368
+  * @}
369
+  */
370
+
371
+/**
372
+  * @}
373
+  */
374
+
375
+
376
+/* Exported macro ------------------------------------------------------------*/
377
+
378
+/* Private macro -------------------------------------------------------------*/
379
+
380
+/** @defgroup ADCEx_Private_Macro ADCEx Private Macro
381
+  * @{
382
+  */
383
+/* Macro reserved for internal HAL driver usage, not intended to be used in   */
384
+/* code of final user.                                                        */
385
+
386
+    
387
+/**
388
+  * @brief For devices with 3 ADCs: Defines the external trigger source 
389
+  *        for regular group according to ADC into common group ADC1&ADC2 or 
390
+  *        ADC3 (some triggers with same source have different value to
391
+  *        be programmed into ADC EXTSEL bits of CR2 register).
392
+  *        For devices with 2 ADCs or less: this macro makes no change.
393
+  * @param __HANDLE__: ADC handle
394
+  * @param __EXT_TRIG_CONV__: External trigger selected for regular group.
395
+  * @retval External trigger to be programmed into EXTSEL bits of CR2 register
396
+  */
397
+#if defined (STM32F103xE) || defined (STM32F103xG)
398
+#define ADC_CFGR_EXTSEL(__HANDLE__, __EXT_TRIG_CONV__)                         \
399
+ (( (((__HANDLE__)->Instance) == ADC3)                                         \
400
+  )?                                                                           \
401
+   ( ( (__EXT_TRIG_CONV__) == ADC_EXTERNALTRIGCONV_T8_TRGO                     \
402
+     )?                                                                        \
403
+      (ADC3_EXTERNALTRIG_T8_TRGO)                                              \
404
+      :                                                                        \
405
+      (__EXT_TRIG_CONV__)                                                      \
406
+   )                                                                           \
407
+   :                                                                           \
408
+   (__EXT_TRIG_CONV__)                                                         \
409
+ )
410
+#else
411
+#define ADC_CFGR_EXTSEL(__HANDLE__, __EXT_TRIG_CONV__)                         \
412
+  (__EXT_TRIG_CONV__)
413
+#endif /* STM32F103xE || STM32F103xG */
414
+
415
+/**
416
+  * @brief For devices with 3 ADCs: Defines the external trigger source 
417
+  *        for injected group according to ADC into common group ADC1&ADC2 or 
418
+  *        ADC3 (some triggers with same source have different value to
419
+  *        be programmed into ADC JEXTSEL bits of CR2 register).
420
+  *        For devices with 2 ADCs or less: this macro makes no change.
421
+  * @param __HANDLE__: ADC handle
422
+  * @param __EXT_TRIG_INJECTCONV__: External trigger selected for injected group.
423
+  * @retval External trigger to be programmed into JEXTSEL bits of CR2 register
424
+  */
425
+#if defined (STM32F103xE) || defined (STM32F103xG)
426
+#define ADC_CFGR_JEXTSEL(__HANDLE__, __EXT_TRIG_INJECTCONV__)                  \
427
+ (( (((__HANDLE__)->Instance) == ADC3)                                         \
428
+  )?                                                                           \
429
+   ( ( (__EXT_TRIG_INJECTCONV__) == ADC_EXTERNALTRIGINJECCONV_T8_CC4           \
430
+     )?                                                                        \
431
+      (ADC3_EXTERNALTRIGINJEC_T8_CC4)                                          \
432
+      :                                                                        \
433
+      (__EXT_TRIG_INJECTCONV__)                                                \
434
+   )                                                                           \
435
+   :                                                                           \
436
+   (__EXT_TRIG_INJECTCONV__)                                                   \
437
+ )
438
+#else
439
+#define ADC_CFGR_JEXTSEL(__HANDLE__, __EXT_TRIG_INJECTCONV__)                  \
440
+   (__EXT_TRIG_INJECTCONV__)
441
+#endif /* STM32F103xE || STM32F103xG */
442
+
443
+
444
+/**
445
+  * @brief Verification if multimode is enabled for the selected ADC (multimode ADC master or ADC slave) (applicable for devices with several ADCs)
446
+  * @param __HANDLE__: ADC handle
447
+  * @retval Multimode state: RESET if multimode is disabled, other value if multimode is enabled
448
+  */
449
+#if defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
450
+#define ADC_MULTIMODE_IS_ENABLE(__HANDLE__)                                    \
451
+ (( (((__HANDLE__)->Instance) == ADC1) || (((__HANDLE__)->Instance) == ADC2)   \
452
+  )?                                                                           \
453
+   (ADC1->CR1 & ADC_CR1_DUALMOD)                                               \
454
+   :                                                                           \
455
+   (RESET)                                                                     \
456
+ )
457
+#else
458
+#define ADC_MULTIMODE_IS_ENABLE(__HANDLE__)                                    \
459
+  (RESET)
460
+#endif /* defined STM32F103x6 || defined STM32F103xB || defined STM32F105xC || defined STM32F107xC || defined STM32F103xE || defined STM32F103xG */
461
+
462
+/**
463
+  * @brief Verification of condition for ADC start conversion: ADC must be in non-multimode, or multimode with handle of ADC master (applicable for devices with several ADCs)
464
+  * @param __HANDLE__: ADC handle
465
+  * @retval None
466
+  */
467
+#if defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
468
+#define ADC_NONMULTIMODE_OR_MULTIMODEMASTER(__HANDLE__)                        \
469
+  (( (((__HANDLE__)->Instance) == ADC2)                                        \
470
+   )?                                                                          \
471
+    ((ADC1->CR1 & ADC_CR1_DUALMOD) == RESET)                                   \
472
+    :                                                                          \
473
+    (!RESET)                                                                   \
474
+  )
475
+#else
476
+#define ADC_NONMULTIMODE_OR_MULTIMODEMASTER(__HANDLE__)                        \
477
+  (!RESET)
478
+#endif /* defined STM32F103x6 || defined STM32F103xB || defined STM32F105xC || defined STM32F107xC || defined STM32F103xE || defined STM32F103xG */
479
+
480
+/**
481
+  * @brief Check ADC multimode setting: In case of multimode, check whether ADC master of the selected ADC has feature auto-injection enabled (applicable for devices with several ADCs)
482
+  * @param __HANDLE__: ADC handle
483
+  * @retval None
484
+  */
485
+#if defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
486
+#define ADC_MULTIMODE_AUTO_INJECTED(__HANDLE__)                                \
487
+  (( (((__HANDLE__)->Instance) == ADC1) || (((__HANDLE__)->Instance) == ADC2)  \
488
+   )?                                                                          \
489
+    (ADC1->CR1 & ADC_CR1_JAUTO)                                                \
490
+    :                                                                          \
491
+    (RESET)                                                                    \
492
+  )
493
+#else
494
+#define ADC_MULTIMODE_AUTO_INJECTED(__HANDLE__)                                \
495
+  (RESET)
496
+#endif /* defined STM32F103x6 || defined STM32F103xB || defined STM32F105xC || defined STM32F107xC || defined STM32F103xE || defined STM32F103xG */
497
+
498
+#if defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
499
+/**
500
+  * @brief Set handle of the other ADC sharing the common multimode settings
501
+  * @param __HANDLE__: ADC handle
502
+  * @param __HANDLE_OTHER_ADC__: other ADC handle
503
+  * @retval None
504
+  */
505
+#define ADC_COMMON_ADC_OTHER(__HANDLE__, __HANDLE_OTHER_ADC__)                 \
506
+  ((__HANDLE_OTHER_ADC__)->Instance = ADC2)
507
+
508
+/**
509
+  * @brief Set handle of the ADC slave associated to the ADC master
510
+  * On STM32F1 devices, ADC slave is always ADC2 (this can be different
511
+  * on other STM32 devices)
512
+  * @param __HANDLE_MASTER__: ADC master handle
513
+  * @param __HANDLE_SLAVE__: ADC slave handle
514
+  * @retval None
515
+  */
516
+#define ADC_MULTI_SLAVE(__HANDLE_MASTER__, __HANDLE_SLAVE__)                   \
517
+  ((__HANDLE_SLAVE__)->Instance = ADC2)
518
+       
519
+#endif /* defined STM32F103x6 || defined STM32F103xB || defined STM32F105xC || defined STM32F107xC || defined STM32F103xE || defined STM32F103xG */
520
+
521
+#define IS_ADC_INJECTED_RANK(CHANNEL) (((CHANNEL) == ADC_INJECTED_RANK_1) || \
522
+                                       ((CHANNEL) == ADC_INJECTED_RANK_2) || \
523
+                                       ((CHANNEL) == ADC_INJECTED_RANK_3) || \
524
+                                       ((CHANNEL) == ADC_INJECTED_RANK_4))
525
+
526
+#define IS_ADC_EXTTRIGINJEC_EDGE(EDGE) (((EDGE) == ADC_EXTERNALTRIGINJECCONV_EDGE_NONE)  || \
527
+                                        ((EDGE) == ADC_EXTERNALTRIGINJECCONV_EDGE_RISING))
528
+
529
+/** @defgroup ADCEx_injected_nb_conv_verification ADCEx injected nb conv verification
530
+  * @{
531
+  */
532
+#define IS_ADC_INJECTED_NB_CONV(LENGTH)  (((LENGTH) >= 1U) && ((LENGTH) <= 4U))
533
+/**
534
+  * @}
535
+  */
536
+
537
+#if defined (STM32F100xB) || defined (STM32F100xE) || defined (STM32F101x6) || defined (STM32F101xB) || defined (STM32F102x6) || defined (STM32F102xB) || defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC)
538
+#define IS_ADC_EXTTRIG(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC1)    || \
539
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC2)    || \
540
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_CC2)    || \
541
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_TRGO)   || \
542
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T4_CC4)    || \
543
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_EXT_IT11)  || \
544
+                                 ((REGTRIG) == ADC_SOFTWARE_START))
545
+#endif
546
+#if defined (STM32F101xE)
547
+#define IS_ADC_EXTTRIG(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC1)    || \
548
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC2)    || \
549
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_CC2)    || \
550
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_TRGO)   || \
551
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T4_CC4)    || \
552
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_EXT_IT11)  || \
553
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T8_TRGO)   || \
554
+                                 ((REGTRIG) == ADC_SOFTWARE_START))
555
+#endif
556
+#if defined (STM32F101xG)
557
+#define IS_ADC_EXTTRIG(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC1)    || \
558
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC2)    || \
559
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_CC2)    || \
560
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_TRGO)   || \
561
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T4_CC4)    || \
562
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_EXT_IT11)  || \
563
+                                 ((REGTRIG) == ADC_SOFTWARE_START))
564
+#endif
565
+#if defined (STM32F103xE) || defined (STM32F103xG)
566
+#define IS_ADC_EXTTRIG(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC1)    || \
567
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC2)    || \
568
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_CC2)    || \
569
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_TRGO)   || \
570
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T4_CC4)    || \
571
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_EXT_IT11)  || \
572
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_CC1)    || \
573
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_CC3)    || \
574
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T8_CC1)    || \
575
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T5_CC1)    || \
576
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T5_CC3)    || \
577
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC3)    || \
578
+                                 ((REGTRIG) == ADC_EXTERNALTRIGCONV_T8_TRGO)   || \
579
+                                 ((REGTRIG) == ADC_SOFTWARE_START))
580
+#endif
581
+
582
+#if defined (STM32F100xB) || defined (STM32F100xE) || defined (STM32F101x6) || defined (STM32F101xB) || defined (STM32F102x6) || defined (STM32F102xB) || defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC)
583
+#define IS_ADC_EXTTRIGINJEC(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T2_TRGO)  || \
584
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T2_CC1)   || \
585
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T3_CC4)   || \
586
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T4_TRGO)  || \
587
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_EXT_IT15) || \
588
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T1_CC4)   || \
589
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T1_TRGO)  || \
590
+                                      ((REGTRIG) == ADC_INJECTED_SOFTWARE_START))
591
+#endif
592
+#if defined (STM32F101xE)
593
+#define IS_ADC_EXTTRIGINJEC(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T2_TRGO)  || \
594
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T2_CC1)   || \
595
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T3_CC4)   || \
596
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T4_TRGO)  || \
597
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_EXT_IT15) || \
598
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T1_CC4)   || \
599
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T1_TRGO)  || \
600
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T8_CC4)   || \
601
+                                      ((REGTRIG) == ADC_INJECTED_SOFTWARE_START))
602
+#endif
603
+#if defined (STM32F101xG)
604
+#define IS_ADC_EXTTRIGINJEC(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T2_TRGO)  || \
605
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T2_CC1)   || \
606
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T3_CC4)   || \
607
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T4_TRGO)  || \
608
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_EXT_IT15) || \
609
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T1_CC4)   || \
610
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T1_TRGO)  || \
611
+                                      ((REGTRIG) == ADC_INJECTED_SOFTWARE_START))
612
+#endif
613
+#if defined (STM32F103xE) || defined (STM32F103xG)
614
+#define IS_ADC_EXTTRIGINJEC(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T2_TRGO)  || \
615
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T2_CC1)   || \
616
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T3_CC4)   || \
617
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T4_TRGO)  || \
618
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T5_CC4)   || \
619
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_EXT_IT15) || \
620
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T4_CC3)   || \
621
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T8_CC2)   || \
622
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T5_TRGO)  || \
623
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T5_CC4)   || \
624
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T1_CC4)   || \
625
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T1_TRGO)  || \
626
+                                      ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T8_CC4)   || \
627
+                                      ((REGTRIG) == ADC_INJECTED_SOFTWARE_START))
628
+#endif
629
+
630
+#if defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
631
+#define IS_ADC_MODE(MODE) (((MODE) == ADC_MODE_INDEPENDENT)                || \
632
+                           ((MODE) == ADC_DUALMODE_REGSIMULT_INJECSIMULT)  || \
633
+                           ((MODE) == ADC_DUALMODE_REGSIMULT_ALTERTRIG)    || \
634
+                           ((MODE) == ADC_DUALMODE_INJECSIMULT_INTERLFAST) || \
635
+                           ((MODE) == ADC_DUALMODE_INJECSIMULT_INTERLSLOW) || \
636
+                           ((MODE) == ADC_DUALMODE_INJECSIMULT)            || \
637
+                           ((MODE) == ADC_DUALMODE_REGSIMULT)              || \
638
+                           ((MODE) == ADC_DUALMODE_INTERLFAST)             || \
639
+                           ((MODE) == ADC_DUALMODE_INTERLSLOW)             || \
640
+                           ((MODE) == ADC_DUALMODE_ALTERTRIG) )
641
+#endif /* defined STM32F103x6 || defined STM32F103xB || defined STM32F105xC || defined STM32F107xC || defined STM32F103xE || defined STM32F103xG */
642
+
643
+/**
644
+  * @}
645
+  */      
646
+   
647
+    
648
+
649
+    
650
+    
651
+   
652
+/* Exported functions --------------------------------------------------------*/
653
+/** @addtogroup ADCEx_Exported_Functions
654
+  * @{
655
+  */
656
+
657
+/* IO operation functions  *****************************************************/
658
+/** @addtogroup ADCEx_Exported_Functions_Group1
659
+  * @{
660
+  */
661
+
662
+/* ADC calibration */
663
+HAL_StatusTypeDef       HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc);
664
+
665
+/* Blocking mode: Polling */
666
+HAL_StatusTypeDef       HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc);
667
+HAL_StatusTypeDef       HAL_ADCEx_InjectedStop(ADC_HandleTypeDef* hadc);
668
+HAL_StatusTypeDef       HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout);
669
+
670
+/* Non-blocking mode: Interruption */
671
+HAL_StatusTypeDef       HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc);
672
+HAL_StatusTypeDef       HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef* hadc);
673
+
674
+#if defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
675
+/* ADC multimode */
676
+HAL_StatusTypeDef       HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef *hadc, uint32_t *pData, uint32_t Length);
677
+HAL_StatusTypeDef       HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef *hadc); 
678
+#endif /* defined STM32F103x6 || defined STM32F103xB || defined STM32F105xC || defined STM32F107xC || defined STM32F103xE || defined STM32F103xG */
679
+
680
+/* ADC retrieve conversion value intended to be used with polling or interruption */
681
+uint32_t                HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef* hadc, uint32_t InjectedRank);
682
+#if defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
683
+uint32_t                HAL_ADCEx_MultiModeGetValue(ADC_HandleTypeDef *hadc);
684
+#endif /* defined STM32F103x6 || defined STM32F103xB || defined STM32F105xC || defined STM32F107xC || defined STM32F103xE || defined STM32F103xG */
685
+
686
+/* ADC IRQHandler and Callbacks used in non-blocking modes (Interruption) */
687
+void                    HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc);
688
+/**
689
+  * @}
690
+  */
691
+
692
+
693
+/* Peripheral Control functions ***********************************************/
694
+/** @addtogroup ADCEx_Exported_Functions_Group2
695
+  * @{
696
+  */
697
+HAL_StatusTypeDef       HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc,ADC_InjectionConfTypeDef* sConfigInjected);
698
+#if defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
699
+HAL_StatusTypeDef       HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef *hadc, ADC_MultiModeTypeDef *multimode);
700
+#endif /* defined STM32F103x6 || defined STM32F103xB || defined STM32F105xC || defined STM32F107xC || defined STM32F103xE || defined STM32F103xG */
701
+/**
702
+  * @}
703
+  */
704
+
705
+
706
+/**
707
+  * @}
708
+  */
709
+
710
+
711
+/**
712
+  * @}
713
+  */ 
714
+
715
+/**
716
+  * @}
717
+  */
718
+  
719
+#ifdef __cplusplus
720
+}
721
+#endif
722
+
723
+#endif /* __STM32F1xx_HAL_ADC_EX_H */
724
+
725
+
726
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 426 - 0
Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_cortex.h

@@ -0,0 +1,426 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_cortex.h
4
+  * @author  MCD Application Team
5
+  * @brief   Header file of CORTEX HAL module.
6
+  ******************************************************************************
7
+  * @attention
8
+  *
9
+  * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
10
+  *
11
+  * Redistribution and use in source and binary forms, with or without modification,
12
+  * are permitted provided that the following conditions are met:
13
+  *   1. Redistributions of source code must retain the above copyright notice,
14
+  *      this list of conditions and the following disclaimer.
15
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
16
+  *      this list of conditions and the following disclaimer in the documentation
17
+  *      and/or other materials provided with the distribution.
18
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
19
+  *      may be used to endorse or promote products derived from this software
20
+  *      without specific prior written permission.
21
+  *
22
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+  *
33
+  ******************************************************************************
34
+  */ 
35
+
36
+/* Define to prevent recursive inclusion -------------------------------------*/
37
+#ifndef __STM32F1xx_HAL_CORTEX_H
38
+#define __STM32F1xx_HAL_CORTEX_H
39
+
40
+#ifdef __cplusplus
41
+ extern "C" {
42
+#endif
43
+
44
+/* Includes ------------------------------------------------------------------*/
45
+#include "stm32f1xx_hal_def.h"
46
+
47
+/** @addtogroup STM32F1xx_HAL_Driver
48
+  * @{
49
+  */
50
+
51
+/** @addtogroup CORTEX
52
+  * @{
53
+  */ 
54
+/* Exported types ------------------------------------------------------------*/
55
+/** @defgroup CORTEX_Exported_Types Cortex Exported Types
56
+  * @{
57
+  */
58
+
59
+#if (__MPU_PRESENT == 1U)
60
+/** @defgroup CORTEX_MPU_Region_Initialization_Structure_definition MPU Region Initialization Structure Definition
61
+  * @brief  MPU Region initialization structure 
62
+  * @{
63
+  */
64
+typedef struct
65
+{
66
+  uint8_t                Enable;                /*!< Specifies the status of the region. 
67
+                                                     This parameter can be a value of @ref CORTEX_MPU_Region_Enable                 */
68
+  uint8_t                Number;                /*!< Specifies the number of the region to protect. 
69
+                                                     This parameter can be a value of @ref CORTEX_MPU_Region_Number                 */
70
+  uint32_t               BaseAddress;           /*!< Specifies the base address of the region to protect.                           */
71
+  uint8_t                Size;                  /*!< Specifies the size of the region to protect. 
72
+                                                     This parameter can be a value of @ref CORTEX_MPU_Region_Size                   */
73
+  uint8_t                SubRegionDisable;      /*!< Specifies the number of the subregion protection to disable. 
74
+                                                     This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF    */         
75
+  uint8_t                TypeExtField;          /*!< Specifies the TEX field level.
76
+                                                     This parameter can be a value of @ref CORTEX_MPU_TEX_Levels                    */                 
77
+  uint8_t                AccessPermission;      /*!< Specifies the region access permission type. 
78
+                                                     This parameter can be a value of @ref CORTEX_MPU_Region_Permission_Attributes  */
79
+  uint8_t                DisableExec;           /*!< Specifies the instruction access status. 
80
+                                                     This parameter can be a value of @ref CORTEX_MPU_Instruction_Access            */
81
+  uint8_t                IsShareable;           /*!< Specifies the shareability status of the protected region. 
82
+                                                     This parameter can be a value of @ref CORTEX_MPU_Access_Shareable              */
83
+  uint8_t                IsCacheable;           /*!< Specifies the cacheable status of the region protected. 
84
+                                                     This parameter can be a value of @ref CORTEX_MPU_Access_Cacheable              */
85
+  uint8_t                IsBufferable;          /*!< Specifies the bufferable status of the protected region. 
86
+                                                     This parameter can be a value of @ref CORTEX_MPU_Access_Bufferable             */
87
+}MPU_Region_InitTypeDef;
88
+/**
89
+  * @}
90
+  */
91
+#endif /* __MPU_PRESENT */
92
+
93
+/**
94
+  * @}
95
+  */
96
+
97
+/* Exported constants --------------------------------------------------------*/
98
+
99
+/** @defgroup CORTEX_Exported_Constants CORTEX Exported Constants
100
+  * @{
101
+  */
102
+
103
+/** @defgroup CORTEX_Preemption_Priority_Group CORTEX Preemption Priority Group
104
+  * @{
105
+  */
106
+#define NVIC_PRIORITYGROUP_0         0x00000007U /*!< 0 bits for pre-emption priority
107
+                                                      4 bits for subpriority */
108
+#define NVIC_PRIORITYGROUP_1         0x00000006U /*!< 1 bits for pre-emption priority
109
+                                                      3 bits for subpriority */
110
+#define NVIC_PRIORITYGROUP_2         0x00000005U /*!< 2 bits for pre-emption priority
111
+                                                      2 bits for subpriority */
112
+#define NVIC_PRIORITYGROUP_3         0x00000004U /*!< 3 bits for pre-emption priority
113
+                                                      1 bits for subpriority */
114
+#define NVIC_PRIORITYGROUP_4         0x00000003U /*!< 4 bits for pre-emption priority
115
+                                                      0 bits for subpriority */
116
+/**
117
+  * @}
118
+  */
119
+
120
+/** @defgroup CORTEX_SysTick_clock_source CORTEX _SysTick clock source 
121
+  * @{
122
+  */
123
+#define SYSTICK_CLKSOURCE_HCLK_DIV8    0x00000000U
124
+#define SYSTICK_CLKSOURCE_HCLK         0x00000004U
125
+
126
+/**
127
+  * @}
128
+  */
129
+
130
+#if (__MPU_PRESENT == 1)
131
+/** @defgroup CORTEX_MPU_HFNMI_PRIVDEF_Control MPU HFNMI and PRIVILEGED Access control
132
+  * @{
133
+  */
134
+#define  MPU_HFNMI_PRIVDEF_NONE           0x00000000U
135
+#define  MPU_HARDFAULT_NMI                MPU_CTRL_HFNMIENA_Msk
136
+#define  MPU_PRIVILEGED_DEFAULT           MPU_CTRL_PRIVDEFENA_Msk
137
+#define  MPU_HFNMI_PRIVDEF               (MPU_CTRL_HFNMIENA_Msk | MPU_CTRL_PRIVDEFENA_Msk)
138
+
139
+/**
140
+  * @}
141
+  */
142
+
143
+/** @defgroup CORTEX_MPU_Region_Enable CORTEX MPU Region Enable
144
+  * @{
145
+  */
146
+#define  MPU_REGION_ENABLE     ((uint8_t)0x01)
147
+#define  MPU_REGION_DISABLE    ((uint8_t)0x00)
148
+/**
149
+  * @}
150
+  */
151
+
152
+/** @defgroup CORTEX_MPU_Instruction_Access CORTEX MPU Instruction Access
153
+  * @{
154
+  */
155
+#define  MPU_INSTRUCTION_ACCESS_ENABLE      ((uint8_t)0x00)
156
+#define  MPU_INSTRUCTION_ACCESS_DISABLE     ((uint8_t)0x01)
157
+/**
158
+  * @}
159
+  */
160
+
161
+/** @defgroup CORTEX_MPU_Access_Shareable CORTEX MPU Instruction Access Shareable
162
+  * @{
163
+  */
164
+#define  MPU_ACCESS_SHAREABLE        ((uint8_t)0x01)
165
+#define  MPU_ACCESS_NOT_SHAREABLE    ((uint8_t)0x00)
166
+/**
167
+  * @}
168
+  */
169
+
170
+/** @defgroup CORTEX_MPU_Access_Cacheable CORTEX MPU Instruction Access Cacheable
171
+  * @{
172
+  */
173
+#define  MPU_ACCESS_CACHEABLE         ((uint8_t)0x01)
174
+#define  MPU_ACCESS_NOT_CACHEABLE     ((uint8_t)0x00)
175
+/**
176
+  * @}
177
+  */
178
+
179
+/** @defgroup CORTEX_MPU_Access_Bufferable CORTEX MPU Instruction Access Bufferable
180
+  * @{
181
+  */
182
+#define  MPU_ACCESS_BUFFERABLE         ((uint8_t)0x01)
183
+#define  MPU_ACCESS_NOT_BUFFERABLE     ((uint8_t)0x00)
184
+/**
185
+  * @}
186
+  */
187
+
188
+/** @defgroup CORTEX_MPU_TEX_Levels MPU TEX Levels
189
+  * @{
190
+  */
191
+#define  MPU_TEX_LEVEL0    ((uint8_t)0x00)
192
+#define  MPU_TEX_LEVEL1    ((uint8_t)0x01)
193
+#define  MPU_TEX_LEVEL2    ((uint8_t)0x02)
194
+/**
195
+  * @}
196
+  */
197
+
198
+/** @defgroup CORTEX_MPU_Region_Size CORTEX MPU Region Size
199
+  * @{
200
+  */
201
+#define   MPU_REGION_SIZE_32B      ((uint8_t)0x04)
202
+#define   MPU_REGION_SIZE_64B      ((uint8_t)0x05)
203
+#define   MPU_REGION_SIZE_128B     ((uint8_t)0x06)
204
+#define   MPU_REGION_SIZE_256B     ((uint8_t)0x07)
205
+#define   MPU_REGION_SIZE_512B     ((uint8_t)0x08)
206
+#define   MPU_REGION_SIZE_1KB      ((uint8_t)0x09)
207
+#define   MPU_REGION_SIZE_2KB      ((uint8_t)0x0A)
208
+#define   MPU_REGION_SIZE_4KB      ((uint8_t)0x0B)
209
+#define   MPU_REGION_SIZE_8KB      ((uint8_t)0x0C)
210
+#define   MPU_REGION_SIZE_16KB     ((uint8_t)0x0D)
211
+#define   MPU_REGION_SIZE_32KB     ((uint8_t)0x0E)
212
+#define   MPU_REGION_SIZE_64KB     ((uint8_t)0x0F)
213
+#define   MPU_REGION_SIZE_128KB    ((uint8_t)0x10)
214
+#define   MPU_REGION_SIZE_256KB    ((uint8_t)0x11)
215
+#define   MPU_REGION_SIZE_512KB    ((uint8_t)0x12)
216
+#define   MPU_REGION_SIZE_1MB      ((uint8_t)0x13)
217
+#define   MPU_REGION_SIZE_2MB      ((uint8_t)0x14)
218
+#define   MPU_REGION_SIZE_4MB      ((uint8_t)0x15)
219
+#define   MPU_REGION_SIZE_8MB      ((uint8_t)0x16)
220
+#define   MPU_REGION_SIZE_16MB     ((uint8_t)0x17)
221
+#define   MPU_REGION_SIZE_32MB     ((uint8_t)0x18)
222
+#define   MPU_REGION_SIZE_64MB     ((uint8_t)0x19)
223
+#define   MPU_REGION_SIZE_128MB    ((uint8_t)0x1A)
224
+#define   MPU_REGION_SIZE_256MB    ((uint8_t)0x1B)
225
+#define   MPU_REGION_SIZE_512MB    ((uint8_t)0x1C)
226
+#define   MPU_REGION_SIZE_1GB      ((uint8_t)0x1D)
227
+#define   MPU_REGION_SIZE_2GB      ((uint8_t)0x1E)
228
+#define   MPU_REGION_SIZE_4GB      ((uint8_t)0x1F)
229
+/**
230
+  * @}
231
+  */
232
+   
233
+/** @defgroup CORTEX_MPU_Region_Permission_Attributes CORTEX MPU Region Permission Attributes 
234
+  * @{
235
+  */
236
+#define  MPU_REGION_NO_ACCESS      ((uint8_t)0x00)
237
+#define  MPU_REGION_PRIV_RW        ((uint8_t)0x01)
238
+#define  MPU_REGION_PRIV_RW_URO    ((uint8_t)0x02)
239
+#define  MPU_REGION_FULL_ACCESS    ((uint8_t)0x03)
240
+#define  MPU_REGION_PRIV_RO        ((uint8_t)0x05)
241
+#define  MPU_REGION_PRIV_RO_URO    ((uint8_t)0x06)
242
+/**
243
+  * @}
244
+  */
245
+
246
+/** @defgroup CORTEX_MPU_Region_Number CORTEX MPU Region Number
247
+  * @{
248
+  */
249
+#define  MPU_REGION_NUMBER0    ((uint8_t)0x00)
250
+#define  MPU_REGION_NUMBER1    ((uint8_t)0x01)
251
+#define  MPU_REGION_NUMBER2    ((uint8_t)0x02)
252
+#define  MPU_REGION_NUMBER3    ((uint8_t)0x03)
253
+#define  MPU_REGION_NUMBER4    ((uint8_t)0x04)
254
+#define  MPU_REGION_NUMBER5    ((uint8_t)0x05)
255
+#define  MPU_REGION_NUMBER6    ((uint8_t)0x06)
256
+#define  MPU_REGION_NUMBER7    ((uint8_t)0x07)
257
+/**
258
+  * @}
259
+  */
260
+#endif /* __MPU_PRESENT */
261
+
262
+/**
263
+  * @}
264
+  */
265
+
266
+
267
+/* Exported Macros -----------------------------------------------------------*/
268
+
269
+/* Exported functions --------------------------------------------------------*/
270
+/** @addtogroup CORTEX_Exported_Functions
271
+  * @{
272
+  */
273
+  
274
+/** @addtogroup CORTEX_Exported_Functions_Group1
275
+  * @{
276
+  */
277
+/* Initialization and de-initialization functions *****************************/
278
+void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup);
279
+void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority);
280
+void HAL_NVIC_EnableIRQ(IRQn_Type IRQn);
281
+void HAL_NVIC_DisableIRQ(IRQn_Type IRQn);
282
+void HAL_NVIC_SystemReset(void);
283
+uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb);
284
+/**
285
+  * @}
286
+  */
287
+
288
+/** @addtogroup CORTEX_Exported_Functions_Group2
289
+  * @{
290
+  */
291
+/* Peripheral Control functions ***********************************************/
292
+uint32_t HAL_NVIC_GetPriorityGrouping(void);
293
+void HAL_NVIC_GetPriority(IRQn_Type IRQn, uint32_t PriorityGroup, uint32_t* pPreemptPriority, uint32_t* pSubPriority);
294
+uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn);
295
+void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn);
296
+void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn);
297
+uint32_t HAL_NVIC_GetActive(IRQn_Type IRQn);
298
+void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource);
299
+void HAL_SYSTICK_IRQHandler(void);
300
+void HAL_SYSTICK_Callback(void);
301
+
302
+#if (__MPU_PRESENT == 1U)
303
+void HAL_MPU_Enable(uint32_t MPU_Control);
304
+void HAL_MPU_Disable(void);
305
+void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init);
306
+#endif /* __MPU_PRESENT */
307
+/**
308
+  * @}
309
+  */
310
+
311
+/**
312
+  * @}
313
+  */
314
+
315
+/* Private types -------------------------------------------------------------*/
316
+/* Private variables ---------------------------------------------------------*/
317
+/* Private constants ---------------------------------------------------------*/
318
+/* Private macros ------------------------------------------------------------*/
319
+/** @defgroup CORTEX_Private_Macros CORTEX Private Macros
320
+  * @{
321
+  */
322
+#define IS_NVIC_PRIORITY_GROUP(GROUP) (((GROUP) == NVIC_PRIORITYGROUP_0) || \
323
+                                       ((GROUP) == NVIC_PRIORITYGROUP_1) || \
324
+                                       ((GROUP) == NVIC_PRIORITYGROUP_2) || \
325
+                                       ((GROUP) == NVIC_PRIORITYGROUP_3) || \
326
+                                       ((GROUP) == NVIC_PRIORITYGROUP_4))
327
+
328
+#define IS_NVIC_PREEMPTION_PRIORITY(PRIORITY)  ((PRIORITY) < 0x10U)
329
+
330
+#define IS_NVIC_SUB_PRIORITY(PRIORITY)         ((PRIORITY) < 0x10U)
331
+
332
+#define IS_NVIC_DEVICE_IRQ(IRQ)                ((IRQ) >= (IRQn_Type)0x00U)
333
+
334
+#define IS_SYSTICK_CLK_SOURCE(SOURCE) (((SOURCE) == SYSTICK_CLKSOURCE_HCLK) || \
335
+                                       ((SOURCE) == SYSTICK_CLKSOURCE_HCLK_DIV8))
336
+
337
+#if (__MPU_PRESENT == 1U)
338
+#define IS_MPU_REGION_ENABLE(STATE) (((STATE) == MPU_REGION_ENABLE) || \
339
+                                     ((STATE) == MPU_REGION_DISABLE))
340
+
341
+#define IS_MPU_INSTRUCTION_ACCESS(STATE) (((STATE) == MPU_INSTRUCTION_ACCESS_ENABLE) || \
342
+                                          ((STATE) == MPU_INSTRUCTION_ACCESS_DISABLE))
343
+
344
+#define IS_MPU_ACCESS_SHAREABLE(STATE)   (((STATE) == MPU_ACCESS_SHAREABLE) || \
345
+                                          ((STATE) == MPU_ACCESS_NOT_SHAREABLE))
346
+
347
+#define IS_MPU_ACCESS_CACHEABLE(STATE)   (((STATE) == MPU_ACCESS_CACHEABLE) || \
348
+                                          ((STATE) == MPU_ACCESS_NOT_CACHEABLE))
349
+
350
+#define IS_MPU_ACCESS_BUFFERABLE(STATE)   (((STATE) == MPU_ACCESS_BUFFERABLE) || \
351
+                                          ((STATE) == MPU_ACCESS_NOT_BUFFERABLE))
352
+
353
+#define IS_MPU_TEX_LEVEL(TYPE) (((TYPE) == MPU_TEX_LEVEL0)  || \
354
+                                ((TYPE) == MPU_TEX_LEVEL1)  || \
355
+                                ((TYPE) == MPU_TEX_LEVEL2))
356
+
357
+#define IS_MPU_REGION_PERMISSION_ATTRIBUTE(TYPE) (((TYPE) == MPU_REGION_NO_ACCESS)   || \
358
+                                                  ((TYPE) == MPU_REGION_PRIV_RW)     || \
359
+                                                  ((TYPE) == MPU_REGION_PRIV_RW_URO) || \
360
+                                                  ((TYPE) == MPU_REGION_FULL_ACCESS) || \
361
+                                                  ((TYPE) == MPU_REGION_PRIV_RO)     || \
362
+                                                  ((TYPE) == MPU_REGION_PRIV_RO_URO))
363
+
364
+#define IS_MPU_REGION_NUMBER(NUMBER)    (((NUMBER) == MPU_REGION_NUMBER0) || \
365
+                                         ((NUMBER) == MPU_REGION_NUMBER1) || \
366
+                                         ((NUMBER) == MPU_REGION_NUMBER2) || \
367
+                                         ((NUMBER) == MPU_REGION_NUMBER3) || \
368
+                                         ((NUMBER) == MPU_REGION_NUMBER4) || \
369
+                                         ((NUMBER) == MPU_REGION_NUMBER5) || \
370
+                                         ((NUMBER) == MPU_REGION_NUMBER6) || \
371
+                                         ((NUMBER) == MPU_REGION_NUMBER7))
372
+
373
+#define IS_MPU_REGION_SIZE(SIZE)    (((SIZE) == MPU_REGION_SIZE_32B)   || \
374
+                                     ((SIZE) == MPU_REGION_SIZE_64B)   || \
375
+                                     ((SIZE) == MPU_REGION_SIZE_128B)  || \
376
+                                     ((SIZE) == MPU_REGION_SIZE_256B)  || \
377
+                                     ((SIZE) == MPU_REGION_SIZE_512B)  || \
378
+                                     ((SIZE) == MPU_REGION_SIZE_1KB)   || \
379
+                                     ((SIZE) == MPU_REGION_SIZE_2KB)   || \
380
+                                     ((SIZE) == MPU_REGION_SIZE_4KB)   || \
381
+                                     ((SIZE) == MPU_REGION_SIZE_8KB)   || \
382
+                                     ((SIZE) == MPU_REGION_SIZE_16KB)  || \
383
+                                     ((SIZE) == MPU_REGION_SIZE_32KB)  || \
384
+                                     ((SIZE) == MPU_REGION_SIZE_64KB)  || \
385
+                                     ((SIZE) == MPU_REGION_SIZE_128KB) || \
386
+                                     ((SIZE) == MPU_REGION_SIZE_256KB) || \
387
+                                     ((SIZE) == MPU_REGION_SIZE_512KB) || \
388
+                                     ((SIZE) == MPU_REGION_SIZE_1MB)   || \
389
+                                     ((SIZE) == MPU_REGION_SIZE_2MB)   || \
390
+                                     ((SIZE) == MPU_REGION_SIZE_4MB)   || \
391
+                                     ((SIZE) == MPU_REGION_SIZE_8MB)   || \
392
+                                     ((SIZE) == MPU_REGION_SIZE_16MB)  || \
393
+                                     ((SIZE) == MPU_REGION_SIZE_32MB)  || \
394
+                                     ((SIZE) == MPU_REGION_SIZE_64MB)  || \
395
+                                     ((SIZE) == MPU_REGION_SIZE_128MB) || \
396
+                                     ((SIZE) == MPU_REGION_SIZE_256MB) || \
397
+                                     ((SIZE) == MPU_REGION_SIZE_512MB) || \
398
+                                     ((SIZE) == MPU_REGION_SIZE_1GB)   || \
399
+                                     ((SIZE) == MPU_REGION_SIZE_2GB)   || \
400
+                                     ((SIZE) == MPU_REGION_SIZE_4GB))
401
+
402
+#define IS_MPU_SUB_REGION_DISABLE(SUBREGION)  ((SUBREGION) < (uint16_t)0x00FF)
403
+#endif /* __MPU_PRESENT */
404
+
405
+/**                                                                          
406
+  * @}                                                                  
407
+  */
408
+
409
+/* Private functions ---------------------------------------------------------*/
410
+
411
+/**
412
+  * @}
413
+  */ 
414
+
415
+/**
416
+  * @}
417
+  */
418
+  
419
+#ifdef __cplusplus
420
+}
421
+#endif
422
+
423
+#endif /* __STM32F1xx_HAL_CORTEX_H */
424
+ 
425
+
426
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 214 - 0
Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_def.h

@@ -0,0 +1,214 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_def.h
4
+  * @author  MCD Application Team
5
+  * @brief   This file contains HAL common defines, enumeration, macros and
6
+  *          structures definitions.
7
+  ******************************************************************************
8
+  * @attention
9
+  *
10
+  * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
11
+  *
12
+  * Redistribution and use in source and binary forms, with or without modification,
13
+  * are permitted provided that the following conditions are met:
14
+  *   1. Redistributions of source code must retain the above copyright notice,
15
+  *      this list of conditions and the following disclaimer.
16
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
17
+  *      this list of conditions and the following disclaimer in the documentation
18
+  *      and/or other materials provided with the distribution.
19
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
20
+  *      may be used to endorse or promote products derived from this software
21
+  *      without specific prior written permission.
22
+  *
23
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
27
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
+  *
34
+  ******************************************************************************
35
+  */
36
+
37
+/* Define to prevent recursive inclusion -------------------------------------*/
38
+#ifndef __STM32F1xx_HAL_DEF
39
+#define __STM32F1xx_HAL_DEF
40
+
41
+#ifdef __cplusplus
42
+extern "C" {
43
+#endif
44
+
45
+/* Includes ------------------------------------------------------------------*/
46
+#include "stm32f1xx.h"
47
+#if defined(USE_HAL_LEGACY)
48
+#include "Legacy/stm32_hal_legacy.h"
49
+#endif
50
+#include <stdio.h>
51
+
52
+/* Exported types ------------------------------------------------------------*/
53
+
54
+/**
55
+  * @brief  HAL Status structures definition
56
+  */
57
+typedef enum
58
+{
59
+  HAL_OK       = 0x00U,
60
+  HAL_ERROR    = 0x01U,
61
+  HAL_BUSY     = 0x02U,
62
+  HAL_TIMEOUT  = 0x03U
63
+} HAL_StatusTypeDef;
64
+
65
+/**
66
+  * @brief  HAL Lock structures definition
67
+  */
68
+typedef enum
69
+{
70
+  HAL_UNLOCKED = 0x00U,
71
+  HAL_LOCKED   = 0x01U
72
+} HAL_LockTypeDef;
73
+
74
+/* Exported macro ------------------------------------------------------------*/
75
+#define HAL_MAX_DELAY      0xFFFFFFFFU
76
+
77
+#define HAL_IS_BIT_SET(REG, BIT)         (((REG) & (BIT)) != 0U)
78
+#define HAL_IS_BIT_CLR(REG, BIT)         (((REG) & (BIT)) == 0U)
79
+
80
+#define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__)               \
81
+                        do{                                                      \
82
+                              (__HANDLE__)->__PPP_DMA_FIELD__ = &(__DMA_HANDLE__); \
83
+                              (__DMA_HANDLE__).Parent = (__HANDLE__);             \
84
+                          } while(0U)
85
+
86
+#define UNUSED(X) (void)X      /* To avoid gcc/g++ warnings */
87
+
88
+/** @brief Reset the Handle's State field.
89
+  * @param __HANDLE__: specifies the Peripheral Handle.
90
+  * @note  This macro can be used for the following purpose:
91
+  *          - When the Handle is declared as local variable; before passing it as parameter
92
+  *            to HAL_PPP_Init() for the first time, it is mandatory to use this macro
93
+  *            to set to 0 the Handle's "State" field.
94
+  *            Otherwise, "State" field may have any random value and the first time the function
95
+  *            HAL_PPP_Init() is called, the low level hardware initialization will be missed
96
+  *            (i.e. HAL_PPP_MspInit() will not be executed).
97
+  *          - When there is a need to reconfigure the low level hardware: instead of calling
98
+  *            HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init().
99
+  *            In this later function, when the Handle's "State" field is set to 0, it will execute the function
100
+  *            HAL_PPP_MspInit() which will reconfigure the low level hardware.
101
+  * @retval None
102
+  */
103
+#define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0U)
104
+
105
+#if (USE_RTOS == 1U)
106
+/* Reserved for future use */
107
+#error "USE_RTOS should be 0 in the current HAL release"
108
+#else
109
+#define __HAL_LOCK(__HANDLE__)                                           \
110
+                                do{                                        \
111
+                                    if((__HANDLE__)->Lock == HAL_LOCKED)   \
112
+                                    {                                      \
113
+                                       return HAL_BUSY;                    \
114
+                                    }                                      \
115
+                                    else                                   \
116
+                                    {                                      \
117
+                                       (__HANDLE__)->Lock = HAL_LOCKED;    \
118
+                                    }                                      \
119
+                                  }while (0U)
120
+
121
+#define __HAL_UNLOCK(__HANDLE__)                                          \
122
+                                  do{                                       \
123
+                                      (__HANDLE__)->Lock = HAL_UNLOCKED;    \
124
+                                    }while (0U)
125
+#endif /* USE_RTOS */
126
+
127
+#if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
128
+#ifndef __weak
129
+#define __weak   __attribute__((weak))
130
+#endif /* __weak */
131
+#ifndef __packed
132
+#define __packed __attribute__((__packed__))
133
+#endif /* __packed */
134
+#endif /* __GNUC__ */
135
+
136
+
137
+/* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */
138
+#if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
139
+#ifndef __ALIGN_END
140
+#define __ALIGN_END    __attribute__ ((aligned (4)))
141
+#endif /* __ALIGN_END */
142
+#ifndef __ALIGN_BEGIN
143
+#define __ALIGN_BEGIN
144
+#endif /* __ALIGN_BEGIN */
145
+#else
146
+#ifndef __ALIGN_END
147
+#define __ALIGN_END
148
+#endif /* __ALIGN_END */
149
+#ifndef __ALIGN_BEGIN
150
+#if defined   (__CC_ARM)      /* ARM Compiler */
151
+#define __ALIGN_BEGIN    __align(4)
152
+#elif defined (__ICCARM__)    /* IAR Compiler */
153
+#define __ALIGN_BEGIN
154
+#endif /* __CC_ARM */
155
+#endif /* __ALIGN_BEGIN */
156
+#endif /* __GNUC__ */
157
+
158
+
159
+/**
160
+  * @brief  __RAM_FUNC definition
161
+  */
162
+#if defined ( __CC_ARM   )
163
+/* ARM Compiler
164
+   ------------
165
+   RAM functions are defined using the toolchain options.
166
+   Functions that are executed in RAM should reside in a separate source module.
167
+   Using the 'Options for File' dialog you can simply change the 'Code / Const'
168
+   area of a module to a memory space in physical RAM.
169
+   Available memory areas are declared in the 'Target' tab of the 'Options for Target'
170
+   dialog.
171
+*/
172
+#define __RAM_FUNC
173
+
174
+#elif defined ( __ICCARM__ )
175
+/* ICCARM Compiler
176
+   ---------------
177
+   RAM functions are defined using a specific toolchain keyword "__ramfunc".
178
+*/
179
+#define __RAM_FUNC __ramfunc
180
+
181
+#elif defined   (  __GNUC__  )
182
+/* GNU Compiler
183
+   ------------
184
+  RAM functions are defined using a specific toolchain attribute
185
+   "__attribute__((section(".RamFunc")))".
186
+*/
187
+#define __RAM_FUNC __attribute__((section(".RamFunc")))
188
+
189
+#endif
190
+
191
+/**
192
+  * @brief  __NOINLINE definition
193
+  */
194
+#if defined ( __CC_ARM   ) || defined   (  __GNUC__  )
195
+/* ARM & GNUCompiler
196
+   ----------------
197
+*/
198
+#define __NOINLINE __attribute__ ( (noinline) )
199
+
200
+#elif defined ( __ICCARM__ )
201
+/* ICCARM Compiler
202
+   ---------------
203
+*/
204
+#define __NOINLINE _Pragma("optimize = no_inline")
205
+
206
+#endif
207
+
208
+#ifdef __cplusplus
209
+}
210
+#endif
211
+
212
+#endif /* ___STM32F1xx_HAL_DEF */
213
+
214
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 473 - 0
Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma.h

@@ -0,0 +1,473 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_dma.h
4
+  * @author  MCD Application Team
5
+  * @brief   Header file of DMA HAL module.
6
+  ******************************************************************************
7
+  * @attention
8
+  *
9
+  * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
10
+  *
11
+  * Redistribution and use in source and binary forms, with or without modification,
12
+  * are permitted provided that the following conditions are met:
13
+  *   1. Redistributions of source code must retain the above copyright notice,
14
+  *      this list of conditions and the following disclaimer.
15
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
16
+  *      this list of conditions and the following disclaimer in the documentation
17
+  *      and/or other materials provided with the distribution.
18
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
19
+  *      may be used to endorse or promote products derived from this software
20
+  *      without specific prior written permission.
21
+  *
22
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+  *
33
+  ******************************************************************************
34
+  */
35
+
36
+/* Define to prevent recursive inclusion -------------------------------------*/
37
+#ifndef __STM32F1xx_HAL_DMA_H
38
+#define __STM32F1xx_HAL_DMA_H
39
+
40
+#ifdef __cplusplus
41
+ extern "C" {
42
+#endif
43
+
44
+/* Includes ------------------------------------------------------------------*/
45
+#include "stm32f1xx_hal_def.h"
46
+
47
+/** @addtogroup STM32F1xx_HAL_Driver
48
+  * @{
49
+  */
50
+
51
+/** @addtogroup DMA
52
+  * @{
53
+  */
54
+
55
+/* Exported types ------------------------------------------------------------*/
56
+
57
+/** @defgroup DMA_Exported_Types DMA Exported Types
58
+  * @{
59
+  */
60
+
61
+/**
62
+  * @brief  DMA Configuration Structure definition
63
+  */
64
+typedef struct
65
+{
66
+  uint32_t Direction;                 /*!< Specifies if the data will be transferred from memory to peripheral, 
67
+                                           from memory to memory or from peripheral to memory.
68
+                                           This parameter can be a value of @ref DMA_Data_transfer_direction */
69
+
70
+  uint32_t PeriphInc;                 /*!< Specifies whether the Peripheral address register should be incremented or not.
71
+                                           This parameter can be a value of @ref DMA_Peripheral_incremented_mode */
72
+
73
+  uint32_t MemInc;                    /*!< Specifies whether the memory address register should be incremented or not.
74
+                                           This parameter can be a value of @ref DMA_Memory_incremented_mode */
75
+
76
+  uint32_t PeriphDataAlignment;       /*!< Specifies the Peripheral data width.
77
+                                           This parameter can be a value of @ref DMA_Peripheral_data_size */
78
+
79
+  uint32_t MemDataAlignment;          /*!< Specifies the Memory data width.
80
+                                           This parameter can be a value of @ref DMA_Memory_data_size */
81
+
82
+  uint32_t Mode;                      /*!< Specifies the operation mode of the DMAy Channelx.
83
+                                           This parameter can be a value of @ref DMA_mode
84
+                                           @note The circular buffer mode cannot be used if the memory-to-memory
85
+                                                 data transfer is configured on the selected Channel */
86
+
87
+  uint32_t Priority;                  /*!< Specifies the software priority for the DMAy Channelx.
88
+                                           This parameter can be a value of @ref DMA_Priority_level */
89
+} DMA_InitTypeDef;
90
+
91
+/**
92
+  * @brief  HAL DMA State structures definition
93
+  */
94
+typedef enum
95
+{
96
+  HAL_DMA_STATE_RESET             = 0x00U,  /*!< DMA not yet initialized or disabled    */
97
+  HAL_DMA_STATE_READY             = 0x01U,  /*!< DMA initialized and ready for use      */
98
+  HAL_DMA_STATE_BUSY              = 0x02U,  /*!< DMA process is ongoing                 */
99
+  HAL_DMA_STATE_TIMEOUT           = 0x03U   /*!< DMA timeout state                      */
100
+}HAL_DMA_StateTypeDef;
101
+
102
+/**
103
+  * @brief  HAL DMA Error Code structure definition
104
+  */
105
+typedef enum
106
+{
107
+  HAL_DMA_FULL_TRANSFER           = 0x00U,    /*!< Full transfer     */
108
+  HAL_DMA_HALF_TRANSFER           = 0x01U     /*!< Half Transfer     */
109
+}HAL_DMA_LevelCompleteTypeDef;
110
+
111
+/** 
112
+  * @brief  HAL DMA Callback ID structure definition
113
+  */
114
+typedef enum
115
+{
116
+  HAL_DMA_XFER_CPLT_CB_ID          = 0x00U,    /*!< Full transfer     */
117
+  HAL_DMA_XFER_HALFCPLT_CB_ID      = 0x01U,    /*!< Half transfer     */
118
+  HAL_DMA_XFER_ERROR_CB_ID         = 0x02U,    /*!< Error             */ 
119
+  HAL_DMA_XFER_ABORT_CB_ID         = 0x03U,    /*!< Abort             */ 
120
+  HAL_DMA_XFER_ALL_CB_ID           = 0x04U     /*!< All               */ 
121
+    
122
+}HAL_DMA_CallbackIDTypeDef;
123
+
124
+/** 
125
+  * @brief  DMA handle Structure definition
126
+  */
127
+typedef struct __DMA_HandleTypeDef
128
+{
129
+  DMA_Channel_TypeDef   *Instance;                       /*!< Register base address                  */
130
+  
131
+  DMA_InitTypeDef       Init;                            /*!< DMA communication parameters           */ 
132
+  
133
+  HAL_LockTypeDef       Lock;                            /*!< DMA locking object                     */  
134
+  
135
+  HAL_DMA_StateTypeDef  State;                           /*!< DMA transfer state                     */
136
+  
137
+  void                  *Parent;                                                      /*!< Parent object state                    */  
138
+  
139
+  void                  (* XferCpltCallback)( struct __DMA_HandleTypeDef * hdma);     /*!< DMA transfer complete callback         */
140
+  
141
+  void                  (* XferHalfCpltCallback)( struct __DMA_HandleTypeDef * hdma); /*!< DMA Half transfer complete callback    */
142
+  
143
+  void                  (* XferErrorCallback)( struct __DMA_HandleTypeDef * hdma);    /*!< DMA transfer error callback            */
144
+
145
+  void                  (* XferAbortCallback)( struct __DMA_HandleTypeDef * hdma);    /*!< DMA transfer abort callback            */  
146
+  
147
+  __IO uint32_t         ErrorCode;                                                    /*!< DMA Error code                         */
148
+
149
+  DMA_TypeDef            *DmaBaseAddress;                                             /*!< DMA Channel Base Address               */
150
+  
151
+  uint32_t               ChannelIndex;                                                /*!< DMA Channel Index                      */  
152
+
153
+} DMA_HandleTypeDef;    
154
+/**
155
+  * @}
156
+  */
157
+
158
+/* Exported constants --------------------------------------------------------*/
159
+
160
+/** @defgroup DMA_Exported_Constants DMA Exported Constants
161
+  * @{
162
+  */
163
+
164
+/** @defgroup DMA_Error_Code DMA Error Code
165
+  * @{
166
+  */
167
+#define HAL_DMA_ERROR_NONE                     0x00000000U    /*!< No error             */
168
+#define HAL_DMA_ERROR_TE                       0x00000001U    /*!< Transfer error       */
169
+#define HAL_DMA_ERROR_NO_XFER                  0x00000004U    /*!< no ongoing transfer  */
170
+#define HAL_DMA_ERROR_TIMEOUT                  0x00000020U    /*!< Timeout error        */
171
+#define HAL_DMA_ERROR_NOT_SUPPORTED            0x00000100U    /*!< Not supported mode                    */ 
172
+/**
173
+  * @}
174
+  */
175
+
176
+/** @defgroup DMA_Data_transfer_direction DMA Data transfer direction
177
+  * @{
178
+  */
179
+#define DMA_PERIPH_TO_MEMORY         0x00000000U                 /*!< Peripheral to memory direction */
180
+#define DMA_MEMORY_TO_PERIPH         ((uint32_t)DMA_CCR_DIR)     /*!< Memory to peripheral direction */
181
+#define DMA_MEMORY_TO_MEMORY         ((uint32_t)DMA_CCR_MEM2MEM) /*!< Memory to memory direction     */
182
+
183
+/**
184
+  * @}
185
+  */
186
+
187
+/** @defgroup DMA_Peripheral_incremented_mode DMA Peripheral incremented mode
188
+  * @{
189
+  */
190
+#define DMA_PINC_ENABLE        ((uint32_t)DMA_CCR_PINC)  /*!< Peripheral increment mode Enable */
191
+#define DMA_PINC_DISABLE       0x00000000U               /*!< Peripheral increment mode Disable */
192
+/**
193
+  * @}
194
+  */
195
+
196
+/** @defgroup DMA_Memory_incremented_mode DMA Memory incremented mode
197
+  * @{
198
+  */
199
+#define DMA_MINC_ENABLE         ((uint32_t)DMA_CCR_MINC)  /*!< Memory increment mode Enable  */
200
+#define DMA_MINC_DISABLE        0x00000000U               /*!< Memory increment mode Disable */
201
+/**
202
+  * @}
203
+  */
204
+
205
+/** @defgroup DMA_Peripheral_data_size DMA Peripheral data size
206
+  * @{
207
+  */
208
+#define DMA_PDATAALIGN_BYTE          0x00000000U                  /*!< Peripheral data alignment: Byte     */
209
+#define DMA_PDATAALIGN_HALFWORD      ((uint32_t)DMA_CCR_PSIZE_0)  /*!< Peripheral data alignment: HalfWord */
210
+#define DMA_PDATAALIGN_WORD          ((uint32_t)DMA_CCR_PSIZE_1)  /*!< Peripheral data alignment: Word     */
211
+/**
212
+  * @}
213
+  */
214
+
215
+/** @defgroup DMA_Memory_data_size DMA Memory data size
216
+  * @{
217
+  */
218
+#define DMA_MDATAALIGN_BYTE          0x00000000U                  /*!< Memory data alignment: Byte     */
219
+#define DMA_MDATAALIGN_HALFWORD      ((uint32_t)DMA_CCR_MSIZE_0)  /*!< Memory data alignment: HalfWord */
220
+#define DMA_MDATAALIGN_WORD          ((uint32_t)DMA_CCR_MSIZE_1)  /*!< Memory data alignment: Word     */
221
+/**
222
+  * @}
223
+  */
224
+
225
+/** @defgroup DMA_mode DMA mode
226
+  * @{
227
+  */
228
+#define DMA_NORMAL         0x00000000U                  /*!< Normal mode                  */
229
+#define DMA_CIRCULAR       ((uint32_t)DMA_CCR_CIRC)     /*!< Circular mode                */
230
+/**
231
+  * @}
232
+  */
233
+
234
+/** @defgroup DMA_Priority_level DMA Priority level
235
+  * @{
236
+  */
237
+#define DMA_PRIORITY_LOW             0x00000000U               /*!< Priority level : Low       */
238
+#define DMA_PRIORITY_MEDIUM          ((uint32_t)DMA_CCR_PL_0)  /*!< Priority level : Medium    */
239
+#define DMA_PRIORITY_HIGH            ((uint32_t)DMA_CCR_PL_1)  /*!< Priority level : High      */
240
+#define DMA_PRIORITY_VERY_HIGH       ((uint32_t)DMA_CCR_PL)    /*!< Priority level : Very_High */
241
+/**
242
+  * @}
243
+  */
244
+
245
+
246
+/** @defgroup DMA_interrupt_enable_definitions DMA interrupt enable definitions
247
+  * @{
248
+  */
249
+#define DMA_IT_TC                         ((uint32_t)DMA_CCR_TCIE)
250
+#define DMA_IT_HT                         ((uint32_t)DMA_CCR_HTIE)
251
+#define DMA_IT_TE                         ((uint32_t)DMA_CCR_TEIE)
252
+/**
253
+  * @}
254
+  */
255
+
256
+/** @defgroup DMA_flag_definitions DMA flag definitions
257
+  * @{
258
+  */
259
+#define DMA_FLAG_GL1                      0x00000001U
260
+#define DMA_FLAG_TC1                      0x00000002U
261
+#define DMA_FLAG_HT1                      0x00000004U
262
+#define DMA_FLAG_TE1                      0x00000008U
263
+#define DMA_FLAG_GL2                      0x00000010U
264
+#define DMA_FLAG_TC2                      0x00000020U
265
+#define DMA_FLAG_HT2                      0x00000040U
266
+#define DMA_FLAG_TE2                      0x00000080U
267
+#define DMA_FLAG_GL3                      0x00000100U
268
+#define DMA_FLAG_TC3                      0x00000200U
269
+#define DMA_FLAG_HT3                      0x00000400U
270
+#define DMA_FLAG_TE3                      0x00000800U
271
+#define DMA_FLAG_GL4                      0x00001000U
272
+#define DMA_FLAG_TC4                      0x00002000U
273
+#define DMA_FLAG_HT4                      0x00004000U
274
+#define DMA_FLAG_TE4                      0x00008000U
275
+#define DMA_FLAG_GL5                      0x00010000U
276
+#define DMA_FLAG_TC5                      0x00020000U
277
+#define DMA_FLAG_HT5                      0x00040000U
278
+#define DMA_FLAG_TE5                      0x00080000U
279
+#define DMA_FLAG_GL6                      0x00100000U
280
+#define DMA_FLAG_TC6                      0x00200000U
281
+#define DMA_FLAG_HT6                      0x00400000U
282
+#define DMA_FLAG_TE6                      0x00800000U
283
+#define DMA_FLAG_GL7                      0x01000000U
284
+#define DMA_FLAG_TC7                      0x02000000U
285
+#define DMA_FLAG_HT7                      0x04000000U
286
+#define DMA_FLAG_TE7                      0x08000000U
287
+/**
288
+  * @}
289
+  */
290
+
291
+/**
292
+  * @}
293
+  */
294
+
295
+
296
+/* Exported macros -----------------------------------------------------------*/
297
+/** @defgroup DMA_Exported_Macros DMA Exported Macros
298
+  * @{
299
+  */
300
+
301
+/** @brief  Reset DMA handle state.
302
+  * @param  __HANDLE__: DMA handle
303
+  * @retval None
304
+  */
305
+#define __HAL_DMA_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_DMA_STATE_RESET)
306
+
307
+/**
308
+  * @brief  Enable the specified DMA Channel.
309
+  * @param  __HANDLE__: DMA handle
310
+  * @retval None
311
+  */
312
+#define __HAL_DMA_ENABLE(__HANDLE__)        (SET_BIT((__HANDLE__)->Instance->CCR, DMA_CCR_EN))
313
+
314
+/**
315
+  * @brief  Disable the specified DMA Channel.
316
+  * @param  __HANDLE__: DMA handle
317
+  * @retval None
318
+  */
319
+#define __HAL_DMA_DISABLE(__HANDLE__)       (CLEAR_BIT((__HANDLE__)->Instance->CCR, DMA_CCR_EN))
320
+
321
+
322
+/* Interrupt & Flag management */
323
+
324
+/**
325
+  * @brief  Enables the specified DMA Channel interrupts.
326
+  * @param  __HANDLE__: DMA handle
327
+  * @param __INTERRUPT__: specifies the DMA interrupt sources to be enabled or disabled.
328
+  *          This parameter can be any combination of the following values:
329
+  *            @arg DMA_IT_TC:  Transfer complete interrupt mask
330
+  *            @arg DMA_IT_HT:  Half transfer complete interrupt mask
331
+  *            @arg DMA_IT_TE:  Transfer error interrupt mask
332
+  * @retval None
333
+  */
334
+#define __HAL_DMA_ENABLE_IT(__HANDLE__, __INTERRUPT__)   (SET_BIT((__HANDLE__)->Instance->CCR, (__INTERRUPT__)))
335
+
336
+/**
337
+  * @brief  Disable the specified DMA Channel interrupts.
338
+  * @param  __HANDLE__: DMA handle
339
+  * @param  __INTERRUPT__: specifies the DMA interrupt sources to be enabled or disabled.
340
+  *          This parameter can be any combination of the following values:
341
+  *            @arg DMA_IT_TC:  Transfer complete interrupt mask
342
+  *            @arg DMA_IT_HT:  Half transfer complete interrupt mask
343
+  *            @arg DMA_IT_TE:  Transfer error interrupt mask
344
+  * @retval None
345
+  */
346
+#define __HAL_DMA_DISABLE_IT(__HANDLE__, __INTERRUPT__)  (CLEAR_BIT((__HANDLE__)->Instance->CCR , (__INTERRUPT__)))
347
+
348
+/**
349
+  * @brief  Check whether the specified DMA Channel interrupt is enabled or not.
350
+  * @param  __HANDLE__: DMA handle
351
+  * @param  __INTERRUPT__: specifies the DMA interrupt source to check.
352
+  *          This parameter can be one of the following values:
353
+  *            @arg DMA_IT_TC:  Transfer complete interrupt mask
354
+  *            @arg DMA_IT_HT:  Half transfer complete interrupt mask
355
+  *            @arg DMA_IT_TE:  Transfer error interrupt mask
356
+  * @retval The state of DMA_IT (SET or RESET).
357
+  */
358
+#define __HAL_DMA_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)  ((((__HANDLE__)->Instance->CCR & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
359
+
360
+/**
361
+  * @brief  Return the number of remaining data units in the current DMA Channel transfer.
362
+  * @param  __HANDLE__: DMA handle
363
+  * @retval The number of remaining data units in the current DMA Channel transfer.
364
+  */
365
+#define __HAL_DMA_GET_COUNTER(__HANDLE__) ((__HANDLE__)->Instance->CNDTR)
366
+
367
+/**
368
+  * @}
369
+  */
370
+
371
+/* Include DMA HAL Extension module */
372
+#include "stm32f1xx_hal_dma_ex.h"   
373
+
374
+/* Exported functions --------------------------------------------------------*/
375
+/** @addtogroup DMA_Exported_Functions
376
+  * @{
377
+  */
378
+
379
+/** @addtogroup DMA_Exported_Functions_Group1
380
+  * @{
381
+  */
382
+/* Initialization and de-initialization functions *****************************/
383
+HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma);
384
+HAL_StatusTypeDef HAL_DMA_DeInit (DMA_HandleTypeDef *hdma);
385
+/**
386
+  * @}
387
+  */
388
+
389
+/** @addtogroup DMA_Exported_Functions_Group2
390
+  * @{
391
+  */
392
+/* IO operation functions *****************************************************/
393
+HAL_StatusTypeDef HAL_DMA_Start (DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
394
+HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
395
+HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma);
396
+HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma);
397
+HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, uint32_t CompleteLevel, uint32_t Timeout);
398
+void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma);
399
+HAL_StatusTypeDef HAL_DMA_RegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID, void (* pCallback)( DMA_HandleTypeDef * _hdma));
400
+HAL_StatusTypeDef HAL_DMA_UnRegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID);
401
+
402
+/**
403
+  * @}
404
+  */
405
+
406
+/** @addtogroup DMA_Exported_Functions_Group3
407
+  * @{
408
+  */
409
+/* Peripheral State and Error functions ***************************************/
410
+HAL_DMA_StateTypeDef HAL_DMA_GetState(DMA_HandleTypeDef *hdma);
411
+uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma);
412
+/**
413
+  * @}
414
+  */
415
+
416
+/**
417
+  * @}
418
+  */
419
+
420
+/* Private macros ------------------------------------------------------------*/
421
+/** @defgroup DMA_Private_Macros DMA Private Macros
422
+  * @{
423
+  */
424
+
425
+#define IS_DMA_DIRECTION(DIRECTION) (((DIRECTION) == DMA_PERIPH_TO_MEMORY ) || \
426
+                                     ((DIRECTION) == DMA_MEMORY_TO_PERIPH)  || \
427
+                                     ((DIRECTION) == DMA_MEMORY_TO_MEMORY))
428
+
429
+#define IS_DMA_BUFFER_SIZE(SIZE) (((SIZE) >= 0x1U) && ((SIZE) < 0x10000U))
430
+
431
+#define IS_DMA_PERIPHERAL_INC_STATE(STATE) (((STATE) == DMA_PINC_ENABLE) || \
432
+                                            ((STATE) == DMA_PINC_DISABLE))
433
+
434
+#define IS_DMA_MEMORY_INC_STATE(STATE) (((STATE) == DMA_MINC_ENABLE)  || \
435
+                                        ((STATE) == DMA_MINC_DISABLE))
436
+
437
+#define IS_DMA_PERIPHERAL_DATA_SIZE(SIZE) (((SIZE) == DMA_PDATAALIGN_BYTE)     || \
438
+                                           ((SIZE) == DMA_PDATAALIGN_HALFWORD) || \
439
+                                           ((SIZE) == DMA_PDATAALIGN_WORD))
440
+
441
+#define IS_DMA_MEMORY_DATA_SIZE(SIZE) (((SIZE) == DMA_MDATAALIGN_BYTE)     || \
442
+                                       ((SIZE) == DMA_MDATAALIGN_HALFWORD) || \
443
+                                       ((SIZE) == DMA_MDATAALIGN_WORD ))
444
+
445
+#define IS_DMA_MODE(MODE) (((MODE) == DMA_NORMAL )  || \
446
+                           ((MODE) == DMA_CIRCULAR))
447
+
448
+#define IS_DMA_PRIORITY(PRIORITY) (((PRIORITY) == DMA_PRIORITY_LOW )   || \
449
+                                   ((PRIORITY) == DMA_PRIORITY_MEDIUM) || \
450
+                                   ((PRIORITY) == DMA_PRIORITY_HIGH)   || \
451
+                                   ((PRIORITY) == DMA_PRIORITY_VERY_HIGH))
452
+
453
+/**
454
+  * @}
455
+  */ 
456
+
457
+/* Private functions ---------------------------------------------------------*/
458
+
459
+/**
460
+  * @}
461
+  */
462
+
463
+/**
464
+  * @}
465
+  */
466
+
467
+#ifdef __cplusplus
468
+}
469
+#endif
470
+
471
+#endif /* __STM32F1xx_HAL_DMA_H */
472
+
473
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 293 - 0
Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma_ex.h

@@ -0,0 +1,293 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_dma_ex.h
4
+  * @author  MCD Application Team
5
+  * @brief   Header file of DMA HAL extension module.
6
+  ******************************************************************************
7
+  * @attention
8
+  *
9
+  * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
10
+  *
11
+  * Redistribution and use in source and binary forms, with or without modification,
12
+  * are permitted provided that the following conditions are met:
13
+  *   1. Redistributions of source code must retain the above copyright notice,
14
+  *      this list of conditions and the following disclaimer.
15
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
16
+  *      this list of conditions and the following disclaimer in the documentation
17
+  *      and/or other materials provided with the distribution.
18
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
19
+  *      may be used to endorse or promote products derived from this software
20
+  *      without specific prior written permission.
21
+  *
22
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+  *
33
+  ******************************************************************************
34
+  */
35
+
36
+/* Define to prevent recursive inclusion -------------------------------------*/
37
+#ifndef __STM32F1xx_HAL_DMA_EX_H
38
+#define __STM32F1xx_HAL_DMA_EX_H
39
+
40
+#ifdef __cplusplus
41
+ extern "C" {
42
+#endif
43
+
44
+/* Includes ------------------------------------------------------------------*/
45
+#include "stm32f1xx_hal_def.h"
46
+
47
+/** @addtogroup STM32F1xx_HAL_Driver
48
+  * @{
49
+  */
50
+
51
+/** @defgroup DMAEx DMAEx
52
+  * @{
53
+  */
54
+
55
+/* Exported types ------------------------------------------------------------*/ 
56
+/* Exported constants --------------------------------------------------------*/
57
+/* Exported macro ------------------------------------------------------------*/
58
+/** @defgroup DMAEx_Exported_Macros DMA Extended Exported Macros
59
+  * @{
60
+  */
61
+/* Interrupt & Flag management */
62
+#if defined (STM32F100xE) || defined (STM32F101xE) || defined (STM32F101xG) || defined (STM32F103xE) || \
63
+    defined (STM32F103xG) || defined (STM32F105xC) || defined (STM32F107xC)
64
+/** @defgroup DMAEx_High_density_XL_density_Product_devices DMAEx High density and XL density product devices
65
+  * @{
66
+  */
67
+
68
+/**
69
+  * @brief  Returns the current DMA Channel transfer complete flag.
70
+  * @param  __HANDLE__: DMA handle
71
+  * @retval The specified transfer complete flag index.
72
+  */
73
+#define __HAL_DMA_GET_TC_FLAG_INDEX(__HANDLE__) \
74
+(((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_FLAG_TC1 :\
75
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_FLAG_TC2 :\
76
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_FLAG_TC3 :\
77
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_FLAG_TC4 :\
78
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_FLAG_TC5 :\
79
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_FLAG_TC6 :\
80
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel7))? DMA_FLAG_TC7 :\
81
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel1))? DMA_FLAG_TC1 :\
82
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel2))? DMA_FLAG_TC2 :\
83
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel3))? DMA_FLAG_TC3 :\
84
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel4))? DMA_FLAG_TC4 :\
85
+   DMA_FLAG_TC5)
86
+
87
+/**
88
+  * @brief  Returns the current DMA Channel half transfer complete flag.
89
+  * @param  __HANDLE__: DMA handle
90
+  * @retval The specified half transfer complete flag index.
91
+  */      
92
+#define __HAL_DMA_GET_HT_FLAG_INDEX(__HANDLE__)\
93
+(((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_FLAG_HT1 :\
94
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_FLAG_HT2 :\
95
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_FLAG_HT3 :\
96
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_FLAG_HT4 :\
97
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_FLAG_HT5 :\
98
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_FLAG_HT6 :\
99
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel7))? DMA_FLAG_HT7 :\
100
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel1))? DMA_FLAG_HT1 :\
101
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel2))? DMA_FLAG_HT2 :\
102
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel3))? DMA_FLAG_HT3 :\
103
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel4))? DMA_FLAG_HT4 :\
104
+   DMA_FLAG_HT5)
105
+
106
+/**
107
+  * @brief  Returns the current DMA Channel transfer error flag.
108
+  * @param  __HANDLE__: DMA handle
109
+  * @retval The specified transfer error flag index.
110
+  */
111
+#define __HAL_DMA_GET_TE_FLAG_INDEX(__HANDLE__)\
112
+(((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_FLAG_TE1 :\
113
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_FLAG_TE2 :\
114
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_FLAG_TE3 :\
115
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_FLAG_TE4 :\
116
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_FLAG_TE5 :\
117
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_FLAG_TE6 :\
118
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel7))? DMA_FLAG_TE7 :\
119
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel1))? DMA_FLAG_TE1 :\
120
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel2))? DMA_FLAG_TE2 :\
121
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel3))? DMA_FLAG_TE3 :\
122
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel4))? DMA_FLAG_TE4 :\
123
+   DMA_FLAG_TE5)
124
+
125
+/**
126
+  * @brief  Return the current DMA Channel Global interrupt flag.
127
+  * @param  __HANDLE__: DMA handle
128
+  * @retval The specified transfer error flag index.
129
+  */
130
+#define __HAL_DMA_GET_GI_FLAG_INDEX(__HANDLE__)\
131
+(((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_FLAG_GL1 :\
132
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_FLAG_GL2 :\
133
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_FLAG_GL3 :\
134
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_FLAG_GL4 :\
135
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_FLAG_GL5 :\
136
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_FLAG_GL6 :\
137
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel7))? DMA_FLAG_GL7 :\
138
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel1))? DMA_FLAG_GL1 :\
139
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel2))? DMA_FLAG_GL2 :\
140
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel3))? DMA_FLAG_GL3 :\
141
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel4))? DMA_FLAG_GL4 :\
142
+   DMA_FLAG_GL5)
143
+   
144
+/**
145
+  * @brief  Get the DMA Channel pending flags.
146
+  * @param  __HANDLE__: DMA handle
147
+  * @param  __FLAG__: Get the specified flag.
148
+  *          This parameter can be any combination of the following values:
149
+  *            @arg DMA_FLAG_TCx:  Transfer complete flag
150
+  *            @arg DMA_FLAG_HTx:  Half transfer complete flag
151
+  *            @arg DMA_FLAG_TEx:  Transfer error flag
152
+  *         Where x can be 1_7 or 1_5 (depending on DMA1 or DMA2) to select the DMA Channel flag.   
153
+  * @retval The state of FLAG (SET or RESET).
154
+  */
155
+#define __HAL_DMA_GET_FLAG(__HANDLE__, __FLAG__)\
156
+(((uint32_t)((__HANDLE__)->Instance) > (uint32_t)DMA1_Channel7)? (DMA2->ISR & (__FLAG__)) :\
157
+  (DMA1->ISR & (__FLAG__)))
158
+
159
+/**
160
+  * @brief  Clears the DMA Channel pending flags.
161
+  * @param  __HANDLE__: DMA handle
162
+  * @param  __FLAG__: specifies the flag to clear.
163
+  *          This parameter can be any combination of the following values:
164
+  *            @arg DMA_FLAG_TCx:  Transfer complete flag
165
+  *            @arg DMA_FLAG_HTx:  Half transfer complete flag
166
+  *            @arg DMA_FLAG_TEx:  Transfer error flag
167
+  *         Where x can be 1_7 or 1_5 (depending on DMA1 or DMA2) to select the DMA Channel flag.   
168
+  * @retval None
169
+  */
170
+#define __HAL_DMA_CLEAR_FLAG(__HANDLE__, __FLAG__) \
171
+(((uint32_t)((__HANDLE__)->Instance) > (uint32_t)DMA1_Channel7)? (DMA2->IFCR = (__FLAG__)) :\
172
+  (DMA1->IFCR = (__FLAG__)))
173
+
174
+/**
175
+  * @}
176
+  */
177
+
178
+#else
179
+/** @defgroup DMA_Low_density_Medium_density_Product_devices DMA Low density and Medium density product devices
180
+  * @{
181
+  */
182
+
183
+/**
184
+  * @brief  Returns the current DMA Channel transfer complete flag.
185
+  * @param  __HANDLE__: DMA handle
186
+  * @retval The specified transfer complete flag index.
187
+  */
188
+#define __HAL_DMA_GET_TC_FLAG_INDEX(__HANDLE__) \
189
+(((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_FLAG_TC1 :\
190
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_FLAG_TC2 :\
191
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_FLAG_TC3 :\
192
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_FLAG_TC4 :\
193
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_FLAG_TC5 :\
194
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_FLAG_TC6 :\
195
+   DMA_FLAG_TC7)
196
+
197
+/**
198
+  * @brief  Return the current DMA Channel half transfer complete flag.
199
+  * @param  __HANDLE__: DMA handle
200
+  * @retval The specified half transfer complete flag index.
201
+  */
202
+#define __HAL_DMA_GET_HT_FLAG_INDEX(__HANDLE__)\
203
+(((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_FLAG_HT1 :\
204
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_FLAG_HT2 :\
205
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_FLAG_HT3 :\
206
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_FLAG_HT4 :\
207
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_FLAG_HT5 :\
208
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_FLAG_HT6 :\
209
+   DMA_FLAG_HT7)
210
+
211
+/**
212
+  * @brief  Return the current DMA Channel transfer error flag.
213
+  * @param  __HANDLE__: DMA handle
214
+  * @retval The specified transfer error flag index.
215
+  */
216
+#define __HAL_DMA_GET_TE_FLAG_INDEX(__HANDLE__)\
217
+(((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_FLAG_TE1 :\
218
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_FLAG_TE2 :\
219
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_FLAG_TE3 :\
220
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_FLAG_TE4 :\
221
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_FLAG_TE5 :\
222
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_FLAG_TE6 :\
223
+   DMA_FLAG_TE7)
224
+
225
+/**
226
+  * @brief  Return the current DMA Channel Global interrupt flag.
227
+  * @param  __HANDLE__: DMA handle
228
+  * @retval The specified transfer error flag index.
229
+  */
230
+#define __HAL_DMA_GET_GI_FLAG_INDEX(__HANDLE__)\
231
+(((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_FLAG_GL1 :\
232
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_FLAG_GL2 :\
233
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_FLAG_GL3 :\
234
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_FLAG_GL4 :\
235
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_FLAG_GL5 :\
236
+ ((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_FLAG_GL6 :\
237
+   DMA_FLAG_GL7)
238
+
239
+/**
240
+  * @brief  Get the DMA Channel pending flags.
241
+  * @param  __HANDLE__: DMA handle
242
+  * @param  __FLAG__: Get the specified flag.
243
+  *          This parameter can be any combination of the following values:
244
+  *            @arg DMA_FLAG_TCx:  Transfer complete flag
245
+  *            @arg DMA_FLAG_HTx:  Half transfer complete flag
246
+  *            @arg DMA_FLAG_TEx:  Transfer error flag
247
+  *            @arg DMA_FLAG_GLx:  Global interrupt flag
248
+  *         Where x can be 1_7 to select the DMA Channel flag.   
249
+  * @retval The state of FLAG (SET or RESET).
250
+  */
251
+
252
+#define __HAL_DMA_GET_FLAG(__HANDLE__, __FLAG__)   (DMA1->ISR & (__FLAG__))
253
+
254
+/**
255
+  * @brief  Clear the DMA Channel pending flags.
256
+  * @param  __HANDLE__: DMA handle
257
+  * @param  __FLAG__: specifies the flag to clear.
258
+  *          This parameter can be any combination of the following values:
259
+  *            @arg DMA_FLAG_TCx:  Transfer complete flag
260
+  *            @arg DMA_FLAG_HTx:  Half transfer complete flag
261
+  *            @arg DMA_FLAG_TEx:  Transfer error flag
262
+  *            @arg DMA_FLAG_GLx:  Global interrupt flag
263
+  *         Where x can be 1_7 to select the DMA Channel flag.   
264
+  * @retval None
265
+  */
266
+#define __HAL_DMA_CLEAR_FLAG(__HANDLE__, __FLAG__) (DMA1->IFCR = (__FLAG__))
267
+
268
+/**
269
+  * @}
270
+  */
271
+
272
+#endif
273
+  
274
+/**
275
+  * @}
276
+  */
277
+
278
+/**
279
+  * @}
280
+  */
281
+
282
+/**
283
+  * @}
284
+  */
285
+
286
+#ifdef __cplusplus
287
+}
288
+#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || */
289
+       /* STM32F103xG || STM32F105xC || STM32F107xC */
290
+
291
+#endif /* __STM32F1xx_HAL_DMA_H */
292
+
293
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 344 - 0
Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash.h

@@ -0,0 +1,344 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_flash.h
4
+  * @author  MCD Application Team
5
+  * @brief   Header file of Flash HAL module.
6
+  ******************************************************************************
7
+  * @attention
8
+  *
9
+  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
10
+  *
11
+  * Redistribution and use in source and binary forms, with or without modification,
12
+  * are permitted provided that the following conditions are met:
13
+  *   1. Redistributions of source code must retain the above copyright notice,
14
+  *      this list of conditions and the following disclaimer.
15
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
16
+  *      this list of conditions and the following disclaimer in the documentation
17
+  *      and/or other materials provided with the distribution.
18
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
19
+  *      may be used to endorse or promote products derived from this software
20
+  *      without specific prior written permission.
21
+  *
22
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+  *
33
+  ******************************************************************************  
34
+  */
35
+
36
+/* Define to prevent recursive inclusion -------------------------------------*/
37
+#ifndef __STM32F1xx_HAL_FLASH_H
38
+#define __STM32F1xx_HAL_FLASH_H
39
+
40
+#ifdef __cplusplus
41
+ extern "C" {
42
+#endif
43
+
44
+/* Includes ------------------------------------------------------------------*/
45
+#include "stm32f1xx_hal_def.h"
46
+   
47
+/** @addtogroup STM32F1xx_HAL_Driver
48
+  * @{
49
+  */
50
+
51
+/** @addtogroup FLASH
52
+  * @{
53
+  */
54
+  
55
+/** @addtogroup FLASH_Private_Constants
56
+  * @{
57
+  */
58
+#define FLASH_TIMEOUT_VALUE              50000U /* 50 s */
59
+/**
60
+  * @}
61
+  */
62
+
63
+/** @addtogroup FLASH_Private_Macros
64
+  * @{
65
+  */
66
+
67
+#define IS_FLASH_TYPEPROGRAM(VALUE)  (((VALUE) == FLASH_TYPEPROGRAM_HALFWORD) || \
68
+                                      ((VALUE) == FLASH_TYPEPROGRAM_WORD)     || \
69
+                                      ((VALUE) == FLASH_TYPEPROGRAM_DOUBLEWORD))  
70
+
71
+#if   defined(FLASH_ACR_LATENCY)
72
+#define IS_FLASH_LATENCY(__LATENCY__) (((__LATENCY__) == FLASH_LATENCY_0) || \
73
+                                       ((__LATENCY__) == FLASH_LATENCY_1) || \
74
+                                       ((__LATENCY__) == FLASH_LATENCY_2))
75
+
76
+#else
77
+#define IS_FLASH_LATENCY(__LATENCY__)   ((__LATENCY__) == FLASH_LATENCY_0)
78
+#endif /* FLASH_ACR_LATENCY */
79
+/**
80
+  * @}
81
+  */  
82
+
83
+/* Exported types ------------------------------------------------------------*/ 
84
+/** @defgroup FLASH_Exported_Types FLASH Exported Types
85
+  * @{
86
+  */  
87
+
88
+/**
89
+  * @brief  FLASH Procedure structure definition
90
+  */
91
+typedef enum 
92
+{
93
+  FLASH_PROC_NONE              = 0U, 
94
+  FLASH_PROC_PAGEERASE         = 1U,
95
+  FLASH_PROC_MASSERASE         = 2U,
96
+  FLASH_PROC_PROGRAMHALFWORD   = 3U,
97
+  FLASH_PROC_PROGRAMWORD       = 4U,
98
+  FLASH_PROC_PROGRAMDOUBLEWORD = 5U
99
+} FLASH_ProcedureTypeDef;
100
+
101
+/** 
102
+  * @brief  FLASH handle Structure definition  
103
+  */
104
+typedef struct
105
+{
106
+  __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /*!< Internal variable to indicate which procedure is ongoing or not in IT context */
107
+  
108
+  __IO uint32_t               DataRemaining;    /*!< Internal variable to save the remaining pages to erase or half-word to program in IT context */
109
+
110
+  __IO uint32_t               Address;          /*!< Internal variable to save address selected for program or erase */
111
+
112
+  __IO uint64_t               Data;             /*!< Internal variable to save data to be programmed */
113
+
114
+  HAL_LockTypeDef             Lock;             /*!< FLASH locking object                */
115
+
116
+  __IO uint32_t               ErrorCode;        /*!< FLASH error code                    
117
+                                                     This parameter can be a value of @ref FLASH_Error_Codes  */
118
+} FLASH_ProcessTypeDef;
119
+
120
+/**
121
+  * @}
122
+  */
123
+
124
+/* Exported constants --------------------------------------------------------*/
125
+/** @defgroup FLASH_Exported_Constants FLASH Exported Constants
126
+  * @{
127
+  */  
128
+
129
+/** @defgroup FLASH_Error_Codes FLASH Error Codes
130
+  * @{
131
+  */
132
+
133
+#define HAL_FLASH_ERROR_NONE      0x00U  /*!< No error */
134
+#define HAL_FLASH_ERROR_PROG      0x01U  /*!< Programming error */
135
+#define HAL_FLASH_ERROR_WRP       0x02U  /*!< Write protection error */
136
+#define HAL_FLASH_ERROR_OPTV      0x04U  /*!< Option validity error */
137
+
138
+/**
139
+  * @}
140
+  */
141
+
142
+/** @defgroup FLASH_Type_Program FLASH Type Program
143
+  * @{
144
+  */ 
145
+#define FLASH_TYPEPROGRAM_HALFWORD             0x01U  /*!<Program a half-word (16-bit) at a specified address.*/
146
+#define FLASH_TYPEPROGRAM_WORD                 0x02U  /*!<Program a word (32-bit) at a specified address.*/
147
+#define FLASH_TYPEPROGRAM_DOUBLEWORD           0x03U  /*!<Program a double word (64-bit) at a specified address*/
148
+
149
+/**
150
+  * @}
151
+  */
152
+
153
+#if   defined(FLASH_ACR_LATENCY)
154
+/** @defgroup FLASH_Latency FLASH Latency
155
+  * @{
156
+  */
157
+#define FLASH_LATENCY_0            0x00000000U               /*!< FLASH Zero Latency cycle */
158
+#define FLASH_LATENCY_1            FLASH_ACR_LATENCY_0       /*!< FLASH One Latency cycle */
159
+#define FLASH_LATENCY_2            FLASH_ACR_LATENCY_1       /*!< FLASH Two Latency cycles */
160
+
161
+/**
162
+  * @}
163
+  */
164
+
165
+#else
166
+/** @defgroup FLASH_Latency FLASH Latency
167
+  * @{
168
+  */
169
+#define FLASH_LATENCY_0            0x00000000U    /*!< FLASH Zero Latency cycle */
170
+
171
+/**
172
+  * @}
173
+  */
174
+
175
+#endif /* FLASH_ACR_LATENCY */
176
+/**
177
+  * @}
178
+  */  
179
+  
180
+/* Exported macro ------------------------------------------------------------*/
181
+
182
+/** @defgroup FLASH_Exported_Macros FLASH Exported Macros
183
+ *  @brief macros to control FLASH features 
184
+ *  @{
185
+ */
186
+ 
187
+/** @defgroup FLASH_Half_Cycle FLASH Half Cycle
188
+ *  @brief macros to handle FLASH half cycle
189
+ * @{
190
+ */
191
+
192
+/**
193
+  * @brief  Enable the FLASH half cycle access.
194
+  * @note   half cycle access can only be used with a low-frequency clock of less than
195
+            8 MHz that can be obtained with the use of HSI or HSE but not of PLL.
196
+  * @retval None
197
+  */
198
+#define __HAL_FLASH_HALF_CYCLE_ACCESS_ENABLE()  (FLASH->ACR |= FLASH_ACR_HLFCYA)
199
+
200
+/**
201
+  * @brief  Disable the FLASH half cycle access.
202
+  * @note   half cycle access can only be used with a low-frequency clock of less than
203
+            8 MHz that can be obtained with the use of HSI or HSE but not of PLL.
204
+  * @retval None
205
+  */
206
+#define __HAL_FLASH_HALF_CYCLE_ACCESS_DISABLE() (FLASH->ACR &= (~FLASH_ACR_HLFCYA))
207
+
208
+/**
209
+  * @}
210
+  */
211
+
212
+#if defined(FLASH_ACR_LATENCY)
213
+/** @defgroup FLASH_EM_Latency FLASH Latency
214
+ *  @brief macros to handle FLASH Latency
215
+ * @{
216
+ */ 
217
+  
218
+/**
219
+  * @brief  Set the FLASH Latency.
220
+  * @param  __LATENCY__ FLASH Latency                   
221
+  *         The value of this parameter depend on device used within the same series
222
+  * @retval None
223
+  */ 
224
+#define __HAL_FLASH_SET_LATENCY(__LATENCY__)    (FLASH->ACR = (FLASH->ACR&(~FLASH_ACR_LATENCY)) | (__LATENCY__))
225
+
226
+
227
+/**
228
+  * @brief  Get the FLASH Latency.
229
+  * @retval FLASH Latency                   
230
+  *         The value of this parameter depend on device used within the same series
231
+  */ 
232
+#define __HAL_FLASH_GET_LATENCY()     (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY))
233
+
234
+/**
235
+  * @}
236
+  */
237
+
238
+#endif /* FLASH_ACR_LATENCY */
239
+/** @defgroup FLASH_Prefetch FLASH Prefetch
240
+ *  @brief macros to handle FLASH Prefetch buffer
241
+ * @{
242
+ */   
243
+/**
244
+  * @brief  Enable the FLASH prefetch buffer.
245
+  * @retval None
246
+  */ 
247
+#define __HAL_FLASH_PREFETCH_BUFFER_ENABLE()    (FLASH->ACR |= FLASH_ACR_PRFTBE)
248
+
249
+/**
250
+  * @brief  Disable the FLASH prefetch buffer.
251
+  * @retval None
252
+  */
253
+#define __HAL_FLASH_PREFETCH_BUFFER_DISABLE()   (FLASH->ACR &= (~FLASH_ACR_PRFTBE))
254
+
255
+/**
256
+  * @}
257
+  */
258
+  
259
+/**
260
+  * @}
261
+  */ 
262
+
263
+/* Include FLASH HAL Extended module */
264
+#include "stm32f1xx_hal_flash_ex.h"  
265
+
266
+/* Exported functions --------------------------------------------------------*/
267
+/** @addtogroup FLASH_Exported_Functions
268
+  * @{
269
+  */
270
+  
271
+/** @addtogroup FLASH_Exported_Functions_Group1
272
+  * @{
273
+  */
274
+/* IO operation functions *****************************************************/
275
+HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
276
+HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
277
+
278
+/* FLASH IRQ handler function */
279
+void       HAL_FLASH_IRQHandler(void);
280
+/* Callbacks in non blocking modes */ 
281
+void       HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
282
+void       HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
283
+
284
+/**
285
+  * @}
286
+  */
287
+
288
+/** @addtogroup FLASH_Exported_Functions_Group2
289
+  * @{
290
+  */
291
+/* Peripheral Control functions ***********************************************/
292
+HAL_StatusTypeDef HAL_FLASH_Unlock(void);
293
+HAL_StatusTypeDef HAL_FLASH_Lock(void);
294
+HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
295
+HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
296
+void HAL_FLASH_OB_Launch(void);
297
+
298
+/**
299
+  * @}
300
+  */
301
+
302
+/** @addtogroup FLASH_Exported_Functions_Group3
303
+  * @{
304
+  */
305
+/* Peripheral State and Error functions ***************************************/
306
+uint32_t HAL_FLASH_GetError(void);
307
+
308
+/**
309
+  * @}
310
+  */
311
+
312
+/**
313
+  * @}
314
+  */
315
+
316
+/* Private function -------------------------------------------------*/
317
+/** @addtogroup FLASH_Private_Functions
318
+ * @{
319
+ */
320
+HAL_StatusTypeDef       FLASH_WaitForLastOperation(uint32_t Timeout);
321
+#if defined(FLASH_BANK2_END)
322
+HAL_StatusTypeDef       FLASH_WaitForLastOperationBank2(uint32_t Timeout);
323
+#endif /* FLASH_BANK2_END */
324
+
325
+/**
326
+  * @}
327
+  */
328
+
329
+/**
330
+  * @}
331
+  */
332
+
333
+/**
334
+  * @}
335
+  */
336
+
337
+#ifdef __cplusplus
338
+}
339
+#endif
340
+
341
+#endif /* __STM32F1xx_HAL_FLASH_H */
342
+
343
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
344
+

+ 802 - 0
Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash_ex.h

@@ -0,0 +1,802 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_flash_ex.h
4
+  * @author  MCD Application Team
5
+  * @brief   Header file of Flash HAL Extended module.
6
+  ******************************************************************************
7
+  * @attention
8
+  *
9
+  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
10
+  *
11
+  * Redistribution and use in source and binary forms, with or without modification,
12
+  * are permitted provided that the following conditions are met:
13
+  *   1. Redistributions of source code must retain the above copyright notice,
14
+  *      this list of conditions and the following disclaimer.
15
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
16
+  *      this list of conditions and the following disclaimer in the documentation
17
+  *      and/or other materials provided with the distribution.
18
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
19
+  *      may be used to endorse or promote products derived from this software
20
+  *      without specific prior written permission.
21
+  *
22
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+  *
33
+  ******************************************************************************
34
+  */
35
+
36
+/* Define to prevent recursive inclusion -------------------------------------*/
37
+#ifndef __STM32F1xx_HAL_FLASH_EX_H
38
+#define __STM32F1xx_HAL_FLASH_EX_H
39
+
40
+#ifdef __cplusplus
41
+ extern "C" {
42
+#endif
43
+
44
+/* Includes ------------------------------------------------------------------*/
45
+#include "stm32f1xx_hal_def.h"
46
+
47
+/** @addtogroup STM32F1xx_HAL_Driver
48
+  * @{
49
+  */
50
+
51
+/** @addtogroup FLASHEx
52
+  * @{
53
+  */ 
54
+
55
+/** @addtogroup FLASHEx_Private_Constants
56
+  * @{
57
+  */
58
+
59
+#define FLASH_SIZE_DATA_REGISTER     0x1FFFF7E0U
60
+#define OBR_REG_INDEX                1U
61
+#define SR_FLAG_MASK                 ((uint32_t)(FLASH_SR_BSY | FLASH_SR_PGERR | FLASH_SR_WRPRTERR | FLASH_SR_EOP))
62
+
63
+/**
64
+  * @}
65
+  */  
66
+
67
+/** @addtogroup FLASHEx_Private_Macros
68
+  * @{
69
+  */
70
+
71
+#define IS_FLASH_TYPEERASE(VALUE)   (((VALUE) == FLASH_TYPEERASE_PAGES) || ((VALUE) == FLASH_TYPEERASE_MASSERASE))
72
+
73
+#define IS_OPTIONBYTE(VALUE)        (((VALUE) <= (OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER | OPTIONBYTE_DATA)))
74
+
75
+#define IS_WRPSTATE(VALUE)          (((VALUE) == OB_WRPSTATE_DISABLE) || ((VALUE) == OB_WRPSTATE_ENABLE))
76
+
77
+#define IS_OB_RDP_LEVEL(LEVEL)      (((LEVEL) == OB_RDP_LEVEL_0) || ((LEVEL) == OB_RDP_LEVEL_1))
78
+
79
+#define IS_OB_DATA_ADDRESS(ADDRESS) (((ADDRESS) == OB_DATA_ADDRESS_DATA0) || ((ADDRESS) == OB_DATA_ADDRESS_DATA1)) 
80
+
81
+#define IS_OB_IWDG_SOURCE(SOURCE)   (((SOURCE) == OB_IWDG_SW) || ((SOURCE) == OB_IWDG_HW))
82
+
83
+#define IS_OB_STOP_SOURCE(SOURCE)   (((SOURCE) == OB_STOP_NO_RST) || ((SOURCE) == OB_STOP_RST))
84
+
85
+#define IS_OB_STDBY_SOURCE(SOURCE)  (((SOURCE) == OB_STDBY_NO_RST) || ((SOURCE) == OB_STDBY_RST))
86
+
87
+#if defined(FLASH_BANK2_END)
88
+#define IS_OB_BOOT1(BOOT1)         (((BOOT1) == OB_BOOT1_RESET) || ((BOOT1) == OB_BOOT1_SET))
89
+#endif /* FLASH_BANK2_END */
90
+
91
+/* Low Density */
92
+#if (defined(STM32F101x6) || defined(STM32F102x6) || defined(STM32F103x6))
93
+#define IS_FLASH_NB_PAGES(ADDRESS,NBPAGES) (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x20U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)- 1 <= 0x08007FFFU) : \
94
+                                           ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)- 1 <= 0x08003FFFU))
95
+#endif /* STM32F101x6 || STM32F102x6 || STM32F103x6 */
96
+
97
+/* Medium Density */
98
+#if (defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB))
99
+#define IS_FLASH_NB_PAGES(ADDRESS,NBPAGES) (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x80U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0801FFFFU) : \
100
+                                           (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x40U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0800FFFFU) : \
101
+                                           (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x20U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x08007FFFU) : \
102
+                                           ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x08003FFFU))))
103
+#endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB*/
104
+
105
+/* High Density */
106
+#if (defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE))
107
+#define IS_FLASH_NB_PAGES(ADDRESS,NBPAGES) (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x200U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0807FFFFU) : \
108
+                                           (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x180U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0805FFFFU) : \
109
+                                           ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0803FFFFU)))
110
+#endif /* STM32F100xE || STM32F101xE || STM32F103xE */
111
+
112
+/* XL Density */
113
+#if defined(FLASH_BANK2_END)
114
+#define IS_FLASH_NB_PAGES(ADDRESS,NBPAGES) (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x400U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x080FFFFFU) : \
115
+                                           ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x080BFFFFU))
116
+#endif /* FLASH_BANK2_END */
117
+
118
+/* Connectivity Line */
119
+#if (defined(STM32F105xC) || defined(STM32F107xC))
120
+#define IS_FLASH_NB_PAGES(ADDRESS,NBPAGES) (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x100U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0803FFFFU) : \
121
+                                           (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) ==  0x80U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0801FFFFU) : \
122
+                                           ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0800FFFFU)))
123
+#endif /* STM32F105xC || STM32F107xC */
124
+
125
+#define IS_OB_WRP(PAGE) (((PAGE) != 0x0000000U))
126
+
127
+#if defined(FLASH_BANK2_END)
128
+#define IS_FLASH_BANK(BANK) (((BANK) == FLASH_BANK_1)  || \
129
+                             ((BANK) == FLASH_BANK_2)  || \
130
+                             ((BANK) == FLASH_BANK_BOTH))
131
+#else
132
+#define IS_FLASH_BANK(BANK) (((BANK) == FLASH_BANK_1))
133
+#endif /* FLASH_BANK2_END */
134
+
135
+/* Low Density */
136
+#if (defined(STM32F101x6) || defined(STM32F102x6) || defined(STM32F103x6))
137
+#define IS_FLASH_PROGRAM_ADDRESS(ADDRESS)  (((ADDRESS) >= FLASH_BASE) && (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x20U) ? \
138
+                                            ((ADDRESS) <= FLASH_BANK1_END) :  ((ADDRESS) <= 0x08003FFFU)))
139
+
140
+#endif /* STM32F101x6 || STM32F102x6 || STM32F103x6 */
141
+
142
+/* Medium Density */
143
+#if (defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB))
144
+#define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x80U) ? \
145
+                                           ((ADDRESS) <= FLASH_BANK1_END) :  (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x40U) ? \
146
+                                           ((ADDRESS) <= 0x0800FFFF) :  (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x20U) ? \
147
+                                           ((ADDRESS) <= 0x08007FFF) :  ((ADDRESS) <= 0x08003FFFU)))))
148
+
149
+#endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB*/
150
+
151
+/* High Density */
152
+#if (defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE))
153
+#define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x200U) ? \
154
+                                           ((ADDRESS) <= FLASH_BANK1_END) :  (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x180U) ? \
155
+                                           ((ADDRESS) <= 0x0805FFFFU) :  ((ADDRESS) <= 0x0803FFFFU))))
156
+
157
+#endif /* STM32F100xE || STM32F101xE || STM32F103xE */
158
+
159
+/* XL Density */
160
+#if defined(FLASH_BANK2_END)
161
+#define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x400U) ? \
162
+                                           ((ADDRESS) <= FLASH_BANK2_END) :  ((ADDRESS) <= 0x080BFFFFU)))
163
+
164
+#endif /* FLASH_BANK2_END */
165
+
166
+/* Connectivity Line */
167
+#if (defined(STM32F105xC) || defined(STM32F107xC))
168
+#define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x100U) ? \
169
+                                           ((ADDRESS) <= FLASH_BANK1_END) :  (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x80U) ? \
170
+                                           ((ADDRESS) <= 0x0801FFFFU) :  ((ADDRESS) <= 0x0800FFFFU))))
171
+
172
+#endif /* STM32F105xC || STM32F107xC */
173
+
174
+/**
175
+  * @}
176
+  */  
177
+
178
+/* Exported types ------------------------------------------------------------*/ 
179
+/** @defgroup FLASHEx_Exported_Types FLASHEx Exported Types
180
+  * @{
181
+  */  
182
+
183
+/**
184
+  * @brief  FLASH Erase structure definition
185
+  */
186
+typedef struct
187
+{
188
+  uint32_t TypeErase;   /*!< TypeErase: Mass erase or page erase.
189
+                             This parameter can be a value of @ref FLASHEx_Type_Erase */
190
+  
191
+  uint32_t Banks;       /*!< Select banks to erase when Mass erase is enabled.
192
+                             This parameter must be a value of @ref FLASHEx_Banks */    
193
+  
194
+  uint32_t PageAddress; /*!< PageAdress: Initial FLASH page address to erase when mass erase is disabled
195
+                             This parameter must be a number between Min_Data = 0x08000000 and Max_Data = FLASH_BANKx_END 
196
+                             (x = 1 or 2 depending on devices)*/
197
+  
198
+  uint32_t NbPages;     /*!< NbPages: Number of pagess to be erased.
199
+                             This parameter must be a value between Min_Data = 1 and Max_Data = (max number of pages - value of initial page)*/
200
+                                                          
201
+} FLASH_EraseInitTypeDef;
202
+
203
+/**
204
+  * @brief  FLASH Options bytes program structure definition
205
+  */
206
+typedef struct
207
+{
208
+  uint32_t OptionType;  /*!< OptionType: Option byte to be configured.
209
+                             This parameter can be a value of @ref FLASHEx_OB_Type */
210
+
211
+  uint32_t WRPState;    /*!< WRPState: Write protection activation or deactivation.
212
+                             This parameter can be a value of @ref FLASHEx_OB_WRP_State */
213
+
214
+  uint32_t WRPPage;     /*!< WRPPage: specifies the page(s) to be write protected
215
+                             This parameter can be a value of @ref FLASHEx_OB_Write_Protection */
216
+
217
+  uint32_t Banks;        /*!< Select banks for WRP activation/deactivation of all sectors.
218
+                              This parameter must be a value of @ref FLASHEx_Banks */ 
219
+    
220
+  uint8_t RDPLevel;     /*!< RDPLevel: Set the read protection level..
221
+                             This parameter can be a value of @ref FLASHEx_OB_Read_Protection */
222
+
223
+#if defined(FLASH_BANK2_END)
224
+  uint8_t USERConfig;   /*!< USERConfig: Program the FLASH User Option Byte: 
225
+                             IWDG / STOP / STDBY / BOOT1
226
+                             This parameter can be a combination of @ref FLASHEx_OB_IWatchdog, @ref FLASHEx_OB_nRST_STOP, 
227
+                             @ref FLASHEx_OB_nRST_STDBY, @ref FLASHEx_OB_BOOT1 */
228
+#else
229
+  uint8_t USERConfig;   /*!< USERConfig: Program the FLASH User Option Byte: 
230
+                             IWDG / STOP / STDBY
231
+                             This parameter can be a combination of @ref FLASHEx_OB_IWatchdog, @ref FLASHEx_OB_nRST_STOP, 
232
+                             @ref FLASHEx_OB_nRST_STDBY */
233
+#endif /* FLASH_BANK2_END */
234
+
235
+  uint32_t DATAAddress; /*!< DATAAddress: Address of the option byte DATA to be programmed
236
+                             This parameter can be a value of @ref FLASHEx_OB_Data_Address */
237
+  
238
+  uint8_t DATAData;     /*!< DATAData: Data to be stored in the option byte DATA
239
+                             This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF */
240
+} FLASH_OBProgramInitTypeDef;
241
+
242
+/**
243
+  * @}
244
+  */
245
+
246
+/* Exported constants --------------------------------------------------------*/
247
+/** @defgroup FLASHEx_Exported_Constants FLASHEx Exported Constants
248
+  * @{
249
+  */  
250
+
251
+/** @defgroup FLASHEx_Constants FLASH Constants
252
+  * @{
253
+  */ 
254
+
255
+/** @defgroup FLASHEx_Page_Size Page Size
256
+  * @{
257
+  */ 
258
+#if (defined(STM32F101x6) || defined(STM32F102x6) || defined(STM32F103x6) || defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB))
259
+#define FLASH_PAGE_SIZE          0x400U
260
+#endif /* STM32F101x6 || STM32F102x6 || STM32F103x6 */
261
+       /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB */
262
+
263
+#if (defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE) || defined(STM32F101xG) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC))
264
+#define FLASH_PAGE_SIZE          0x800U
265
+#endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB */
266
+       /* STM32F101xG || STM32F103xG */ 
267
+       /* STM32F105xC || STM32F107xC */
268
+
269
+/**
270
+  * @}
271
+  */
272
+
273
+/** @defgroup FLASHEx_Type_Erase Type Erase
274
+  * @{
275
+  */ 
276
+#define FLASH_TYPEERASE_PAGES     0x00U  /*!<Pages erase only*/
277
+#define FLASH_TYPEERASE_MASSERASE 0x02U  /*!<Flash mass erase activation*/
278
+
279
+/**
280
+  * @}
281
+  */
282
+
283
+/** @defgroup FLASHEx_Banks Banks
284
+  * @{
285
+  */
286
+#if defined(FLASH_BANK2_END)
287
+#define FLASH_BANK_1     1U /*!< Bank 1   */
288
+#define FLASH_BANK_2     2U /*!< Bank 2   */
289
+#define FLASH_BANK_BOTH  ((uint32_t)FLASH_BANK_1 | FLASH_BANK_2) /*!< Bank1 and Bank2  */
290
+
291
+#else
292
+#define FLASH_BANK_1     1U /*!< Bank 1   */
293
+#endif
294
+/**
295
+  * @}
296
+  */
297
+
298
+/**
299
+  * @}
300
+  */
301
+
302
+/** @defgroup FLASHEx_OptionByte_Constants Option Byte Constants
303
+  * @{
304
+  */ 
305
+
306
+/** @defgroup FLASHEx_OB_Type Option Bytes Type
307
+  * @{
308
+  */
309
+#define OPTIONBYTE_WRP            0x01U  /*!<WRP option byte configuration*/
310
+#define OPTIONBYTE_RDP            0x02U  /*!<RDP option byte configuration*/
311
+#define OPTIONBYTE_USER           0x04U  /*!<USER option byte configuration*/
312
+#define OPTIONBYTE_DATA           0x08U  /*!<DATA option byte configuration*/
313
+
314
+/**
315
+  * @}
316
+  */
317
+
318
+/** @defgroup FLASHEx_OB_WRP_State Option Byte WRP State
319
+  * @{
320
+  */ 
321
+#define OB_WRPSTATE_DISABLE       0x00U  /*!<Disable the write protection of the desired pages*/
322
+#define OB_WRPSTATE_ENABLE        0x01U  /*!<Enable the write protection of the desired pagess*/
323
+
324
+/**
325
+  * @}
326
+  */
327
+
328
+/** @defgroup FLASHEx_OB_Write_Protection Option Bytes Write Protection
329
+  * @{
330
+  */
331
+/* STM32 Low and Medium density devices */
332
+#if  defined(STM32F101x6) || defined(STM32F102x6) || defined(STM32F103x6) \
333
+  || defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) \
334
+  || defined(STM32F103xB)
335
+#define OB_WRP_PAGES0TO3               0x00000001U /*!< Write protection of page 0 to 3 */
336
+#define OB_WRP_PAGES4TO7               0x00000002U /*!< Write protection of page 4 to 7 */
337
+#define OB_WRP_PAGES8TO11              0x00000004U /*!< Write protection of page 8 to 11 */
338
+#define OB_WRP_PAGES12TO15             0x00000008U /*!< Write protection of page 12 to 15 */
339
+#define OB_WRP_PAGES16TO19             0x00000010U /*!< Write protection of page 16 to 19 */
340
+#define OB_WRP_PAGES20TO23             0x00000020U /*!< Write protection of page 20 to 23 */
341
+#define OB_WRP_PAGES24TO27             0x00000040U /*!< Write protection of page 24 to 27 */
342
+#define OB_WRP_PAGES28TO31             0x00000080U /*!< Write protection of page 28 to 31 */
343
+#endif /* STM32F101x6 || STM32F102x6 || STM32F103x6 */
344
+       /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB */
345
+       
346
+/* STM32 Medium-density devices */
347
+#if  defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB)
348
+#define OB_WRP_PAGES32TO35             0x00000100U   /*!< Write protection of page 32 to 35 */
349
+#define OB_WRP_PAGES36TO39             0x00000200U   /*!< Write protection of page 36 to 39 */
350
+#define OB_WRP_PAGES40TO43             0x00000400U   /*!< Write protection of page 40 to 43 */
351
+#define OB_WRP_PAGES44TO47             0x00000800U   /*!< Write protection of page 44 to 47 */
352
+#define OB_WRP_PAGES48TO51             0x00001000U   /*!< Write protection of page 48 to 51 */
353
+#define OB_WRP_PAGES52TO55             0x00002000U   /*!< Write protection of page 52 to 55 */
354
+#define OB_WRP_PAGES56TO59             0x00004000U   /*!< Write protection of page 56 to 59 */
355
+#define OB_WRP_PAGES60TO63             0x00008000U   /*!< Write protection of page 60 to 63 */
356
+#define OB_WRP_PAGES64TO67             0x00010000U   /*!< Write protection of page 64 to 67 */
357
+#define OB_WRP_PAGES68TO71             0x00020000U   /*!< Write protection of page 68 to 71 */
358
+#define OB_WRP_PAGES72TO75             0x00040000U   /*!< Write protection of page 72 to 75 */
359
+#define OB_WRP_PAGES76TO79             0x00080000U   /*!< Write protection of page 76 to 79 */
360
+#define OB_WRP_PAGES80TO83             0x00100000U   /*!< Write protection of page 80 to 83 */
361
+#define OB_WRP_PAGES84TO87             0x00200000U   /*!< Write protection of page 84 to 87 */
362
+#define OB_WRP_PAGES88TO91             0x00400000U   /*!< Write protection of page 88 to 91 */
363
+#define OB_WRP_PAGES92TO95             0x00800000U   /*!< Write protection of page 92 to 95 */
364
+#define OB_WRP_PAGES96TO99             0x01000000U   /*!< Write protection of page 96 to 99 */
365
+#define OB_WRP_PAGES100TO103           0x02000000U   /*!< Write protection of page 100 to 103 */
366
+#define OB_WRP_PAGES104TO107           0x04000000U   /*!< Write protection of page 104 to 107 */
367
+#define OB_WRP_PAGES108TO111           0x08000000U   /*!< Write protection of page 108 to 111 */
368
+#define OB_WRP_PAGES112TO115           0x10000000U   /*!< Write protection of page 112 to 115 */
369
+#define OB_WRP_PAGES116TO119           0x20000000U   /*!< Write protection of page 115 to 119 */
370
+#define OB_WRP_PAGES120TO123           0x40000000U   /*!< Write protection of page 120 to 123 */
371
+#define OB_WRP_PAGES124TO127           0x80000000U    /*!< Write protection of page 124 to 127 */
372
+#endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB */
373
+
374
+
375
+/* STM32 High-density, XL-density and Connectivity line devices */
376
+#if  defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE) \
377
+  || defined(STM32F101xG) || defined(STM32F103xG) \
378
+  || defined(STM32F105xC) || defined(STM32F107xC)
379
+#define OB_WRP_PAGES0TO1               0x00000001U  /*!< Write protection of page 0 TO 1 */
380
+#define OB_WRP_PAGES2TO3               0x00000002U  /*!< Write protection of page 2 TO 3 */
381
+#define OB_WRP_PAGES4TO5               0x00000004U  /*!< Write protection of page 4 TO 5 */
382
+#define OB_WRP_PAGES6TO7               0x00000008U  /*!< Write protection of page 6 TO 7 */
383
+#define OB_WRP_PAGES8TO9               0x00000010U  /*!< Write protection of page 8 TO 9 */
384
+#define OB_WRP_PAGES10TO11             0x00000020U  /*!< Write protection of page 10 TO 11 */
385
+#define OB_WRP_PAGES12TO13             0x00000040U  /*!< Write protection of page 12 TO 13 */
386
+#define OB_WRP_PAGES14TO15             0x00000080U  /*!< Write protection of page 14 TO 15 */
387
+#define OB_WRP_PAGES16TO17             0x00000100U  /*!< Write protection of page 16 TO 17 */
388
+#define OB_WRP_PAGES18TO19             0x00000200U  /*!< Write protection of page 18 TO 19 */
389
+#define OB_WRP_PAGES20TO21             0x00000400U  /*!< Write protection of page 20 TO 21 */
390
+#define OB_WRP_PAGES22TO23             0x00000800U  /*!< Write protection of page 22 TO 23 */
391
+#define OB_WRP_PAGES24TO25             0x00001000U  /*!< Write protection of page 24 TO 25 */
392
+#define OB_WRP_PAGES26TO27             0x00002000U  /*!< Write protection of page 26 TO 27 */
393
+#define OB_WRP_PAGES28TO29             0x00004000U  /*!< Write protection of page 28 TO 29 */
394
+#define OB_WRP_PAGES30TO31             0x00008000U  /*!< Write protection of page 30 TO 31 */
395
+#define OB_WRP_PAGES32TO33             0x00010000U  /*!< Write protection of page 32 TO 33 */
396
+#define OB_WRP_PAGES34TO35             0x00020000U  /*!< Write protection of page 34 TO 35 */
397
+#define OB_WRP_PAGES36TO37             0x00040000U  /*!< Write protection of page 36 TO 37 */
398
+#define OB_WRP_PAGES38TO39             0x00080000U  /*!< Write protection of page 38 TO 39 */
399
+#define OB_WRP_PAGES40TO41             0x00100000U  /*!< Write protection of page 40 TO 41 */
400
+#define OB_WRP_PAGES42TO43             0x00200000U  /*!< Write protection of page 42 TO 43 */
401
+#define OB_WRP_PAGES44TO45             0x00400000U  /*!< Write protection of page 44 TO 45 */
402
+#define OB_WRP_PAGES46TO47             0x00800000U  /*!< Write protection of page 46 TO 47 */
403
+#define OB_WRP_PAGES48TO49             0x01000000U  /*!< Write protection of page 48 TO 49 */
404
+#define OB_WRP_PAGES50TO51             0x02000000U  /*!< Write protection of page 50 TO 51 */
405
+#define OB_WRP_PAGES52TO53             0x04000000U  /*!< Write protection of page 52 TO 53 */
406
+#define OB_WRP_PAGES54TO55             0x08000000U  /*!< Write protection of page 54 TO 55 */
407
+#define OB_WRP_PAGES56TO57             0x10000000U  /*!< Write protection of page 56 TO 57 */
408
+#define OB_WRP_PAGES58TO59             0x20000000U  /*!< Write protection of page 58 TO 59 */
409
+#define OB_WRP_PAGES60TO61             0x40000000U  /*!< Write protection of page 60 TO 61 */
410
+#define OB_WRP_PAGES62TO127            0x80000000U   /*!< Write protection of page 62 TO 127 */
411
+#define OB_WRP_PAGES62TO255            0x80000000U   /*!< Write protection of page 62 TO 255 */
412
+#define OB_WRP_PAGES62TO511            0x80000000U   /*!< Write protection of page 62 TO 511 */
413
+#endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB */
414
+       /* STM32F101xG || STM32F103xG */ 
415
+       /* STM32F105xC || STM32F107xC */
416
+
417
+#define OB_WRP_ALLPAGES                0xFFFFFFFFU  /*!< Write protection of all Pages */
418
+ 
419
+/* Low Density */
420
+#if  defined(STM32F101x6) || defined(STM32F102x6) || defined(STM32F103x6)
421
+#define OB_WRP_PAGES0TO31MASK          0x000000FFU 
422
+#endif /* STM32F101x6 || STM32F102x6 || STM32F103x6 */
423
+
424
+/* Medium Density */
425
+#if  defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB)
426
+#define OB_WRP_PAGES0TO31MASK          0x000000FFU
427
+#define OB_WRP_PAGES32TO63MASK         0x0000FF00U
428
+#define OB_WRP_PAGES64TO95MASK         0x00FF0000U
429
+#define OB_WRP_PAGES96TO127MASK        0xFF000000U
430
+#endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB*/
431
+       
432
+/* High Density */
433
+#if  defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE)  
434
+#define OB_WRP_PAGES0TO15MASK          0x000000FFU
435
+#define OB_WRP_PAGES16TO31MASK         0x0000FF00U
436
+#define OB_WRP_PAGES32TO47MASK         0x00FF0000U
437
+#define OB_WRP_PAGES48TO255MASK        0xFF000000U
438
+#endif /* STM32F100xE || STM32F101xE || STM32F103xE */
439
+
440
+/* XL Density */
441
+#if  defined(STM32F101xG) || defined(STM32F103xG) 
442
+#define OB_WRP_PAGES0TO15MASK          0x000000FFU
443
+#define OB_WRP_PAGES16TO31MASK         0x0000FF00U
444
+#define OB_WRP_PAGES32TO47MASK         0x00FF0000U
445
+#define OB_WRP_PAGES48TO511MASK        0xFF000000U
446
+#endif /* STM32F101xG || STM32F103xG */
447
+      
448
+/* Connectivity line devices */
449
+#if defined(STM32F105xC) || defined(STM32F107xC)
450
+#define OB_WRP_PAGES0TO15MASK          0x000000FFU
451
+#define OB_WRP_PAGES16TO31MASK         0x0000FF00U
452
+#define OB_WRP_PAGES32TO47MASK         0x00FF0000U
453
+#define OB_WRP_PAGES48TO127MASK        0xFF000000U
454
+#endif /* STM32F105xC || STM32F107xC */
455
+
456
+/**
457
+  * @}
458
+  */
459
+
460
+/** @defgroup FLASHEx_OB_Read_Protection Option Byte Read Protection
461
+  * @{
462
+  */
463
+#define OB_RDP_LEVEL_0            ((uint8_t)0xA5)
464
+#define OB_RDP_LEVEL_1            ((uint8_t)0x00)
465
+/**
466
+  * @}
467
+  */
468
+  
469
+/** @defgroup FLASHEx_OB_IWatchdog Option Byte IWatchdog
470
+  * @{
471
+  */ 
472
+#define OB_IWDG_SW                ((uint16_t)0x0001)  /*!< Software IWDG selected */
473
+#define OB_IWDG_HW                ((uint16_t)0x0000)  /*!< Hardware IWDG selected */
474
+/**
475
+  * @}
476
+  */
477
+
478
+/** @defgroup FLASHEx_OB_nRST_STOP Option Byte nRST STOP
479
+  * @{
480
+  */ 
481
+#define OB_STOP_NO_RST            ((uint16_t)0x0002) /*!< No reset generated when entering in STOP */
482
+#define OB_STOP_RST               ((uint16_t)0x0000) /*!< Reset generated when entering in STOP */
483
+/**
484
+  * @}
485
+  */ 
486
+
487
+/** @defgroup FLASHEx_OB_nRST_STDBY Option Byte nRST STDBY
488
+  * @{
489
+  */ 
490
+#define OB_STDBY_NO_RST           ((uint16_t)0x0004) /*!< No reset generated when entering in STANDBY */
491
+#define OB_STDBY_RST              ((uint16_t)0x0000) /*!< Reset generated when entering in STANDBY */
492
+/**
493
+  * @}
494
+  */
495
+
496
+#if defined(FLASH_BANK2_END)
497
+/** @defgroup FLASHEx_OB_BOOT1 Option Byte BOOT1
498
+  * @{
499
+  */
500
+#define OB_BOOT1_RESET            ((uint16_t)0x0000) /*!< BOOT1 Reset */
501
+#define OB_BOOT1_SET              ((uint16_t)0x0008) /*!< BOOT1 Set */
502
+/**
503
+  * @}
504
+  */
505
+#endif /* FLASH_BANK2_END */
506
+
507
+/** @defgroup FLASHEx_OB_Data_Address  Option Byte Data Address
508
+  * @{
509
+  */
510
+#define OB_DATA_ADDRESS_DATA0     0x1FFFF804U
511
+#define OB_DATA_ADDRESS_DATA1     0x1FFFF806U
512
+/**
513
+  * @}
514
+  */
515
+
516
+/**
517
+  * @}
518
+  */
519
+
520
+/** @addtogroup FLASHEx_Constants
521
+  * @{
522
+  */ 
523
+
524
+/** @defgroup FLASH_Flag_definition Flag definition
525
+  * @brief Flag definition
526
+  * @{
527
+  */
528
+#if defined(FLASH_BANK2_END)
529
+ #define FLASH_FLAG_BSY             FLASH_FLAG_BSY_BANK1       /*!< FLASH Bank1 Busy flag                   */ 
530
+ #define FLASH_FLAG_PGERR           FLASH_FLAG_PGERR_BANK1     /*!< FLASH Bank1 Programming error flag      */
531
+ #define FLASH_FLAG_WRPERR          FLASH_FLAG_WRPERR_BANK1    /*!< FLASH Bank1 Write protected error flag  */
532
+ #define FLASH_FLAG_EOP             FLASH_FLAG_EOP_BANK1       /*!< FLASH Bank1 End of Operation flag       */
533
+
534
+ #define FLASH_FLAG_BSY_BANK1       FLASH_SR_BSY               /*!< FLASH Bank1 Busy flag                   */ 
535
+ #define FLASH_FLAG_PGERR_BANK1     FLASH_SR_PGERR             /*!< FLASH Bank1 Programming error flag      */
536
+ #define FLASH_FLAG_WRPERR_BANK1    FLASH_SR_WRPRTERR          /*!< FLASH Bank1 Write protected error flag  */
537
+ #define FLASH_FLAG_EOP_BANK1       FLASH_SR_EOP               /*!< FLASH Bank1 End of Operation flag       */
538
+       
539
+ #define FLASH_FLAG_BSY_BANK2       (FLASH_SR2_BSY << 16U)      /*!< FLASH Bank2 Busy flag                   */ 
540
+ #define FLASH_FLAG_PGERR_BANK2     (FLASH_SR2_PGERR << 16U)    /*!< FLASH Bank2 Programming error flag      */
541
+ #define FLASH_FLAG_WRPERR_BANK2    (FLASH_SR2_WRPRTERR << 16U) /*!< FLASH Bank2 Write protected error flag  */
542
+ #define FLASH_FLAG_EOP_BANK2       (FLASH_SR2_EOP << 16U)      /*!< FLASH Bank2 End of Operation flag       */
543
+
544
+#else  
545
+
546
+ #define FLASH_FLAG_BSY             FLASH_SR_BSY              /*!< FLASH Busy flag                          */ 
547
+ #define FLASH_FLAG_PGERR           FLASH_SR_PGERR            /*!< FLASH Programming error flag             */
548
+ #define FLASH_FLAG_WRPERR          FLASH_SR_WRPRTERR         /*!< FLASH Write protected error flag         */
549
+ #define FLASH_FLAG_EOP             FLASH_SR_EOP              /*!< FLASH End of Operation flag              */
550
+
551
+#endif
552
+ #define FLASH_FLAG_OPTVERR         ((OBR_REG_INDEX << 8U | FLASH_OBR_OPTERR)) /*!< Option Byte Error        */
553
+/**
554
+  * @}
555
+  */
556
+  
557
+/** @defgroup FLASH_Interrupt_definition Interrupt definition
558
+  * @brief FLASH Interrupt definition
559
+  * @{
560
+  */
561
+#if defined(FLASH_BANK2_END)
562
+ #define FLASH_IT_EOP               FLASH_IT_EOP_BANK1        /*!< End of FLASH Operation Interrupt source Bank1 */
563
+ #define FLASH_IT_ERR               FLASH_IT_ERR_BANK1        /*!< Error Interrupt source Bank1                  */
564
+
565
+ #define FLASH_IT_EOP_BANK1         FLASH_CR_EOPIE            /*!< End of FLASH Operation Interrupt source Bank1 */
566
+ #define FLASH_IT_ERR_BANK1         FLASH_CR_ERRIE            /*!< Error Interrupt source Bank1                  */
567
+
568
+ #define FLASH_IT_EOP_BANK2         (FLASH_CR2_EOPIE << 16U)   /*!< End of FLASH Operation Interrupt source Bank2 */
569
+ #define FLASH_IT_ERR_BANK2         (FLASH_CR2_ERRIE << 16U)   /*!< Error Interrupt source Bank2                  */
570
+
571
+#else
572
+
573
+ #define FLASH_IT_EOP               FLASH_CR_EOPIE          /*!< End of FLASH Operation Interrupt source */
574
+ #define FLASH_IT_ERR               FLASH_CR_ERRIE          /*!< Error Interrupt source                  */
575
+
576
+#endif
577
+/**
578
+  * @}
579
+  */  
580
+
581
+/**
582
+  * @}
583
+  */
584
+  
585
+
586
+/**
587
+  * @}
588
+  */
589
+
590
+/* Exported macro ------------------------------------------------------------*/
591
+/** @defgroup FLASHEx_Exported_Macros FLASHEx Exported Macros
592
+  * @{
593
+  */
594
+
595
+/** @defgroup FLASH_Interrupt Interrupt
596
+ *  @brief macros to handle FLASH interrupts
597
+ * @{
598
+ */ 
599
+
600
+#if defined(FLASH_BANK2_END)
601
+/**
602
+  * @brief  Enable the specified FLASH interrupt.
603
+  * @param  __INTERRUPT__  FLASH interrupt 
604
+  *     This parameter can be any combination of the following values:
605
+  *     @arg @ref FLASH_IT_EOP_BANK1 End of FLASH Operation Interrupt on bank1
606
+  *     @arg @ref FLASH_IT_ERR_BANK1 Error Interrupt on bank1
607
+  *     @arg @ref FLASH_IT_EOP_BANK2 End of FLASH Operation Interrupt on bank2
608
+  *     @arg @ref FLASH_IT_ERR_BANK2 Error Interrupt on bank2
609
+  * @retval none
610
+  */ 
611
+#define __HAL_FLASH_ENABLE_IT(__INTERRUPT__)  do { \
612
+                          /* Enable Bank1 IT */ \
613
+                          SET_BIT(FLASH->CR, ((__INTERRUPT__) & 0x0000FFFFU)); \
614
+                          /* Enable Bank2 IT */ \
615
+                          SET_BIT(FLASH->CR2, ((__INTERRUPT__) >> 16U)); \
616
+                    } while(0U)
617
+
618
+/**
619
+  * @brief  Disable the specified FLASH interrupt.
620
+  * @param  __INTERRUPT__  FLASH interrupt 
621
+  *     This parameter can be any combination of the following values:
622
+  *     @arg @ref FLASH_IT_EOP_BANK1 End of FLASH Operation Interrupt on bank1
623
+  *     @arg @ref FLASH_IT_ERR_BANK1 Error Interrupt on bank1
624
+  *     @arg @ref FLASH_IT_EOP_BANK2 End of FLASH Operation Interrupt on bank2
625
+  *     @arg @ref FLASH_IT_ERR_BANK2 Error Interrupt on bank2
626
+  * @retval none
627
+  */ 
628
+#define __HAL_FLASH_DISABLE_IT(__INTERRUPT__)  do { \
629
+                          /* Disable Bank1 IT */ \
630
+                          CLEAR_BIT(FLASH->CR, ((__INTERRUPT__) & 0x0000FFFFU)); \
631
+                          /* Disable Bank2 IT */ \
632
+                          CLEAR_BIT(FLASH->CR2, ((__INTERRUPT__) >> 16U)); \
633
+                    } while(0U)
634
+
635
+/**
636
+  * @brief  Get the specified FLASH flag status. 
637
+  * @param  __FLAG__ specifies the FLASH flag to check.
638
+  *          This parameter can be one of the following values:
639
+  *            @arg @ref FLASH_FLAG_EOP_BANK1    FLASH End of Operation flag on bank1
640
+  *            @arg @ref FLASH_FLAG_WRPERR_BANK1 FLASH Write protected error flag on bank1
641
+  *            @arg @ref FLASH_FLAG_PGERR_BANK1  FLASH Programming error flag on bank1
642
+  *            @arg @ref FLASH_FLAG_BSY_BANK1    FLASH Busy flag on bank1
643
+  *            @arg @ref FLASH_FLAG_EOP_BANK2    FLASH End of Operation flag on bank2
644
+  *            @arg @ref FLASH_FLAG_WRPERR_BANK2 FLASH Write protected error flag on bank2
645
+  *            @arg @ref FLASH_FLAG_PGERR_BANK2  FLASH Programming error flag on bank2
646
+  *            @arg @ref FLASH_FLAG_BSY_BANK2    FLASH Busy flag on bank2
647
+  *            @arg @ref FLASH_FLAG_OPTVERR  Loaded OB and its complement do not match
648
+  * @retval The new state of __FLAG__ (SET or RESET).
649
+  */
650
+#define __HAL_FLASH_GET_FLAG(__FLAG__) (((__FLAG__) == FLASH_FLAG_OPTVERR) ? \
651
+                                            (FLASH->OBR & FLASH_OBR_OPTERR) : \
652
+                                        ((((__FLAG__) & SR_FLAG_MASK) != RESET)? \
653
+                                            (FLASH->SR & ((__FLAG__) & SR_FLAG_MASK)) : \
654
+                                            (FLASH->SR2 & ((__FLAG__) >> 16U))))
655
+
656
+/**
657
+  * @brief  Clear the specified FLASH flag.
658
+  * @param  __FLAG__ specifies the FLASH flags to clear.
659
+  *          This parameter can be any combination of the following values:
660
+  *            @arg @ref FLASH_FLAG_EOP_BANK1    FLASH End of Operation flag on bank1
661
+  *            @arg @ref FLASH_FLAG_WRPERR_BANK1 FLASH Write protected error flag on bank1
662
+  *            @arg @ref FLASH_FLAG_PGERR_BANK1  FLASH Programming error flag on bank1
663
+  *            @arg @ref FLASH_FLAG_BSY_BANK1    FLASH Busy flag on bank1
664
+  *            @arg @ref FLASH_FLAG_EOP_BANK2    FLASH End of Operation flag on bank2
665
+  *            @arg @ref FLASH_FLAG_WRPERR_BANK2 FLASH Write protected error flag on bank2
666
+  *            @arg @ref FLASH_FLAG_PGERR_BANK2  FLASH Programming error flag on bank2
667
+  *            @arg @ref FLASH_FLAG_BSY_BANK2    FLASH Busy flag on bank2
668
+  *            @arg @ref FLASH_FLAG_OPTVERR  Loaded OB and its complement do not match
669
+  * @retval none
670
+  */
671
+#define __HAL_FLASH_CLEAR_FLAG(__FLAG__)  do { \
672
+                          /* Clear FLASH_FLAG_OPTVERR flag */ \
673
+                          if ((__FLAG__) == FLASH_FLAG_OPTVERR) \
674
+                          { \
675
+                            CLEAR_BIT(FLASH->OBR, FLASH_OBR_OPTERR); \
676
+                          } \
677
+                          else { \
678
+                          /* Clear Flag in Bank1 */ \
679
+                          if (((__FLAG__) & SR_FLAG_MASK) != RESET) \
680
+                          { \
681
+                            FLASH->SR  = ((__FLAG__) & SR_FLAG_MASK); \
682
+                          } \
683
+                          /* Clear Flag in Bank2 */ \
684
+                          if (((__FLAG__) >> 16U) != RESET) \
685
+                          { \
686
+                            FLASH->SR2 = ((__FLAG__) >> 16U); \
687
+                          } \
688
+                          } \
689
+                    } while(0U)
690
+#else
691
+/**
692
+  * @brief  Enable the specified FLASH interrupt.
693
+  * @param  __INTERRUPT__  FLASH interrupt 
694
+  *         This parameter can be any combination of the following values:
695
+  *     @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt
696
+  *     @arg @ref FLASH_IT_ERR Error Interrupt    
697
+  * @retval none
698
+  */ 
699
+#define __HAL_FLASH_ENABLE_IT(__INTERRUPT__)  (FLASH->CR |= (__INTERRUPT__))
700
+
701
+/**
702
+  * @brief  Disable the specified FLASH interrupt.
703
+  * @param  __INTERRUPT__  FLASH interrupt 
704
+  *         This parameter can be any combination of the following values:
705
+  *     @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt
706
+  *     @arg @ref FLASH_IT_ERR Error Interrupt    
707
+  * @retval none
708
+  */ 
709
+#define __HAL_FLASH_DISABLE_IT(__INTERRUPT__)   (FLASH->CR &= ~(__INTERRUPT__))
710
+
711
+/**
712
+  * @brief  Get the specified FLASH flag status. 
713
+  * @param  __FLAG__ specifies the FLASH flag to check.
714
+  *          This parameter can be one of the following values:
715
+  *            @arg @ref FLASH_FLAG_EOP    FLASH End of Operation flag 
716
+  *            @arg @ref FLASH_FLAG_WRPERR FLASH Write protected error flag 
717
+  *            @arg @ref FLASH_FLAG_PGERR  FLASH Programming error flag
718
+  *            @arg @ref FLASH_FLAG_BSY    FLASH Busy flag
719
+  *            @arg @ref FLASH_FLAG_OPTVERR  Loaded OB and its complement do not match
720
+  * @retval The new state of __FLAG__ (SET or RESET).
721
+  */
722
+#define __HAL_FLASH_GET_FLAG(__FLAG__)  (((__FLAG__) == FLASH_FLAG_OPTVERR) ? \
723
+                                            (FLASH->OBR & FLASH_OBR_OPTERR) : \
724
+                                            (FLASH->SR & (__FLAG__)))
725
+/**
726
+  * @brief  Clear the specified FLASH flag.
727
+  * @param  __FLAG__ specifies the FLASH flags to clear.
728
+  *          This parameter can be any combination of the following values:
729
+  *            @arg @ref FLASH_FLAG_EOP    FLASH End of Operation flag 
730
+  *            @arg @ref FLASH_FLAG_WRPERR FLASH Write protected error flag 
731
+  *            @arg @ref FLASH_FLAG_PGERR  FLASH Programming error flag 
732
+  *            @arg @ref FLASH_FLAG_OPTVERR  Loaded OB and its complement do not match
733
+  * @retval none
734
+  */
735
+#define __HAL_FLASH_CLEAR_FLAG(__FLAG__)   do { \
736
+                          /* Clear FLASH_FLAG_OPTVERR flag */ \
737
+                          if ((__FLAG__) == FLASH_FLAG_OPTVERR) \
738
+                          { \
739
+                            CLEAR_BIT(FLASH->OBR, FLASH_OBR_OPTERR); \
740
+                          } \
741
+                          else { \
742
+                            /* Clear Flag in Bank1 */ \
743
+                            FLASH->SR  = (__FLAG__); \
744
+                          } \
745
+                    } while(0U)
746
+
747
+#endif
748
+
749
+/**
750
+  * @}
751
+  */
752
+
753
+/**
754
+  * @}
755
+  */
756
+
757
+/* Exported functions --------------------------------------------------------*/
758
+/** @addtogroup FLASHEx_Exported_Functions
759
+  * @{
760
+  */
761
+
762
+/** @addtogroup FLASHEx_Exported_Functions_Group1
763
+  * @{
764
+  */
765
+/* IO operation functions *****************************************************/
766
+HAL_StatusTypeDef  HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError);
767
+HAL_StatusTypeDef  HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit);
768
+
769
+/**
770
+  * @}
771
+  */
772
+
773
+/** @addtogroup FLASHEx_Exported_Functions_Group2
774
+  * @{
775
+  */
776
+/* Peripheral Control functions ***********************************************/
777
+HAL_StatusTypeDef  HAL_FLASHEx_OBErase(void);
778
+HAL_StatusTypeDef  HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit);
779
+void               HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit);
780
+uint32_t           HAL_FLASHEx_OBGetUserData(uint32_t DATAAdress);
781
+/**
782
+  * @}
783
+  */
784
+
785
+/**
786
+  * @}
787
+  */
788
+
789
+/**
790
+  * @}
791
+  */
792
+
793
+/**
794
+  * @}
795
+  */
796
+#ifdef __cplusplus
797
+}
798
+#endif
799
+
800
+#endif /* __STM32F1xx_HAL_FLASH_EX_H */
801
+
802
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 324 - 0
Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio.h

@@ -0,0 +1,324 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_gpio.h
4
+  * @author  MCD Application Team
5
+  * @brief   Header file of GPIO HAL module.
6
+  ******************************************************************************
7
+  * @attention
8
+  *
9
+  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
10
+  *
11
+  * Redistribution and use in source and binary forms, with or without modification,
12
+  * are permitted provided that the following conditions are met:
13
+  *   1. Redistributions of source code must retain the above copyright notice,
14
+  *      this list of conditions and the following disclaimer.
15
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
16
+  *      this list of conditions and the following disclaimer in the documentation
17
+  *      and/or other materials provided with the distribution.
18
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
19
+  *      may be used to endorse or promote products derived from this software
20
+  *      without specific prior written permission.
21
+  *
22
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+  *
33
+  ******************************************************************************
34
+  */
35
+
36
+/* Define to prevent recursive inclusion -------------------------------------*/
37
+#ifndef __STM32F1xx_HAL_GPIO_H
38
+#define __STM32F1xx_HAL_GPIO_H
39
+
40
+#ifdef __cplusplus
41
+extern "C" {
42
+#endif
43
+
44
+/* Includes ------------------------------------------------------------------*/
45
+#include "stm32f1xx_hal_def.h"
46
+
47
+/** @addtogroup STM32F1xx_HAL_Driver
48
+  * @{
49
+  */
50
+
51
+/** @addtogroup GPIO
52
+  * @{
53
+  */
54
+
55
+/* Exported types ------------------------------------------------------------*/
56
+/** @defgroup GPIO_Exported_Types GPIO Exported Types
57
+  * @{
58
+  */
59
+
60
+/**
61
+  * @brief GPIO Init structure definition
62
+  */
63
+typedef struct
64
+{
65
+  uint32_t Pin;       /*!< Specifies the GPIO pins to be configured.
66
+                           This parameter can be any value of @ref GPIO_pins_define */
67
+
68
+  uint32_t Mode;      /*!< Specifies the operating mode for the selected pins.
69
+                           This parameter can be a value of @ref GPIO_mode_define */
70
+
71
+  uint32_t Pull;      /*!< Specifies the Pull-up or Pull-Down activation for the selected pins.
72
+                           This parameter can be a value of @ref GPIO_pull_define */
73
+
74
+  uint32_t Speed;     /*!< Specifies the speed for the selected pins.
75
+                           This parameter can be a value of @ref GPIO_speed_define */
76
+} GPIO_InitTypeDef;
77
+
78
+/**
79
+  * @brief  GPIO Bit SET and Bit RESET enumeration
80
+  */
81
+typedef enum
82
+{
83
+  GPIO_PIN_RESET = 0U,
84
+  GPIO_PIN_SET
85
+} GPIO_PinState;
86
+/**
87
+  * @}
88
+  */
89
+
90
+/* Exported constants --------------------------------------------------------*/
91
+
92
+/** @defgroup GPIO_Exported_Constants GPIO Exported Constants
93
+  * @{
94
+  */
95
+
96
+/** @defgroup GPIO_pins_define GPIO pins define
97
+  * @{
98
+  */
99
+#define GPIO_PIN_0                 ((uint16_t)0x0001)  /* Pin 0 selected    */
100
+#define GPIO_PIN_1                 ((uint16_t)0x0002)  /* Pin 1 selected    */
101
+#define GPIO_PIN_2                 ((uint16_t)0x0004)  /* Pin 2 selected    */
102
+#define GPIO_PIN_3                 ((uint16_t)0x0008)  /* Pin 3 selected    */
103
+#define GPIO_PIN_4                 ((uint16_t)0x0010)  /* Pin 4 selected    */
104
+#define GPIO_PIN_5                 ((uint16_t)0x0020)  /* Pin 5 selected    */
105
+#define GPIO_PIN_6                 ((uint16_t)0x0040)  /* Pin 6 selected    */
106
+#define GPIO_PIN_7                 ((uint16_t)0x0080)  /* Pin 7 selected    */
107
+#define GPIO_PIN_8                 ((uint16_t)0x0100)  /* Pin 8 selected    */
108
+#define GPIO_PIN_9                 ((uint16_t)0x0200)  /* Pin 9 selected    */
109
+#define GPIO_PIN_10                ((uint16_t)0x0400)  /* Pin 10 selected   */
110
+#define GPIO_PIN_11                ((uint16_t)0x0800)  /* Pin 11 selected   */
111
+#define GPIO_PIN_12                ((uint16_t)0x1000)  /* Pin 12 selected   */
112
+#define GPIO_PIN_13                ((uint16_t)0x2000)  /* Pin 13 selected   */
113
+#define GPIO_PIN_14                ((uint16_t)0x4000)  /* Pin 14 selected   */
114
+#define GPIO_PIN_15                ((uint16_t)0x8000)  /* Pin 15 selected   */
115
+#define GPIO_PIN_All               ((uint16_t)0xFFFF)  /* All pins selected */
116
+
117
+#define GPIO_PIN_MASK              0x0000FFFFU /* PIN mask for assert test */
118
+/**
119
+  * @}
120
+  */
121
+
122
+/** @defgroup GPIO_mode_define GPIO mode define
123
+  * @brief GPIO Configuration Mode
124
+  *        Elements values convention: 0xX0yz00YZ
125
+  *           - X  : GPIO mode or EXTI Mode
126
+  *           - y  : External IT or Event trigger detection
127
+  *           - z  : IO configuration on External IT or Event
128
+  *           - Y  : Output type (Push Pull or Open Drain)
129
+  *           - Z  : IO Direction mode (Input, Output, Alternate or Analog)
130
+  * @{
131
+  */
132
+#define  GPIO_MODE_INPUT                        0x00000000U   /*!< Input Floating Mode                   */
133
+#define  GPIO_MODE_OUTPUT_PP                    0x00000001U   /*!< Output Push Pull Mode                 */
134
+#define  GPIO_MODE_OUTPUT_OD                    0x00000011U   /*!< Output Open Drain Mode                */
135
+#define  GPIO_MODE_AF_PP                        0x00000002U   /*!< Alternate Function Push Pull Mode     */
136
+#define  GPIO_MODE_AF_OD                        0x00000012U   /*!< Alternate Function Open Drain Mode    */
137
+#define  GPIO_MODE_AF_INPUT                     GPIO_MODE_INPUT          /*!< Alternate Function Input Mode         */
138
+
139
+#define  GPIO_MODE_ANALOG                       0x00000003U   /*!< Analog Mode  */
140
+
141
+#define  GPIO_MODE_IT_RISING                    0x10110000U   /*!< External Interrupt Mode with Rising edge trigger detection          */
142
+#define  GPIO_MODE_IT_FALLING                   0x10210000U   /*!< External Interrupt Mode with Falling edge trigger detection         */
143
+#define  GPIO_MODE_IT_RISING_FALLING            0x10310000U   /*!< External Interrupt Mode with Rising/Falling edge trigger detection  */
144
+
145
+#define  GPIO_MODE_EVT_RISING                   0x10120000U   /*!< External Event Mode with Rising edge trigger detection               */
146
+#define  GPIO_MODE_EVT_FALLING                  0x10220000U   /*!< External Event Mode with Falling edge trigger detection              */
147
+#define  GPIO_MODE_EVT_RISING_FALLING           0x10320000U   /*!< External Event Mode with Rising/Falling edge trigger detection       */
148
+
149
+/**
150
+  * @}
151
+  */
152
+
153
+/** @defgroup GPIO_speed_define  GPIO speed define
154
+  * @brief GPIO Output Maximum frequency
155
+  * @{
156
+  */
157
+#define  GPIO_SPEED_FREQ_LOW              (GPIO_CRL_MODE0_1) /*!< Low speed */
158
+#define  GPIO_SPEED_FREQ_MEDIUM           (GPIO_CRL_MODE0_0) /*!< Medium speed */
159
+#define  GPIO_SPEED_FREQ_HIGH             (GPIO_CRL_MODE0)   /*!< High speed */
160
+
161
+/**
162
+  * @}
163
+  */
164
+
165
+/** @defgroup GPIO_pull_define GPIO pull define
166
+  * @brief GPIO Pull-Up or Pull-Down Activation
167
+  * @{
168
+  */
169
+#define  GPIO_NOPULL        0x00000000U   /*!< No Pull-up or Pull-down activation  */
170
+#define  GPIO_PULLUP        0x00000001U   /*!< Pull-up activation                  */
171
+#define  GPIO_PULLDOWN      0x00000002U   /*!< Pull-down activation                */
172
+/**
173
+  * @}
174
+  */
175
+
176
+/**
177
+  * @}
178
+  */
179
+
180
+/* Exported macro ------------------------------------------------------------*/
181
+/** @defgroup GPIO_Exported_Macros GPIO Exported Macros
182
+  * @{
183
+  */
184
+
185
+/**
186
+  * @brief  Checks whether the specified EXTI line flag is set or not.
187
+  * @param  __EXTI_LINE__: specifies the EXTI line flag to check.
188
+  *         This parameter can be GPIO_PIN_x where x can be(0..15)
189
+  * @retval The new state of __EXTI_LINE__ (SET or RESET).
190
+  */
191
+#define __HAL_GPIO_EXTI_GET_FLAG(__EXTI_LINE__) (EXTI->PR & (__EXTI_LINE__))
192
+
193
+/**
194
+  * @brief  Clears the EXTI's line pending flags.
195
+  * @param  __EXTI_LINE__: specifies the EXTI lines flags to clear.
196
+  *         This parameter can be any combination of GPIO_PIN_x where x can be (0..15)
197
+  * @retval None
198
+  */
199
+#define __HAL_GPIO_EXTI_CLEAR_FLAG(__EXTI_LINE__) (EXTI->PR = (__EXTI_LINE__))
200
+
201
+/**
202
+  * @brief  Checks whether the specified EXTI line is asserted or not.
203
+  * @param  __EXTI_LINE__: specifies the EXTI line to check.
204
+  *          This parameter can be GPIO_PIN_x where x can be(0..15)
205
+  * @retval The new state of __EXTI_LINE__ (SET or RESET).
206
+  */
207
+#define __HAL_GPIO_EXTI_GET_IT(__EXTI_LINE__) (EXTI->PR & (__EXTI_LINE__))
208
+
209
+/**
210
+  * @brief  Clears the EXTI's line pending bits.
211
+  * @param  __EXTI_LINE__: specifies the EXTI lines to clear.
212
+  *          This parameter can be any combination of GPIO_PIN_x where x can be (0..15)
213
+  * @retval None
214
+  */
215
+#define __HAL_GPIO_EXTI_CLEAR_IT(__EXTI_LINE__) (EXTI->PR = (__EXTI_LINE__))
216
+
217
+/**
218
+  * @brief  Generates a Software interrupt on selected EXTI line.
219
+  * @param  __EXTI_LINE__: specifies the EXTI line to check.
220
+  *          This parameter can be GPIO_PIN_x where x can be(0..15)
221
+  * @retval None
222
+  */
223
+#define __HAL_GPIO_EXTI_GENERATE_SWIT(__EXTI_LINE__) (EXTI->SWIER |= (__EXTI_LINE__))
224
+/**
225
+  * @}
226
+  */
227
+
228
+/* Include GPIO HAL Extension module */
229
+#include "stm32f1xx_hal_gpio_ex.h"
230
+
231
+/* Exported functions --------------------------------------------------------*/
232
+/** @addtogroup GPIO_Exported_Functions
233
+  * @{
234
+  */
235
+
236
+/** @addtogroup GPIO_Exported_Functions_Group1
237
+  * @{
238
+  */
239
+/* Initialization and de-initialization functions *****************************/
240
+void  HAL_GPIO_Init(GPIO_TypeDef  *GPIOx, GPIO_InitTypeDef *GPIO_Init);
241
+void  HAL_GPIO_DeInit(GPIO_TypeDef  *GPIOx, uint32_t GPIO_Pin);
242
+/**
243
+  * @}
244
+  */
245
+
246
+/** @addtogroup GPIO_Exported_Functions_Group2
247
+  * @{
248
+  */
249
+/* IO operation functions *****************************************************/
250
+GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin);
251
+void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState);
252
+void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin);
253
+HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin);
254
+void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin);
255
+void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin);
256
+
257
+/**
258
+  * @}
259
+  */
260
+
261
+/**
262
+  * @}
263
+  */
264
+/* Private types -------------------------------------------------------------*/
265
+/* Private variables ---------------------------------------------------------*/
266
+/* Private constants ---------------------------------------------------------*/
267
+/** @defgroup GPIO_Private_Constants GPIO Private Constants
268
+  * @{
269
+  */
270
+
271
+/**
272
+  * @}
273
+  */
274
+
275
+/* Private macros ------------------------------------------------------------*/
276
+/** @defgroup GPIO_Private_Macros GPIO Private Macros
277
+  * @{
278
+  */
279
+#define IS_GPIO_PIN_ACTION(ACTION) (((ACTION) == GPIO_PIN_RESET) || ((ACTION) == GPIO_PIN_SET))
280
+#define IS_GPIO_PIN(PIN)           ((((PIN) & GPIO_PIN_MASK ) != 0x00U) && (((PIN) & ~GPIO_PIN_MASK) == 0x00U))
281
+#define IS_GPIO_MODE(MODE) (((MODE) == GPIO_MODE_INPUT)              ||\
282
+                            ((MODE) == GPIO_MODE_OUTPUT_PP)          ||\
283
+                            ((MODE) == GPIO_MODE_OUTPUT_OD)          ||\
284
+                            ((MODE) == GPIO_MODE_AF_PP)              ||\
285
+                            ((MODE) == GPIO_MODE_AF_OD)              ||\
286
+                            ((MODE) == GPIO_MODE_IT_RISING)          ||\
287
+                            ((MODE) == GPIO_MODE_IT_FALLING)         ||\
288
+                            ((MODE) == GPIO_MODE_IT_RISING_FALLING)  ||\
289
+                            ((MODE) == GPIO_MODE_EVT_RISING)         ||\
290
+                            ((MODE) == GPIO_MODE_EVT_FALLING)        ||\
291
+                            ((MODE) == GPIO_MODE_EVT_RISING_FALLING) ||\
292
+                            ((MODE) == GPIO_MODE_ANALOG))
293
+#define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_SPEED_FREQ_LOW) || \
294
+                              ((SPEED) == GPIO_SPEED_FREQ_MEDIUM) || ((SPEED) == GPIO_SPEED_FREQ_HIGH))
295
+#define IS_GPIO_PULL(PULL) (((PULL) == GPIO_NOPULL) || ((PULL) == GPIO_PULLUP) || \
296
+                            ((PULL) == GPIO_PULLDOWN))
297
+/**
298
+  * @}
299
+  */
300
+
301
+/* Private functions ---------------------------------------------------------*/
302
+/** @defgroup GPIO_Private_Functions GPIO Private Functions
303
+  * @{
304
+  */
305
+
306
+/**
307
+  * @}
308
+  */
309
+
310
+/**
311
+  * @}
312
+  */
313
+
314
+/**
315
+  * @}
316
+  */
317
+
318
+#ifdef __cplusplus
319
+}
320
+#endif
321
+
322
+#endif /* __STM32F1xx_HAL_GPIO_H */
323
+
324
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 910 - 0
Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio_ex.h

@@ -0,0 +1,910 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_gpio_ex.h
4
+  * @author  MCD Application Team
5
+  * @brief   Header file of GPIO HAL Extension module.
6
+  ******************************************************************************
7
+  * @attention
8
+  *
9
+  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
10
+  *
11
+  * Redistribution and use in source and binary forms, with or without modification,
12
+  * are permitted provided that the following conditions are met:
13
+  *   1. Redistributions of source code must retain the above copyright notice,
14
+  *      this list of conditions and the following disclaimer.
15
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
16
+  *      this list of conditions and the following disclaimer in the documentation
17
+  *      and/or other materials provided with the distribution.
18
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
19
+  *      may be used to endorse or promote products derived from this software
20
+  *      without specific prior written permission.
21
+  *
22
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+  *
33
+  ******************************************************************************
34
+  */
35
+
36
+/* Define to prevent recursive inclusion -------------------------------------*/
37
+#ifndef __STM32F1xx_HAL_GPIO_EX_H
38
+#define __STM32F1xx_HAL_GPIO_EX_H
39
+
40
+#ifdef __cplusplus
41
+extern "C" {
42
+#endif
43
+
44
+/* Includes ------------------------------------------------------------------*/
45
+#include "stm32f1xx_hal_def.h"
46
+
47
+/** @addtogroup STM32F1xx_HAL_Driver
48
+  * @{
49
+  */
50
+
51
+/** @defgroup GPIOEx GPIOEx
52
+  * @{
53
+  */
54
+/* Exported types ------------------------------------------------------------*/
55
+/* Exported constants --------------------------------------------------------*/
56
+
57
+/** @defgroup GPIOEx_Exported_Constants GPIOEx Exported Constants
58
+  * @{
59
+  */
60
+
61
+/** @defgroup GPIOEx_EVENTOUT EVENTOUT Cortex Configuration
62
+  * @brief This section propose definition to use the Cortex EVENTOUT signal.
63
+  * @{
64
+  */
65
+
66
+/** @defgroup GPIOEx_EVENTOUT_PIN EVENTOUT Pin
67
+  * @{
68
+  */
69
+
70
+#define AFIO_EVENTOUT_PIN_0  AFIO_EVCR_PIN_PX0 /*!< EVENTOUT on pin 0 */
71
+#define AFIO_EVENTOUT_PIN_1  AFIO_EVCR_PIN_PX1 /*!< EVENTOUT on pin 1 */
72
+#define AFIO_EVENTOUT_PIN_2  AFIO_EVCR_PIN_PX2 /*!< EVENTOUT on pin 2 */
73
+#define AFIO_EVENTOUT_PIN_3  AFIO_EVCR_PIN_PX3 /*!< EVENTOUT on pin 3 */
74
+#define AFIO_EVENTOUT_PIN_4  AFIO_EVCR_PIN_PX4 /*!< EVENTOUT on pin 4 */
75
+#define AFIO_EVENTOUT_PIN_5  AFIO_EVCR_PIN_PX5 /*!< EVENTOUT on pin 5 */
76
+#define AFIO_EVENTOUT_PIN_6  AFIO_EVCR_PIN_PX6 /*!< EVENTOUT on pin 6 */
77
+#define AFIO_EVENTOUT_PIN_7  AFIO_EVCR_PIN_PX7 /*!< EVENTOUT on pin 7 */
78
+#define AFIO_EVENTOUT_PIN_8  AFIO_EVCR_PIN_PX8 /*!< EVENTOUT on pin 8 */
79
+#define AFIO_EVENTOUT_PIN_9  AFIO_EVCR_PIN_PX9 /*!< EVENTOUT on pin 9 */
80
+#define AFIO_EVENTOUT_PIN_10 AFIO_EVCR_PIN_PX10 /*!< EVENTOUT on pin 10 */
81
+#define AFIO_EVENTOUT_PIN_11 AFIO_EVCR_PIN_PX11 /*!< EVENTOUT on pin 11 */
82
+#define AFIO_EVENTOUT_PIN_12 AFIO_EVCR_PIN_PX12 /*!< EVENTOUT on pin 12 */
83
+#define AFIO_EVENTOUT_PIN_13 AFIO_EVCR_PIN_PX13 /*!< EVENTOUT on pin 13 */
84
+#define AFIO_EVENTOUT_PIN_14 AFIO_EVCR_PIN_PX14 /*!< EVENTOUT on pin 14 */
85
+#define AFIO_EVENTOUT_PIN_15 AFIO_EVCR_PIN_PX15 /*!< EVENTOUT on pin 15 */
86
+
87
+#define IS_AFIO_EVENTOUT_PIN(__PIN__) (((__PIN__) == AFIO_EVENTOUT_PIN_0) || \
88
+                                       ((__PIN__) == AFIO_EVENTOUT_PIN_1) || \
89
+                                       ((__PIN__) == AFIO_EVENTOUT_PIN_2) || \
90
+                                       ((__PIN__) == AFIO_EVENTOUT_PIN_3) || \
91
+                                       ((__PIN__) == AFIO_EVENTOUT_PIN_4) || \
92
+                                       ((__PIN__) == AFIO_EVENTOUT_PIN_5) || \
93
+                                       ((__PIN__) == AFIO_EVENTOUT_PIN_6) || \
94
+                                       ((__PIN__) == AFIO_EVENTOUT_PIN_7) || \
95
+                                       ((__PIN__) == AFIO_EVENTOUT_PIN_8) || \
96
+                                       ((__PIN__) == AFIO_EVENTOUT_PIN_9) || \
97
+                                       ((__PIN__) == AFIO_EVENTOUT_PIN_10) || \
98
+                                       ((__PIN__) == AFIO_EVENTOUT_PIN_11) || \
99
+                                       ((__PIN__) == AFIO_EVENTOUT_PIN_12) || \
100
+                                       ((__PIN__) == AFIO_EVENTOUT_PIN_13) || \
101
+                                       ((__PIN__) == AFIO_EVENTOUT_PIN_14) || \
102
+                                       ((__PIN__) == AFIO_EVENTOUT_PIN_15))
103
+/**
104
+  * @}
105
+  */
106
+
107
+/** @defgroup GPIOEx_EVENTOUT_PORT EVENTOUT Port
108
+  * @{
109
+  */
110
+
111
+#define AFIO_EVENTOUT_PORT_A AFIO_EVCR_PORT_PA /*!< EVENTOUT on port A */
112
+#define AFIO_EVENTOUT_PORT_B AFIO_EVCR_PORT_PB /*!< EVENTOUT on port B */
113
+#define AFIO_EVENTOUT_PORT_C AFIO_EVCR_PORT_PC /*!< EVENTOUT on port C */
114
+#define AFIO_EVENTOUT_PORT_D AFIO_EVCR_PORT_PD /*!< EVENTOUT on port D */
115
+#define AFIO_EVENTOUT_PORT_E AFIO_EVCR_PORT_PE /*!< EVENTOUT on port E */
116
+
117
+#define IS_AFIO_EVENTOUT_PORT(__PORT__) (((__PORT__) == AFIO_EVENTOUT_PORT_A) || \
118
+                                         ((__PORT__) == AFIO_EVENTOUT_PORT_B) || \
119
+                                         ((__PORT__) == AFIO_EVENTOUT_PORT_C) || \
120
+                                         ((__PORT__) == AFIO_EVENTOUT_PORT_D) || \
121
+                                         ((__PORT__) == AFIO_EVENTOUT_PORT_E))
122
+/**
123
+  * @}
124
+  */
125
+
126
+/**
127
+  * @}
128
+  */
129
+
130
+/** @defgroup GPIOEx_AFIO_AF_REMAPPING Alternate Function Remapping
131
+  * @brief This section propose definition to remap the alternate function to some other port/pins.
132
+  * @{
133
+  */
134
+
135
+/**
136
+  * @brief Enable the remapping of SPI1 alternate function NSS, SCK, MISO and MOSI.
137
+  * @note  ENABLE: Remap     (NSS/PA15, SCK/PB3, MISO/PB4, MOSI/PB5)
138
+  * @retval None
139
+  */
140
+#define __HAL_AFIO_REMAP_SPI1_ENABLE()  AFIO_REMAP_ENABLE(AFIO_MAPR_SPI1_REMAP)
141
+
142
+/**
143
+  * @brief Disable the remapping of SPI1 alternate function NSS, SCK, MISO and MOSI.
144
+  * @note  DISABLE: No remap (NSS/PA4,  SCK/PA5, MISO/PA6, MOSI/PA7)
145
+  * @retval None
146
+  */
147
+#define __HAL_AFIO_REMAP_SPI1_DISABLE()  AFIO_REMAP_DISABLE(AFIO_MAPR_SPI1_REMAP)
148
+
149
+/**
150
+  * @brief Enable the remapping of I2C1 alternate function SCL and SDA.
151
+  * @note  ENABLE: Remap     (SCL/PB8, SDA/PB9)
152
+  * @retval None
153
+  */
154
+#define __HAL_AFIO_REMAP_I2C1_ENABLE()  AFIO_REMAP_ENABLE(AFIO_MAPR_I2C1_REMAP)
155
+
156
+/**
157
+  * @brief Disable the remapping of I2C1 alternate function SCL and SDA.
158
+  * @note  DISABLE: No remap (SCL/PB6, SDA/PB7)
159
+  * @retval None
160
+  */
161
+#define __HAL_AFIO_REMAP_I2C1_DISABLE() AFIO_REMAP_DISABLE(AFIO_MAPR_I2C1_REMAP)
162
+
163
+/**
164
+  * @brief Enable the remapping of USART1 alternate function TX and RX.
165
+  * @note  ENABLE: Remap     (TX/PB6, RX/PB7)
166
+  * @retval None
167
+  */
168
+#define __HAL_AFIO_REMAP_USART1_ENABLE()  AFIO_REMAP_ENABLE(AFIO_MAPR_USART1_REMAP)
169
+
170
+/**
171
+  * @brief Disable the remapping of USART1 alternate function TX and RX.
172
+  * @note  DISABLE: No remap (TX/PA9, RX/PA10)
173
+  * @retval None
174
+  */
175
+#define __HAL_AFIO_REMAP_USART1_DISABLE() AFIO_REMAP_DISABLE(AFIO_MAPR_USART1_REMAP)
176
+
177
+/**
178
+  * @brief Enable the remapping of USART2 alternate function CTS, RTS, CK, TX and RX.
179
+  * @note  ENABLE: Remap     (CTS/PD3, RTS/PD4, TX/PD5, RX/PD6, CK/PD7)
180
+  * @retval None
181
+  */
182
+#define __HAL_AFIO_REMAP_USART2_ENABLE()  AFIO_REMAP_ENABLE(AFIO_MAPR_USART2_REMAP)
183
+
184
+/**
185
+  * @brief Disable the remapping of USART2 alternate function CTS, RTS, CK, TX and RX.
186
+  * @note  DISABLE: No remap (CTS/PA0, RTS/PA1, TX/PA2, RX/PA3, CK/PA4)
187
+  * @retval None
188
+  */
189
+#define __HAL_AFIO_REMAP_USART2_DISABLE() AFIO_REMAP_DISABLE(AFIO_MAPR_USART2_REMAP)
190
+
191
+/**
192
+  * @brief Enable the remapping of USART3 alternate function CTS, RTS, CK, TX and RX.
193
+  * @note  ENABLE: Full remap     (TX/PD8,  RX/PD9,  CK/PD10, CTS/PD11, RTS/PD12)
194
+  * @retval None
195
+  */
196
+#define __HAL_AFIO_REMAP_USART3_ENABLE()  AFIO_REMAP_PARTIAL(AFIO_MAPR_USART3_REMAP_FULLREMAP, AFIO_MAPR_USART3_REMAP_FULLREMAP)
197
+
198
+/**
199
+  * @brief Enable the remapping of USART3 alternate function CTS, RTS, CK, TX and RX.
200
+  * @note  PARTIAL: Partial remap (TX/PC10, RX/PC11, CK/PC12, CTS/PB13, RTS/PB14)
201
+  * @retval None
202
+  */
203
+#define __HAL_AFIO_REMAP_USART3_PARTIAL()  AFIO_REMAP_PARTIAL(AFIO_MAPR_USART3_REMAP_PARTIALREMAP, AFIO_MAPR_USART3_REMAP_FULLREMAP)
204
+
205
+/**
206
+  * @brief Disable the remapping of USART3 alternate function CTS, RTS, CK, TX and RX.
207
+  * @note  DISABLE: No remap      (TX/PB10, RX/PB11, CK/PB12, CTS/PB13, RTS/PB14)
208
+  * @retval None
209
+  */
210
+#define __HAL_AFIO_REMAP_USART3_DISABLE()  AFIO_REMAP_PARTIAL(AFIO_MAPR_USART3_REMAP_NOREMAP, AFIO_MAPR_USART3_REMAP_FULLREMAP)
211
+
212
+/**
213
+  * @brief Enable the remapping of TIM1 alternate function channels 1 to 4, 1N to 3N, external trigger (ETR) and Break input (BKIN)
214
+  * @note  ENABLE: Full remap     (ETR/PE7,  CH1/PE9, CH2/PE11, CH3/PE13, CH4/PE14, BKIN/PE15, CH1N/PE8,  CH2N/PE10, CH3N/PE12)
215
+  * @retval None
216
+  */
217
+#define __HAL_AFIO_REMAP_TIM1_ENABLE()  AFIO_REMAP_PARTIAL(AFIO_MAPR_TIM1_REMAP_FULLREMAP, AFIO_MAPR_TIM1_REMAP_FULLREMAP)
218
+
219
+/**
220
+  * @brief Enable the remapping of TIM1 alternate function channels 1 to 4, 1N to 3N, external trigger (ETR) and Break input (BKIN)
221
+  * @note  PARTIAL: Partial remap (ETR/PA12, CH1/PA8, CH2/PA9,  CH3/PA10, CH4/PA11, BKIN/PA6,  CH1N/PA7,  CH2N/PB0,  CH3N/PB1)
222
+  * @retval None
223
+  */
224
+#define __HAL_AFIO_REMAP_TIM1_PARTIAL()  AFIO_REMAP_PARTIAL(AFIO_MAPR_TIM1_REMAP_PARTIALREMAP, AFIO_MAPR_TIM1_REMAP_FULLREMAP)
225
+
226
+/**
227
+  * @brief Disable the remapping of TIM1 alternate function channels 1 to 4, 1N to 3N, external trigger (ETR) and Break input (BKIN)
228
+  * @note  DISABLE: No remap      (ETR/PA12, CH1/PA8, CH2/PA9,  CH3/PA10, CH4/PA11, BKIN/PB12, CH1N/PB13, CH2N/PB14, CH3N/PB15)
229
+  * @retval None
230
+  */
231
+#define __HAL_AFIO_REMAP_TIM1_DISABLE()  AFIO_REMAP_PARTIAL(AFIO_MAPR_TIM1_REMAP_NOREMAP, AFIO_MAPR_TIM1_REMAP_FULLREMAP)
232
+
233
+/**
234
+  * @brief Enable the remapping of TIM2 alternate function channels 1 to 4 and external trigger (ETR)
235
+  * @note  ENABLE: Full remap       (CH1/ETR/PA15, CH2/PB3, CH3/PB10, CH4/PB11)
236
+  * @retval None
237
+  */
238
+#define __HAL_AFIO_REMAP_TIM2_ENABLE()  AFIO_REMAP_PARTIAL(AFIO_MAPR_TIM2_REMAP_FULLREMAP, AFIO_MAPR_TIM2_REMAP_FULLREMAP)
239
+
240
+/**
241
+  * @brief Enable the remapping of TIM2 alternate function channels 1 to 4 and external trigger (ETR)
242
+  * @note  PARTIAL_2: Partial remap (CH1/ETR/PA0,  CH2/PA1, CH3/PB10, CH4/PB11)
243
+  * @retval None
244
+  */
245
+#define __HAL_AFIO_REMAP_TIM2_PARTIAL_2()  AFIO_REMAP_PARTIAL(AFIO_MAPR_TIM2_REMAP_PARTIALREMAP2, AFIO_MAPR_TIM2_REMAP_FULLREMAP)
246
+
247
+/**
248
+  * @brief Enable the remapping of TIM2 alternate function channels 1 to 4 and external trigger (ETR)
249
+  * @note  PARTIAL_1: Partial remap (CH1/ETR/PA15, CH2/PB3, CH3/PA2,  CH4/PA3)
250
+  * @retval None
251
+  */
252
+#define __HAL_AFIO_REMAP_TIM2_PARTIAL_1()  AFIO_REMAP_PARTIAL(AFIO_MAPR_TIM2_REMAP_PARTIALREMAP1, AFIO_MAPR_TIM2_REMAP_FULLREMAP)
253
+
254
+/**
255
+  * @brief Disable the remapping of TIM2 alternate function channels 1 to 4 and external trigger (ETR)
256
+  * @note  DISABLE: No remap        (CH1/ETR/PA0,  CH2/PA1, CH3/PA2,  CH4/PA3)
257
+  * @retval None
258
+  */
259
+#define __HAL_AFIO_REMAP_TIM2_DISABLE()  AFIO_REMAP_PARTIAL(AFIO_MAPR_TIM2_REMAP_NOREMAP, AFIO_MAPR_TIM2_REMAP_FULLREMAP)
260
+
261
+/**
262
+  * @brief Enable the remapping of TIM3 alternate function channels 1 to 4
263
+  * @note  ENABLE: Full remap     (CH1/PC6, CH2/PC7, CH3/PC8, CH4/PC9)
264
+  * @note  TIM3_ETR on PE0 is not re-mapped.
265
+  * @retval None
266
+  */
267
+#define __HAL_AFIO_REMAP_TIM3_ENABLE()  AFIO_REMAP_PARTIAL(AFIO_MAPR_TIM3_REMAP_FULLREMAP, AFIO_MAPR_TIM3_REMAP_FULLREMAP)
268
+
269
+/**
270
+  * @brief Enable the remapping of TIM3 alternate function channels 1 to 4
271
+  * @note  PARTIAL: Partial remap (CH1/PB4, CH2/PB5, CH3/PB0, CH4/PB1)
272
+  * @note  TIM3_ETR on PE0 is not re-mapped.
273
+  * @retval None
274
+  */
275
+#define __HAL_AFIO_REMAP_TIM3_PARTIAL()  AFIO_REMAP_PARTIAL(AFIO_MAPR_TIM3_REMAP_PARTIALREMAP, AFIO_MAPR_TIM3_REMAP_FULLREMAP)
276
+
277
+/**
278
+  * @brief Disable the remapping of TIM3 alternate function channels 1 to 4
279
+  * @note  DISABLE: No remap      (CH1/PA6, CH2/PA7, CH3/PB0, CH4/PB1)
280
+  * @note  TIM3_ETR on PE0 is not re-mapped.
281
+  * @retval None
282
+  */
283
+#define __HAL_AFIO_REMAP_TIM3_DISABLE()  AFIO_REMAP_PARTIAL(AFIO_MAPR_TIM3_REMAP_NOREMAP, AFIO_MAPR_TIM3_REMAP_FULLREMAP)
284
+
285
+/**
286
+  * @brief Enable the remapping of TIM4 alternate function channels 1 to 4.
287
+  * @note  ENABLE: Full remap (TIM4_CH1/PD12, TIM4_CH2/PD13, TIM4_CH3/PD14, TIM4_CH4/PD15)
288
+  * @note  TIM4_ETR on PE0 is not re-mapped.
289
+  * @retval None
290
+  */
291
+#define __HAL_AFIO_REMAP_TIM4_ENABLE()  AFIO_REMAP_ENABLE(AFIO_MAPR_TIM4_REMAP)
292
+
293
+/**
294
+  * @brief Disable the remapping of TIM4 alternate function channels 1 to 4.
295
+  * @note  DISABLE: No remap  (TIM4_CH1/PB6,  TIM4_CH2/PB7,  TIM4_CH3/PB8,  TIM4_CH4/PB9)
296
+  * @note  TIM4_ETR on PE0 is not re-mapped.
297
+  * @retval None
298
+  */
299
+#define __HAL_AFIO_REMAP_TIM4_DISABLE() AFIO_REMAP_DISABLE(AFIO_MAPR_TIM4_REMAP)
300
+
301
+#if defined(AFIO_MAPR_CAN_REMAP_REMAP1)
302
+
303
+/**
304
+  * @brief Enable or disable the remapping of CAN alternate function CAN_RX and CAN_TX in devices with a single CAN interface.
305
+  * @note  CASE 1: CAN_RX mapped to PA11, CAN_TX mapped to PA12
306
+  * @retval None
307
+  */
308
+#define __HAL_AFIO_REMAP_CAN1_1()  AFIO_REMAP_PARTIAL(AFIO_MAPR_CAN_REMAP_REMAP1, AFIO_MAPR_CAN_REMAP)
309
+
310
+/**
311
+  * @brief Enable or disable the remapping of CAN alternate function CAN_RX and CAN_TX in devices with a single CAN interface.
312
+  * @note  CASE 2: CAN_RX mapped to PB8,  CAN_TX mapped to PB9 (not available on 36-pin package)
313
+  * @retval None
314
+  */
315
+#define __HAL_AFIO_REMAP_CAN1_2()  AFIO_REMAP_PARTIAL(AFIO_MAPR_CAN_REMAP_REMAP2, AFIO_MAPR_CAN_REMAP)
316
+
317
+/**
318
+  * @brief Enable or disable the remapping of CAN alternate function CAN_RX and CAN_TX in devices with a single CAN interface.
319
+  * @note  CASE 3: CAN_RX mapped to PD0,  CAN_TX mapped to PD1
320
+  * @retval None
321
+  */
322
+#define __HAL_AFIO_REMAP_CAN1_3()  AFIO_REMAP_PARTIAL(AFIO_MAPR_CAN_REMAP_REMAP3, AFIO_MAPR_CAN_REMAP)
323
+
324
+#endif
325
+
326
+/**
327
+  * @brief Enable the remapping of PD0 and PD1. When the HSE oscillator is not used
328
+  *        (application running on internal 8 MHz RC) PD0 and PD1 can be mapped on OSC_IN and
329
+  *        OSC_OUT. This is available only on 36, 48 and 64 pins packages (PD0 and PD1 are available
330
+  *        on 100-pin and 144-pin packages, no need for remapping).
331
+  * @note  ENABLE: PD0 remapped on OSC_IN, PD1 remapped on OSC_OUT.
332
+  * @retval None
333
+  */
334
+#define __HAL_AFIO_REMAP_PD01_ENABLE()  AFIO_REMAP_ENABLE(AFIO_MAPR_PD01_REMAP)
335
+
336
+/**
337
+  * @brief Disable the remapping of PD0 and PD1. When the HSE oscillator is not used
338
+  *        (application running on internal 8 MHz RC) PD0 and PD1 can be mapped on OSC_IN and
339
+  *        OSC_OUT. This is available only on 36, 48 and 64 pins packages (PD0 and PD1 are available
340
+  *        on 100-pin and 144-pin packages, no need for remapping).
341
+  * @note  DISABLE: No remapping of PD0 and PD1
342
+  * @retval None
343
+  */
344
+#define __HAL_AFIO_REMAP_PD01_DISABLE() AFIO_REMAP_DISABLE(AFIO_MAPR_PD01_REMAP)
345
+
346
+#if defined(AFIO_MAPR_TIM5CH4_IREMAP)
347
+/**
348
+  * @brief Enable the remapping of TIM5CH4.
349
+  * @note  ENABLE: LSI internal clock is connected to TIM5_CH4 input for calibration purpose.
350
+  * @note  This function is available only in high density value line devices.
351
+  * @retval None
352
+  */
353
+#define __HAL_AFIO_REMAP_TIM5CH4_ENABLE()  AFIO_REMAP_ENABLE(AFIO_MAPR_TIM5CH4_IREMAP)
354
+
355
+/**
356
+  * @brief Disable the remapping of TIM5CH4.
357
+  * @note  DISABLE: TIM5_CH4 is connected to PA3
358
+  * @note  This function is available only in high density value line devices.
359
+  * @retval None
360
+  */
361
+#define __HAL_AFIO_REMAP_TIM5CH4_DISABLE() AFIO_REMAP_DISABLE(AFIO_MAPR_TIM5CH4_IREMAP)
362
+#endif
363
+
364
+#if defined(AFIO_MAPR_ETH_REMAP)
365
+/**
366
+  * @brief Enable the remapping of Ethernet MAC connections with the PHY.
367
+  * @note  ENABLE: Remap     (RX_DV-CRS_DV/PD8, RXD0/PD9, RXD1/PD10, RXD2/PD11, RXD3/PD12)
368
+  * @note  This bit is available only in connectivity line devices and is reserved otherwise.
369
+  * @retval None
370
+  */
371
+#define __HAL_AFIO_REMAP_ETH_ENABLE()  AFIO_REMAP_ENABLE(AFIO_MAPR_ETH_REMAP)
372
+
373
+/**
374
+  * @brief Disable the remapping of Ethernet MAC connections with the PHY.
375
+  * @note  DISABLE: No remap (RX_DV-CRS_DV/PA7, RXD0/PC4, RXD1/PC5,  RXD2/PB0,  RXD3/PB1)
376
+  * @note  This bit is available only in connectivity line devices and is reserved otherwise.
377
+  * @retval None
378
+  */
379
+#define __HAL_AFIO_REMAP_ETH_DISABLE() AFIO_REMAP_DISABLE(AFIO_MAPR_ETH_REMAP)
380
+#endif
381
+
382
+#if defined(AFIO_MAPR_CAN2_REMAP)
383
+
384
+/**
385
+  * @brief Enable the remapping of CAN2 alternate function CAN2_RX and CAN2_TX.
386
+  * @note  ENABLE: Remap     (CAN2_RX/PB5,  CAN2_TX/PB6)
387
+  * @note  This bit is available only in connectivity line devices and is reserved otherwise.
388
+  * @retval None
389
+  */
390
+#define __HAL_AFIO_REMAP_CAN2_ENABLE()  AFIO_REMAP_ENABLE(AFIO_MAPR_CAN2_REMAP)
391
+
392
+/**
393
+  * @brief Disable the remapping of CAN2 alternate function CAN2_RX and CAN2_TX.
394
+  * @note  DISABLE: No remap (CAN2_RX/PB12, CAN2_TX/PB13)
395
+  * @note  This bit is available only in connectivity line devices and is reserved otherwise.
396
+  * @retval None
397
+  */
398
+#define __HAL_AFIO_REMAP_CAN2_DISABLE() AFIO_REMAP_DISABLE(AFIO_MAPR_CAN2_REMAP)
399
+#endif
400
+
401
+#if defined(AFIO_MAPR_MII_RMII_SEL)
402
+/**
403
+  * @brief Configures the Ethernet MAC internally for use with an external MII or RMII PHY.
404
+  * @note  ETH_RMII: Configure Ethernet MAC for connection with an RMII PHY
405
+  * @note  This bit is available only in connectivity line devices and is reserved otherwise.
406
+  * @retval None
407
+  */
408
+#define __HAL_AFIO_ETH_RMII() AFIO_REMAP_ENABLE(AFIO_MAPR_MII_RMII_SEL)
409
+
410
+/**
411
+  * @brief Configures the Ethernet MAC internally for use with an external MII or RMII PHY.
412
+  * @note  ETH_MII: Configure Ethernet MAC for connection with an MII PHY
413
+  * @note  This bit is available only in connectivity line devices and is reserved otherwise.
414
+  * @retval None
415
+  */
416
+#define __HAL_AFIO_ETH_MII()  AFIO_REMAP_DISABLE(AFIO_MAPR_MII_RMII_SEL)
417
+#endif
418
+
419
+/**
420
+  * @brief Enable the remapping of ADC1_ETRGINJ (ADC 1 External trigger injected conversion).
421
+  * @note  ENABLE: ADC1 External Event injected conversion is connected to TIM8 Channel4.
422
+  * @retval None
423
+  */
424
+#define __HAL_AFIO_REMAP_ADC1_ETRGINJ_ENABLE()  AFIO_REMAP_ENABLE(AFIO_MAPR_ADC1_ETRGINJ_REMAP)
425
+
426
+/**
427
+  * @brief Disable the remapping of ADC1_ETRGINJ (ADC 1 External trigger injected conversion).
428
+  * @note  DISABLE: ADC1 External trigger injected conversion is connected to EXTI15
429
+  * @retval None
430
+  */
431
+#define __HAL_AFIO_REMAP_ADC1_ETRGINJ_DISABLE() AFIO_REMAP_DISABLE(AFIO_MAPR_ADC1_ETRGINJ_REMAP)
432
+
433
+/**
434
+  * @brief Enable the remapping of ADC1_ETRGREG (ADC 1 External trigger regular conversion).
435
+  * @note  ENABLE: ADC1 External Event regular conversion is connected to TIM8 TRG0.
436
+  * @retval None
437
+  */
438
+#define __HAL_AFIO_REMAP_ADC1_ETRGREG_ENABLE()  AFIO_REMAP_ENABLE(AFIO_MAPR_ADC1_ETRGREG_REMAP)
439
+
440
+/**
441
+  * @brief Disable the remapping of ADC1_ETRGREG (ADC 1 External trigger regular conversion).
442
+  * @note  DISABLE: ADC1 External trigger regular conversion is connected to EXTI11
443
+  * @retval None
444
+  */
445
+#define __HAL_AFIO_REMAP_ADC1_ETRGREG_DISABLE() AFIO_REMAP_DISABLE(AFIO_MAPR_ADC1_ETRGREG_REMAP)
446
+
447
+#if defined(AFIO_MAPR_ADC2_ETRGINJ_REMAP)
448
+
449
+/**
450
+  * @brief Enable the remapping of ADC2_ETRGREG (ADC 2 External trigger injected conversion).
451
+  * @note  ENABLE: ADC2 External Event injected conversion is connected to TIM8 Channel4.
452
+  * @retval None
453
+  */
454
+#define __HAL_AFIO_REMAP_ADC2_ETRGINJ_ENABLE()  AFIO_REMAP_ENABLE(AFIO_MAPR_ADC2_ETRGINJ_REMAP)
455
+
456
+/**
457
+  * @brief Disable the remapping of ADC2_ETRGREG (ADC 2 External trigger injected conversion).
458
+  * @note  DISABLE: ADC2 External trigger injected conversion is connected to EXTI15
459
+  * @retval None
460
+  */
461
+#define __HAL_AFIO_REMAP_ADC2_ETRGINJ_DISABLE() AFIO_REMAP_DISABLE(AFIO_MAPR_ADC2_ETRGINJ_REMAP)
462
+#endif
463
+
464
+#if defined (AFIO_MAPR_ADC2_ETRGREG_REMAP)
465
+
466
+/**
467
+  * @brief Enable the remapping of ADC2_ETRGREG (ADC 2 External trigger regular conversion).
468
+  * @note  ENABLE: ADC2 External Event regular conversion is connected to TIM8 TRG0.
469
+  * @retval None
470
+  */
471
+#define __HAL_AFIO_REMAP_ADC2_ETRGREG_ENABLE()  AFIO_REMAP_ENABLE(AFIO_MAPR_ADC2_ETRGREG_REMAP)
472
+
473
+/**
474
+  * @brief Disable the remapping of ADC2_ETRGREG (ADC 2 External trigger regular conversion).
475
+  * @note  DISABLE: ADC2 External trigger regular conversion is connected to EXTI11
476
+  * @retval None
477
+  */
478
+#define __HAL_AFIO_REMAP_ADC2_ETRGREG_DISABLE() AFIO_REMAP_DISABLE(AFIO_MAPR_ADC2_ETRGREG_REMAP)
479
+#endif
480
+
481
+/**
482
+  * @brief Enable the Serial wire JTAG configuration
483
+  * @note  ENABLE: Full SWJ (JTAG-DP + SW-DP): Reset State
484
+  * @retval None
485
+  */
486
+#define __HAL_AFIO_REMAP_SWJ_ENABLE()  AFIO_DBGAFR_CONFIG(AFIO_MAPR_SWJ_CFG_RESET)
487
+
488
+/**
489
+  * @brief Enable the Serial wire JTAG configuration
490
+  * @note  NONJTRST: Full SWJ (JTAG-DP + SW-DP) but without NJTRST
491
+  * @retval None
492
+  */
493
+#define __HAL_AFIO_REMAP_SWJ_NONJTRST()  AFIO_DBGAFR_CONFIG(AFIO_MAPR_SWJ_CFG_NOJNTRST)
494
+
495
+/**
496
+  * @brief Enable the Serial wire JTAG configuration
497
+  * @note  NOJTAG: JTAG-DP Disabled and SW-DP Enabled
498
+  * @retval None
499
+  */
500
+
501
+#define __HAL_AFIO_REMAP_SWJ_NOJTAG()  AFIO_DBGAFR_CONFIG(AFIO_MAPR_SWJ_CFG_JTAGDISABLE)
502
+
503
+/**
504
+  * @brief Disable the Serial wire JTAG configuration
505
+  * @note  DISABLE: JTAG-DP Disabled and SW-DP Disabled
506
+  * @retval None
507
+  */
508
+#define __HAL_AFIO_REMAP_SWJ_DISABLE()  AFIO_DBGAFR_CONFIG(AFIO_MAPR_SWJ_CFG_DISABLE)
509
+
510
+#if defined(AFIO_MAPR_SPI3_REMAP)
511
+
512
+/**
513
+  * @brief Enable the remapping of SPI3 alternate functions SPI3_NSS/I2S3_WS, SPI3_SCK/I2S3_CK, SPI3_MISO, SPI3_MOSI/I2S3_SD.
514
+  * @note  ENABLE: Remap     (SPI3_NSS-I2S3_WS/PA4,  SPI3_SCK-I2S3_CK/PC10, SPI3_MISO/PC11, SPI3_MOSI-I2S3_SD/PC12)
515
+  * @note  This bit is available only in connectivity line devices and is reserved otherwise.
516
+  * @retval None
517
+  */
518
+#define __HAL_AFIO_REMAP_SPI3_ENABLE()  AFIO_REMAP_ENABLE(AFIO_MAPR_SPI3_REMAP)
519
+
520
+/**
521
+  * @brief Disable the remapping of SPI3 alternate functions SPI3_NSS/I2S3_WS, SPI3_SCK/I2S3_CK, SPI3_MISO, SPI3_MOSI/I2S3_SD.
522
+  * @note  DISABLE: No remap (SPI3_NSS-I2S3_WS/PA15, SPI3_SCK-I2S3_CK/PB3,  SPI3_MISO/PB4,  SPI3_MOSI-I2S3_SD/PB5).
523
+  * @note  This bit is available only in connectivity line devices and is reserved otherwise.
524
+  * @retval None
525
+  */
526
+#define __HAL_AFIO_REMAP_SPI3_DISABLE() AFIO_REMAP_DISABLE(AFIO_MAPR_SPI3_REMAP)
527
+#endif
528
+
529
+#if defined(AFIO_MAPR_TIM2ITR1_IREMAP)
530
+
531
+/**
532
+  * @brief Control of TIM2_ITR1 internal mapping.
533
+  * @note  TO_USB: Connect USB OTG SOF (Start of Frame) output to TIM2_ITR1 for calibration purposes.
534
+  * @note  This bit is available only in connectivity line devices and is reserved otherwise.
535
+  * @retval None
536
+  */
537
+#define __HAL_AFIO_TIM2ITR1_TO_USB() AFIO_REMAP_ENABLE(AFIO_MAPR_TIM2ITR1_IREMAP)
538
+
539
+/**
540
+  * @brief Control of TIM2_ITR1 internal mapping.
541
+  * @note  TO_ETH: Connect TIM2_ITR1 internally to the Ethernet PTP output for calibration purposes.
542
+  * @note  This bit is available only in connectivity line devices and is reserved otherwise.
543
+  * @retval None
544
+  */
545
+#define __HAL_AFIO_TIM2ITR1_TO_ETH() AFIO_REMAP_DISABLE(AFIO_MAPR_TIM2ITR1_IREMAP)
546
+#endif
547
+
548
+#if defined(AFIO_MAPR_PTP_PPS_REMAP)
549
+
550
+/**
551
+  * @brief Enable the remapping of ADC2_ETRGREG (ADC 2 External trigger regular conversion).
552
+  * @note  ENABLE: PTP_PPS is output on PB5 pin.
553
+  * @note  This bit is available only in connectivity line devices and is reserved otherwise.
554
+  * @retval None
555
+  */
556
+#define __HAL_AFIO_ETH_PTP_PPS_ENABLE()  AFIO_REMAP_ENABLE(AFIO_MAPR_PTP_PPS_REMAP)
557
+
558
+/**
559
+  * @brief Disable the remapping of ADC2_ETRGREG (ADC 2 External trigger regular conversion).
560
+  * @note  DISABLE: PTP_PPS not output on PB5 pin.
561
+  * @note  This bit is available only in connectivity line devices and is reserved otherwise.
562
+  * @retval None
563
+  */
564
+#define __HAL_AFIO_ETH_PTP_PPS_DISABLE() AFIO_REMAP_DISABLE(AFIO_MAPR_PTP_PPS_REMAP)
565
+#endif
566
+
567
+#if defined(AFIO_MAPR2_TIM9_REMAP)
568
+
569
+/**
570
+  * @brief Enable the remapping of TIM9_CH1 and TIM9_CH2.
571
+  * @note  ENABLE: Remap     (TIM9_CH1 on PE5 and TIM9_CH2 on PE6).
572
+  * @retval None
573
+  */
574
+#define __HAL_AFIO_REMAP_TIM9_ENABLE()  SET_BIT(AFIO->MAPR2, AFIO_MAPR2_TIM9_REMAP)
575
+
576
+/**
577
+  * @brief Disable the remapping of TIM9_CH1 and TIM9_CH2.
578
+  * @note  DISABLE: No remap (TIM9_CH1 on PA2 and TIM9_CH2 on PA3).
579
+  * @retval None
580
+  */
581
+#define __HAL_AFIO_REMAP_TIM9_DISABLE() CLEAR_BIT(AFIO->MAPR2, AFIO_MAPR2_TIM9_REMAP)
582
+#endif
583
+
584
+#if defined(AFIO_MAPR2_TIM10_REMAP)
585
+
586
+/**
587
+  * @brief Enable the remapping of TIM10_CH1.
588
+  * @note  ENABLE: Remap     (TIM10_CH1 on PF6).
589
+  * @retval None
590
+  */
591
+#define __HAL_AFIO_REMAP_TIM10_ENABLE()  SET_BIT(AFIO->MAPR2, AFIO_MAPR2_TIM10_REMAP)
592
+
593
+/**
594
+  * @brief Disable the remapping of TIM10_CH1.
595
+  * @note  DISABLE: No remap (TIM10_CH1 on PB8).
596
+  * @retval None
597
+  */
598
+#define __HAL_AFIO_REMAP_TIM10_DISABLE() CLEAR_BIT(AFIO->MAPR2, AFIO_MAPR2_TIM10_REMAP)
599
+#endif
600
+
601
+#if defined(AFIO_MAPR2_TIM11_REMAP)
602
+/**
603
+  * @brief Enable the remapping of TIM11_CH1.
604
+  * @note  ENABLE: Remap     (TIM11_CH1 on PF7).
605
+  * @retval None
606
+  */
607
+#define __HAL_AFIO_REMAP_TIM11_ENABLE()  SET_BIT(AFIO->MAPR2, AFIO_MAPR2_TIM11_REMAP)
608
+
609
+/**
610
+  * @brief Disable the remapping of TIM11_CH1.
611
+  * @note  DISABLE: No remap (TIM11_CH1 on PB9).
612
+  * @retval None
613
+  */
614
+#define __HAL_AFIO_REMAP_TIM11_DISABLE() CLEAR_BIT(AFIO->MAPR2, AFIO_MAPR2_TIM11_REMAP)
615
+#endif
616
+
617
+#if defined(AFIO_MAPR2_TIM13_REMAP)
618
+
619
+/**
620
+  * @brief Enable the remapping of TIM13_CH1.
621
+  * @note  ENABLE: Remap     STM32F100:(TIM13_CH1 on PF8). Others:(TIM13_CH1 on PB0).
622
+  * @retval None
623
+  */
624
+#define __HAL_AFIO_REMAP_TIM13_ENABLE()  SET_BIT(AFIO->MAPR2, AFIO_MAPR2_TIM13_REMAP)
625
+
626
+/**
627
+  * @brief Disable the remapping of TIM13_CH1.
628
+  * @note  DISABLE: No remap STM32F100:(TIM13_CH1 on PA6). Others:(TIM13_CH1 on PC8).
629
+  * @retval None
630
+  */
631
+#define __HAL_AFIO_REMAP_TIM13_DISABLE() CLEAR_BIT(AFIO->MAPR2, AFIO_MAPR2_TIM13_REMAP)
632
+#endif
633
+
634
+#if defined(AFIO_MAPR2_TIM14_REMAP)
635
+
636
+/**
637
+  * @brief Enable the remapping of TIM14_CH1.
638
+  * @note  ENABLE: Remap     STM32F100:(TIM14_CH1 on PB1). Others:(TIM14_CH1 on PF9).
639
+  * @retval None
640
+  */
641
+#define __HAL_AFIO_REMAP_TIM14_ENABLE()  SET_BIT(AFIO->MAPR2, AFIO_MAPR2_TIM14_REMAP)
642
+
643
+/**
644
+  * @brief Disable the remapping of TIM14_CH1.
645
+  * @note  DISABLE: No remap STM32F100:(TIM14_CH1 on PC9). Others:(TIM14_CH1 on PA7).
646
+  * @retval None
647
+  */
648
+#define __HAL_AFIO_REMAP_TIM14_DISABLE() CLEAR_BIT(AFIO->MAPR2, AFIO_MAPR2_TIM14_REMAP)
649
+#endif
650
+
651
+#if defined(AFIO_MAPR2_FSMC_NADV_REMAP)
652
+
653
+/**
654
+  * @brief Controls the use of the optional FSMC_NADV signal.
655
+  * @note  DISCONNECTED: The NADV signal is not connected. The I/O pin can be used by another peripheral.
656
+  * @retval None
657
+  */
658
+#define __HAL_AFIO_FSMCNADV_DISCONNECTED() SET_BIT(AFIO->MAPR2, AFIO_MAPR2_FSMC_NADV_REMAP)
659
+
660
+/**
661
+  * @brief Controls the use of the optional FSMC_NADV signal.
662
+  * @note  CONNECTED: The NADV signal is connected to the output (default).
663
+  * @retval None
664
+  */
665
+#define __HAL_AFIO_FSMCNADV_CONNECTED()    CLEAR_BIT(AFIO->MAPR2, AFIO_MAPR2_FSMC_NADV_REMAP)
666
+#endif
667
+
668
+#if defined(AFIO_MAPR2_TIM15_REMAP)
669
+
670
+/**
671
+  * @brief Enable the remapping of TIM15_CH1 and TIM15_CH2.
672
+  * @note  ENABLE: Remap     (TIM15_CH1 on PB14 and TIM15_CH2 on PB15).
673
+  * @retval None
674
+  */
675
+#define __HAL_AFIO_REMAP_TIM15_ENABLE()  SET_BIT(AFIO->MAPR2, AFIO_MAPR2_TIM15_REMAP)
676
+
677
+/**
678
+  * @brief Disable the remapping of TIM15_CH1 and TIM15_CH2.
679
+  * @note  DISABLE: No remap (TIM15_CH1 on PA2  and TIM15_CH2 on PA3).
680
+  * @retval None
681
+  */
682
+#define __HAL_AFIO_REMAP_TIM15_DISABLE() CLEAR_BIT(AFIO->MAPR2, AFIO_MAPR2_TIM15_REMAP)
683
+#endif
684
+
685
+#if defined(AFIO_MAPR2_TIM16_REMAP)
686
+
687
+/**
688
+  * @brief Enable the remapping of TIM16_CH1.
689
+  * @note  ENABLE: Remap     (TIM16_CH1 on PA6).
690
+  * @retval None
691
+  */
692
+#define __HAL_AFIO_REMAP_TIM16_ENABLE()  SET_BIT(AFIO->MAPR2, AFIO_MAPR2_TIM16_REMAP)
693
+
694
+/**
695
+  * @brief Disable the remapping of TIM16_CH1.
696
+  * @note  DISABLE: No remap (TIM16_CH1 on PB8).
697
+  * @retval None
698
+  */
699
+#define __HAL_AFIO_REMAP_TIM16_DISABLE() CLEAR_BIT(AFIO->MAPR2, AFIO_MAPR2_TIM16_REMAP)
700
+#endif
701
+
702
+#if defined(AFIO_MAPR2_TIM17_REMAP)
703
+
704
+/**
705
+  * @brief Enable the remapping of TIM17_CH1.
706
+  * @note  ENABLE: Remap     (TIM17_CH1 on PA7).
707
+  * @retval None
708
+  */
709
+#define __HAL_AFIO_REMAP_TIM17_ENABLE()  SET_BIT(AFIO->MAPR2, AFIO_MAPR2_TIM17_REMAP)
710
+
711
+/**
712
+  * @brief Disable the remapping of TIM17_CH1.
713
+  * @note  DISABLE: No remap (TIM17_CH1 on PB9).
714
+  * @retval None
715
+  */
716
+#define __HAL_AFIO_REMAP_TIM17_DISABLE() CLEAR_BIT(AFIO->MAPR2, AFIO_MAPR2_TIM17_REMAP)
717
+#endif
718
+
719
+#if defined(AFIO_MAPR2_CEC_REMAP)
720
+
721
+/**
722
+  * @brief Enable the remapping of CEC.
723
+  * @note  ENABLE: Remap     (CEC on PB10).
724
+  * @retval None
725
+  */
726
+#define __HAL_AFIO_REMAP_CEC_ENABLE()  SET_BIT(AFIO->MAPR2, AFIO_MAPR2_CEC_REMAP)
727
+
728
+/**
729
+  * @brief Disable the remapping of CEC.
730
+  * @note  DISABLE: No remap (CEC on PB8).
731
+  * @retval None
732
+  */
733
+#define __HAL_AFIO_REMAP_CEC_DISABLE() CLEAR_BIT(AFIO->MAPR2, AFIO_MAPR2_CEC_REMAP)
734
+#endif
735
+
736
+#if defined(AFIO_MAPR2_TIM1_DMA_REMAP)
737
+
738
+/**
739
+  * @brief Controls the mapping of the TIM1_CH1 TIM1_CH2 DMA requests onto the DMA1 channels.
740
+  * @note  ENABLE: Remap (TIM1_CH1 DMA request/DMA1 Channel6, TIM1_CH2 DMA request/DMA1 Channel6)
741
+  * @retval None
742
+  */
743
+#define __HAL_AFIO_REMAP_TIM1DMA_ENABLE()  SET_BIT(AFIO->MAPR2, AFIO_MAPR2_TIM1_DMA_REMAP)
744
+
745
+/**
746
+  * @brief Controls the mapping of the TIM1_CH1 TIM1_CH2 DMA requests onto the DMA1 channels.
747
+  * @note  DISABLE: No remap (TIM1_CH1 DMA request/DMA1 Channel2, TIM1_CH2 DMA request/DMA1 Channel3).
748
+  * @retval None
749
+  */
750
+#define __HAL_AFIO_REMAP_TIM1DMA_DISABLE() CLEAR_BIT(AFIO->MAPR2, AFIO_MAPR2_TIM1_DMA_REMAP)
751
+#endif
752
+
753
+#if defined(AFIO_MAPR2_TIM67_DAC_DMA_REMAP)
754
+
755
+/**
756
+  * @brief Controls the mapping of the TIM6_DAC1 and TIM7_DAC2 DMA requests onto the DMA1 channels.
757
+  * @note  ENABLE: Remap (TIM6_DAC1 DMA request/DMA1 Channel3, TIM7_DAC2 DMA request/DMA1 Channel4)
758
+  * @retval None
759
+  */
760
+#define __HAL_AFIO_REMAP_TIM67DACDMA_ENABLE()  SET_BIT(AFIO->MAPR2, AFIO_MAPR2_TIM67_DAC_DMA_REMAP)
761
+
762
+/**
763
+  * @brief Controls the mapping of the TIM6_DAC1 and TIM7_DAC2 DMA requests onto the DMA1 channels.
764
+  * @note  DISABLE: No remap (TIM6_DAC1 DMA request/DMA2 Channel3, TIM7_DAC2 DMA request/DMA2 Channel4)
765
+  * @retval None
766
+  */
767
+#define __HAL_AFIO_REMAP_TIM67DACDMA_DISABLE() CLEAR_BIT(AFIO->MAPR2, AFIO_MAPR2_TIM67_DAC_DMA_REMAP)
768
+#endif
769
+
770
+#if defined(AFIO_MAPR2_TIM12_REMAP)
771
+
772
+/**
773
+  * @brief Enable the remapping of TIM12_CH1 and TIM12_CH2.
774
+  * @note  ENABLE: Remap     (TIM12_CH1 on PB12 and TIM12_CH2 on PB13).
775
+  * @note  This bit is available only in high density value line devices.
776
+  * @retval None
777
+  */
778
+#define __HAL_AFIO_REMAP_TIM12_ENABLE()  SET_BIT(AFIO->MAPR2, AFIO_MAPR2_TIM12_REMAP)
779
+
780
+/**
781
+  * @brief Disable the remapping of TIM12_CH1 and TIM12_CH2.
782
+  * @note  DISABLE: No remap (TIM12_CH1 on PC4  and TIM12_CH2 on PC5).
783
+  * @note  This bit is available only in high density value line devices.
784
+  * @retval None
785
+  */
786
+#define __HAL_AFIO_REMAP_TIM12_DISABLE() CLEAR_BIT(AFIO->MAPR2, AFIO_MAPR2_TIM12_REMAP)
787
+#endif
788
+
789
+#if defined(AFIO_MAPR2_MISC_REMAP)
790
+
791
+/**
792
+  * @brief Miscellaneous features remapping.
793
+  *        This bit is set and cleared by software. It controls miscellaneous features.
794
+  *        The DMA2 channel 5 interrupt position in the vector table.
795
+  *        The timer selection for DAC trigger 3 (TSEL[2:0] = 011, for more details refer to the DAC_CR register).
796
+  * @note  ENABLE: DMA2 channel 5 interrupt is mapped separately at position 60 and TIM15 TRGO event is
797
+  *        selected as DAC Trigger 3, TIM15 triggers TIM1/3.
798
+  * @note  This bit is available only in high density value line devices.
799
+  * @retval None
800
+  */
801
+#define __HAL_AFIO_REMAP_MISC_ENABLE()  SET_BIT(AFIO->MAPR2, AFIO_MAPR2_MISC_REMAP)
802
+
803
+/**
804
+  * @brief Miscellaneous features remapping.
805
+  *        This bit is set and cleared by software. It controls miscellaneous features.
806
+  *        The DMA2 channel 5 interrupt position in the vector table.
807
+  *        The timer selection for DAC trigger 3 (TSEL[2:0] = 011, for more details refer to the DAC_CR register).
808
+  * @note  DISABLE: DMA2 channel 5 interrupt is mapped with DMA2 channel 4 at position 59, TIM5 TRGO
809
+  *        event is selected as DAC Trigger 3, TIM5 triggers TIM1/3.
810
+  * @note  This bit is available only in high density value line devices.
811
+  * @retval None
812
+  */
813
+#define __HAL_AFIO_REMAP_MISC_DISABLE() CLEAR_BIT(AFIO->MAPR2, AFIO_MAPR2_MISC_REMAP)
814
+#endif
815
+
816
+/**
817
+  * @}
818
+  */
819
+
820
+/**
821
+  * @}
822
+  */
823
+
824
+/** @defgroup GPIOEx_Private_Macros GPIOEx Private Macros
825
+  * @{
826
+  */
827
+#if defined(STM32F101x6) || defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6)
828
+#define GPIO_GET_INDEX(__GPIOx__) (((__GPIOx__) == (GPIOA))? 0U :\
829
+                                   ((__GPIOx__) == (GPIOB))? 1U :\
830
+                                   ((__GPIOx__) == (GPIOC))? 2U :3U)
831
+#elif defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F103xB) || defined(STM32F105xC) || defined(STM32F107xC)
832
+#define GPIO_GET_INDEX(__GPIOx__) (((__GPIOx__) == (GPIOA))? 0U :\
833
+                                   ((__GPIOx__) == (GPIOB))? 1U :\
834
+                                   ((__GPIOx__) == (GPIOC))? 2U :\
835
+                                   ((__GPIOx__) == (GPIOD))? 3U :4U)
836
+#elif defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
837
+#define GPIO_GET_INDEX(__GPIOx__) (((__GPIOx__) == (GPIOA))? 0U :\
838
+                                   ((__GPIOx__) == (GPIOB))? 1U :\
839
+                                   ((__GPIOx__) == (GPIOC))? 2U :\
840
+                                   ((__GPIOx__) == (GPIOD))? 3U :\
841
+                                   ((__GPIOx__) == (GPIOE))? 4U :\
842
+                                   ((__GPIOx__) == (GPIOF))? 5U :6U)
843
+#endif
844
+
845
+#define AFIO_REMAP_ENABLE(REMAP_PIN)       do{ uint32_t tmpreg = AFIO->MAPR; \
846
+                                               tmpreg |= AFIO_MAPR_SWJ_CFG;  \
847
+                                               tmpreg |= REMAP_PIN;          \
848
+                                               AFIO->MAPR = tmpreg;          \
849
+                                               }while(0U)
850
+
851
+#define AFIO_REMAP_DISABLE(REMAP_PIN)      do{ uint32_t tmpreg = AFIO->MAPR;  \
852
+                                               tmpreg |= AFIO_MAPR_SWJ_CFG;   \
853
+                                               tmpreg &= ~REMAP_PIN;          \
854
+                                               AFIO->MAPR = tmpreg;           \
855
+                                               }while(0U)
856
+
857
+#define AFIO_REMAP_PARTIAL(REMAP_PIN, REMAP_PIN_MASK) do{ uint32_t tmpreg = AFIO->MAPR; \
858
+                                                          tmpreg &= ~REMAP_PIN_MASK;    \
859
+                                                          tmpreg |= AFIO_MAPR_SWJ_CFG;  \
860
+                                                          tmpreg |= REMAP_PIN;          \
861
+                                                          AFIO->MAPR = tmpreg;          \
862
+                                                          }while(0U)
863
+
864
+#define AFIO_DBGAFR_CONFIG(DBGAFR_SWJCFG)  do{ uint32_t tmpreg = AFIO->MAPR;     \
865
+                                               tmpreg &= ~AFIO_MAPR_SWJ_CFG_Msk; \
866
+                                               tmpreg |= DBGAFR_SWJCFG;          \
867
+                                               AFIO->MAPR = tmpreg;              \
868
+                                               }while(0U)
869
+
870
+/**
871
+  * @}
872
+  */
873
+
874
+/* Exported macro ------------------------------------------------------------*/
875
+/* Exported functions --------------------------------------------------------*/
876
+
877
+/** @addtogroup GPIOEx_Exported_Functions
878
+  * @{
879
+  */
880
+
881
+/** @addtogroup GPIOEx_Exported_Functions_Group1
882
+  * @{
883
+  */
884
+void HAL_GPIOEx_ConfigEventout(uint32_t GPIO_PortSource, uint32_t GPIO_PinSource);
885
+void HAL_GPIOEx_EnableEventout(void);
886
+void HAL_GPIOEx_DisableEventout(void);
887
+
888
+/**
889
+  * @}
890
+  */
891
+
892
+/**
893
+  * @}
894
+  */
895
+
896
+/**
897
+  * @}
898
+  */
899
+
900
+/**
901
+  * @}
902
+  */
903
+
904
+#ifdef __cplusplus
905
+}
906
+#endif
907
+
908
+#endif /* __STM32F1xx_HAL_GPIO_EX_H */
909
+
910
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 404 - 0
Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pwr.h

@@ -0,0 +1,404 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_pwr.h
4
+  * @author  MCD Application Team
5
+  * @brief   Header file of PWR HAL module.
6
+  ******************************************************************************
7
+  * @attention
8
+  *
9
+  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
10
+  *
11
+  * Redistribution and use in source and binary forms, with or without modification,
12
+  * are permitted provided that the following conditions are met:
13
+  *   1. Redistributions of source code must retain the above copyright notice,
14
+  *      this list of conditions and the following disclaimer.
15
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
16
+  *      this list of conditions and the following disclaimer in the documentation
17
+  *      and/or other materials provided with the distribution.
18
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
19
+  *      may be used to endorse or promote products derived from this software
20
+  *      without specific prior written permission.
21
+  *
22
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+  *
33
+  ******************************************************************************
34
+  */
35
+
36
+/* Define to prevent recursive inclusion -------------------------------------*/
37
+#ifndef __STM32F1xx_HAL_PWR_H
38
+#define __STM32F1xx_HAL_PWR_H
39
+
40
+#ifdef __cplusplus
41
+ extern "C" {
42
+#endif
43
+
44
+/* Includes ------------------------------------------------------------------*/
45
+#include "stm32f1xx_hal_def.h"
46
+
47
+/** @addtogroup STM32F1xx_HAL_Driver
48
+  * @{
49
+  */
50
+
51
+/** @addtogroup PWR
52
+  * @{
53
+  */
54
+
55
+/* Exported types ------------------------------------------------------------*/
56
+
57
+/** @defgroup PWR_Exported_Types PWR Exported Types
58
+  * @{
59
+  */ 
60
+
61
+/**
62
+  * @brief  PWR PVD configuration structure definition
63
+  */
64
+typedef struct
65
+{
66
+  uint32_t PVDLevel;   /*!< PVDLevel: Specifies the PVD detection level.
67
+                            This parameter can be a value of @ref PWR_PVD_detection_level */
68
+
69
+  uint32_t Mode;      /*!< Mode: Specifies the operating mode for the selected pins.
70
+                           This parameter can be a value of @ref PWR_PVD_Mode */
71
+}PWR_PVDTypeDef;
72
+
73
+
74
+/**
75
+  * @}
76
+  */
77
+
78
+
79
+/* Internal constants --------------------------------------------------------*/
80
+
81
+/** @addtogroup PWR_Private_Constants
82
+  * @{
83
+  */ 
84
+
85
+#define PWR_EXTI_LINE_PVD  ((uint32_t)0x00010000)  /*!< External interrupt line 16 Connected to the PVD EXTI Line */
86
+
87
+/**
88
+  * @}
89
+  */
90
+
91
+ 
92
+/* Exported constants --------------------------------------------------------*/
93
+
94
+/** @defgroup PWR_Exported_Constants PWR Exported Constants
95
+  * @{
96
+  */ 
97
+
98
+/** @defgroup PWR_PVD_detection_level PWR PVD detection level
99
+  * @{
100
+  */
101
+#define PWR_PVDLEVEL_0                  PWR_CR_PLS_2V2
102
+#define PWR_PVDLEVEL_1                  PWR_CR_PLS_2V3
103
+#define PWR_PVDLEVEL_2                  PWR_CR_PLS_2V4
104
+#define PWR_PVDLEVEL_3                  PWR_CR_PLS_2V5
105
+#define PWR_PVDLEVEL_4                  PWR_CR_PLS_2V6
106
+#define PWR_PVDLEVEL_5                  PWR_CR_PLS_2V7
107
+#define PWR_PVDLEVEL_6                  PWR_CR_PLS_2V8
108
+#define PWR_PVDLEVEL_7                  PWR_CR_PLS_2V9 
109
+                                                          
110
+/**
111
+  * @}
112
+  */
113
+
114
+/** @defgroup PWR_PVD_Mode PWR PVD Mode
115
+  * @{
116
+  */
117
+#define PWR_PVD_MODE_NORMAL                 0x00000000U   /*!< basic mode is used */
118
+#define PWR_PVD_MODE_IT_RISING              0x00010001U   /*!< External Interrupt Mode with Rising edge trigger detection */
119
+#define PWR_PVD_MODE_IT_FALLING             0x00010002U   /*!< External Interrupt Mode with Falling edge trigger detection */
120
+#define PWR_PVD_MODE_IT_RISING_FALLING      0x00010003U   /*!< External Interrupt Mode with Rising/Falling edge trigger detection */
121
+#define PWR_PVD_MODE_EVENT_RISING           0x00020001U   /*!< Event Mode with Rising edge trigger detection */
122
+#define PWR_PVD_MODE_EVENT_FALLING          0x00020002U   /*!< Event Mode with Falling edge trigger detection */
123
+#define PWR_PVD_MODE_EVENT_RISING_FALLING   0x00020003U   /*!< Event Mode with Rising/Falling edge trigger detection */
124
+
125
+/**
126
+  * @}
127
+  */
128
+
129
+
130
+/** @defgroup PWR_WakeUp_Pins PWR WakeUp Pins
131
+  * @{
132
+  */
133
+
134
+#define PWR_WAKEUP_PIN1                 PWR_CSR_EWUP
135
+
136
+/**
137
+  * @}
138
+  */
139
+
140
+/** @defgroup PWR_Regulator_state_in_SLEEP_STOP_mode PWR Regulator state in SLEEP/STOP mode
141
+  * @{
142
+  */
143
+#define PWR_MAINREGULATOR_ON                        0x00000000U
144
+#define PWR_LOWPOWERREGULATOR_ON                    PWR_CR_LPDS
145
+
146
+/**
147
+  * @}
148
+  */
149
+
150
+/** @defgroup PWR_SLEEP_mode_entry PWR SLEEP mode entry
151
+  * @{
152
+  */
153
+#define PWR_SLEEPENTRY_WFI              ((uint8_t)0x01)
154
+#define PWR_SLEEPENTRY_WFE              ((uint8_t)0x02)
155
+
156
+/**
157
+  * @}
158
+  */
159
+
160
+/** @defgroup PWR_STOP_mode_entry PWR STOP mode entry
161
+  * @{
162
+  */
163
+#define PWR_STOPENTRY_WFI               ((uint8_t)0x01)
164
+#define PWR_STOPENTRY_WFE               ((uint8_t)0x02)
165
+
166
+/**
167
+  * @}
168
+  */
169
+
170
+/** @defgroup PWR_Flag PWR Flag
171
+  * @{
172
+  */
173
+#define PWR_FLAG_WU                     PWR_CSR_WUF
174
+#define PWR_FLAG_SB                     PWR_CSR_SBF
175
+#define PWR_FLAG_PVDO                   PWR_CSR_PVDO
176
+
177
+
178
+/**
179
+  * @}
180
+  */
181
+
182
+/**
183
+  * @}
184
+  */
185
+
186
+/* Exported macro ------------------------------------------------------------*/
187
+/** @defgroup PWR_Exported_Macros PWR Exported Macros
188
+  * @{
189
+  */
190
+
191
+/** @brief  Check PWR flag is set or not.
192
+  * @param  __FLAG__: specifies the flag to check.
193
+  *           This parameter can be one of the following values:
194
+  *            @arg PWR_FLAG_WU: Wake Up flag. This flag indicates that a wakeup event
195
+  *                  was received from the WKUP pin or from the RTC alarm
196
+  *                  An additional wakeup event is detected if the WKUP pin is enabled
197
+  *                  (by setting the EWUP bit) when the WKUP pin level is already high.
198
+  *            @arg PWR_FLAG_SB: StandBy flag. This flag indicates that the system was
199
+  *                  resumed from StandBy mode.
200
+  *            @arg PWR_FLAG_PVDO: PVD Output. This flag is valid only if PVD is enabled
201
+  *                  by the HAL_PWR_EnablePVD() function. The PVD is stopped by Standby mode
202
+  *                  For this reason, this bit is equal to 0 after Standby or reset
203
+  *                  until the PVDE bit is set.
204
+  * @retval The new state of __FLAG__ (TRUE or FALSE).
205
+  */
206
+#define __HAL_PWR_GET_FLAG(__FLAG__) ((PWR->CSR & (__FLAG__)) == (__FLAG__))
207
+
208
+/** @brief  Clear the PWR's pending flags.
209
+  * @param  __FLAG__: specifies the flag to clear.
210
+  *          This parameter can be one of the following values:
211
+  *            @arg PWR_FLAG_WU: Wake Up flag
212
+  *            @arg PWR_FLAG_SB: StandBy flag
213
+  */
214
+#define __HAL_PWR_CLEAR_FLAG(__FLAG__) SET_BIT(PWR->CR, ((__FLAG__) << 2))
215
+
216
+/**
217
+  * @brief Enable interrupt on PVD Exti Line 16.
218
+  * @retval None.
219
+  */
220
+#define __HAL_PWR_PVD_EXTI_ENABLE_IT()      SET_BIT(EXTI->IMR, PWR_EXTI_LINE_PVD)
221
+
222
+/**
223
+  * @brief Disable interrupt on PVD Exti Line 16. 
224
+  * @retval None.
225
+  */
226
+#define __HAL_PWR_PVD_EXTI_DISABLE_IT()     CLEAR_BIT(EXTI->IMR, PWR_EXTI_LINE_PVD)
227
+
228
+/**
229
+  * @brief Enable event on PVD Exti Line 16.
230
+  * @retval None.
231
+  */
232
+#define __HAL_PWR_PVD_EXTI_ENABLE_EVENT()   SET_BIT(EXTI->EMR, PWR_EXTI_LINE_PVD)
233
+
234
+/**
235
+  * @brief Disable event on PVD Exti Line 16.
236
+  * @retval None.
237
+  */
238
+#define __HAL_PWR_PVD_EXTI_DISABLE_EVENT()  CLEAR_BIT(EXTI->EMR, PWR_EXTI_LINE_PVD)
239
+
240
+
241
+/**
242
+  * @brief  PVD EXTI line configuration: set falling edge trigger.  
243
+  * @retval None.
244
+  */
245
+#define __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE()  SET_BIT(EXTI->FTSR, PWR_EXTI_LINE_PVD)
246
+
247
+
248
+/**
249
+  * @brief Disable the PVD Extended Interrupt Falling Trigger.
250
+  * @retval None.
251
+  */
252
+#define __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE()  CLEAR_BIT(EXTI->FTSR, PWR_EXTI_LINE_PVD)
253
+
254
+
255
+/**
256
+  * @brief  PVD EXTI line configuration: set rising edge trigger.
257
+  * @retval None.
258
+  */
259
+#define __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE()   SET_BIT(EXTI->RTSR, PWR_EXTI_LINE_PVD)
260
+
261
+/**
262
+  * @brief Disable the PVD Extended Interrupt Rising Trigger.
263
+  * This parameter can be:
264
+  * @retval None.
265
+  */
266
+#define __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE()  CLEAR_BIT(EXTI->RTSR, PWR_EXTI_LINE_PVD)
267
+
268
+/**
269
+  * @brief  PVD EXTI line configuration: set rising & falling edge trigger.
270
+  * @retval None.
271
+  */
272
+#define __HAL_PWR_PVD_EXTI_ENABLE_RISING_FALLING_EDGE()   __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE();__HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE();
273
+
274
+/**
275
+  * @brief Disable the PVD Extended Interrupt Rising & Falling Trigger.
276
+  * This parameter can be:
277
+  * @retval None.
278
+  */
279
+#define __HAL_PWR_PVD_EXTI_DISABLE_RISING_FALLING_EDGE()  __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE();__HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE();
280
+
281
+
282
+
283
+/**
284
+  * @brief Check whether the specified PVD EXTI interrupt flag is set or not.
285
+  * @retval EXTI PVD Line Status.
286
+  */
287
+#define __HAL_PWR_PVD_EXTI_GET_FLAG()       (EXTI->PR & (PWR_EXTI_LINE_PVD))
288
+
289
+/**
290
+  * @brief Clear the PVD EXTI flag.
291
+  * @retval None.
292
+  */
293
+#define __HAL_PWR_PVD_EXTI_CLEAR_FLAG()     (EXTI->PR = (PWR_EXTI_LINE_PVD))
294
+
295
+/**
296
+  * @brief Generate a Software interrupt on selected EXTI line.
297
+  * @retval None.
298
+  */
299
+#define __HAL_PWR_PVD_EXTI_GENERATE_SWIT()  SET_BIT(EXTI->SWIER, PWR_EXTI_LINE_PVD)
300
+/**
301
+  * @}
302
+  */
303
+
304
+/* Private macro -------------------------------------------------------------*/
305
+/** @defgroup PWR_Private_Macros PWR Private Macros
306
+  * @{
307
+  */
308
+#define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLEVEL_0) || ((LEVEL) == PWR_PVDLEVEL_1)|| \
309
+                                 ((LEVEL) == PWR_PVDLEVEL_2) || ((LEVEL) == PWR_PVDLEVEL_3)|| \
310
+                                 ((LEVEL) == PWR_PVDLEVEL_4) || ((LEVEL) == PWR_PVDLEVEL_5)|| \
311
+                                 ((LEVEL) == PWR_PVDLEVEL_6) || ((LEVEL) == PWR_PVDLEVEL_7))
312
+
313
+
314
+#define IS_PWR_PVD_MODE(MODE) (((MODE) == PWR_PVD_MODE_IT_RISING)|| ((MODE) == PWR_PVD_MODE_IT_FALLING) || \
315
+                              ((MODE) == PWR_PVD_MODE_IT_RISING_FALLING) || ((MODE) == PWR_PVD_MODE_EVENT_RISING) || \
316
+                              ((MODE) == PWR_PVD_MODE_EVENT_FALLING) || ((MODE) == PWR_PVD_MODE_EVENT_RISING_FALLING) || \
317
+                              ((MODE) == PWR_PVD_MODE_NORMAL)) 
318
+
319
+#define IS_PWR_WAKEUP_PIN(PIN) (((PIN) == PWR_WAKEUP_PIN1))
320
+
321
+#define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_ON) || \
322
+                                     ((REGULATOR) == PWR_LOWPOWERREGULATOR_ON))
323
+
324
+#define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPENTRY_WFI) || ((ENTRY) == PWR_SLEEPENTRY_WFE))
325
+
326
+#define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) || ((ENTRY) == PWR_STOPENTRY_WFE))
327
+
328
+/**
329
+  * @}
330
+  */
331
+
332
+
333
+
334
+/* Exported functions --------------------------------------------------------*/
335
+
336
+/** @addtogroup PWR_Exported_Functions PWR Exported Functions
337
+  * @{
338
+  */
339
+  
340
+/** @addtogroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions 
341
+  * @{
342
+  */
343
+
344
+/* Initialization and de-initialization functions *******************************/
345
+void HAL_PWR_DeInit(void);
346
+void HAL_PWR_EnableBkUpAccess(void);
347
+void HAL_PWR_DisableBkUpAccess(void);
348
+
349
+/**
350
+  * @}
351
+  */
352
+
353
+/** @addtogroup PWR_Exported_Functions_Group2 Peripheral Control functions 
354
+  * @{
355
+  */
356
+
357
+/* Peripheral Control functions  ************************************************/
358
+void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD);
359
+/* #define HAL_PWR_ConfigPVD 12*/
360
+void HAL_PWR_EnablePVD(void);
361
+void HAL_PWR_DisablePVD(void);
362
+
363
+/* WakeUp pins configuration functions ****************************************/
364
+void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx);
365
+void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx);
366
+
367
+/* Low Power modes configuration functions ************************************/
368
+void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry);
369
+void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry);
370
+void HAL_PWR_EnterSTANDBYMode(void);
371
+
372
+void HAL_PWR_EnableSleepOnExit(void);
373
+void HAL_PWR_DisableSleepOnExit(void);
374
+void HAL_PWR_EnableSEVOnPend(void);
375
+void HAL_PWR_DisableSEVOnPend(void);
376
+
377
+
378
+
379
+void HAL_PWR_PVD_IRQHandler(void);
380
+void HAL_PWR_PVDCallback(void);
381
+/**
382
+  * @}
383
+  */
384
+
385
+/**
386
+  * @}
387
+  */
388
+
389
+/**
390
+  * @}
391
+  */
392
+
393
+/**
394
+  * @}
395
+  */
396
+
397
+#ifdef __cplusplus
398
+}
399
+#endif
400
+
401
+
402
+#endif /* __STM32F1xx_HAL_PWR_H */
403
+
404
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

Разлика између датотеке није приказан због своје велике величине
+ 1393 - 0
Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc.h


Разлика између датотеке није приказан због своје велике величине
+ 1924 - 0
Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc_ex.h


Разлика између датотеке није приказан због своје велике величине
+ 1793 - 0
Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h


+ 343 - 0
Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim_ex.h

@@ -0,0 +1,343 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_tim_ex.h
4
+  * @author  MCD Application Team
5
+  * @brief   Header file of TIM HAL Extension module.
6
+  ******************************************************************************
7
+  * @attention
8
+  *
9
+  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
10
+  *
11
+  * Redistribution and use in source and binary forms, with or without modification,
12
+  * are permitted provided that the following conditions are met:
13
+  *   1. Redistributions of source code must retain the above copyright notice,
14
+  *      this list of conditions and the following disclaimer.
15
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
16
+  *      this list of conditions and the following disclaimer in the documentation
17
+  *      and/or other materials provided with the distribution.
18
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
19
+  *      may be used to endorse or promote products derived from this software
20
+  *      without specific prior written permission.
21
+  *
22
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+  *
33
+  ******************************************************************************
34
+  */ 
35
+
36
+/* Define to prevent recursive inclusion -------------------------------------*/
37
+#ifndef __STM32F1xx_HAL_TIM_EX_H
38
+#define __STM32F1xx_HAL_TIM_EX_H
39
+
40
+#ifdef __cplusplus
41
+ extern "C" {
42
+#endif
43
+
44
+/* Includes ------------------------------------------------------------------*/
45
+#include "stm32f1xx_hal_def.h"
46
+
47
+/** @addtogroup STM32F1xx_HAL_Driver
48
+  * @{
49
+  */
50
+
51
+/** @addtogroup TIMEx
52
+  * @{
53
+  */ 
54
+
55
+/* Exported types ------------------------------------------------------------*/ 
56
+/** @defgroup TIMEx_Exported_Types TIMEx Exported Types
57
+  * @{
58
+  */
59
+
60
+
61
+/** 
62
+  * @brief  TIM Hall sensor Configuration Structure definition  
63
+  */
64
+
65
+typedef struct
66
+{
67
+
68
+  uint32_t IC1Polarity;            /*!< Specifies the active edge of the input signal.
69
+                                        This parameter can be a value of @ref TIM_Input_Capture_Polarity */
70
+
71
+  uint32_t IC1Prescaler;        /*!< Specifies the Input Capture Prescaler.
72
+                                     This parameter can be a value of @ref TIM_Input_Capture_Prescaler */
73
+
74
+  uint32_t IC1Filter;           /*!< Specifies the input capture filter.
75
+                                     This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */  
76
+  uint32_t Commutation_Delay;  /*!< Specifies the pulse value to be loaded into the Capture Compare Register. 
77
+                                    This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */
78
+} TIM_HallSensor_InitTypeDef;
79
+
80
+
81
+#if defined (STM32F100xB) || defined (STM32F100xE) ||                                                   \
82
+    defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F103xE) || defined (STM32F103xG) || \
83
+    defined (STM32F105xC) || defined (STM32F107xC)
84
+
85
+/** 
86
+  * @brief  TIM Break and Dead time configuration Structure definition  
87
+  */ 
88
+typedef struct
89
+{
90
+  uint32_t OffStateRunMode;       /*!< TIM off state in run mode
91
+                                     This parameter can be a value of @ref TIM_OSSR_Off_State_Selection_for_Run_mode_state */
92
+  uint32_t OffStateIDLEMode;      /*!< TIM off state in IDLE mode
93
+                                     This parameter can be a value of @ref TIM_OSSI_Off_State_Selection_for_Idle_mode_state */
94
+  uint32_t LockLevel;             /*!< TIM Lock level
95
+                                     This parameter can be a value of @ref TIM_Lock_level */                             
96
+  uint32_t DeadTime;              /*!< TIM dead Time 
97
+                                     This parameter can be a number between Min_Data = 0x00 and Max_Data = 0xFF */
98
+  uint32_t BreakState;            /*!< TIM Break State 
99
+                                     This parameter can be a value of @ref TIM_Break_Input_enable_disable */
100
+  uint32_t BreakPolarity;         /*!< TIM Break input polarity 
101
+                                     This parameter can be a value of @ref TIM_Break_Polarity */
102
+  uint32_t AutomaticOutput;       /*!< TIM Automatic Output Enable state 
103
+                                     This parameter can be a value of @ref TIM_AOE_Bit_Set_Reset */           
104
+} TIM_BreakDeadTimeConfigTypeDef;
105
+
106
+#endif /* defined(STM32F100xB) || defined(STM32F100xE) ||                                                 */
107
+       /* defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || */
108
+       /* defined(STM32F105xC) || defined(STM32F107xC)                                                    */
109
+
110
+/** 
111
+  * @brief  TIM Master configuration Structure definition  
112
+  */ 
113
+typedef struct {
114
+  uint32_t  MasterOutputTrigger;   /*!< Trigger output (TRGO) selection 
115
+                                      This parameter can be a value of @ref TIM_Master_Mode_Selection */ 
116
+  uint32_t  MasterSlaveMode;       /*!< Master/slave mode selection 
117
+                                      This parameter can be a value of @ref TIM_Master_Slave_Mode */
118
+}TIM_MasterConfigTypeDef;
119
+
120
+/**
121
+  * @}
122
+  */ 
123
+
124
+/* Exported constants --------------------------------------------------------*/
125
+#if defined (STM32F100xB) || defined (STM32F100xE) ||                                                   \
126
+    defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F103xE) || defined (STM32F103xG) || \
127
+    defined (STM32F105xC) || defined (STM32F107xC)
128
+/** @defgroup TIMEx_Exported_Constants TIMEx Exported Constants
129
+  * @{
130
+  */
131
+    
132
+/** @defgroup TIMEx_Clock_Filter TIMEx Clock Filter
133
+  * @{
134
+  */
135
+#define IS_TIM_DEADTIME(DEADTIME)      ((DEADTIME) <= 0xFFU)          /*!< BreakDead Time */
136
+/**
137
+  * @}
138
+  */
139
+
140
+/**
141
+  * @}
142
+  */
143
+#endif /* defined(STM32F100xB) || defined(STM32F100xE) ||                                                 */
144
+       /* defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || */
145
+       /* defined(STM32F105xC) || defined(STM32F107xC)                                                    */
146
+
147
+/* Exported macro ------------------------------------------------------------*/
148
+/**
149
+  * @brief  Sets the TIM Output compare preload.
150
+  * @param  __HANDLE__: TIM handle.
151
+  * @param  __CHANNEL__: TIM Channels to be configured.
152
+  *          This parameter can be one of the following values:
153
+  *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
154
+  *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
155
+  *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
156
+  *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
157
+  * @retval None
158
+  */
159
+#define __HAL_TIM_ENABLE_OCxPRELOAD(__HANDLE__, __CHANNEL__)    \
160
+        (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 |= TIM_CCMR1_OC1PE) :\
161
+         ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCMR1 |= TIM_CCMR1_OC2PE) :\
162
+         ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 |= TIM_CCMR2_OC3PE) :\
163
+         ((__HANDLE__)->Instance->CCMR2 |= TIM_CCMR2_OC4PE))
164
+
165
+/**
166
+  * @brief  Resets the TIM Output compare preload.
167
+  * @param  __HANDLE__: TIM handle.
168
+  * @param  __CHANNEL__: TIM Channels to be configured.
169
+  *          This parameter can be one of the following values:
170
+  *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
171
+  *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
172
+  *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
173
+  *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
174
+  * @retval None
175
+  */
176
+#define __HAL_TIM_DISABLE_OCxPRELOAD(__HANDLE__, __CHANNEL__)    \
177
+        (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 &= (uint16_t)~TIM_CCMR1_OC1PE) :\
178
+         ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCMR1 &= (uint16_t)~TIM_CCMR1_OC2PE) :\
179
+         ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 &= (uint16_t)~TIM_CCMR2_OC3PE) :\
180
+         ((__HANDLE__)->Instance->CCMR2 &= (uint16_t)~TIM_CCMR2_OC4PE))
181
+
182
+/* Exported functions --------------------------------------------------------*/
183
+/** @addtogroup TIMEx_Exported_Functions
184
+  * @{
185
+  */
186
+
187
+/** @addtogroup TIMEx_Exported_Functions_Group1
188
+  * @{
189
+ */
190
+/* Timer Hall Sensor functions  **********************************************/
191
+HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSensor_InitTypeDef* sConfig);
192
+HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim);
193
+
194
+void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim);
195
+void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim);
196
+
197
+ /* Blocking mode: Polling */
198
+HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim);
199
+HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim);
200
+/* Non-Blocking mode: Interrupt */
201
+HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim);
202
+HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim);
203
+/* Non-Blocking mode: DMA */
204
+HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length);
205
+HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim);
206
+/**
207
+  * @}
208
+  */
209
+
210
+#if defined (STM32F100xB) || defined (STM32F100xE) ||                                                   \
211
+    defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F103xE) || defined (STM32F103xG) || \
212
+    defined (STM32F105xC) || defined (STM32F107xC)
213
+
214
+/** @addtogroup TIMEx_Exported_Functions_Group2
215
+ * @{
216
+ */
217
+/* Timer Complementary Output Compare functions  *****************************/
218
+/* Blocking mode: Polling */
219
+HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
220
+HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
221
+
222
+/* Non-Blocking mode: Interrupt */
223
+HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
224
+HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
225
+
226
+/* Non-Blocking mode: DMA */
227
+HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
228
+HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
229
+/**
230
+  * @}
231
+  */
232
+
233
+/** @addtogroup TIMEx_Exported_Functions_Group3
234
+ * @{
235
+ */
236
+/* Timer Complementary PWM functions  ****************************************/
237
+/* Blocking mode: Polling */
238
+HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
239
+HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
240
+
241
+/* Non-Blocking mode: Interrupt */
242
+HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
243
+HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
244
+/* Non-Blocking mode: DMA */
245
+HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
246
+HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
247
+/**
248
+  * @}
249
+  */
250
+
251
+/** @addtogroup TIMEx_Exported_Functions_Group4
252
+ * @{
253
+ */
254
+/* Timer Complementary One Pulse functions  **********************************/
255
+/* Blocking mode: Polling */
256
+HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
257
+HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
258
+
259
+/* Non-Blocking mode: Interrupt */
260
+HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
261
+HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
262
+/**
263
+  * @}
264
+  */
265
+#endif /* defined(STM32F100xB) || defined(STM32F100xE) ||                                                 */
266
+       /* defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || */
267
+       /* defined(STM32F105xC) || defined(STM32F107xC)                                                    */
268
+
269
+/** @addtogroup TIMEx_Exported_Functions_Group5
270
+ * @{
271
+ */
272
+/* Extended Control functions  ************************************************/
273
+#if defined (STM32F100xB) || defined (STM32F100xE) ||                                                   \
274
+    defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F103xE) || defined (STM32F103xG) || \
275
+    defined (STM32F105xC) || defined (STM32F107xC)
276
+HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent(TIM_HandleTypeDef *htim, uint32_t  InputTrigger, uint32_t  CommutationSource);
277
+HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_IT(TIM_HandleTypeDef *htim, uint32_t  InputTrigger, uint32_t  CommutationSource);
278
+HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_DMA(TIM_HandleTypeDef *htim, uint32_t  InputTrigger, uint32_t  CommutationSource);
279
+HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim, TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig);
280
+#endif /* defined(STM32F100xB) || defined(STM32F100xE) ||                                                 */
281
+       /* defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || */
282
+       /* defined(STM32F105xC) || defined(STM32F107xC)                                                    */
283
+HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim, TIM_MasterConfigTypeDef * sMasterConfig);
284
+/**
285
+  * @}
286
+  */
287
+
288
+/** @addtogroup TIMEx_Exported_Functions_Group6
289
+  * @{
290
+  */
291
+/* Extension Callback *********************************************************/
292
+void HAL_TIMEx_CommutationCallback(TIM_HandleTypeDef *htim);
293
+void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim);
294
+/**
295
+  * @}
296
+  */
297
+
298
+#if defined (STM32F100xB) || defined (STM32F100xE) ||                                                   \
299
+    defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F103xE) || defined (STM32F103xG) || \
300
+    defined (STM32F105xC) || defined (STM32F107xC)
301
+/** @addtogroup TIMEx_Exported_Functions_Group7
302
+  * @{
303
+  */
304
+/* Extension Peripheral State functions  **************************************/
305
+HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim);
306
+/**
307
+  * @}
308
+  */
309
+#endif /* defined(STM32F100xB) || defined(STM32F100xE) ||                                                 */
310
+       /* defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || */
311
+       /* defined(STM32F105xC) || defined(STM32F107xC)                                                    */
312
+
313
+/**
314
+  * @}
315
+  */ 
316
+/* End of exported functions -------------------------------------------------*/
317
+
318
+/* Private functions----------------------------------------------------------*/
319
+/** @defgroup TIMEx_Private_Functions TIMEx Private Functions
320
+* @{
321
+*/
322
+void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma);
323
+/**
324
+* @}
325
+*/ 
326
+/* End of private functions --------------------------------------------------*/
327
+
328
+/**
329
+  * @}
330
+  */ 
331
+
332
+/**
333
+  * @}
334
+  */
335
+  
336
+#ifdef __cplusplus
337
+}
338
+#endif
339
+
340
+
341
+#endif /* __STM32F1xx_HAL_TIM_EX_H */
342
+
343
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 785 - 0
Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_uart.h

@@ -0,0 +1,785 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_uart.h
4
+  * @author  MCD Application Team
5
+  * @brief   Header file of UART HAL module.
6
+  ******************************************************************************
7
+  * @attention
8
+  *
9
+  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
10
+  *
11
+  * Redistribution and use in source and binary forms, with or without modification,
12
+  * are permitted provided that the following conditions are met:
13
+  *   1. Redistributions of source code must retain the above copyright notice,
14
+  *      this list of conditions and the following disclaimer.
15
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
16
+  *      this list of conditions and the following disclaimer in the documentation
17
+  *      and/or other materials provided with the distribution.
18
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
19
+  *      may be used to endorse or promote products derived from this software
20
+  *      without specific prior written permission.
21
+  *
22
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+  *
33
+  ******************************************************************************
34
+  */
35
+
36
+/* Define to prevent recursive inclusion -------------------------------------*/
37
+#ifndef __STM32F1xx_HAL_UART_H
38
+#define __STM32F1xx_HAL_UART_H
39
+
40
+#ifdef __cplusplus
41
+ extern "C" {
42
+#endif
43
+
44
+/* Includes ------------------------------------------------------------------*/
45
+#include "stm32f1xx_hal_def.h"
46
+
47
+/** @addtogroup STM32F1xx_HAL_Driver
48
+  * @{
49
+  */
50
+
51
+/** @addtogroup UART
52
+  * @{
53
+  */
54
+
55
+/* Exported types ------------------------------------------------------------*/ 
56
+/** @defgroup UART_Exported_Types UART Exported Types
57
+  * @{
58
+  */
59
+
60
+/**
61
+  * @brief UART Init Structure definition
62
+  */
63
+typedef struct
64
+{
65
+  uint32_t BaudRate;                  /*!< This member configures the UART communication baud rate.
66
+                                           The baud rate is computed using the following formula:
67
+                                           - IntegerDivider = ((PCLKx) / (16 * (huart->Init.BaudRate)))
68
+                                           - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 16) + 0.5 */
69
+
70
+  uint32_t WordLength;                /*!< Specifies the number of data bits transmitted or received in a frame.
71
+                                           This parameter can be a value of @ref UART_Word_Length */
72
+
73
+  uint32_t StopBits;                  /*!< Specifies the number of stop bits transmitted.
74
+                                           This parameter can be a value of @ref UART_Stop_Bits */
75
+
76
+  uint32_t Parity;                    /*!< Specifies the parity mode.
77
+                                           This parameter can be a value of @ref UART_Parity
78
+                                           @note When parity is enabled, the computed parity is inserted
79
+                                                 at the MSB position of the transmitted data (9th bit when
80
+                                                 the word length is set to 9 data bits; 8th bit when the
81
+                                                 word length is set to 8 data bits). */
82
+
83
+  uint32_t Mode;                      /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
84
+                                           This parameter can be a value of @ref UART_Mode */
85
+
86
+  uint32_t HwFlowCtl;                 /*!< Specifies whether the hardware flow control mode is enabled or disabled.
87
+                                           This parameter can be a value of @ref UART_Hardware_Flow_Control */
88
+
89
+  uint32_t OverSampling;              /*!< Specifies whether the Over sampling 8 is enabled or disabled, to achieve higher speed (up to fPCLK/8).
90
+                                           This parameter can be a value of @ref UART_Over_Sampling. This feature is only available 
91
+                                           on STM32F100xx family, so OverSampling parameter should always be set to 16. */
92
+}UART_InitTypeDef;
93
+
94
+/** 
95
+  * @brief HAL UART State structures definition
96
+  * @note  HAL UART State value is a combination of 2 different substates: gState and RxState.
97
+  *        - gState contains UART state information related to global Handle management 
98
+  *          and also information related to Tx operations.
99
+  *          gState value coding follow below described bitmap :
100
+  *          b7-b6  Error information 
101
+  *             00 : No Error
102
+  *             01 : (Not Used)
103
+  *             10 : Timeout
104
+  *             11 : Error
105
+  *          b5     IP initilisation status
106
+  *             0  : Reset (IP not initialized)
107
+  *             1  : Init done (IP not initialized. HAL UART Init function already called)
108
+  *          b4-b3  (not used)
109
+  *             xx : Should be set to 00
110
+  *          b2     Intrinsic process state
111
+  *             0  : Ready
112
+  *             1  : Busy (IP busy with some configuration or internal operations)
113
+  *          b1     (not used)
114
+  *             x  : Should be set to 0
115
+  *          b0     Tx state
116
+  *             0  : Ready (no Tx operation ongoing)
117
+  *             1  : Busy (Tx operation ongoing)
118
+  *        - RxState contains information related to Rx operations.
119
+  *          RxState value coding follow below described bitmap :
120
+  *          b7-b6  (not used)
121
+  *             xx : Should be set to 00
122
+  *          b5     IP initilisation status
123
+  *             0  : Reset (IP not initialized)
124
+  *             1  : Init done (IP not initialized)
125
+  *          b4-b2  (not used)
126
+  *            xxx : Should be set to 000
127
+  *          b1     Rx state
128
+  *             0  : Ready (no Rx operation ongoing)
129
+  *             1  : Busy (Rx operation ongoing)
130
+  *          b0     (not used)
131
+  *             x  : Should be set to 0.
132
+  */
133
+typedef enum
134
+{
135
+  HAL_UART_STATE_RESET             = 0x00U,    /*!< Peripheral is not yet Initialized 
136
+                                                   Value is allowed for gState and RxState */
137
+  HAL_UART_STATE_READY             = 0x20U,    /*!< Peripheral Initialized and ready for use
138
+                                                   Value is allowed for gState and RxState */
139
+  HAL_UART_STATE_BUSY              = 0x24U,    /*!< an internal process is ongoing
140
+                                                   Value is allowed for gState only */
141
+  HAL_UART_STATE_BUSY_TX           = 0x21U,    /*!< Data Transmission process is ongoing 
142
+                                                   Value is allowed for gState only */
143
+  HAL_UART_STATE_BUSY_RX           = 0x22U,    /*!< Data Reception process is ongoing
144
+                                                   Value is allowed for RxState only */
145
+  HAL_UART_STATE_BUSY_TX_RX        = 0x23U,    /*!< Data Transmission and Reception process is ongoing 
146
+                                                   Not to be used for neither gState nor RxState.
147
+                                                   Value is result of combination (Or) between gState and RxState values */
148
+  HAL_UART_STATE_TIMEOUT           = 0xA0U,    /*!< Timeout state    
149
+                                                   Value is allowed for gState only */
150
+  HAL_UART_STATE_ERROR             = 0xE0U     /*!< Error   
151
+                                                   Value is allowed for gState only */
152
+}HAL_UART_StateTypeDef;
153
+
154
+/** 
155
+  * @brief  UART handle Structure definition
156
+  */
157
+typedef struct
158
+{
159
+  USART_TypeDef                 *Instance;        /*!< UART registers base address        */
160
+
161
+  UART_InitTypeDef              Init;             /*!< UART communication parameters      */
162
+
163
+  uint8_t                       *pTxBuffPtr;      /*!< Pointer to UART Tx transfer Buffer */
164
+
165
+  uint16_t                      TxXferSize;       /*!< UART Tx Transfer size              */
166
+
167
+  __IO uint16_t                 TxXferCount;      /*!< UART Tx Transfer Counter           */
168
+
169
+  uint8_t                       *pRxBuffPtr;      /*!< Pointer to UART Rx transfer Buffer */
170
+
171
+  uint16_t                      RxXferSize;       /*!< UART Rx Transfer size              */
172
+
173
+  __IO uint16_t                 RxXferCount;      /*!< UART Rx Transfer Counter           */
174
+
175
+  DMA_HandleTypeDef             *hdmatx;          /*!< UART Tx DMA Handle parameters      */
176
+
177
+  DMA_HandleTypeDef             *hdmarx;          /*!< UART Rx DMA Handle parameters      */
178
+
179
+  HAL_LockTypeDef               Lock;             /*!< Locking object                     */
180
+
181
+  __IO HAL_UART_StateTypeDef    gState;           /*!< UART state information related to global Handle management 
182
+                                                       and also related to Tx operations.
183
+                                                       This parameter can be a value of @ref HAL_UART_StateTypeDef */
184
+  
185
+  __IO HAL_UART_StateTypeDef    RxState;          /*!< UART state information related to Rx operations.
186
+                                                       This parameter can be a value of @ref HAL_UART_StateTypeDef */
187
+
188
+  __IO uint32_t                 ErrorCode;        /*!< UART Error code                    */
189
+}UART_HandleTypeDef;
190
+
191
+/**
192
+  * @}
193
+  */
194
+
195
+/* Exported constants --------------------------------------------------------*/
196
+/** @defgroup UART_Exported_Constants UART Exported constants
197
+  * @{
198
+  */
199
+
200
+/** @defgroup UART_Error_Code UART Error Code
201
+  * @{
202
+  */
203
+#define HAL_UART_ERROR_NONE         0x00000000U   /*!< No error            */
204
+#define HAL_UART_ERROR_PE           0x00000001U   /*!< Parity error        */
205
+#define HAL_UART_ERROR_NE           0x00000002U   /*!< Noise error         */
206
+#define HAL_UART_ERROR_FE           0x00000004U   /*!< Frame error         */
207
+#define HAL_UART_ERROR_ORE          0x00000008U   /*!< Overrun error       */
208
+#define HAL_UART_ERROR_DMA          0x00000010U   /*!< DMA transfer error  */
209
+/**
210
+  * @}
211
+  */
212
+
213
+/** @defgroup UART_Word_Length UART Word Length
214
+  * @{
215
+  */
216
+#define UART_WORDLENGTH_8B                  0x00000000U
217
+#define UART_WORDLENGTH_9B                  ((uint32_t)USART_CR1_M)
218
+/**
219
+  * @}
220
+  */
221
+
222
+/** @defgroup UART_Stop_Bits  UART Number of Stop Bits
223
+  * @{
224
+  */
225
+#define UART_STOPBITS_1                     0x00000000U
226
+#define UART_STOPBITS_2                     ((uint32_t)USART_CR2_STOP_1)
227
+/**
228
+  * @}
229
+  */
230
+
231
+/** @defgroup UART_Parity  UART Parity
232
+  * @{
233
+  */
234
+#define UART_PARITY_NONE                    0x00000000U
235
+#define UART_PARITY_EVEN                    ((uint32_t)USART_CR1_PCE)
236
+#define UART_PARITY_ODD                     ((uint32_t)(USART_CR1_PCE | USART_CR1_PS)) 
237
+/**
238
+  * @}
239
+  */
240
+
241
+/** @defgroup UART_Hardware_Flow_Control UART Hardware Flow Control
242
+  * @{
243
+  */
244
+#define UART_HWCONTROL_NONE                  0x00000000U
245
+#define UART_HWCONTROL_RTS                   ((uint32_t)USART_CR3_RTSE)
246
+#define UART_HWCONTROL_CTS                   ((uint32_t)USART_CR3_CTSE)
247
+#define UART_HWCONTROL_RTS_CTS               ((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE))
248
+/**
249
+  * @}
250
+  */
251
+
252
+/** @defgroup UART_Mode UART Transfer Mode
253
+  * @{
254
+  */ 
255
+#define UART_MODE_RX                        ((uint32_t)USART_CR1_RE)
256
+#define UART_MODE_TX                        ((uint32_t)USART_CR1_TE)
257
+#define UART_MODE_TX_RX                     ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
258
+/**
259
+  * @}
260
+  */
261
+
262
+/** @defgroup UART_State  UART State
263
+  * @{
264
+  */
265
+#define UART_STATE_DISABLE                  0x00000000U
266
+#define UART_STATE_ENABLE                   ((uint32_t)USART_CR1_UE)
267
+/**
268
+  * @}
269
+  */
270
+
271
+
272
+/** @defgroup UART_Over_Sampling UART Over Sampling
273
+  * @{
274
+  */
275
+#define UART_OVERSAMPLING_16                    0x00000000U
276
+#if defined(USART_CR1_OVER8)
277
+#define UART_OVERSAMPLING_8                     ((uint32_t)USART_CR1_OVER8)
278
+#endif /* USART_CR1_OVER8 */
279
+/**
280
+  * @}
281
+  */
282
+
283
+
284
+/** @defgroup UART_LIN_Break_Detection_Length  UART LIN Break Detection Length
285
+  * @{
286
+  */  
287
+#define UART_LINBREAKDETECTLENGTH_10B      0x00000000U
288
+#define UART_LINBREAKDETECTLENGTH_11B      ((uint32_t)USART_CR2_LBDL)
289
+/**
290
+  * @}
291
+  */
292
+/** @defgroup UART_WakeUp_functions  UART Wakeup Functions
293
+  * @{
294
+  */
295
+#define UART_WAKEUPMETHOD_IDLELINE                0x00000000U
296
+#define UART_WAKEUPMETHOD_ADDRESSMARK             ((uint32_t)USART_CR1_WAKE)
297
+/**
298
+  * @}
299
+  */
300
+
301
+/** @defgroup UART_Flags   UART FLags
302
+  *        Elements values convention: 0xXXXX
303
+  *           - 0xXXXX  : Flag mask in the SR register
304
+  * @{
305
+  */
306
+#define UART_FLAG_CTS                       ((uint32_t)USART_SR_CTS)
307
+#define UART_FLAG_LBD                       ((uint32_t)USART_SR_LBD)
308
+#define UART_FLAG_TXE                       ((uint32_t)USART_SR_TXE)
309
+#define UART_FLAG_TC                        ((uint32_t)USART_SR_TC)
310
+#define UART_FLAG_RXNE                      ((uint32_t)USART_SR_RXNE)
311
+#define UART_FLAG_IDLE                      ((uint32_t)USART_SR_IDLE)
312
+#define UART_FLAG_ORE                       ((uint32_t)USART_SR_ORE)
313
+#define UART_FLAG_NE                        ((uint32_t)USART_SR_NE)
314
+#define UART_FLAG_FE                        ((uint32_t)USART_SR_FE)
315
+#define UART_FLAG_PE                        ((uint32_t)USART_SR_PE)
316
+/**
317
+  * @}
318
+  */
319
+
320
+/** @defgroup UART_Interrupt_definition  UART Interrupt Definitions
321
+  *        Elements values convention: 0xY000XXXX
322
+  *           - XXXX  : Interrupt mask (16 bits) in the Y register
323
+  *           - Y  : Interrupt source register (2bits)
324
+  *                   - 01: CR1 register
325
+  *                   - 10: CR2 register
326
+  *                   - 11: CR3 register
327
+  * @{
328
+  */
329
+
330
+#define UART_IT_PE                       ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_PEIE))
331
+#define UART_IT_TXE                      ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_TXEIE))
332
+#define UART_IT_TC                       ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_TCIE))
333
+#define UART_IT_RXNE                     ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_RXNEIE))
334
+#define UART_IT_IDLE                     ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_IDLEIE))
335
+
336
+#define UART_IT_LBD                      ((uint32_t)(UART_CR2_REG_INDEX << 28U | USART_CR2_LBDIE))
337
+
338
+#define UART_IT_CTS                      ((uint32_t)(UART_CR3_REG_INDEX << 28U | USART_CR3_CTSIE))
339
+#define UART_IT_ERR                      ((uint32_t)(UART_CR3_REG_INDEX << 28U | USART_CR3_EIE))
340
+/**
341
+  * @}
342
+  */
343
+
344
+/**
345
+  * @}
346
+  */
347
+
348
+/* Exported macro ------------------------------------------------------------*/
349
+/** @defgroup UART_Exported_Macros UART Exported Macros
350
+  * @{
351
+  */
352
+
353
+/** @brief Reset UART handle gstate & RxState
354
+  * @param  __HANDLE__: specifies the UART Handle.
355
+  *         UART Handle selects the USARTx or UARTy peripheral 
356
+  *         (USART,UART availability and x,y values depending on device).
357
+  */
358
+#define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__)  do{                                                   \
359
+                                                       (__HANDLE__)->gState = HAL_UART_STATE_RESET;      \
360
+                                                       (__HANDLE__)->RxState = HAL_UART_STATE_RESET;     \
361
+                                                     } while(0U)
362
+
363
+/** @brief  Flushs the UART DR register 
364
+  * @param  __HANDLE__: specifies the UART Handle.
365
+  *         UART Handle selects the USARTx or UARTy peripheral 
366
+  *         (USART,UART availability and x,y values depending on device).
367
+  */
368
+#define __HAL_UART_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR)
369
+
370
+/** @brief  Checks whether the specified UART flag is set or not.
371
+  * @param  __HANDLE__: specifies the UART Handle.
372
+  *         This parameter can be UARTx where x: 1, 2, 3, 4 or 5 to select the USART or 
373
+  *         UART peripheral.
374
+  * @param  __FLAG__: specifies the flag to check.
375
+  *        This parameter can be one of the following values:
376
+  *            @arg UART_FLAG_CTS:  CTS Change flag (not available for UART4 and UART5)
377
+  *            @arg UART_FLAG_LBD:  LIN Break detection flag
378
+  *            @arg UART_FLAG_TXE:  Transmit data register empty flag
379
+  *            @arg UART_FLAG_TC:   Transmission Complete flag
380
+  *            @arg UART_FLAG_RXNE: Receive data register not empty flag
381
+  *            @arg UART_FLAG_IDLE: Idle Line detection flag
382
+  *            @arg UART_FLAG_ORE:  OverRun Error flag
383
+  *            @arg UART_FLAG_NE:   Noise Error flag
384
+  *            @arg UART_FLAG_FE:   Framing Error flag
385
+  *            @arg UART_FLAG_PE:   Parity Error flag
386
+  * @retval The new state of __FLAG__ (TRUE or FALSE).
387
+  */
388
+#define __HAL_UART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))   
389
+
390
+/** @brief  Clears the specified UART pending flag.
391
+  * @param  __HANDLE__: specifies the UART Handle.
392
+  *         UART Handle selects the USARTx or UARTy peripheral 
393
+  *         (USART,UART availability and x,y values depending on device).
394
+  * @param  __FLAG__: specifies the flag to check.
395
+  *          This parameter can be any combination of the following values:
396
+  *            @arg UART_FLAG_CTS:  CTS Change flag (not available for UART4 and UART5).
397
+  *            @arg UART_FLAG_LBD:  LIN Break detection flag.
398
+  *            @arg UART_FLAG_TC:   Transmission Complete flag.
399
+  *            @arg UART_FLAG_RXNE: Receive data register not empty flag.
400
+  *   
401
+  * @note   PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun 
402
+  *          error) and IDLE (Idle line detected) flags are cleared by software 
403
+  *          sequence: a read operation to USART_SR register followed by a read
404
+  *          operation to USART_DR register.
405
+  * @note   RXNE flag can be also cleared by a read to the USART_DR register.
406
+  * @note   TC flag can be also cleared by software sequence: a read operation to 
407
+  *          USART_SR register followed by a write operation to USART_DR register.
408
+  * @note   TXE flag is cleared only by a write to the USART_DR register.
409
+  *   
410
+  */
411
+#define __HAL_UART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
412
+
413
+/** @brief  Clears the UART PE pending flag.
414
+  * @param  __HANDLE__: specifies the UART Handle.
415
+  *         UART Handle selects the USARTx or UARTy peripheral 
416
+  *         (USART,UART availability and x,y values depending on device).
417
+  */
418
+#define __HAL_UART_CLEAR_PEFLAG(__HANDLE__)     \
419
+  do{                                           \
420
+    __IO uint32_t tmpreg = 0x00U;               \
421
+    tmpreg = (__HANDLE__)->Instance->SR;        \
422
+    tmpreg = (__HANDLE__)->Instance->DR;        \
423
+    UNUSED(tmpreg);                             \
424
+  } while(0U)
425
+
426
+/** @brief  Clears the UART FE pending flag.
427
+  * @param  __HANDLE__: specifies the UART Handle.
428
+  *         UART Handle selects the USARTx or UARTy peripheral 
429
+  *         (USART,UART availability and x,y values depending on device).
430
+  */
431
+#define __HAL_UART_CLEAR_FEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
432
+
433
+/** @brief  Clears the UART NE pending flag.
434
+  * @param  __HANDLE__: specifies the UART Handle.
435
+  *         UART Handle selects the USARTx or UARTy peripheral 
436
+  *         (USART,UART availability and x,y values depending on device).
437
+  */
438
+#define __HAL_UART_CLEAR_NEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
439
+
440
+/** @brief  Clears the UART ORE pending flag.
441
+  * @param  __HANDLE__: specifies the UART Handle.
442
+  *         UART Handle selects the USARTx or UARTy peripheral 
443
+  *         (USART,UART availability and x,y values depending on device).
444
+  */
445
+#define __HAL_UART_CLEAR_OREFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
446
+
447
+/** @brief  Clears the UART IDLE pending flag.
448
+  * @param  __HANDLE__: specifies the UART Handle.
449
+  *         UART Handle selects the USARTx or UARTy peripheral 
450
+  *         (USART,UART availability and x,y values depending on device).
451
+  */
452
+#define __HAL_UART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
453
+
454
+/** @brief  Enable the specified UART interrupt.
455
+  * @param  __HANDLE__: specifies the UART Handle.
456
+  *         UART Handle selects the USARTx or UARTy peripheral 
457
+  *         (USART,UART availability and x,y values depending on device).
458
+  * @param  __INTERRUPT__: specifies the UART interrupt source to enable.
459
+  *          This parameter can be one of the following values:
460
+  *            @arg UART_IT_CTS:  CTS change interrupt
461
+  *            @arg UART_IT_LBD:  LIN Break detection interrupt
462
+  *            @arg UART_IT_TXE:  Transmit Data Register empty interrupt
463
+  *            @arg UART_IT_TC:   Transmission complete interrupt
464
+  *            @arg UART_IT_RXNE: Receive Data register not empty interrupt
465
+  *            @arg UART_IT_IDLE: Idle line detection interrupt
466
+  *            @arg UART_IT_PE:   Parity Error interrupt
467
+  *            @arg UART_IT_ERR:  Error interrupt(Frame error, noise error, overrun error)
468
+  */
469
+#define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__)   ((((__INTERRUPT__) >> 28U) == UART_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & UART_IT_MASK)): \
470
+                                                           (((__INTERRUPT__) >> 28U) == UART_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 |= ((__INTERRUPT__) & UART_IT_MASK)): \
471
+                                                           ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & UART_IT_MASK)))
472
+
473
+/** @brief  Disable the specified UART interrupt.
474
+  * @param  __HANDLE__: specifies the UART Handle.
475
+  *         UART Handle selects the USARTx or UARTy peripheral 
476
+  *         (USART,UART availability and x,y values depending on device).
477
+  * @param  __INTERRUPT__: specifies the UART interrupt source to disable.
478
+  *          This parameter can be one of the following values:
479
+  *            @arg UART_IT_CTS:  CTS change interrupt
480
+  *            @arg UART_IT_LBD:  LIN Break detection interrupt
481
+  *            @arg UART_IT_TXE:  Transmit Data Register empty interrupt
482
+  *            @arg UART_IT_TC:   Transmission complete interrupt
483
+  *            @arg UART_IT_RXNE: Receive Data register not empty interrupt
484
+  *            @arg UART_IT_IDLE: Idle line detection interrupt
485
+  *            @arg UART_IT_PE:   Parity Error interrupt
486
+  *            @arg UART_IT_ERR:  Error interrupt(Frame error, noise error, overrun error)
487
+  */
488
+#define __HAL_UART_DISABLE_IT(__HANDLE__, __INTERRUPT__)  ((((__INTERRUPT__) >> 28U) == UART_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & UART_IT_MASK)): \
489
+                                                           (((__INTERRUPT__) >> 28U) == UART_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 &= ~((__INTERRUPT__) & UART_IT_MASK)): \
490
+                                                           ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & UART_IT_MASK)))
491
+
492
+/** @brief  Checks whether the specified UART interrupt has occurred or not.
493
+  * @param  __HANDLE__: specifies the UART Handle.
494
+  *         UART Handle selects the USARTx or UARTy peripheral 
495
+  *         (USART,UART availability and x,y values depending on device).
496
+  * @param  __IT__: specifies the UART interrupt source to check.
497
+  *          This parameter can be one of the following values:
498
+  *            @arg UART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
499
+  *            @arg UART_IT_LBD: LIN Break detection interrupt
500
+  *            @arg UART_IT_TXE: Transmit Data Register empty interrupt
501
+  *            @arg UART_IT_TC:  Transmission complete interrupt
502
+  *            @arg UART_IT_RXNE: Receive Data register not empty interrupt
503
+  *            @arg UART_IT_IDLE: Idle line detection interrupt
504
+  *            @arg UART_IT_ERR: Error interrupt
505
+  * @retval The new state of __IT__ (TRUE or FALSE).
506
+  */
507
+#define __HAL_UART_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28U) == UART_CR1_REG_INDEX)? (__HANDLE__)->Instance->CR1:(((((uint32_t)(__IT__)) >> 28U) == UART_CR2_REG_INDEX)? \
508
+                                                      (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (((uint32_t)(__IT__)) & UART_IT_MASK))
509
+
510
+/** @brief  Enable CTS flow control 
511
+  *         This macro allows to enable CTS hardware flow control for a given UART instance, 
512
+  *         without need to call HAL_UART_Init() function.
513
+  *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
514
+  * @note   As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
515
+  *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
516
+  *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
517
+  *           - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
518
+  *             and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).                                                                                                                  
519
+  * @param  __HANDLE__: specifies the UART Handle.
520
+  *         The Handle Instance can be any USARTx (supporting the HW Flow control feature).
521
+  *         It is used to select the USART peripheral (USART availability and x value depending on device).
522
+  */
523
+#define __HAL_UART_HWCONTROL_CTS_ENABLE(__HANDLE__)        \
524
+  do{                                                      \
525
+    SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE);  \
526
+    (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_CTSE;        \
527
+  } while(0U)
528
+
529
+/** @brief  Disable CTS flow control 
530
+  *         This macro allows to disable CTS hardware flow control for a given UART instance, 
531
+  *         without need to call HAL_UART_Init() function.
532
+  *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
533
+  * @note   As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
534
+  *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
535
+  *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
536
+  *           - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
537
+  *             and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)). 
538
+  * @param  __HANDLE__: specifies the UART Handle.
539
+  *         The Handle Instance can be any USARTx (supporting the HW Flow control feature).
540
+  *         It is used to select the USART peripheral (USART availability and x value depending on device).
541
+  */
542
+#define __HAL_UART_HWCONTROL_CTS_DISABLE(__HANDLE__)        \
543
+  do{                                                       \
544
+    CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
545
+    (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_CTSE);      \
546
+  } while(0U)
547
+
548
+/** @brief  Enable RTS flow control 
549
+  *         This macro allows to enable RTS hardware flow control for a given UART instance, 
550
+  *         without need to call HAL_UART_Init() function.
551
+  *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
552
+  * @note   As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
553
+  *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
554
+  *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
555
+  *           - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
556
+  *             and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)). 
557
+  * @param  __HANDLE__: specifies the UART Handle.
558
+  *         The Handle Instance can be any USARTx (supporting the HW Flow control feature).
559
+  *         It is used to select the USART peripheral (USART availability and x value depending on device).
560
+  */
561
+#define __HAL_UART_HWCONTROL_RTS_ENABLE(__HANDLE__)       \
562
+  do{                                                     \
563
+    SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE); \
564
+    (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_RTSE;       \
565
+  } while(0U)
566
+
567
+/** @brief  Disable RTS flow control 
568
+  *         This macro allows to disable RTS hardware flow control for a given UART instance, 
569
+  *         without need to call HAL_UART_Init() function.
570
+  *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
571
+  * @note   As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
572
+  *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
573
+  *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
574
+  *           - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
575
+  *             and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)). 
576
+  * @param  __HANDLE__: specifies the UART Handle.
577
+  *         The Handle Instance can be any USARTx (supporting the HW Flow control feature).
578
+  *         It is used to select the USART peripheral (USART availability and x value depending on device).
579
+  */
580
+#define __HAL_UART_HWCONTROL_RTS_DISABLE(__HANDLE__)       \
581
+  do{                                                      \
582
+    CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE);\
583
+    (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_RTSE);     \
584
+  } while(0U)
585
+
586
+#if defined(USART_CR3_ONEBIT)
587
+/** @brief  macros to enables the UART's one bit sample method
588
+  * @param  __HANDLE__: specifies the UART Handle.  
589
+  */
590
+#define __HAL_UART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
591
+
592
+/** @brief  macros to disables the UART's one bit sample method
593
+  * @param  __HANDLE__: specifies the UART Handle.  
594
+  * @retval None
595
+  */
596
+#define __HAL_UART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT))
597
+#endif /* USART_CR3_ONEBIT */
598
+
599
+/** @brief  Enable UART
600
+  * @param  __HANDLE__: specifies the UART Handle.
601
+  */
602
+#define __HAL_UART_ENABLE(__HANDLE__)               ((__HANDLE__)->Instance->CR1 |=  USART_CR1_UE)
603
+
604
+/** @brief  Disable UART
605
+  * @param  __HANDLE__: specifies the UART Handle.
606
+  */
607
+#define __HAL_UART_DISABLE(__HANDLE__)              ((__HANDLE__)->Instance->CR1 &=  ~USART_CR1_UE)
608
+/**
609
+  * @}
610
+  */
611
+/* Exported functions --------------------------------------------------------*/
612
+/** @addtogroup UART_Exported_Functions
613
+  * @{
614
+  */
615
+
616
+/** @addtogroup UART_Exported_Functions_Group1
617
+  * @{
618
+  */
619
+/* Initialization/de-initialization functions  **********************************/
620
+HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart);
621
+HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart);
622
+HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength);
623
+HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod);
624
+HAL_StatusTypeDef HAL_UART_DeInit (UART_HandleTypeDef *huart);
625
+void HAL_UART_MspInit(UART_HandleTypeDef *huart);
626
+void HAL_UART_MspDeInit(UART_HandleTypeDef *huart);
627
+/**
628
+  * @}
629
+  */
630
+
631
+/** @addtogroup UART_Exported_Functions_Group2
632
+  * @{
633
+  */
634
+/* IO operation functions *******************************************************/
635
+HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
636
+HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
637
+HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
638
+HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
639
+HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
640
+HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
641
+HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart);
642
+HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart);
643
+HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart);
644
+/* Transfer Abort functions */
645
+HAL_StatusTypeDef HAL_UART_Abort(UART_HandleTypeDef *huart);
646
+HAL_StatusTypeDef HAL_UART_AbortTransmit(UART_HandleTypeDef *huart);
647
+HAL_StatusTypeDef HAL_UART_AbortReceive(UART_HandleTypeDef *huart);
648
+HAL_StatusTypeDef HAL_UART_Abort_IT(UART_HandleTypeDef *huart);
649
+HAL_StatusTypeDef HAL_UART_AbortTransmit_IT(UART_HandleTypeDef *huart);
650
+HAL_StatusTypeDef HAL_UART_AbortReceive_IT(UART_HandleTypeDef *huart);
651
+
652
+void HAL_UART_IRQHandler(UART_HandleTypeDef *huart);
653
+void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart);
654
+void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart);
655
+void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart);
656
+void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart);
657
+void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart);
658
+void HAL_UART_AbortCpltCallback (UART_HandleTypeDef *huart);
659
+void HAL_UART_AbortTransmitCpltCallback (UART_HandleTypeDef *huart);
660
+void HAL_UART_AbortReceiveCpltCallback (UART_HandleTypeDef *huart);
661
+/**
662
+  * @}
663
+  */
664
+
665
+/** @addtogroup UART_Exported_Functions_Group3
666
+  * @{
667
+  */
668
+/* Peripheral Control functions  ************************************************/
669
+HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart);
670
+HAL_StatusTypeDef HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart);
671
+HAL_StatusTypeDef HAL_MultiProcessor_ExitMuteMode(UART_HandleTypeDef *huart);
672
+HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart);
673
+HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart);
674
+/**
675
+  * @}
676
+  */
677
+
678
+/** @addtogroup UART_Exported_Functions_Group4
679
+  * @{
680
+  */
681
+/* Peripheral State functions  **************************************************/
682
+HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart);
683
+uint32_t HAL_UART_GetError(UART_HandleTypeDef *huart);
684
+/**
685
+  * @}
686
+  */
687
+
688
+/**
689
+  * @}
690
+  */
691
+/* Private types -------------------------------------------------------------*/
692
+/* Private variables ---------------------------------------------------------*/
693
+/* Private constants ---------------------------------------------------------*/
694
+/** @defgroup UART_Private_Constants UART Private Constants
695
+  * @{
696
+  */
697
+/** @brief UART interruptions flag mask
698
+  * 
699
+  */
700
+#define UART_IT_MASK                     0x0000FFFFU
701
+
702
+#define UART_CR1_REG_INDEX               1U
703
+#define UART_CR2_REG_INDEX               2U
704
+#define UART_CR3_REG_INDEX               3U
705
+/**
706
+  * @}
707
+  */
708
+
709
+/* Private macros ------------------------------------------------------------*/
710
+/** @defgroup UART_Private_Macros UART Private Macros
711
+  * @{
712
+  */
713
+#define IS_UART_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_8B) || \
714
+                                     ((LENGTH) == UART_WORDLENGTH_9B))
715
+#define IS_UART_LIN_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_8B))
716
+#define IS_UART_STOPBITS(STOPBITS) (((STOPBITS) == UART_STOPBITS_1) || \
717
+                                    ((STOPBITS) == UART_STOPBITS_2))
718
+#define IS_UART_PARITY(PARITY) (((PARITY) == UART_PARITY_NONE) || \
719
+                                ((PARITY) == UART_PARITY_EVEN) || \
720
+                                ((PARITY) == UART_PARITY_ODD))
721
+#define IS_UART_HARDWARE_FLOW_CONTROL(CONTROL)\
722
+                              (((CONTROL) == UART_HWCONTROL_NONE) || \
723
+                               ((CONTROL) == UART_HWCONTROL_RTS) || \
724
+                               ((CONTROL) == UART_HWCONTROL_CTS) || \
725
+                               ((CONTROL) == UART_HWCONTROL_RTS_CTS))
726
+#define IS_UART_MODE(MODE) ((((MODE) & 0x0000FFF3U) == 0x00U) && ((MODE) != 0x00U))
727
+#define IS_UART_STATE(STATE) (((STATE) == UART_STATE_DISABLE) || \
728
+                              ((STATE) == UART_STATE_ENABLE))
729
+#if defined(USART_CR1_OVER8)
730
+#define IS_UART_OVERSAMPLING(SAMPLING) (((SAMPLING) == UART_OVERSAMPLING_16) || \
731
+                                        ((SAMPLING) == UART_OVERSAMPLING_8))
732
+#endif /* USART_CR1_OVER8 */
733
+#define IS_UART_LIN_OVERSAMPLING(SAMPLING) (((SAMPLING) == UART_OVERSAMPLING_16))
734
+#define IS_UART_LIN_BREAK_DETECT_LENGTH(LENGTH) (((LENGTH) == UART_LINBREAKDETECTLENGTH_10B) || \
735
+                                                 ((LENGTH) == UART_LINBREAKDETECTLENGTH_11B))
736
+#define IS_UART_WAKEUPMETHOD(WAKEUP) (((WAKEUP) == UART_WAKEUPMETHOD_IDLELINE) || \
737
+                                      ((WAKEUP) == UART_WAKEUPMETHOD_ADDRESSMARK))
738
+#define IS_UART_BAUDRATE(BAUDRATE) ((BAUDRATE) < 4500001U)
739
+#define IS_UART_ADDRESS(ADDRESS) ((ADDRESS) <= 0x0FU)
740
+
741
+#define UART_DIV_SAMPLING16(_PCLK_, _BAUD_)            (((_PCLK_)*25U)/(4U*(_BAUD_)))
742
+#define UART_DIVMANT_SAMPLING16(_PCLK_, _BAUD_)        (UART_DIV_SAMPLING16((_PCLK_), (_BAUD_))/100U)
743
+#define UART_DIVFRAQ_SAMPLING16(_PCLK_, _BAUD_)        (((UART_DIV_SAMPLING16((_PCLK_), (_BAUD_)) - (UART_DIVMANT_SAMPLING16((_PCLK_), (_BAUD_)) * 100U)) * 16U + 50U) / 100U)
744
+/* UART BRR = mantissa + overflow + fraction
745
+            = (UART DIVMANT << 4) + (UART DIVFRAQ & 0xF0) + (UART DIVFRAQ & 0x0FU) */
746
+#define UART_BRR_SAMPLING16(_PCLK_, _BAUD_)            (((UART_DIVMANT_SAMPLING16((_PCLK_), (_BAUD_)) << 4U) + \
747
+                                                        (UART_DIVFRAQ_SAMPLING16((_PCLK_), (_BAUD_)) & 0xF0U)) + \
748
+                                                        (UART_DIVFRAQ_SAMPLING16((_PCLK_), (_BAUD_)) & 0x0FU))
749
+
750
+#define UART_DIV_SAMPLING8(_PCLK_, _BAUD_)             (((_PCLK_)*25U)/(2U*(_BAUD_)))
751
+#define UART_DIVMANT_SAMPLING8(_PCLK_, _BAUD_)         (UART_DIV_SAMPLING8((_PCLK_), (_BAUD_))/100U)
752
+#define UART_DIVFRAQ_SAMPLING8(_PCLK_, _BAUD_)         (((UART_DIV_SAMPLING8((_PCLK_), (_BAUD_)) - (UART_DIVMANT_SAMPLING8((_PCLK_), (_BAUD_)) * 100U)) * 8U + 50U) / 100U)
753
+/* UART BRR = mantissa + overflow + fraction
754
+            = (UART DIVMANT << 4) + ((UART DIVFRAQ & 0xF8) << 1) + (UART DIVFRAQ & 0x07U) */
755
+#define UART_BRR_SAMPLING8(_PCLK_, _BAUD_)             (((UART_DIVMANT_SAMPLING8((_PCLK_), (_BAUD_)) << 4U) + \
756
+                                                        ((UART_DIVFRAQ_SAMPLING8((_PCLK_), (_BAUD_)) & 0xF8U) << 1U)) + \
757
+                                                        (UART_DIVFRAQ_SAMPLING8((_PCLK_), (_BAUD_)) & 0x07U))
758
+/**
759
+  * @}
760
+  */
761
+
762
+/* Private functions ---------------------------------------------------------*/
763
+/** @defgroup UART_Private_Functions UART Private Functions
764
+  * @{
765
+  */
766
+
767
+/**
768
+  * @}
769
+  */
770
+
771
+/**
772
+  * @}
773
+  */ 
774
+
775
+/**
776
+  * @}
777
+  */
778
+
779
+#ifdef __cplusplus
780
+}
781
+#endif
782
+
783
+#endif /* __STM32F1xx_HAL_UART_H */
784
+
785
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 595 - 0
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c

@@ -0,0 +1,595 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal.c
4
+  * @author  MCD Application Team
5
+  * @brief   HAL module driver.
6
+  *          This is the common part of the HAL initialization
7
+  *
8
+  @verbatim
9
+  ==============================================================================
10
+                     ##### How to use this driver #####
11
+  ==============================================================================
12
+    [..]
13
+    The common HAL driver contains a set of generic and common APIs that can be
14
+    used by the PPP peripheral drivers and the user to start using the HAL.
15
+    [..]
16
+    The HAL contains two APIs' categories:
17
+         (+) Common HAL APIs
18
+         (+) Services HAL APIs
19
+
20
+  @endverbatim
21
+  ******************************************************************************
22
+  * @attention
23
+  *
24
+  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
25
+  *
26
+  * Redistribution and use in source and binary forms, with or without modification,
27
+  * are permitted provided that the following conditions are met:
28
+  *   1. Redistributions of source code must retain the above copyright notice,
29
+  *      this list of conditions and the following disclaimer.
30
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
31
+  *      this list of conditions and the following disclaimer in the documentation
32
+  *      and/or other materials provided with the distribution.
33
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
34
+  *      may be used to endorse or promote products derived from this software
35
+  *      without specific prior written permission.
36
+  *
37
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
38
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
41
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
42
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
43
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
44
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
46
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47
+  *
48
+  ******************************************************************************
49
+  */
50
+
51
+/* Includes ------------------------------------------------------------------*/
52
+#include "stm32f1xx_hal.h"
53
+
54
+/** @addtogroup STM32F1xx_HAL_Driver
55
+  * @{
56
+  */
57
+
58
+/** @defgroup HAL HAL
59
+  * @brief HAL module driver.
60
+  * @{
61
+  */
62
+
63
+#ifdef HAL_MODULE_ENABLED
64
+
65
+/* Private typedef -----------------------------------------------------------*/
66
+/* Private define ------------------------------------------------------------*/
67
+
68
+/** @defgroup HAL_Private_Constants HAL Private Constants
69
+  * @{
70
+  */
71
+/**
72
+ * @brief STM32F1xx HAL Driver version number V1.1.3
73
+   */
74
+#define __STM32F1xx_HAL_VERSION_MAIN   (0x01U) /*!< [31:24] main version */
75
+#define __STM32F1xx_HAL_VERSION_SUB1   (0x01U) /*!< [23:16] sub1 version */
76
+#define __STM32F1xx_HAL_VERSION_SUB2   (0x03U) /*!< [15:8]  sub2 version */
77
+#define __STM32F1xx_HAL_VERSION_RC     (0x00U) /*!< [7:0]  release candidate */
78
+#define __STM32F1xx_HAL_VERSION         ((__STM32F1xx_HAL_VERSION_MAIN << 24)\
79
+                                        |(__STM32F1xx_HAL_VERSION_SUB1 << 16)\
80
+                                        |(__STM32F1xx_HAL_VERSION_SUB2 << 8 )\
81
+                                        |(__STM32F1xx_HAL_VERSION_RC))
82
+
83
+#define IDCODE_DEVID_MASK    0x00000FFFU
84
+
85
+/**
86
+  * @}
87
+  */
88
+
89
+/* Private macro -------------------------------------------------------------*/
90
+/* Private variables ---------------------------------------------------------*/
91
+
92
+/** @defgroup HAL_Private_Variables HAL Private Variables
93
+  * @{
94
+  */
95
+__IO uint32_t uwTick;
96
+uint32_t uwTickPrio   = (1UL << __NVIC_PRIO_BITS); /* Invalid PRIO */
97
+HAL_TickFreqTypeDef uwTickFreq = HAL_TICK_FREQ_DEFAULT;  /* 1KHz */
98
+/**
99
+  * @}
100
+  */
101
+/* Private function prototypes -----------------------------------------------*/
102
+/* Exported functions ---------------------------------------------------------*/
103
+
104
+/** @defgroup HAL_Exported_Functions HAL Exported Functions
105
+  * @{
106
+  */
107
+
108
+/** @defgroup HAL_Exported_Functions_Group1 Initialization and de-initialization Functions
109
+ *  @brief    Initialization and de-initialization functions
110
+ *
111
+@verbatim
112
+ ===============================================================================
113
+              ##### Initialization and de-initialization functions #####
114
+ ===============================================================================
115
+   [..]  This section provides functions allowing to:
116
+      (+) Initializes the Flash interface, the NVIC allocation and initial clock
117
+          configuration. It initializes the systick also when timeout is needed
118
+          and the backup domain when enabled.
119
+      (+) de-Initializes common part of the HAL.
120
+      (+) Configure The time base source to have 1ms time base with a dedicated
121
+          Tick interrupt priority.
122
+        (++) SysTick timer is used by default as source of time base, but user
123
+             can eventually implement his proper time base source (a general purpose
124
+             timer for example or other time source), keeping in mind that Time base
125
+             duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
126
+             handled in milliseconds basis.
127
+        (++) Time base configuration function (HAL_InitTick ()) is called automatically
128
+             at the beginning of the program after reset by HAL_Init() or at any time
129
+             when clock is configured, by HAL_RCC_ClockConfig().
130
+        (++) Source of time base is configured  to generate interrupts at regular
131
+             time intervals. Care must be taken if HAL_Delay() is called from a
132
+             peripheral ISR process, the Tick interrupt line must have higher priority
133
+            (numerically lower) than the peripheral interrupt. Otherwise the caller
134
+            ISR process will be blocked.
135
+       (++) functions affecting time base configurations are declared as __weak
136
+             to make  override possible  in case of other  implementations in user file.
137
+@endverbatim
138
+  * @{
139
+  */
140
+
141
+/**
142
+  * @brief  This function is used to initialize the HAL Library; it must be the first
143
+  *         instruction to be executed in the main program (before to call any other
144
+  *         HAL function), it performs the following:
145
+  *           Configure the Flash prefetch.
146
+  *           Configures the SysTick to generate an interrupt each 1 millisecond,
147
+  *           which is clocked by the HSI (at this stage, the clock is not yet
148
+  *           configured and thus the system is running from the internal HSI at 16 MHz).
149
+  *           Set NVIC Group Priority to 4.
150
+  *           Calls the HAL_MspInit() callback function defined in user file
151
+  *           "stm32f1xx_hal_msp.c" to do the global low level hardware initialization
152
+  *
153
+  * @note   SysTick is used as time base for the HAL_Delay() function, the application
154
+  *         need to ensure that the SysTick time base is always set to 1 millisecond
155
+  *         to have correct HAL operation.
156
+  * @retval HAL status
157
+  */
158
+HAL_StatusTypeDef HAL_Init(void)
159
+{
160
+  /* Configure Flash prefetch */
161
+#if (PREFETCH_ENABLE != 0)
162
+#if defined(STM32F101x6) || defined(STM32F101xB) || defined(STM32F101xE) || defined(STM32F101xG) || \
163
+    defined(STM32F102x6) || defined(STM32F102xB) || \
164
+    defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || \
165
+    defined(STM32F105xC) || defined(STM32F107xC)
166
+
167
+  /* Prefetch buffer is not available on value line devices */
168
+  __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
169
+#endif
170
+#endif /* PREFETCH_ENABLE */
171
+
172
+  /* Set Interrupt Group Priority */
173
+  HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
174
+
175
+  /* Use systick as time base source and configure 1ms tick (default clock after Reset is HSI) */
176
+  HAL_InitTick(TICK_INT_PRIORITY);
177
+
178
+  /* Init the low level hardware */
179
+  HAL_MspInit();
180
+
181
+  /* Return function status */
182
+  return HAL_OK;
183
+}
184
+
185
+/**
186
+  * @brief This function de-Initializes common part of the HAL and stops the systick.
187
+  *        of time base.
188
+  * @note This function is optional.
189
+  * @retval HAL status
190
+  */
191
+HAL_StatusTypeDef HAL_DeInit(void)
192
+{
193
+  /* Reset of all peripherals */
194
+  __HAL_RCC_APB1_FORCE_RESET();
195
+  __HAL_RCC_APB1_RELEASE_RESET();
196
+
197
+  __HAL_RCC_APB2_FORCE_RESET();
198
+  __HAL_RCC_APB2_RELEASE_RESET();
199
+
200
+#if defined(STM32F105xC) || defined(STM32F107xC)
201
+  __HAL_RCC_AHB_FORCE_RESET();
202
+  __HAL_RCC_AHB_RELEASE_RESET();
203
+#endif
204
+
205
+  /* De-Init the low level hardware */
206
+  HAL_MspDeInit();
207
+
208
+  /* Return function status */
209
+  return HAL_OK;
210
+}
211
+
212
+/**
213
+  * @brief  Initialize the MSP.
214
+  * @retval None
215
+  */
216
+__weak void HAL_MspInit(void)
217
+{
218
+  /* NOTE : This function should not be modified, when the callback is needed,
219
+            the HAL_MspInit could be implemented in the user file
220
+   */
221
+}
222
+
223
+/**
224
+  * @brief  DeInitializes the MSP.
225
+  * @retval None
226
+  */
227
+__weak void HAL_MspDeInit(void)
228
+{
229
+  /* NOTE : This function should not be modified, when the callback is needed,
230
+            the HAL_MspDeInit could be implemented in the user file
231
+   */
232
+}
233
+
234
+/**
235
+  * @brief This function configures the source of the time base.
236
+  *        The time source is configured  to have 1ms time base with a dedicated
237
+  *        Tick interrupt priority.
238
+  * @note This function is called  automatically at the beginning of program after
239
+  *       reset by HAL_Init() or at any time when clock is reconfigured  by HAL_RCC_ClockConfig().
240
+  * @note In the default implementation, SysTick timer is the source of time base.
241
+  *       It is used to generate interrupts at regular time intervals.
242
+  *       Care must be taken if HAL_Delay() is called from a peripheral ISR process,
243
+  *       The SysTick interrupt must have higher priority (numerically lower)
244
+  *       than the peripheral interrupt. Otherwise the caller ISR process will be blocked.
245
+  *       The function is declared as __weak  to be overwritten  in case of other
246
+  *       implementation  in user file.
247
+  * @param TickPriority Tick interrupt priority.
248
+  * @retval HAL status
249
+  */
250
+__weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
251
+{
252
+  /* Configure the SysTick to have interrupt in 1ms time basis*/
253
+  if (HAL_SYSTICK_Config(SystemCoreClock / (1000U / uwTickFreq)) > 0U)
254
+  {
255
+    return HAL_ERROR;
256
+  }
257
+
258
+  /* Configure the SysTick IRQ priority */
259
+  if (TickPriority < (1UL << __NVIC_PRIO_BITS))
260
+  {
261
+    HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U);
262
+    uwTickPrio = TickPriority;
263
+  }
264
+  else
265
+  {
266
+    return HAL_ERROR;
267
+  }
268
+
269
+  /* Return function status */
270
+  return HAL_OK;
271
+}
272
+
273
+/**
274
+  * @}
275
+  */
276
+
277
+/** @defgroup HAL_Exported_Functions_Group2 HAL Control functions
278
+  *  @brief    HAL Control functions
279
+  *
280
+@verbatim
281
+ ===============================================================================
282
+                      ##### HAL Control functions #####
283
+ ===============================================================================
284
+    [..]  This section provides functions allowing to:
285
+      (+) Provide a tick value in millisecond
286
+      (+) Provide a blocking delay in millisecond
287
+      (+) Suspend the time base source interrupt
288
+      (+) Resume the time base source interrupt
289
+      (+) Get the HAL API driver version
290
+      (+) Get the device identifier
291
+      (+) Get the device revision identifier
292
+      (+) Enable/Disable Debug module during SLEEP mode
293
+      (+) Enable/Disable Debug module during STOP mode
294
+      (+) Enable/Disable Debug module during STANDBY mode
295
+
296
+@endverbatim
297
+  * @{
298
+  */
299
+
300
+/**
301
+  * @brief This function is called to increment  a global variable "uwTick"
302
+  *        used as application time base.
303
+  * @note In the default implementation, this variable is incremented each 1ms
304
+  *       in SysTick ISR.
305
+  * @note This function is declared as __weak to be overwritten in case of other
306
+  *      implementations in user file.
307
+  * @retval None
308
+  */
309
+__weak void HAL_IncTick(void)
310
+{
311
+  uwTick += uwTickFreq;
312
+}
313
+
314
+/**
315
+  * @brief Provides a tick value in millisecond.
316
+  * @note  This function is declared as __weak to be overwritten in case of other
317
+  *       implementations in user file.
318
+  * @retval tick value
319
+  */
320
+__weak uint32_t HAL_GetTick(void)
321
+{
322
+  return uwTick;
323
+}
324
+
325
+/**
326
+  * @brief This function returns a tick priority.
327
+  * @retval tick priority
328
+  */
329
+uint32_t HAL_GetTickPrio(void)
330
+{
331
+  return uwTickPrio;
332
+}
333
+
334
+/**
335
+  * @brief Set new tick Freq.
336
+  * @retval Status
337
+  */
338
+HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq)
339
+{
340
+  HAL_StatusTypeDef status  = HAL_OK;
341
+  assert_param(IS_TICKFREQ(Freq));
342
+
343
+  if (uwTickFreq != Freq)
344
+  {
345
+    uwTickFreq = Freq;
346
+
347
+    /* Apply the new tick Freq  */
348
+    status = HAL_InitTick(uwTickPrio);
349
+  }
350
+
351
+  return status;
352
+}
353
+
354
+/**
355
+  * @brief Return tick frequency.
356
+  * @retval tick period in Hz
357
+  */
358
+HAL_TickFreqTypeDef HAL_GetTickFreq(void)
359
+{
360
+  return uwTickFreq;
361
+}
362
+
363
+/**
364
+  * @brief This function provides minimum delay (in milliseconds) based
365
+  *        on variable incremented.
366
+  * @note In the default implementation , SysTick timer is the source of time base.
367
+  *       It is used to generate interrupts at regular time intervals where uwTick
368
+  *       is incremented.
369
+  * @note This function is declared as __weak to be overwritten in case of other
370
+  *       implementations in user file.
371
+  * @param Delay specifies the delay time length, in milliseconds.
372
+  * @retval None
373
+  */
374
+__weak void HAL_Delay(uint32_t Delay)
375
+{
376
+  uint32_t tickstart = HAL_GetTick();
377
+  uint32_t wait = Delay;
378
+
379
+  /* Add a freq to guarantee minimum wait */
380
+  if (wait < HAL_MAX_DELAY)
381
+  {
382
+    wait += (uint32_t)(uwTickFreq);
383
+  }
384
+
385
+  while ((HAL_GetTick() - tickstart) < wait)
386
+  {
387
+  }
388
+}
389
+
390
+/**
391
+  * @brief Suspend Tick increment.
392
+  * @note In the default implementation , SysTick timer is the source of time base. It is
393
+  *       used to generate interrupts at regular time intervals. Once HAL_SuspendTick()
394
+  *       is called, the SysTick interrupt will be disabled and so Tick increment
395
+  *       is suspended.
396
+  * @note This function is declared as __weak to be overwritten in case of other
397
+  *       implementations in user file.
398
+  * @retval None
399
+  */
400
+__weak void HAL_SuspendTick(void)
401
+{
402
+  /* Disable SysTick Interrupt */
403
+  CLEAR_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
404
+}
405
+
406
+/**
407
+  * @brief Resume Tick increment.
408
+  * @note In the default implementation , SysTick timer is the source of time base. It is
409
+  *       used to generate interrupts at regular time intervals. Once HAL_ResumeTick()
410
+  *       is called, the SysTick interrupt will be enabled and so Tick increment
411
+  *       is resumed.
412
+  * @note This function is declared as __weak to be overwritten in case of other
413
+  *       implementations in user file.
414
+  * @retval None
415
+  */
416
+__weak void HAL_ResumeTick(void)
417
+{
418
+  /* Enable SysTick Interrupt */
419
+  SET_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
420
+}
421
+
422
+/**
423
+  * @brief  Returns the HAL revision
424
+  * @retval version 0xXYZR (8bits for each decimal, R for RC)
425
+  */
426
+uint32_t HAL_GetHalVersion(void)
427
+{
428
+  return __STM32F1xx_HAL_VERSION;
429
+}
430
+
431
+/**
432
+  * @brief Returns the device revision identifier.
433
+  * Note: On devices STM32F10xx8 and STM32F10xxB,
434
+  *                  STM32F101xC/D/E and STM32F103xC/D/E,
435
+  *                  STM32F101xF/G and STM32F103xF/G
436
+  *                  STM32F10xx4 and STM32F10xx6
437
+  *       Debug registers DBGMCU_IDCODE and DBGMCU_CR are accessible only in
438
+  *       debug mode (not accessible by the user software in normal mode).
439
+  *       Refer to errata sheet of these devices for more details.
440
+  * @retval Device revision identifier
441
+  */
442
+uint32_t HAL_GetREVID(void)
443
+{
444
+  return ((DBGMCU->IDCODE) >> DBGMCU_IDCODE_REV_ID_Pos);
445
+}
446
+
447
+/**
448
+  * @brief  Returns the device identifier.
449
+  * Note: On devices STM32F10xx8 and STM32F10xxB,
450
+  *                  STM32F101xC/D/E and STM32F103xC/D/E,
451
+  *                  STM32F101xF/G and STM32F103xF/G
452
+  *                  STM32F10xx4 and STM32F10xx6
453
+  *       Debug registers DBGMCU_IDCODE and DBGMCU_CR are accessible only in
454
+  *       debug mode (not accessible by the user software in normal mode).
455
+  *       Refer to errata sheet of these devices for more details.
456
+  * @retval Device identifier
457
+  */
458
+uint32_t HAL_GetDEVID(void)
459
+{
460
+  return ((DBGMCU->IDCODE) & IDCODE_DEVID_MASK);
461
+}
462
+
463
+/**
464
+  * @brief  Enable the Debug Module during SLEEP mode
465
+  * @retval None
466
+  */
467
+void HAL_DBGMCU_EnableDBGSleepMode(void)
468
+{
469
+  SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
470
+}
471
+
472
+/**
473
+  * @brief  Disable the Debug Module during SLEEP mode
474
+  * Note: On devices STM32F10xx8 and STM32F10xxB,
475
+  *                  STM32F101xC/D/E and STM32F103xC/D/E,
476
+  *                  STM32F101xF/G and STM32F103xF/G
477
+  *                  STM32F10xx4 and STM32F10xx6
478
+  *       Debug registers DBGMCU_IDCODE and DBGMCU_CR are accessible only in
479
+  *       debug mode (not accessible by the user software in normal mode).
480
+  *       Refer to errata sheet of these devices for more details.
481
+  * @retval None
482
+  */
483
+void HAL_DBGMCU_DisableDBGSleepMode(void)
484
+{
485
+  CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
486
+}
487
+
488
+/**
489
+  * @brief  Enable the Debug Module during STOP mode
490
+  * Note: On devices STM32F10xx8 and STM32F10xxB,
491
+  *                  STM32F101xC/D/E and STM32F103xC/D/E,
492
+  *                  STM32F101xF/G and STM32F103xF/G
493
+  *                  STM32F10xx4 and STM32F10xx6
494
+  *       Debug registers DBGMCU_IDCODE and DBGMCU_CR are accessible only in
495
+  *       debug mode (not accessible by the user software in normal mode).
496
+  *       Refer to errata sheet of these devices for more details.
497
+  * Note: On all STM32F1 devices:
498
+  *       If the system tick timer interrupt is enabled during the Stop mode
499
+  *       debug (DBG_STOP bit set in the DBGMCU_CR register ), it will wakeup
500
+  *       the system from Stop mode.
501
+  *       Workaround: To debug the Stop mode, disable the system tick timer
502
+  *       interrupt.
503
+  *       Refer to errata sheet of these devices for more details.
504
+  * Note: On all STM32F1 devices:
505
+  *       If the system tick timer interrupt is enabled during the Stop mode
506
+  *       debug (DBG_STOP bit set in the DBGMCU_CR register ), it will wakeup
507
+  *       the system from Stop mode.
508
+  *       Workaround: To debug the Stop mode, disable the system tick timer
509
+  *       interrupt.
510
+  *       Refer to errata sheet of these devices for more details.
511
+  * @retval None
512
+  */
513
+void HAL_DBGMCU_EnableDBGStopMode(void)
514
+{
515
+  SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
516
+}
517
+
518
+/**
519
+  * @brief  Disable the Debug Module during STOP mode
520
+  * Note: On devices STM32F10xx8 and STM32F10xxB,
521
+  *                  STM32F101xC/D/E and STM32F103xC/D/E,
522
+  *                  STM32F101xF/G and STM32F103xF/G
523
+  *                  STM32F10xx4 and STM32F10xx6
524
+  *       Debug registers DBGMCU_IDCODE and DBGMCU_CR are accessible only in
525
+  *       debug mode (not accessible by the user software in normal mode).
526
+  *       Refer to errata sheet of these devices for more details.
527
+  * @retval None
528
+  */
529
+void HAL_DBGMCU_DisableDBGStopMode(void)
530
+{
531
+  CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
532
+}
533
+
534
+/**
535
+  * @brief  Enable the Debug Module during STANDBY mode
536
+  * Note: On devices STM32F10xx8 and STM32F10xxB,
537
+  *                  STM32F101xC/D/E and STM32F103xC/D/E,
538
+  *                  STM32F101xF/G and STM32F103xF/G
539
+  *                  STM32F10xx4 and STM32F10xx6
540
+  *       Debug registers DBGMCU_IDCODE and DBGMCU_CR are accessible only in
541
+  *       debug mode (not accessible by the user software in normal mode).
542
+  *       Refer to errata sheet of these devices for more details.
543
+  * @retval None
544
+  */
545
+void HAL_DBGMCU_EnableDBGStandbyMode(void)
546
+{
547
+  SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
548
+}
549
+
550
+/**
551
+  * @brief  Disable the Debug Module during STANDBY mode
552
+  * Note: On devices STM32F10xx8 and STM32F10xxB,
553
+  *                  STM32F101xC/D/E and STM32F103xC/D/E,
554
+  *                  STM32F101xF/G and STM32F103xF/G
555
+  *                  STM32F10xx4 and STM32F10xx6
556
+  *       Debug registers DBGMCU_IDCODE and DBGMCU_CR are accessible only in
557
+  *       debug mode (not accessible by the user software in normal mode).
558
+  *       Refer to errata sheet of these devices for more details.
559
+  * @retval None
560
+  */
561
+void HAL_DBGMCU_DisableDBGStandbyMode(void)
562
+{
563
+  CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
564
+}
565
+
566
+/**
567
+  * @brief Return the unique device identifier (UID based on 96 bits)
568
+  * @param UID pointer to 3 words array.
569
+  * @retval Device identifier
570
+  */
571
+void HAL_GetUID(uint32_t *UID)
572
+{
573
+  UID[0] = (uint32_t)(READ_REG(*((uint32_t *)UID_BASE)));
574
+  UID[1] = (uint32_t)(READ_REG(*((uint32_t *)(UID_BASE + 4U))));
575
+  UID[2] = (uint32_t)(READ_REG(*((uint32_t *)(UID_BASE + 8U))));
576
+}
577
+
578
+/**
579
+  * @}
580
+  */
581
+
582
+/**
583
+  * @}
584
+  */
585
+
586
+#endif /* HAL_MODULE_ENABLED */
587
+/**
588
+  * @}
589
+  */
590
+
591
+/**
592
+  * @}
593
+  */
594
+
595
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

Разлика између датотеке није приказан због своје велике величине
+ 2110 - 0
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc.c


Разлика између датотеке није приказан због своје велике величине
+ 1339 - 0
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.c


+ 521 - 0
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c

@@ -0,0 +1,521 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_cortex.c
4
+  * @author  MCD Application Team
5
+  * @brief   CORTEX HAL module driver.
6
+  *          This file provides firmware functions to manage the following 
7
+  *          functionalities of the CORTEX:
8
+  *           + Initialization and de-initialization functions
9
+  *           + Peripheral Control functions 
10
+  *
11
+  @verbatim  
12
+  ==============================================================================
13
+                        ##### How to use this driver #####
14
+  ==============================================================================
15
+
16
+    [..]  
17
+    *** How to configure Interrupts using CORTEX HAL driver ***
18
+    ===========================================================
19
+    [..]     
20
+    This section provides functions allowing to configure the NVIC interrupts (IRQ).
21
+    The Cortex-M3 exceptions are managed by CMSIS functions.
22
+   
23
+    (#) Configure the NVIC Priority Grouping using HAL_NVIC_SetPriorityGrouping()
24
+        function according to the following table.
25
+    (#) Configure the priority of the selected IRQ Channels using HAL_NVIC_SetPriority(). 
26
+    (#) Enable the selected IRQ Channels using HAL_NVIC_EnableIRQ().
27
+    (#) please refer to programming manual for details in how to configure priority. 
28
+      
29
+     -@- When the NVIC_PRIORITYGROUP_0 is selected, IRQ preemption is no more possible. 
30
+         The pending IRQ priority will be managed only by the sub priority.
31
+   
32
+     -@- IRQ priority order (sorted by highest to lowest priority):
33
+        (+@) Lowest preemption priority
34
+        (+@) Lowest sub priority
35
+        (+@) Lowest hardware priority (IRQ number)
36
+ 
37
+    [..]  
38
+    *** How to configure Systick using CORTEX HAL driver ***
39
+    ========================================================
40
+    [..]
41
+    Setup SysTick Timer for time base.
42
+           
43
+   (+) The HAL_SYSTICK_Config()function calls the SysTick_Config() function which
44
+       is a CMSIS function that:
45
+        (++) Configures the SysTick Reload register with value passed as function parameter.
46
+        (++) Configures the SysTick IRQ priority to the lowest value 0x0F.
47
+        (++) Resets the SysTick Counter register.
48
+        (++) Configures the SysTick Counter clock source to be Core Clock Source (HCLK).
49
+        (++) Enables the SysTick Interrupt.
50
+        (++) Starts the SysTick Counter.
51
+    
52
+   (+) You can change the SysTick Clock source to be HCLK_Div8 by calling the macro
53
+       __HAL_CORTEX_SYSTICKCLK_CONFIG(SYSTICK_CLKSOURCE_HCLK_DIV8) just after the
54
+       HAL_SYSTICK_Config() function call. The __HAL_CORTEX_SYSTICKCLK_CONFIG() macro is defined
55
+       inside the stm32f1xx_hal_cortex.h file.
56
+
57
+   (+) You can change the SysTick IRQ priority by calling the
58
+       HAL_NVIC_SetPriority(SysTick_IRQn,...) function just after the HAL_SYSTICK_Config() function 
59
+       call. The HAL_NVIC_SetPriority() call the NVIC_SetPriority() function which is a CMSIS function.
60
+
61
+   (+) To adjust the SysTick time base, use the following formula:
62
+                            
63
+       Reload Value = SysTick Counter Clock (Hz) x  Desired Time base (s)
64
+       (++) Reload Value is the parameter to be passed for HAL_SYSTICK_Config() function
65
+       (++) Reload Value should not exceed 0xFFFFFF
66
+   
67
+  @endverbatim
68
+  ******************************************************************************
69
+  * @attention
70
+  *
71
+  * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
72
+  *
73
+  * Redistribution and use in source and binary forms, with or without modification,
74
+  * are permitted provided that the following conditions are met:
75
+  *   1. Redistributions of source code must retain the above copyright notice,
76
+  *      this list of conditions and the following disclaimer.
77
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
78
+  *      this list of conditions and the following disclaimer in the documentation
79
+  *      and/or other materials provided with the distribution.
80
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
81
+  *      may be used to endorse or promote products derived from this software
82
+  *      without specific prior written permission.
83
+  *
84
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
85
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
86
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
87
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
88
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
89
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
90
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
91
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
92
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
93
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
94
+  *
95
+  ******************************************************************************
96
+  */
97
+
98
+/* Includes ------------------------------------------------------------------*/
99
+#include "stm32f1xx_hal.h"
100
+
101
+/** @addtogroup STM32F1xx_HAL_Driver
102
+  * @{
103
+  */
104
+
105
+/** @defgroup CORTEX CORTEX
106
+  * @brief CORTEX HAL module driver
107
+  * @{
108
+  */
109
+
110
+#ifdef HAL_CORTEX_MODULE_ENABLED
111
+
112
+/* Private types -------------------------------------------------------------*/
113
+/* Private variables ---------------------------------------------------------*/
114
+/* Private constants ---------------------------------------------------------*/
115
+/* Private macros ------------------------------------------------------------*/
116
+/* Private functions ---------------------------------------------------------*/
117
+/* Exported functions --------------------------------------------------------*/
118
+
119
+/** @defgroup CORTEX_Exported_Functions CORTEX Exported Functions
120
+  * @{
121
+  */
122
+
123
+
124
+/** @defgroup CORTEX_Exported_Functions_Group1 Initialization and de-initialization functions
125
+  *  @brief    Initialization and Configuration functions 
126
+  *
127
+@verbatim    
128
+  ==============================================================================
129
+              ##### Initialization and de-initialization functions #####
130
+  ==============================================================================
131
+    [..]
132
+      This section provides the CORTEX HAL driver functions allowing to configure Interrupts
133
+      Systick functionalities 
134
+
135
+@endverbatim
136
+  * @{
137
+  */
138
+
139
+
140
+/**
141
+  * @brief  Sets the priority grouping field (preemption priority and subpriority)
142
+  *         using the required unlock sequence.
143
+  * @param  PriorityGroup: The priority grouping bits length. 
144
+  *         This parameter can be one of the following values:
145
+  *         @arg NVIC_PRIORITYGROUP_0: 0 bits for preemption priority
146
+  *                                    4 bits for subpriority
147
+  *         @arg NVIC_PRIORITYGROUP_1: 1 bits for preemption priority
148
+  *                                    3 bits for subpriority
149
+  *         @arg NVIC_PRIORITYGROUP_2: 2 bits for preemption priority
150
+  *                                    2 bits for subpriority
151
+  *         @arg NVIC_PRIORITYGROUP_3: 3 bits for preemption priority
152
+  *                                    1 bits for subpriority
153
+  *         @arg NVIC_PRIORITYGROUP_4: 4 bits for preemption priority
154
+  *                                    0 bits for subpriority
155
+  * @note   When the NVIC_PriorityGroup_0 is selected, IRQ preemption is no more possible. 
156
+  *         The pending IRQ priority will be managed only by the subpriority. 
157
+  * @retval None
158
+  */
159
+void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
160
+{
161
+  /* Check the parameters */
162
+  assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup));
163
+  
164
+  /* Set the PRIGROUP[10:8] bits according to the PriorityGroup parameter value */
165
+  NVIC_SetPriorityGrouping(PriorityGroup);
166
+}
167
+
168
+/**
169
+  * @brief  Sets the priority of an interrupt.
170
+  * @param  IRQn: External interrupt number.
171
+  *         This parameter can be an enumerator of IRQn_Type enumeration
172
+  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xx.h))
173
+  * @param  PreemptPriority: The preemption priority for the IRQn channel.
174
+  *         This parameter can be a value between 0 and 15
175
+  *         A lower priority value indicates a higher priority 
176
+  * @param  SubPriority: the subpriority level for the IRQ channel.
177
+  *         This parameter can be a value between 0 and 15
178
+  *         A lower priority value indicates a higher priority.          
179
+  * @retval None
180
+  */
181
+void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
182
+{ 
183
+  uint32_t prioritygroup = 0x00U;
184
+  
185
+  /* Check the parameters */
186
+  assert_param(IS_NVIC_SUB_PRIORITY(SubPriority));
187
+  assert_param(IS_NVIC_PREEMPTION_PRIORITY(PreemptPriority));
188
+  
189
+  prioritygroup = NVIC_GetPriorityGrouping();
190
+  
191
+  NVIC_SetPriority(IRQn, NVIC_EncodePriority(prioritygroup, PreemptPriority, SubPriority));
192
+}
193
+
194
+/**
195
+  * @brief  Enables a device specific interrupt in the NVIC interrupt controller.
196
+  * @note   To configure interrupts priority correctly, the NVIC_PriorityGroupConfig()
197
+  *         function should be called before. 
198
+  * @param  IRQn External interrupt number.
199
+  *         This parameter can be an enumerator of IRQn_Type enumeration
200
+  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xxx.h))
201
+  * @retval None
202
+  */
203
+void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
204
+{
205
+  /* Check the parameters */
206
+  assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
207
+
208
+  /* Enable interrupt */
209
+  NVIC_EnableIRQ(IRQn);
210
+}
211
+
212
+/**
213
+  * @brief  Disables a device specific interrupt in the NVIC interrupt controller.
214
+  * @param  IRQn External interrupt number.
215
+  *         This parameter can be an enumerator of IRQn_Type enumeration
216
+  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xxx.h))  
217
+  * @retval None
218
+  */
219
+void HAL_NVIC_DisableIRQ(IRQn_Type IRQn)
220
+{
221
+  /* Check the parameters */
222
+  assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
223
+
224
+  /* Disable interrupt */
225
+  NVIC_DisableIRQ(IRQn);
226
+}
227
+
228
+/**
229
+  * @brief  Initiates a system reset request to reset the MCU.
230
+  * @retval None
231
+  */
232
+void HAL_NVIC_SystemReset(void)
233
+{
234
+  /* System Reset */
235
+  NVIC_SystemReset();
236
+}
237
+
238
+/**
239
+  * @brief  Initializes the System Timer and its interrupt, and starts the System Tick Timer.
240
+  *         Counter is in free running mode to generate periodic interrupts.
241
+  * @param  TicksNumb: Specifies the ticks Number of ticks between two interrupts.
242
+  * @retval status:  - 0  Function succeeded.
243
+  *                  - 1  Function failed.
244
+  */
245
+uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb)
246
+{
247
+   return SysTick_Config(TicksNumb);
248
+}
249
+/**
250
+  * @}
251
+  */
252
+
253
+/** @defgroup CORTEX_Exported_Functions_Group2 Peripheral Control functions
254
+  *  @brief   Cortex control functions 
255
+  *
256
+@verbatim   
257
+  ==============================================================================
258
+                      ##### Peripheral Control functions #####
259
+  ==============================================================================
260
+    [..]
261
+      This subsection provides a set of functions allowing to control the CORTEX
262
+      (NVIC, SYSTICK, MPU) functionalities. 
263
+ 
264
+      
265
+@endverbatim
266
+  * @{
267
+  */
268
+
269
+#if (__MPU_PRESENT == 1U)
270
+/**
271
+  * @brief  Disables the MPU
272
+  * @retval None
273
+  */
274
+void HAL_MPU_Disable(void)
275
+{
276
+  /* Make sure outstanding transfers are done */
277
+  __DMB();
278
+
279
+  /* Disable fault exceptions */
280
+  SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
281
+  
282
+  /* Disable the MPU and clear the control register*/
283
+  MPU->CTRL = 0U;
284
+}
285
+
286
+/**
287
+  * @brief  Enable the MPU.
288
+  * @param  MPU_Control: Specifies the control mode of the MPU during hard fault, 
289
+  *          NMI, FAULTMASK and privileged access to the default memory 
290
+  *          This parameter can be one of the following values:
291
+  *            @arg MPU_HFNMI_PRIVDEF_NONE
292
+  *            @arg MPU_HARDFAULT_NMI
293
+  *            @arg MPU_PRIVILEGED_DEFAULT
294
+  *            @arg MPU_HFNMI_PRIVDEF
295
+  * @retval None
296
+  */
297
+void HAL_MPU_Enable(uint32_t MPU_Control)
298
+{
299
+  /* Enable the MPU */
300
+  MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
301
+  
302
+  /* Enable fault exceptions */
303
+  SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
304
+  
305
+  /* Ensure MPU setting take effects */
306
+  __DSB();
307
+  __ISB();
308
+}
309
+
310
+/**
311
+  * @brief  Initializes and configures the Region and the memory to be protected.
312
+  * @param  MPU_Init: Pointer to a MPU_Region_InitTypeDef structure that contains
313
+  *                the initialization and configuration information.
314
+  * @retval None
315
+  */
316
+void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init)
317
+{
318
+  /* Check the parameters */
319
+  assert_param(IS_MPU_REGION_NUMBER(MPU_Init->Number));
320
+  assert_param(IS_MPU_REGION_ENABLE(MPU_Init->Enable));
321
+
322
+  /* Set the Region number */
323
+  MPU->RNR = MPU_Init->Number;
324
+
325
+  if ((MPU_Init->Enable) != RESET)
326
+  {
327
+    /* Check the parameters */
328
+    assert_param(IS_MPU_INSTRUCTION_ACCESS(MPU_Init->DisableExec));
329
+    assert_param(IS_MPU_REGION_PERMISSION_ATTRIBUTE(MPU_Init->AccessPermission));
330
+    assert_param(IS_MPU_TEX_LEVEL(MPU_Init->TypeExtField));
331
+    assert_param(IS_MPU_ACCESS_SHAREABLE(MPU_Init->IsShareable));
332
+    assert_param(IS_MPU_ACCESS_CACHEABLE(MPU_Init->IsCacheable));
333
+    assert_param(IS_MPU_ACCESS_BUFFERABLE(MPU_Init->IsBufferable));
334
+    assert_param(IS_MPU_SUB_REGION_DISABLE(MPU_Init->SubRegionDisable));
335
+    assert_param(IS_MPU_REGION_SIZE(MPU_Init->Size));
336
+    
337
+    MPU->RBAR = MPU_Init->BaseAddress;
338
+    MPU->RASR = ((uint32_t)MPU_Init->DisableExec             << MPU_RASR_XN_Pos)   |
339
+                ((uint32_t)MPU_Init->AccessPermission        << MPU_RASR_AP_Pos)   |
340
+                ((uint32_t)MPU_Init->TypeExtField            << MPU_RASR_TEX_Pos)  |
341
+                ((uint32_t)MPU_Init->IsShareable             << MPU_RASR_S_Pos)    |
342
+                ((uint32_t)MPU_Init->IsCacheable             << MPU_RASR_C_Pos)    |
343
+                ((uint32_t)MPU_Init->IsBufferable            << MPU_RASR_B_Pos)    |
344
+                ((uint32_t)MPU_Init->SubRegionDisable        << MPU_RASR_SRD_Pos)  |
345
+                ((uint32_t)MPU_Init->Size                    << MPU_RASR_SIZE_Pos) |
346
+                ((uint32_t)MPU_Init->Enable                  << MPU_RASR_ENABLE_Pos);
347
+  }
348
+  else
349
+  {
350
+    MPU->RBAR = 0x00U;
351
+    MPU->RASR = 0x00U;
352
+  }
353
+}
354
+#endif /* __MPU_PRESENT */
355
+
356
+/**
357
+  * @brief  Gets the priority grouping field from the NVIC Interrupt Controller.
358
+  * @retval Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field)
359
+  */
360
+uint32_t HAL_NVIC_GetPriorityGrouping(void)
361
+{
362
+  /* Get the PRIGROUP[10:8] field value */
363
+  return NVIC_GetPriorityGrouping();
364
+}
365
+
366
+/**
367
+  * @brief  Gets the priority of an interrupt.
368
+  * @param  IRQn: External interrupt number.
369
+  *         This parameter can be an enumerator of IRQn_Type enumeration
370
+  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xxx.h))
371
+  * @param   PriorityGroup: the priority grouping bits length.
372
+  *         This parameter can be one of the following values:
373
+  *           @arg NVIC_PRIORITYGROUP_0: 0 bits for preemption priority
374
+  *                                      4 bits for subpriority
375
+  *           @arg NVIC_PRIORITYGROUP_1: 1 bits for preemption priority
376
+  *                                      3 bits for subpriority
377
+  *           @arg NVIC_PRIORITYGROUP_2: 2 bits for preemption priority
378
+  *                                      2 bits for subpriority
379
+  *           @arg NVIC_PRIORITYGROUP_3: 3 bits for preemption priority
380
+  *                                      1 bits for subpriority
381
+  *           @arg NVIC_PRIORITYGROUP_4: 4 bits for preemption priority
382
+  *                                      0 bits for subpriority
383
+  * @param  pPreemptPriority: Pointer on the Preemptive priority value (starting from 0).
384
+  * @param  pSubPriority: Pointer on the Subpriority value (starting from 0).
385
+  * @retval None
386
+  */
387
+void HAL_NVIC_GetPriority(IRQn_Type IRQn, uint32_t PriorityGroup, uint32_t *pPreemptPriority, uint32_t *pSubPriority)
388
+{
389
+  /* Check the parameters */
390
+  assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup));
391
+ /* Get priority for Cortex-M system or device specific interrupts */
392
+  NVIC_DecodePriority(NVIC_GetPriority(IRQn), PriorityGroup, pPreemptPriority, pSubPriority);
393
+}
394
+
395
+/**
396
+  * @brief  Sets Pending bit of an external interrupt.
397
+  * @param  IRQn External interrupt number
398
+  *         This parameter can be an enumerator of IRQn_Type enumeration
399
+  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xxx.h))  
400
+  * @retval None
401
+  */
402
+void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn)
403
+{
404
+  /* Check the parameters */
405
+  assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
406
+  
407
+  /* Set interrupt pending */
408
+  NVIC_SetPendingIRQ(IRQn);
409
+}
410
+
411
+/**
412
+  * @brief  Gets Pending Interrupt (reads the pending register in the NVIC 
413
+  *         and returns the pending bit for the specified interrupt).
414
+  * @param  IRQn External interrupt number.
415
+  *         This parameter can be an enumerator of IRQn_Type enumeration
416
+  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xxx.h))  
417
+  * @retval status: - 0  Interrupt status is not pending.
418
+  *                 - 1  Interrupt status is pending.
419
+  */
420
+uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn)
421
+{
422
+  /* Check the parameters */
423
+  assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
424
+
425
+  /* Return 1 if pending else 0 */
426
+  return NVIC_GetPendingIRQ(IRQn);
427
+}
428
+
429
+/**
430
+  * @brief  Clears the pending bit of an external interrupt.
431
+  * @param  IRQn External interrupt number.
432
+  *         This parameter can be an enumerator of IRQn_Type enumeration
433
+  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xxx.h))  
434
+  * @retval None
435
+  */
436
+void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn)
437
+{
438
+  /* Check the parameters */
439
+  assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
440
+
441
+  /* Clear pending interrupt */
442
+  NVIC_ClearPendingIRQ(IRQn);
443
+}
444
+
445
+/**
446
+  * @brief Gets active interrupt ( reads the active register in NVIC and returns the active bit).
447
+  * @param IRQn External interrupt number
448
+  *         This parameter can be an enumerator of IRQn_Type enumeration
449
+  *         (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xxx.h))  
450
+  * @retval status: - 0  Interrupt status is not pending.
451
+  *                 - 1  Interrupt status is pending.
452
+  */
453
+uint32_t HAL_NVIC_GetActive(IRQn_Type IRQn)
454
+{
455
+  /* Check the parameters */
456
+  assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
457
+
458
+  /* Return 1 if active else 0 */
459
+  return NVIC_GetActive(IRQn);
460
+}
461
+
462
+/**
463
+  * @brief  Configures the SysTick clock source.
464
+  * @param  CLKSource: specifies the SysTick clock source.
465
+  *         This parameter can be one of the following values:
466
+  *             @arg SYSTICK_CLKSOURCE_HCLK_DIV8: AHB clock divided by 8 selected as SysTick clock source.
467
+  *             @arg SYSTICK_CLKSOURCE_HCLK: AHB clock selected as SysTick clock source.
468
+  * @retval None
469
+  */
470
+void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource)
471
+{
472
+  /* Check the parameters */
473
+  assert_param(IS_SYSTICK_CLK_SOURCE(CLKSource));
474
+  if (CLKSource == SYSTICK_CLKSOURCE_HCLK)
475
+  {
476
+    SysTick->CTRL |= SYSTICK_CLKSOURCE_HCLK;
477
+  }
478
+  else
479
+  {
480
+    SysTick->CTRL &= ~SYSTICK_CLKSOURCE_HCLK;
481
+  }
482
+}
483
+
484
+/**
485
+  * @brief  This function handles SYSTICK interrupt request.
486
+  * @retval None
487
+  */
488
+void HAL_SYSTICK_IRQHandler(void)
489
+{
490
+  HAL_SYSTICK_Callback();
491
+}
492
+
493
+/**
494
+  * @brief  SYSTICK callback.
495
+  * @retval None
496
+  */
497
+__weak void HAL_SYSTICK_Callback(void)
498
+{
499
+  /* NOTE : This function Should not be modified, when the callback is needed,
500
+            the HAL_SYSTICK_Callback could be implemented in the user file
501
+   */
502
+}
503
+
504
+/**
505
+  * @}
506
+  */
507
+
508
+/**
509
+  * @}
510
+  */
511
+
512
+#endif /* HAL_CORTEX_MODULE_ENABLED */
513
+/**
514
+  * @}
515
+  */
516
+
517
+/**
518
+  * @}
519
+  */
520
+
521
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 902 - 0
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c

@@ -0,0 +1,902 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_dma.c
4
+  * @author  MCD Application Team
5
+  * @brief   DMA HAL module driver.
6
+  *         This file provides firmware functions to manage the following
7
+  *         functionalities of the Direct Memory Access (DMA) peripheral:
8
+  *           + Initialization and de-initialization functions
9
+  *           + IO operation functions
10
+  *           + Peripheral State and errors functions
11
+  @verbatim
12
+  ==============================================================================
13
+                        ##### How to use this driver #####
14
+  ==============================================================================
15
+  [..]
16
+   (#) Enable and configure the peripheral to be connected to the DMA Channel
17
+       (except for internal SRAM / FLASH memories: no initialization is 
18
+       necessary). Please refer to the Reference manual for connection between peripherals
19
+       and DMA requests.
20
+
21
+   (#) For a given Channel, program the required configuration through the following parameters:
22
+       Channel request, Transfer Direction, Source and Destination data formats,
23
+       Circular or Normal mode, Channel Priority level, Source and Destination Increment mode
24
+       using HAL_DMA_Init() function.
25
+
26
+   (#) Use HAL_DMA_GetState() function to return the DMA state and HAL_DMA_GetError() in case of error 
27
+       detection.
28
+                    
29
+   (#) Use HAL_DMA_Abort() function to abort the current transfer
30
+                   
31
+     -@-   In Memory-to-Memory transfer mode, Circular mode is not allowed.
32
+     *** Polling mode IO operation ***
33
+     =================================
34
+    [..]
35
+          (+) Use HAL_DMA_Start() to start DMA transfer after the configuration of Source
36
+              address and destination address and the Length of data to be transferred
37
+          (+) Use HAL_DMA_PollForTransfer() to poll for the end of current transfer, in this
38
+              case a fixed Timeout can be configured by User depending from his application.
39
+
40
+     *** Interrupt mode IO operation ***
41
+     ===================================
42
+    [..]
43
+          (+) Configure the DMA interrupt priority using HAL_NVIC_SetPriority()
44
+          (+) Enable the DMA IRQ handler using HAL_NVIC_EnableIRQ()
45
+          (+) Use HAL_DMA_Start_IT() to start DMA transfer after the configuration of
46
+              Source address and destination address and the Length of data to be transferred.
47
+              In this case the DMA interrupt is configured
48
+          (+) Use HAL_DMA_IRQHandler() called under DMA_IRQHandler() Interrupt subroutine
49
+          (+) At the end of data transfer HAL_DMA_IRQHandler() function is executed and user can
50
+              add his own function by customization of function pointer XferCpltCallback and
51
+              XferErrorCallback (i.e. a member of DMA handle structure).
52
+
53
+     *** DMA HAL driver macros list ***
54
+     ============================================= 
55
+      [..]
56
+       Below the list of most used macros in DMA HAL driver.
57
+
58
+       (+) __HAL_DMA_ENABLE: Enable the specified DMA Channel.
59
+       (+) __HAL_DMA_DISABLE: Disable the specified DMA Channel.
60
+       (+) __HAL_DMA_GET_FLAG: Get the DMA Channel pending flags.
61
+       (+) __HAL_DMA_CLEAR_FLAG: Clear the DMA Channel pending flags.
62
+       (+) __HAL_DMA_ENABLE_IT: Enable the specified DMA Channel interrupts.
63
+       (+) __HAL_DMA_DISABLE_IT: Disable the specified DMA Channel interrupts.
64
+       (+) __HAL_DMA_GET_IT_SOURCE: Check whether the specified DMA Channel interrupt has occurred or not. 
65
+
66
+     [..] 
67
+      (@) You can refer to the DMA HAL driver header file for more useful macros  
68
+
69
+  @endverbatim
70
+  ******************************************************************************
71
+  * @attention
72
+  *
73
+  * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
74
+  *
75
+  * Redistribution and use in source and binary forms, with or without modification,
76
+  * are permitted provided that the following conditions are met:
77
+  *   1. Redistributions of source code must retain the above copyright notice,
78
+  *      this list of conditions and the following disclaimer.
79
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
80
+  *      this list of conditions and the following disclaimer in the documentation
81
+  *      and/or other materials provided with the distribution.
82
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
83
+  *      may be used to endorse or promote products derived from this software
84
+  *      without specific prior written permission.
85
+  *
86
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
87
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
88
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
89
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
90
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
91
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
92
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
93
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
94
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
95
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
96
+  *
97
+  ******************************************************************************
98
+  */
99
+
100
+/* Includes ------------------------------------------------------------------*/
101
+#include "stm32f1xx_hal.h"
102
+
103
+/** @addtogroup STM32F1xx_HAL_Driver
104
+  * @{
105
+  */
106
+
107
+/** @defgroup DMA DMA
108
+  * @brief DMA HAL module driver
109
+  * @{
110
+  */
111
+
112
+#ifdef HAL_DMA_MODULE_ENABLED
113
+
114
+/* Private typedef -----------------------------------------------------------*/
115
+/* Private define ------------------------------------------------------------*/
116
+/* Private macro -------------------------------------------------------------*/
117
+/* Private variables ---------------------------------------------------------*/
118
+/* Private function prototypes -----------------------------------------------*/
119
+/** @defgroup DMA_Private_Functions DMA Private Functions
120
+  * @{
121
+  */
122
+static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength);
123
+/**
124
+  * @}
125
+  */
126
+
127
+/* Exported functions ---------------------------------------------------------*/
128
+
129
+/** @defgroup DMA_Exported_Functions DMA Exported Functions
130
+  * @{
131
+  */
132
+
133
+/** @defgroup DMA_Exported_Functions_Group1 Initialization and de-initialization functions
134
+  *  @brief   Initialization and de-initialization functions 
135
+  *
136
+@verbatim
137
+ ===============================================================================
138
+             ##### Initialization and de-initialization functions  #####
139
+ ===============================================================================
140
+    [..]
141
+    This section provides functions allowing to initialize the DMA Channel source
142
+    and destination addresses, incrementation and data sizes, transfer direction, 
143
+    circular/normal mode selection, memory-to-memory mode selection and Channel priority value.
144
+    [..]
145
+    The HAL_DMA_Init() function follows the DMA configuration procedures as described in
146
+    reference manual.  
147
+
148
+@endverbatim
149
+  * @{
150
+  */
151
+
152
+/**
153
+  * @brief  Initialize the DMA according to the specified
154
+  *         parameters in the DMA_InitTypeDef and initialize the associated handle.
155
+  * @param  hdma: Pointer to a DMA_HandleTypeDef structure that contains
156
+  *               the configuration information for the specified DMA Channel.
157
+  * @retval HAL status
158
+  */
159
+HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma)
160
+{
161
+  uint32_t tmp = 0U;
162
+
163
+  /* Check the DMA handle allocation */
164
+  if(hdma == NULL)
165
+  {
166
+    return HAL_ERROR;
167
+  }
168
+
169
+  /* Check the parameters */
170
+  assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
171
+  assert_param(IS_DMA_DIRECTION(hdma->Init.Direction));
172
+  assert_param(IS_DMA_PERIPHERAL_INC_STATE(hdma->Init.PeriphInc));
173
+  assert_param(IS_DMA_MEMORY_INC_STATE(hdma->Init.MemInc));
174
+  assert_param(IS_DMA_PERIPHERAL_DATA_SIZE(hdma->Init.PeriphDataAlignment));
175
+  assert_param(IS_DMA_MEMORY_DATA_SIZE(hdma->Init.MemDataAlignment));
176
+  assert_param(IS_DMA_MODE(hdma->Init.Mode));
177
+  assert_param(IS_DMA_PRIORITY(hdma->Init.Priority));
178
+
179
+#if defined (STM32F101xE) || defined (STM32F101xG) || defined (STM32F103xE) || defined (STM32F103xG) || defined (STM32F100xE) || defined (STM32F105xC) || defined (STM32F107xC)
180
+  /* calculation of the channel index */
181
+  if ((uint32_t)(hdma->Instance) < (uint32_t)(DMA2_Channel1))
182
+  {
183
+    /* DMA1 */
184
+    hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA1_Channel1) / ((uint32_t)DMA1_Channel2 - (uint32_t)DMA1_Channel1)) << 2;
185
+    hdma->DmaBaseAddress = DMA1;
186
+  }
187
+  else 
188
+  {
189
+    /* DMA2 */
190
+    hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA2_Channel1) / ((uint32_t)DMA2_Channel2 - (uint32_t)DMA2_Channel1)) << 2;
191
+    hdma->DmaBaseAddress = DMA2;
192
+  }
193
+#else
194
+  /* DMA1 */
195
+  hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA1_Channel1) / ((uint32_t)DMA1_Channel2 - (uint32_t)DMA1_Channel1)) << 2;
196
+  hdma->DmaBaseAddress = DMA1;
197
+#endif /* STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG || STM32F100xE || STM32F105xC || STM32F107xC */
198
+
199
+  /* Change DMA peripheral state */
200
+  hdma->State = HAL_DMA_STATE_BUSY;
201
+
202
+  /* Get the CR register value */
203
+  tmp = hdma->Instance->CCR;
204
+
205
+  /* Clear PL, MSIZE, PSIZE, MINC, PINC, CIRC and DIR bits */
206
+  tmp &= ((uint32_t)~(DMA_CCR_PL    | DMA_CCR_MSIZE  | DMA_CCR_PSIZE  | \
207
+                      DMA_CCR_MINC  | DMA_CCR_PINC   | DMA_CCR_CIRC   | \
208
+                      DMA_CCR_DIR));
209
+
210
+  /* Prepare the DMA Channel configuration */
211
+  tmp |=  hdma->Init.Direction        |
212
+          hdma->Init.PeriphInc           | hdma->Init.MemInc           |
213
+          hdma->Init.PeriphDataAlignment | hdma->Init.MemDataAlignment |
214
+          hdma->Init.Mode                | hdma->Init.Priority;
215
+
216
+  /* Write to DMA Channel CR register */
217
+  hdma->Instance->CCR = tmp;
218
+
219
+  /* Initialise the error code */
220
+  hdma->ErrorCode = HAL_DMA_ERROR_NONE;
221
+
222
+  /* Initialize the DMA state*/
223
+  hdma->State = HAL_DMA_STATE_READY;
224
+  /* Allocate lock resource and initialize it */
225
+  hdma->Lock = HAL_UNLOCKED;
226
+
227
+  return HAL_OK;
228
+}
229
+
230
+/**
231
+  * @brief  DeInitialize the DMA peripheral.
232
+  * @param  hdma: pointer to a DMA_HandleTypeDef structure that contains
233
+  *               the configuration information for the specified DMA Channel.
234
+  * @retval HAL status
235
+  */
236
+HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma)
237
+{
238
+  /* Check the DMA handle allocation */
239
+  if(hdma == NULL)
240
+  {
241
+    return HAL_ERROR;
242
+  }
243
+
244
+  /* Check the parameters */
245
+  assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance));
246
+
247
+  /* Disable the selected DMA Channelx */
248
+  __HAL_DMA_DISABLE(hdma);
249
+
250
+  /* Reset DMA Channel control register */
251
+  hdma->Instance->CCR  = 0U;
252
+
253
+  /* Reset DMA Channel Number of Data to Transfer register */
254
+  hdma->Instance->CNDTR = 0U;
255
+
256
+  /* Reset DMA Channel peripheral address register */
257
+  hdma->Instance->CPAR  = 0U;
258
+
259
+  /* Reset DMA Channel memory address register */
260
+  hdma->Instance->CMAR = 0U;
261
+
262
+#if defined (STM32F101xE) || defined (STM32F101xG) || defined (STM32F103xE) || defined (STM32F103xG) || defined (STM32F100xE) || defined (STM32F105xC) || defined (STM32F107xC)
263
+  /* calculation of the channel index */
264
+  if ((uint32_t)(hdma->Instance) < (uint32_t)(DMA2_Channel1))
265
+  {
266
+    /* DMA1 */
267
+    hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA1_Channel1) / ((uint32_t)DMA1_Channel2 - (uint32_t)DMA1_Channel1)) << 2;
268
+    hdma->DmaBaseAddress = DMA1;
269
+  }
270
+  else
271
+  {
272
+    /* DMA2 */
273
+    hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA2_Channel1) / ((uint32_t)DMA2_Channel2 - (uint32_t)DMA2_Channel1)) << 2;
274
+    hdma->DmaBaseAddress = DMA2;
275
+  }
276
+#else
277
+  /* DMA1 */
278
+  hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA1_Channel1) / ((uint32_t)DMA1_Channel2 - (uint32_t)DMA1_Channel1)) << 2;
279
+  hdma->DmaBaseAddress = DMA1;
280
+#endif /* STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG || STM32F100xE || STM32F105xC || STM32F107xC */
281
+
282
+  /* Clear all flags */
283
+  hdma->DmaBaseAddress->IFCR = (DMA_ISR_GIF1 << (hdma->ChannelIndex));
284
+
285
+  /* Clean all callbacks */
286
+  hdma->XferCpltCallback = NULL;
287
+  hdma->XferHalfCpltCallback = NULL;
288
+  hdma->XferErrorCallback = NULL;
289
+  hdma->XferAbortCallback = NULL;
290
+
291
+  /* Reset the error code */
292
+  hdma->ErrorCode = HAL_DMA_ERROR_NONE;
293
+
294
+  /* Reset the DMA state */
295
+  hdma->State = HAL_DMA_STATE_RESET;
296
+
297
+  /* Release Lock */
298
+  __HAL_UNLOCK(hdma);
299
+
300
+  return HAL_OK;
301
+}
302
+
303
+/**
304
+  * @}
305
+  */
306
+
307
+/** @defgroup DMA_Exported_Functions_Group2 Input and Output operation functions
308
+  *  @brief   Input and Output operation functions
309
+  *
310
+@verbatim
311
+ ===============================================================================
312
+                      #####  IO operation functions  #####
313
+ ===============================================================================
314
+    [..]  This section provides functions allowing to:
315
+      (+) Configure the source, destination address and data length and Start DMA transfer
316
+      (+) Configure the source, destination address and data length and
317
+          Start DMA transfer with interrupt
318
+      (+) Abort DMA transfer
319
+      (+) Poll for transfer complete
320
+      (+) Handle DMA interrupt request
321
+
322
+@endverbatim
323
+  * @{
324
+  */
325
+
326
+/**
327
+  * @brief  Start the DMA Transfer.
328
+  * @param  hdma: pointer to a DMA_HandleTypeDef structure that contains
329
+  *               the configuration information for the specified DMA Channel.
330
+  * @param  SrcAddress: The source memory Buffer address
331
+  * @param  DstAddress: The destination memory Buffer address
332
+  * @param  DataLength: The length of data to be transferred from source to destination
333
+  * @retval HAL status
334
+  */
335
+HAL_StatusTypeDef HAL_DMA_Start(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
336
+{
337
+  HAL_StatusTypeDef status = HAL_OK;
338
+
339
+  /* Check the parameters */
340
+  assert_param(IS_DMA_BUFFER_SIZE(DataLength));
341
+
342
+  /* Process locked */
343
+  __HAL_LOCK(hdma);
344
+
345
+  if(HAL_DMA_STATE_READY == hdma->State)
346
+  {
347
+    /* Change DMA peripheral state */
348
+    hdma->State = HAL_DMA_STATE_BUSY;
349
+    hdma->ErrorCode = HAL_DMA_ERROR_NONE;
350
+            
351
+    /* Disable the peripheral */
352
+    __HAL_DMA_DISABLE(hdma);
353
+    
354
+    /* Configure the source, destination address and the data length & clear flags*/
355
+    DMA_SetConfig(hdma, SrcAddress, DstAddress, DataLength);
356
+    
357
+    /* Enable the Peripheral */
358
+    __HAL_DMA_ENABLE(hdma);
359
+  }
360
+  else
361
+  {
362
+   /* Process Unlocked */
363
+   __HAL_UNLOCK(hdma);  
364
+   status = HAL_BUSY;
365
+  }  
366
+  return status;
367
+}
368
+
369
+/**
370
+  * @brief  Start the DMA Transfer with interrupt enabled.
371
+  * @param  hdma: pointer to a DMA_HandleTypeDef structure that contains
372
+  *               the configuration information for the specified DMA Channel.
373
+  * @param  SrcAddress: The source memory Buffer address
374
+  * @param  DstAddress: The destination memory Buffer address
375
+  * @param  DataLength: The length of data to be transferred from source to destination
376
+  * @retval HAL status
377
+  */
378
+HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
379
+{
380
+  HAL_StatusTypeDef status = HAL_OK;
381
+
382
+  /* Check the parameters */
383
+  assert_param(IS_DMA_BUFFER_SIZE(DataLength));
384
+
385
+  /* Process locked */
386
+  __HAL_LOCK(hdma);
387
+  
388
+  if(HAL_DMA_STATE_READY == hdma->State)
389
+  {
390
+    /* Change DMA peripheral state */
391
+    hdma->State = HAL_DMA_STATE_BUSY;
392
+    hdma->ErrorCode = HAL_DMA_ERROR_NONE;
393
+    
394
+    /* Disable the peripheral */
395
+    __HAL_DMA_DISABLE(hdma);
396
+    
397
+    /* Configure the source, destination address and the data length & clear flags*/
398
+    DMA_SetConfig(hdma, SrcAddress, DstAddress, DataLength);
399
+    
400
+    /* Enable the transfer complete interrupt */
401
+    /* Enable the transfer Error interrupt */
402
+    if(NULL != hdma->XferHalfCpltCallback)
403
+    {
404
+      /* Enable the Half transfer complete interrupt as well */
405
+      __HAL_DMA_ENABLE_IT(hdma, (DMA_IT_TC | DMA_IT_HT | DMA_IT_TE));
406
+    }
407
+    else
408
+    {
409
+      __HAL_DMA_DISABLE_IT(hdma, DMA_IT_HT);
410
+      __HAL_DMA_ENABLE_IT(hdma, (DMA_IT_TC | DMA_IT_TE));
411
+    }
412
+    /* Enable the Peripheral */
413
+    __HAL_DMA_ENABLE(hdma);
414
+  }
415
+  else
416
+  {      
417
+    /* Process Unlocked */
418
+    __HAL_UNLOCK(hdma); 
419
+
420
+    /* Remain BUSY */
421
+    status = HAL_BUSY;
422
+  }    
423
+  return status;
424
+}
425
+
426
+/**
427
+  * @brief  Abort the DMA Transfer.
428
+  * @param  hdma: pointer to a DMA_HandleTypeDef structure that contains
429
+  *               the configuration information for the specified DMA Channel.
430
+  * @retval HAL status
431
+  */
432
+HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
433
+{
434
+  HAL_StatusTypeDef status = HAL_OK;
435
+
436
+  /* Disable DMA IT */
437
+  __HAL_DMA_DISABLE_IT(hdma, (DMA_IT_TC | DMA_IT_HT | DMA_IT_TE));
438
+    
439
+  /* Disable the channel */
440
+  __HAL_DMA_DISABLE(hdma);
441
+    
442
+  /* Clear all flags */
443
+  hdma->DmaBaseAddress->IFCR = (DMA_ISR_GIF1 << hdma->ChannelIndex);
444
+
445
+  /* Change the DMA state */
446
+  hdma->State = HAL_DMA_STATE_READY;
447
+
448
+  /* Process Unlocked */
449
+  __HAL_UNLOCK(hdma);      
450
+  
451
+  return status; 
452
+}
453
+
454
+/**
455
+  * @brief  Aborts the DMA Transfer in Interrupt mode.
456
+  * @param  hdma  : pointer to a DMA_HandleTypeDef structure that contains
457
+  *                 the configuration information for the specified DMA Channel.
458
+  * @retval HAL status
459
+  */
460
+HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
461
+{  
462
+  HAL_StatusTypeDef status = HAL_OK;
463
+  
464
+  if(HAL_DMA_STATE_BUSY != hdma->State)
465
+  {
466
+    /* no transfer ongoing */
467
+    hdma->ErrorCode = HAL_DMA_ERROR_NO_XFER;
468
+        
469
+    status = HAL_ERROR;
470
+  }
471
+  else
472
+  { 
473
+    /* Disable DMA IT */
474
+    __HAL_DMA_DISABLE_IT(hdma, (DMA_IT_TC | DMA_IT_HT | DMA_IT_TE));
475
+
476
+    /* Disable the channel */
477
+    __HAL_DMA_DISABLE(hdma);
478
+
479
+    /* Clear all flags */
480
+    __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_GI_FLAG_INDEX(hdma));
481
+
482
+    /* Change the DMA state */
483
+    hdma->State = HAL_DMA_STATE_READY;
484
+
485
+    /* Process Unlocked */
486
+    __HAL_UNLOCK(hdma);
487
+
488
+    /* Call User Abort callback */
489
+    if(hdma->XferAbortCallback != NULL)
490
+    {
491
+      hdma->XferAbortCallback(hdma);
492
+    } 
493
+  }
494
+  return status;
495
+}
496
+
497
+/**
498
+  * @brief  Polling for transfer complete.
499
+  * @param  hdma:    pointer to a DMA_HandleTypeDef structure that contains
500
+  *                  the configuration information for the specified DMA Channel.
501
+  * @param  CompleteLevel: Specifies the DMA level complete.
502
+  * @param  Timeout:       Timeout duration.
503
+  * @retval HAL status
504
+  */
505
+HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, uint32_t CompleteLevel, uint32_t Timeout)
506
+{
507
+  uint32_t temp;
508
+  uint32_t tickstart = 0U;
509
+
510
+  if(HAL_DMA_STATE_BUSY != hdma->State)
511
+  {
512
+    /* no transfer ongoing */
513
+    hdma->ErrorCode = HAL_DMA_ERROR_NO_XFER;
514
+    __HAL_UNLOCK(hdma);
515
+    return HAL_ERROR;
516
+  }
517
+
518
+  /* Polling mode not supported in circular mode */
519
+  if (RESET != (hdma->Instance->CCR & DMA_CCR_CIRC))
520
+  {
521
+    hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED;
522
+    return HAL_ERROR;
523
+  }
524
+  
525
+  /* Get the level transfer complete flag */
526
+  if(CompleteLevel == HAL_DMA_FULL_TRANSFER)
527
+  {
528
+    /* Transfer Complete flag */
529
+    temp = __HAL_DMA_GET_TC_FLAG_INDEX(hdma);
530
+  }
531
+  else
532
+  {
533
+    /* Half Transfer Complete flag */
534
+    temp = __HAL_DMA_GET_HT_FLAG_INDEX(hdma);
535
+  }
536
+
537
+  /* Get tick */
538
+  tickstart = HAL_GetTick();
539
+
540
+  while(__HAL_DMA_GET_FLAG(hdma, temp) == RESET)
541
+  {
542
+    if((__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma)) != RESET))
543
+    {
544
+      /* When a DMA transfer error occurs */
545
+      /* A hardware clear of its EN bits is performed */
546
+      /* Clear all flags */
547
+      hdma->DmaBaseAddress->IFCR = (DMA_ISR_GIF1 << hdma->ChannelIndex);
548
+
549
+      /* Update error code */
550
+      SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_TE);
551
+
552
+      /* Change the DMA state */
553
+      hdma->State= HAL_DMA_STATE_READY;
554
+
555
+      /* Process Unlocked */
556
+      __HAL_UNLOCK(hdma);
557
+
558
+      return HAL_ERROR;
559
+    }
560
+    /* Check for the Timeout */
561
+    if(Timeout != HAL_MAX_DELAY)
562
+    {
563
+      if((Timeout == 0U) || ((HAL_GetTick() - tickstart) > Timeout))
564
+      {
565
+        /* Update error code */
566
+        SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_TIMEOUT);
567
+
568
+        /* Change the DMA state */
569
+        hdma->State = HAL_DMA_STATE_READY;
570
+
571
+        /* Process Unlocked */
572
+        __HAL_UNLOCK(hdma);
573
+
574
+        return HAL_ERROR;
575
+      }
576
+    }
577
+  }
578
+
579
+  if(CompleteLevel == HAL_DMA_FULL_TRANSFER)
580
+  {
581
+    /* Clear the transfer complete flag */
582
+    __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma));
583
+
584
+    /* The selected Channelx EN bit is cleared (DMA is disabled and
585
+    all transfers are complete) */
586
+    hdma->State = HAL_DMA_STATE_READY;
587
+  }
588
+  else
589
+  {
590
+    /* Clear the half transfer complete flag */
591
+    __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma));
592
+  }
593
+  
594
+  /* Process unlocked */
595
+  __HAL_UNLOCK(hdma);
596
+
597
+  return HAL_OK;
598
+}
599
+
600
+/**
601
+  * @brief  Handles DMA interrupt request.
602
+  * @param  hdma: pointer to a DMA_HandleTypeDef structure that contains
603
+  *               the configuration information for the specified DMA Channel.  
604
+  * @retval None
605
+  */
606
+void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma)
607
+{
608
+  uint32_t flag_it = hdma->DmaBaseAddress->ISR;
609
+  uint32_t source_it = hdma->Instance->CCR;
610
+  
611
+  /* Half Transfer Complete Interrupt management ******************************/
612
+  if (((flag_it & (DMA_FLAG_HT1 << hdma->ChannelIndex)) != RESET) && ((source_it & DMA_IT_HT) != RESET))
613
+  {
614
+    /* Disable the half transfer interrupt if the DMA mode is not CIRCULAR */
615
+    if((hdma->Instance->CCR & DMA_CCR_CIRC) == 0U)
616
+    {
617
+      /* Disable the half transfer interrupt */
618
+      __HAL_DMA_DISABLE_IT(hdma, DMA_IT_HT);
619
+    }
620
+    /* Clear the half transfer complete flag */
621
+    __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma));
622
+
623
+    /* DMA peripheral state is not updated in Half Transfer */
624
+    /* but in Transfer Complete case */
625
+
626
+    if(hdma->XferHalfCpltCallback != NULL)
627
+    {
628
+      /* Half transfer callback */
629
+      hdma->XferHalfCpltCallback(hdma);
630
+    }
631
+  }
632
+
633
+  /* Transfer Complete Interrupt management ***********************************/
634
+  else if (((flag_it & (DMA_FLAG_TC1 << hdma->ChannelIndex)) != RESET) && ((source_it & DMA_IT_TC) != RESET))
635
+  {
636
+    if((hdma->Instance->CCR & DMA_CCR_CIRC) == 0U)
637
+    {
638
+      /* Disable the transfer complete and error interrupt */
639
+      __HAL_DMA_DISABLE_IT(hdma, DMA_IT_TE | DMA_IT_TC);  
640
+
641
+      /* Change the DMA state */
642
+      hdma->State = HAL_DMA_STATE_READY;
643
+    }
644
+    /* Clear the transfer complete flag */
645
+      __HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma));
646
+
647
+    /* Process Unlocked */
648
+    __HAL_UNLOCK(hdma);
649
+
650
+    if(hdma->XferCpltCallback != NULL)
651
+    {
652
+      /* Transfer complete callback */
653
+      hdma->XferCpltCallback(hdma);
654
+    }
655
+  }
656
+
657
+  /* Transfer Error Interrupt management **************************************/
658
+  else if (( RESET != (flag_it & (DMA_FLAG_TE1 << hdma->ChannelIndex))) && (RESET != (source_it & DMA_IT_TE)))
659
+  {
660
+    /* When a DMA transfer error occurs */
661
+    /* A hardware clear of its EN bits is performed */
662
+    /* Disable ALL DMA IT */
663
+    __HAL_DMA_DISABLE_IT(hdma, (DMA_IT_TC | DMA_IT_HT | DMA_IT_TE));
664
+
665
+    /* Clear all flags */
666
+    hdma->DmaBaseAddress->IFCR = (DMA_ISR_GIF1 << hdma->ChannelIndex);
667
+
668
+    /* Update error code */
669
+    hdma->ErrorCode = HAL_DMA_ERROR_TE;
670
+
671
+    /* Change the DMA state */
672
+    hdma->State = HAL_DMA_STATE_READY;
673
+
674
+    /* Process Unlocked */
675
+    __HAL_UNLOCK(hdma);
676
+
677
+    if (hdma->XferErrorCallback != NULL)
678
+    {
679
+      /* Transfer error callback */
680
+      hdma->XferErrorCallback(hdma);
681
+    }
682
+  }
683
+  return;
684
+}
685
+
686
+/**
687
+  * @brief Register callbacks
688
+  * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
689
+  *              the configuration information for the specified DMA Channel.
690
+  * @param CallbackID: User Callback identifer
691
+  *                    a HAL_DMA_CallbackIDTypeDef ENUM as parameter.
692
+  * @param pCallback: pointer to private callbacsk function which has pointer to 
693
+  *                   a DMA_HandleTypeDef structure as parameter.
694
+  * @retval HAL status
695
+  */                          
696
+HAL_StatusTypeDef HAL_DMA_RegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID, void (* pCallback)( DMA_HandleTypeDef * _hdma))
697
+{
698
+  HAL_StatusTypeDef status = HAL_OK;
699
+  
700
+  /* Process locked */
701
+  __HAL_LOCK(hdma);
702
+  
703
+  if(HAL_DMA_STATE_READY == hdma->State)
704
+  {
705
+    switch (CallbackID)
706
+    {
707
+    case  HAL_DMA_XFER_CPLT_CB_ID:
708
+      hdma->XferCpltCallback = pCallback;
709
+      break;
710
+      
711
+    case  HAL_DMA_XFER_HALFCPLT_CB_ID:
712
+      hdma->XferHalfCpltCallback = pCallback;
713
+      break;         
714
+
715
+    case  HAL_DMA_XFER_ERROR_CB_ID:
716
+      hdma->XferErrorCallback = pCallback;
717
+      break;         
718
+      
719
+    case  HAL_DMA_XFER_ABORT_CB_ID:
720
+      hdma->XferAbortCallback = pCallback;
721
+      break; 
722
+      
723
+    default:
724
+      status = HAL_ERROR;
725
+      break;                                                            
726
+    }
727
+  }
728
+  else
729
+  {
730
+    status = HAL_ERROR;
731
+  } 
732
+  
733
+  /* Release Lock */
734
+  __HAL_UNLOCK(hdma);
735
+  
736
+  return status;
737
+}
738
+
739
+/**
740
+  * @brief UnRegister callbacks
741
+  * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
742
+  *              the configuration information for the specified DMA Channel.
743
+  * @param CallbackID: User Callback identifer
744
+  *                    a HAL_DMA_CallbackIDTypeDef ENUM as parameter.
745
+  * @retval HAL status
746
+  */              
747
+HAL_StatusTypeDef HAL_DMA_UnRegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID)
748
+{
749
+  HAL_StatusTypeDef status = HAL_OK;
750
+
751
+  /* Process locked */
752
+  __HAL_LOCK(hdma);
753
+  
754
+  if(HAL_DMA_STATE_READY == hdma->State)
755
+  {
756
+    switch (CallbackID)
757
+    {
758
+    case  HAL_DMA_XFER_CPLT_CB_ID:
759
+      hdma->XferCpltCallback = NULL;
760
+      break;
761
+
762
+    case  HAL_DMA_XFER_HALFCPLT_CB_ID:
763
+      hdma->XferHalfCpltCallback = NULL;
764
+      break;         
765
+
766
+    case  HAL_DMA_XFER_ERROR_CB_ID:
767
+      hdma->XferErrorCallback = NULL;
768
+      break;         
769
+
770
+    case  HAL_DMA_XFER_ABORT_CB_ID:
771
+      hdma->XferAbortCallback = NULL;
772
+      break; 
773
+
774
+    case   HAL_DMA_XFER_ALL_CB_ID:
775
+      hdma->XferCpltCallback = NULL;
776
+      hdma->XferHalfCpltCallback = NULL;
777
+      hdma->XferErrorCallback = NULL;
778
+      hdma->XferAbortCallback = NULL;
779
+      break; 
780
+
781
+    default:
782
+      status = HAL_ERROR;
783
+      break;
784
+    }
785
+  }
786
+  else
787
+  {
788
+    status = HAL_ERROR;
789
+  } 
790
+  
791
+  /* Release Lock */
792
+  __HAL_UNLOCK(hdma);
793
+  
794
+  return status;
795
+}
796
+  
797
+/**
798
+  * @}
799
+  */
800
+
801
+/** @defgroup DMA_Exported_Functions_Group3 Peripheral State and Errors functions
802
+  *  @brief    Peripheral State and Errors functions
803
+  *
804
+@verbatim
805
+ ===============================================================================
806
+            ##### Peripheral State and Errors functions #####
807
+ ===============================================================================  
808
+    [..]
809
+    This subsection provides functions allowing to
810
+      (+) Check the DMA state
811
+      (+) Get error code
812
+
813
+@endverbatim
814
+  * @{
815
+  */
816
+
817
+/**
818
+  * @brief  Return the DMA hande state.
819
+  * @param  hdma: pointer to a DMA_HandleTypeDef structure that contains
820
+  *               the configuration information for the specified DMA Channel.
821
+  * @retval HAL state
822
+  */
823
+HAL_DMA_StateTypeDef HAL_DMA_GetState(DMA_HandleTypeDef *hdma)
824
+{
825
+  /* Return DMA handle state */
826
+  return hdma->State;
827
+}
828
+
829
+/**
830
+  * @brief  Return the DMA error code.
831
+  * @param  hdma : pointer to a DMA_HandleTypeDef structure that contains
832
+  *              the configuration information for the specified DMA Channel.
833
+  * @retval DMA Error Code
834
+  */
835
+uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma)
836
+{
837
+  return hdma->ErrorCode;
838
+}
839
+
840
+/**
841
+  * @}
842
+  */
843
+
844
+/**
845
+  * @}
846
+  */
847
+
848
+/** @addtogroup DMA_Private_Functions
849
+  * @{
850
+  */
851
+
852
+/**
853
+  * @brief  Sets the DMA Transfer parameter.
854
+  * @param  hdma:       pointer to a DMA_HandleTypeDef structure that contains
855
+  *                     the configuration information for the specified DMA Channel.
856
+  * @param  SrcAddress: The source memory Buffer address
857
+  * @param  DstAddress: The destination memory Buffer address
858
+  * @param  DataLength: The length of data to be transferred from source to destination
859
+  * @retval HAL status
860
+  */
861
+static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
862
+{
863
+  /* Clear all flags */
864
+  hdma->DmaBaseAddress->IFCR = (DMA_ISR_GIF1 << hdma->ChannelIndex);
865
+
866
+  /* Configure DMA Channel data length */
867
+  hdma->Instance->CNDTR = DataLength;
868
+
869
+  /* Memory to Peripheral */
870
+  if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH)
871
+  {
872
+    /* Configure DMA Channel destination address */
873
+    hdma->Instance->CPAR = DstAddress;
874
+
875
+    /* Configure DMA Channel source address */
876
+    hdma->Instance->CMAR = SrcAddress;
877
+  }
878
+  /* Peripheral to Memory */
879
+  else
880
+  {
881
+    /* Configure DMA Channel source address */
882
+    hdma->Instance->CPAR = SrcAddress;
883
+
884
+    /* Configure DMA Channel destination address */
885
+    hdma->Instance->CMAR = DstAddress;
886
+  }
887
+}
888
+
889
+/**
890
+  * @}
891
+  */
892
+
893
+#endif /* HAL_DMA_MODULE_ENABLED */
894
+/**
895
+  * @}
896
+  */
897
+
898
+/**
899
+  * @}
900
+  */
901
+
902
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 983 - 0
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c

@@ -0,0 +1,983 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_flash.c
4
+  * @author  MCD Application Team
5
+  * @brief   FLASH HAL module driver.
6
+  *          This file provides firmware functions to manage the following 
7
+  *          functionalities of the internal FLASH memory:
8
+  *           + Program operations functions
9
+  *           + Memory Control functions 
10
+  *           + Peripheral State functions
11
+  *         
12
+  @verbatim
13
+  ==============================================================================
14
+                        ##### FLASH peripheral features #####
15
+  ==============================================================================
16
+  [..] The Flash memory interface manages CPU AHB I-Code and D-Code accesses 
17
+       to the Flash memory. It implements the erase and program Flash memory operations 
18
+       and the read and write protection mechanisms.
19
+
20
+  [..] The Flash memory interface accelerates code execution with a system of instruction
21
+      prefetch. 
22
+
23
+  [..] The FLASH main features are:
24
+      (+) Flash memory read operations
25
+      (+) Flash memory program/erase operations
26
+      (+) Read / write protections
27
+      (+) Prefetch on I-Code
28
+      (+) Option Bytes programming
29
+
30
+
31
+                     ##### How to use this driver #####
32
+  ==============================================================================
33
+  [..]                             
34
+      This driver provides functions and macros to configure and program the FLASH 
35
+      memory of all STM32F1xx devices.
36
+    
37
+      (#) FLASH Memory I/O Programming functions: this group includes all needed
38
+          functions to erase and program the main memory:
39
+        (++) Lock and Unlock the FLASH interface
40
+        (++) Erase function: Erase page, erase all pages
41
+        (++) Program functions: half word, word and doubleword
42
+      (#) FLASH Option Bytes Programming functions: this group includes all needed
43
+          functions to manage the Option Bytes:
44
+        (++) Lock and Unlock the Option Bytes
45
+        (++) Set/Reset the write protection
46
+        (++) Set the Read protection Level
47
+        (++) Program the user Option Bytes
48
+        (++) Launch the Option Bytes loader
49
+        (++) Erase Option Bytes
50
+        (++) Program the data Option Bytes
51
+        (++) Get the Write protection.
52
+        (++) Get the user option bytes.
53
+    
54
+      (#) Interrupts and flags management functions : this group 
55
+          includes all needed functions to:
56
+        (++) Handle FLASH interrupts
57
+        (++) Wait for last FLASH operation according to its status
58
+        (++) Get error flag status
59
+
60
+  [..] In addition to these function, this driver includes a set of macros allowing
61
+       to handle the following operations:
62
+      
63
+      (+) Set/Get the latency
64
+      (+) Enable/Disable the prefetch buffer
65
+      (+) Enable/Disable the half cycle access
66
+      (+) Enable/Disable the FLASH interrupts
67
+      (+) Monitor the FLASH flags status
68
+          
69
+  @endverbatim
70
+  ******************************************************************************
71
+  * @attention
72
+  *
73
+  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
74
+  *
75
+  * Redistribution and use in source and binary forms, with or without modification,
76
+  * are permitted provided that the following conditions are met:
77
+  *   1. Redistributions of source code must retain the above copyright notice,
78
+  *      this list of conditions and the following disclaimer.
79
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
80
+  *      this list of conditions and the following disclaimer in the documentation
81
+  *      and/or other materials provided with the distribution.
82
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
83
+  *      may be used to endorse or promote products derived from this software
84
+  *      without specific prior written permission.
85
+  *
86
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
87
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
88
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
89
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
90
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
91
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
92
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
93
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
94
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
95
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
96
+  *
97
+  ******************************************************************************  
98
+  */
99
+
100
+/* Includes ------------------------------------------------------------------*/
101
+#include "stm32f1xx_hal.h"
102
+
103
+/** @addtogroup STM32F1xx_HAL_Driver
104
+  * @{
105
+  */
106
+
107
+#ifdef HAL_FLASH_MODULE_ENABLED
108
+
109
+/** @defgroup FLASH FLASH
110
+  * @brief FLASH HAL module driver
111
+  * @{
112
+  */
113
+
114
+/* Private typedef -----------------------------------------------------------*/
115
+/* Private define ------------------------------------------------------------*/
116
+/** @defgroup FLASH_Private_Constants FLASH Private Constants
117
+  * @{
118
+  */
119
+/**
120
+  * @}
121
+  */
122
+
123
+/* Private macro ---------------------------- ---------------------------------*/
124
+/** @defgroup FLASH_Private_Macros FLASH Private Macros
125
+  * @{
126
+  */
127
+ 
128
+/**
129
+  * @}
130
+  */
131
+
132
+/* Private variables ---------------------------------------------------------*/
133
+/** @defgroup FLASH_Private_Variables FLASH Private Variables
134
+  * @{
135
+  */
136
+/* Variables used for Erase pages under interruption*/
137
+FLASH_ProcessTypeDef pFlash;
138
+/**
139
+  * @}
140
+  */
141
+
142
+/* Private function prototypes -----------------------------------------------*/
143
+/** @defgroup FLASH_Private_Functions FLASH Private Functions
144
+  * @{
145
+  */
146
+static  void   FLASH_Program_HalfWord(uint32_t Address, uint16_t Data);
147
+static  void   FLASH_SetErrorCode(void);
148
+extern void    FLASH_PageErase(uint32_t PageAddress);
149
+/**
150
+  * @}
151
+  */
152
+
153
+/* Exported functions ---------------------------------------------------------*/
154
+/** @defgroup FLASH_Exported_Functions FLASH Exported Functions
155
+  * @{
156
+  */
157
+  
158
+/** @defgroup FLASH_Exported_Functions_Group1 Programming operation functions 
159
+  *  @brief   Programming operation functions 
160
+  *
161
+@verbatim   
162
+@endverbatim
163
+  * @{
164
+  */
165
+
166
+/**
167
+  * @brief  Program halfword, word or double word at a specified address
168
+  * @note   The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface
169
+  *         The function HAL_FLASH_Lock() should be called after to lock the FLASH interface
170
+  *
171
+  * @note   If an erase and a program operations are requested simultaneously,    
172
+  *         the erase operation is performed before the program one.
173
+  *  
174
+  * @note   FLASH should be previously erased before new programmation (only exception to this 
175
+  *         is when 0x0000 is programmed)
176
+  *
177
+  * @param  TypeProgram:  Indicate the way to program at a specified address.
178
+  *                       This parameter can be a value of @ref FLASH_Type_Program
179
+  * @param  Address:      Specifies the address to be programmed.
180
+  * @param  Data:         Specifies the data to be programmed
181
+  * 
182
+  * @retval HAL_StatusTypeDef HAL Status
183
+  */
184
+HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
185
+{
186
+  HAL_StatusTypeDef status = HAL_ERROR;
187
+  uint8_t index = 0;
188
+  uint8_t nbiterations = 0;
189
+  
190
+  /* Process Locked */
191
+  __HAL_LOCK(&pFlash);
192
+
193
+  /* Check the parameters */
194
+  assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram));
195
+  assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
196
+
197
+#if defined(FLASH_BANK2_END)
198
+  if(Address <= FLASH_BANK1_END)
199
+  {
200
+#endif /* FLASH_BANK2_END */
201
+    /* Wait for last operation to be completed */
202
+    status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
203
+#if defined(FLASH_BANK2_END)
204
+  }
205
+  else
206
+  {
207
+    /* Wait for last operation to be completed */
208
+    status = FLASH_WaitForLastOperationBank2(FLASH_TIMEOUT_VALUE);
209
+  }
210
+#endif /* FLASH_BANK2_END */
211
+  
212
+  if(status == HAL_OK)
213
+  {
214
+    if(TypeProgram == FLASH_TYPEPROGRAM_HALFWORD)
215
+    {
216
+      /* Program halfword (16-bit) at a specified address. */
217
+      nbiterations = 1U;
218
+    }
219
+    else if(TypeProgram == FLASH_TYPEPROGRAM_WORD)
220
+    {
221
+      /* Program word (32-bit = 2*16-bit) at a specified address. */
222
+      nbiterations = 2U;
223
+    }
224
+    else
225
+    {
226
+      /* Program double word (64-bit = 4*16-bit) at a specified address. */
227
+      nbiterations = 4U;
228
+    }
229
+
230
+    for (index = 0U; index < nbiterations; index++)
231
+    {
232
+      FLASH_Program_HalfWord((Address + (2U*index)), (uint16_t)(Data >> (16U*index)));
233
+
234
+#if defined(FLASH_BANK2_END)
235
+      if(Address <= FLASH_BANK1_END)
236
+      {
237
+#endif /* FLASH_BANK2_END */
238
+        /* Wait for last operation to be completed */
239
+        status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
240
+    
241
+        /* If the program operation is completed, disable the PG Bit */
242
+        CLEAR_BIT(FLASH->CR, FLASH_CR_PG);
243
+#if defined(FLASH_BANK2_END)
244
+      }
245
+      else
246
+      {
247
+        /* Wait for last operation to be completed */
248
+        status = FLASH_WaitForLastOperationBank2(FLASH_TIMEOUT_VALUE);
249
+        
250
+        /* If the program operation is completed, disable the PG Bit */
251
+        CLEAR_BIT(FLASH->CR2, FLASH_CR2_PG);
252
+      }
253
+#endif /* FLASH_BANK2_END */
254
+      /* In case of error, stop programation procedure */
255
+      if (status != HAL_OK)
256
+      {
257
+        break;
258
+      }
259
+    }
260
+  }
261
+
262
+  /* Process Unlocked */
263
+  __HAL_UNLOCK(&pFlash);
264
+
265
+  return status;
266
+}
267
+
268
+/**
269
+  * @brief  Program halfword, word or double word at a specified address  with interrupt enabled.
270
+  * @note   The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface
271
+  *         The function HAL_FLASH_Lock() should be called after to lock the FLASH interface
272
+  *
273
+  * @note   If an erase and a program operations are requested simultaneously,    
274
+  *         the erase operation is performed before the program one.
275
+  *
276
+  * @param  TypeProgram: Indicate the way to program at a specified address.
277
+  *                      This parameter can be a value of @ref FLASH_Type_Program
278
+  * @param  Address:     Specifies the address to be programmed.
279
+  * @param  Data:        Specifies the data to be programmed
280
+  * 
281
+  * @retval HAL_StatusTypeDef HAL Status
282
+  */
283
+HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
284
+{
285
+  HAL_StatusTypeDef status = HAL_OK;
286
+  
287
+  /* Process Locked */
288
+  __HAL_LOCK(&pFlash);
289
+
290
+  /* Check the parameters */
291
+  assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram));
292
+  assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
293
+
294
+#if defined(FLASH_BANK2_END)
295
+  /* If procedure already ongoing, reject the next one */
296
+  if (pFlash.ProcedureOnGoing != FLASH_PROC_NONE)
297
+  {
298
+    return HAL_ERROR;
299
+  }
300
+  
301
+  if(Address <= FLASH_BANK1_END)
302
+  {
303
+    /* Enable End of FLASH Operation and Error source interrupts */
304
+    __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP_BANK1 | FLASH_IT_ERR_BANK1);
305
+
306
+  }else
307
+  {
308
+    /* Enable End of FLASH Operation and Error source interrupts */
309
+    __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP_BANK2 | FLASH_IT_ERR_BANK2);
310
+  }
311
+#else
312
+  /* Enable End of FLASH Operation and Error source interrupts */
313
+  __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP | FLASH_IT_ERR);
314
+#endif /* FLASH_BANK2_END */
315
+  
316
+  pFlash.Address = Address;
317
+  pFlash.Data = Data;
318
+
319
+  if(TypeProgram == FLASH_TYPEPROGRAM_HALFWORD)
320
+  {
321
+    pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMHALFWORD;
322
+    /* Program halfword (16-bit) at a specified address. */
323
+    pFlash.DataRemaining = 1U;
324
+  }
325
+  else if(TypeProgram == FLASH_TYPEPROGRAM_WORD)
326
+  {
327
+    pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMWORD;
328
+    /* Program word (32-bit : 2*16-bit) at a specified address. */
329
+    pFlash.DataRemaining = 2U;
330
+  }
331
+  else
332
+  {
333
+    pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMDOUBLEWORD;
334
+    /* Program double word (64-bit : 4*16-bit) at a specified address. */
335
+    pFlash.DataRemaining = 4U;
336
+  }
337
+
338
+  /* Program halfword (16-bit) at a specified address. */
339
+  FLASH_Program_HalfWord(Address, (uint16_t)Data);
340
+
341
+  return status;
342
+}
343
+
344
+/**
345
+  * @brief This function handles FLASH interrupt request.
346
+  * @retval None
347
+  */
348
+void HAL_FLASH_IRQHandler(void)
349
+{
350
+  uint32_t addresstmp = 0U;
351
+  
352
+  /* Check FLASH operation error flags */
353
+#if defined(FLASH_BANK2_END)
354
+  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK1) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK1) || \
355
+    (__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK2) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK2)))
356
+#else
357
+  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) ||__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR))
358
+#endif /* FLASH_BANK2_END */
359
+  {
360
+    /* Return the faulty address */
361
+    addresstmp = pFlash.Address;
362
+    /* Reset address */
363
+    pFlash.Address = 0xFFFFFFFFU;
364
+  
365
+    /* Save the Error code */
366
+    FLASH_SetErrorCode();
367
+    
368
+    /* FLASH error interrupt user callback */
369
+    HAL_FLASH_OperationErrorCallback(addresstmp);
370
+
371
+    /* Stop the procedure ongoing */
372
+    pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
373
+  }
374
+
375
+  /* Check FLASH End of Operation flag  */
376
+#if defined(FLASH_BANK2_END)
377
+  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP_BANK1))
378
+  {
379
+    /* Clear FLASH End of Operation pending bit */
380
+    __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP_BANK1);
381
+#else
382
+  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP))
383
+  {
384
+    /* Clear FLASH End of Operation pending bit */
385
+    __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
386
+#endif /* FLASH_BANK2_END */
387
+    
388
+    /* Process can continue only if no error detected */
389
+    if(pFlash.ProcedureOnGoing != FLASH_PROC_NONE)
390
+    {
391
+      if(pFlash.ProcedureOnGoing == FLASH_PROC_PAGEERASE)
392
+      {
393
+        /* Nb of pages to erased can be decreased */
394
+        pFlash.DataRemaining--;
395
+
396
+        /* Check if there are still pages to erase */
397
+        if(pFlash.DataRemaining != 0U)
398
+        {
399
+          addresstmp = pFlash.Address;
400
+          /*Indicate user which sector has been erased */
401
+          HAL_FLASH_EndOfOperationCallback(addresstmp);
402
+
403
+          /*Increment sector number*/
404
+          addresstmp = pFlash.Address + FLASH_PAGE_SIZE;
405
+          pFlash.Address = addresstmp;
406
+
407
+          /* If the erase operation is completed, disable the PER Bit */
408
+          CLEAR_BIT(FLASH->CR, FLASH_CR_PER);
409
+
410
+          FLASH_PageErase(addresstmp);
411
+        }
412
+        else
413
+        {
414
+          /* No more pages to Erase, user callback can be called. */
415
+          /* Reset Sector and stop Erase pages procedure */
416
+          pFlash.Address = addresstmp = 0xFFFFFFFFU;
417
+          pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
418
+          /* FLASH EOP interrupt user callback */
419
+          HAL_FLASH_EndOfOperationCallback(addresstmp);
420
+        }
421
+      }
422
+      else if(pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE)
423
+      {
424
+        /* Operation is completed, disable the MER Bit */
425
+        CLEAR_BIT(FLASH->CR, FLASH_CR_MER);
426
+
427
+#if defined(FLASH_BANK2_END)
428
+        /* Stop Mass Erase procedure if no pending mass erase on other bank */
429
+        if (HAL_IS_BIT_CLR(FLASH->CR2, FLASH_CR2_MER))
430
+        {
431
+#endif /* FLASH_BANK2_END */
432
+          /* MassErase ended. Return the selected bank */
433
+          /* FLASH EOP interrupt user callback */
434
+          HAL_FLASH_EndOfOperationCallback(0U);
435
+
436
+          /* Stop Mass Erase procedure*/
437
+          pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
438
+        }
439
+#if defined(FLASH_BANK2_END)
440
+      }
441
+#endif /* FLASH_BANK2_END */
442
+      else
443
+      {
444
+        /* Nb of 16-bit data to program can be decreased */
445
+        pFlash.DataRemaining--;
446
+        
447
+        /* Check if there are still 16-bit data to program */
448
+        if(pFlash.DataRemaining != 0U)
449
+        {
450
+          /* Increment address to 16-bit */
451
+          pFlash.Address += 2U;
452
+          addresstmp = pFlash.Address;
453
+          
454
+          /* Shift to have next 16-bit data */
455
+          pFlash.Data = (pFlash.Data >> 16U);
456
+          
457
+          /* Operation is completed, disable the PG Bit */
458
+          CLEAR_BIT(FLASH->CR, FLASH_CR_PG);
459
+
460
+          /*Program halfword (16-bit) at a specified address.*/
461
+          FLASH_Program_HalfWord(addresstmp, (uint16_t)pFlash.Data);
462
+        }
463
+        else
464
+        {
465
+          /* Program ended. Return the selected address */
466
+          /* FLASH EOP interrupt user callback */
467
+          if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMHALFWORD)
468
+          {
469
+            HAL_FLASH_EndOfOperationCallback(pFlash.Address);
470
+          }
471
+          else if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMWORD)
472
+          {
473
+            HAL_FLASH_EndOfOperationCallback(pFlash.Address - 2U);
474
+          }
475
+          else 
476
+          {
477
+            HAL_FLASH_EndOfOperationCallback(pFlash.Address - 6U);
478
+          }
479
+        
480
+          /* Reset Address and stop Program procedure */
481
+          pFlash.Address = 0xFFFFFFFFU;
482
+          pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
483
+        }
484
+      }
485
+    }
486
+  }
487
+  
488
+#if defined(FLASH_BANK2_END)
489
+  /* Check FLASH End of Operation flag  */
490
+  if(__HAL_FLASH_GET_FLAG( FLASH_FLAG_EOP_BANK2))
491
+  {
492
+    /* Clear FLASH End of Operation pending bit */
493
+    __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP_BANK2);
494
+    
495
+    /* Process can continue only if no error detected */
496
+    if(pFlash.ProcedureOnGoing != FLASH_PROC_NONE)
497
+    {
498
+      if(pFlash.ProcedureOnGoing == FLASH_PROC_PAGEERASE)
499
+      {
500
+        /* Nb of pages to erased can be decreased */
501
+        pFlash.DataRemaining--;
502
+        
503
+        /* Check if there are still pages to erase*/
504
+        if(pFlash.DataRemaining != 0U)
505
+        {
506
+          /* Indicate user which page address has been erased*/
507
+          HAL_FLASH_EndOfOperationCallback(pFlash.Address);
508
+        
509
+          /* Increment page address to next page */
510
+          pFlash.Address += FLASH_PAGE_SIZE;
511
+          addresstmp = pFlash.Address;
512
+
513
+          /* Operation is completed, disable the PER Bit */
514
+          CLEAR_BIT(FLASH->CR2, FLASH_CR2_PER);
515
+
516
+          FLASH_PageErase(addresstmp);
517
+        }
518
+        else
519
+        {
520
+          /*No more pages to Erase*/
521
+          
522
+          /*Reset Address and stop Erase pages procedure*/
523
+          pFlash.Address = 0xFFFFFFFFU;
524
+          pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
525
+
526
+          /* FLASH EOP interrupt user callback */
527
+          HAL_FLASH_EndOfOperationCallback(pFlash.Address);
528
+        }
529
+      }
530
+      else if(pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE)
531
+      {
532
+        /* Operation is completed, disable the MER Bit */
533
+        CLEAR_BIT(FLASH->CR2, FLASH_CR2_MER);
534
+
535
+        if (HAL_IS_BIT_CLR(FLASH->CR, FLASH_CR_MER))
536
+        {
537
+          /* MassErase ended. Return the selected bank*/
538
+          /* FLASH EOP interrupt user callback */
539
+          HAL_FLASH_EndOfOperationCallback(0U);
540
+        
541
+          pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
542
+        }
543
+      }
544
+      else
545
+      {
546
+        /* Nb of 16-bit data to program can be decreased */
547
+        pFlash.DataRemaining--;
548
+        
549
+        /* Check if there are still 16-bit data to program */
550
+        if(pFlash.DataRemaining != 0U)
551
+        {
552
+          /* Increment address to 16-bit */
553
+          pFlash.Address += 2U;
554
+          addresstmp = pFlash.Address;
555
+          
556
+          /* Shift to have next 16-bit data */
557
+          pFlash.Data = (pFlash.Data >> 16U);
558
+          
559
+          /* Operation is completed, disable the PG Bit */
560
+          CLEAR_BIT(FLASH->CR2, FLASH_CR2_PG);
561
+
562
+          /*Program halfword (16-bit) at a specified address.*/
563
+          FLASH_Program_HalfWord(addresstmp, (uint16_t)pFlash.Data);
564
+        }
565
+        else
566
+        {
567
+          /*Program ended. Return the selected address*/
568
+          /* FLASH EOP interrupt user callback */
569
+          if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMHALFWORD)
570
+          {
571
+            HAL_FLASH_EndOfOperationCallback(pFlash.Address);
572
+          }
573
+          else if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMWORD)
574
+          {
575
+            HAL_FLASH_EndOfOperationCallback(pFlash.Address-2U);
576
+          }
577
+          else 
578
+          {
579
+            HAL_FLASH_EndOfOperationCallback(pFlash.Address-6U);
580
+          }
581
+          
582
+          /* Reset Address and stop Program procedure*/
583
+          pFlash.Address = 0xFFFFFFFFU;
584
+          pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
585
+        }
586
+      }
587
+    }
588
+  }
589
+#endif 
590
+
591
+  if(pFlash.ProcedureOnGoing == FLASH_PROC_NONE)
592
+  {
593
+#if defined(FLASH_BANK2_END)
594
+    /* Operation is completed, disable the PG, PER and MER Bits for both bank */
595
+    CLEAR_BIT(FLASH->CR, (FLASH_CR_PG | FLASH_CR_PER | FLASH_CR_MER));
596
+    CLEAR_BIT(FLASH->CR2, (FLASH_CR2_PG | FLASH_CR2_PER | FLASH_CR2_MER));  
597
+  
598
+    /* Disable End of FLASH Operation and Error source interrupts for both banks */
599
+    __HAL_FLASH_DISABLE_IT(FLASH_IT_EOP_BANK1 | FLASH_IT_ERR_BANK1 | FLASH_IT_EOP_BANK2 | FLASH_IT_ERR_BANK2);
600
+#else
601
+    /* Operation is completed, disable the PG, PER and MER Bits */
602
+    CLEAR_BIT(FLASH->CR, (FLASH_CR_PG | FLASH_CR_PER | FLASH_CR_MER));
603
+
604
+    /* Disable End of FLASH Operation and Error source interrupts */
605
+    __HAL_FLASH_DISABLE_IT(FLASH_IT_EOP | FLASH_IT_ERR);
606
+#endif /* FLASH_BANK2_END */
607
+
608
+    /* Process Unlocked */
609
+    __HAL_UNLOCK(&pFlash);
610
+  }
611
+}
612
+
613
+/**
614
+  * @brief  FLASH end of operation interrupt callback
615
+  * @param  ReturnValue: The value saved in this parameter depends on the ongoing procedure
616
+  *                 - Mass Erase: No return value expected
617
+  *                 - Pages Erase: Address of the page which has been erased 
618
+  *                    (if 0xFFFFFFFF, it means that all the selected pages have been erased)
619
+  *                 - Program: Address which was selected for data program
620
+  * @retval none
621
+  */
622
+__weak void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue)
623
+{
624
+  /* Prevent unused argument(s) compilation warning */
625
+  UNUSED(ReturnValue);
626
+
627
+  /* NOTE : This function Should not be modified, when the callback is needed,
628
+            the HAL_FLASH_EndOfOperationCallback could be implemented in the user file
629
+   */ 
630
+}
631
+
632
+/**
633
+  * @brief  FLASH operation error interrupt callback
634
+  * @param  ReturnValue: The value saved in this parameter depends on the ongoing procedure
635
+  *                 - Mass Erase: No return value expected
636
+  *                 - Pages Erase: Address of the page which returned an error
637
+  *                 - Program: Address which was selected for data program
638
+  * @retval none
639
+  */
640
+__weak void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue)
641
+{
642
+  /* Prevent unused argument(s) compilation warning */
643
+  UNUSED(ReturnValue);
644
+
645
+  /* NOTE : This function Should not be modified, when the callback is needed,
646
+            the HAL_FLASH_OperationErrorCallback could be implemented in the user file
647
+   */ 
648
+}
649
+
650
+/**
651
+  * @}
652
+  */
653
+
654
+/** @defgroup FLASH_Exported_Functions_Group2 Peripheral Control functions 
655
+ *  @brief   management functions 
656
+ *
657
+@verbatim   
658
+ ===============================================================================
659
+                      ##### Peripheral Control functions #####
660
+ ===============================================================================  
661
+    [..]
662
+    This subsection provides a set of functions allowing to control the FLASH 
663
+    memory operations.
664
+
665
+@endverbatim
666
+  * @{
667
+  */
668
+
669
+/**
670
+  * @brief  Unlock the FLASH control register access
671
+  * @retval HAL Status
672
+  */
673
+HAL_StatusTypeDef HAL_FLASH_Unlock(void)
674
+{
675
+  HAL_StatusTypeDef status = HAL_OK;
676
+
677
+  if(READ_BIT(FLASH->CR, FLASH_CR_LOCK) != RESET)
678
+  {
679
+    /* Authorize the FLASH Registers access */
680
+    WRITE_REG(FLASH->KEYR, FLASH_KEY1);
681
+    WRITE_REG(FLASH->KEYR, FLASH_KEY2);
682
+
683
+    /* Verify Flash is unlocked */
684
+    if(READ_BIT(FLASH->CR, FLASH_CR_LOCK) != RESET)
685
+    {
686
+      status = HAL_ERROR;
687
+    }
688
+  }
689
+#if defined(FLASH_BANK2_END)
690
+  if(READ_BIT(FLASH->CR2, FLASH_CR2_LOCK) != RESET)
691
+  {
692
+    /* Authorize the FLASH BANK2 Registers access */
693
+    WRITE_REG(FLASH->KEYR2, FLASH_KEY1);
694
+    WRITE_REG(FLASH->KEYR2, FLASH_KEY2);
695
+    
696
+    /* Verify Flash BANK2 is unlocked */
697
+    if(READ_BIT(FLASH->CR2, FLASH_CR2_LOCK) != RESET)
698
+    {
699
+      status = HAL_ERROR;
700
+    }
701
+  }
702
+#endif /* FLASH_BANK2_END */
703
+
704
+  return status;
705
+}
706
+
707
+/**
708
+  * @brief  Locks the FLASH control register access
709
+  * @retval HAL Status
710
+  */
711
+HAL_StatusTypeDef HAL_FLASH_Lock(void)
712
+{
713
+  /* Set the LOCK Bit to lock the FLASH Registers access */
714
+  SET_BIT(FLASH->CR, FLASH_CR_LOCK);
715
+  
716
+#if defined(FLASH_BANK2_END)
717
+  /* Set the LOCK Bit to lock the FLASH BANK2 Registers access */
718
+  SET_BIT(FLASH->CR2, FLASH_CR2_LOCK);
719
+
720
+#endif /* FLASH_BANK2_END */
721
+  return HAL_OK;  
722
+}
723
+
724
+/**
725
+  * @brief  Unlock the FLASH Option Control Registers access.
726
+  * @retval HAL Status
727
+  */
728
+HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void)
729
+{
730
+  if (HAL_IS_BIT_CLR(FLASH->CR, FLASH_CR_OPTWRE))
731
+  {
732
+    /* Authorizes the Option Byte register programming */
733
+    WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY1);
734
+    WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY2);
735
+  }
736
+  else
737
+  {
738
+    return HAL_ERROR;
739
+  }  
740
+  
741
+  return HAL_OK;  
742
+}
743
+
744
+/**
745
+  * @brief  Lock the FLASH Option Control Registers access.
746
+  * @retval HAL Status 
747
+  */
748
+HAL_StatusTypeDef HAL_FLASH_OB_Lock(void)
749
+{
750
+  /* Clear the OPTWRE Bit to lock the FLASH Option Byte Registers access */
751
+  CLEAR_BIT(FLASH->CR, FLASH_CR_OPTWRE);
752
+  
753
+  return HAL_OK;  
754
+}
755
+  
756
+/**
757
+  * @brief  Launch the option byte loading.
758
+  * @note   This function will reset automatically the MCU.
759
+  * @retval None
760
+  */
761
+void HAL_FLASH_OB_Launch(void)
762
+{
763
+  /* Initiates a system reset request to launch the option byte loading */
764
+  HAL_NVIC_SystemReset();
765
+}
766
+
767
+/**
768
+  * @}
769
+  */  
770
+
771
+/** @defgroup FLASH_Exported_Functions_Group3 Peripheral errors functions 
772
+ *  @brief    Peripheral errors functions 
773
+ *
774
+@verbatim   
775
+ ===============================================================================
776
+                      ##### Peripheral Errors functions #####
777
+ ===============================================================================  
778
+    [..]
779
+    This subsection permit to get in run-time errors of  the FLASH peripheral.
780
+
781
+@endverbatim
782
+  * @{
783
+  */
784
+
785
+/**
786
+  * @brief  Get the specific FLASH error flag.
787
+  * @retval FLASH_ErrorCode The returned value can be:
788
+  *            @ref FLASH_Error_Codes
789
+  */
790
+uint32_t HAL_FLASH_GetError(void)
791
+{
792
+   return pFlash.ErrorCode;
793
+}
794
+
795
+/**
796
+  * @}
797
+  */
798
+
799
+/**
800
+  * @}
801
+  */
802
+
803
+/** @addtogroup FLASH_Private_Functions
804
+ * @{
805
+ */
806
+
807
+/**
808
+  * @brief  Program a half-word (16-bit) at a specified address.
809
+  * @param  Address specify the address to be programmed.
810
+  * @param  Data    specify the data to be programmed.
811
+  * @retval None
812
+  */
813
+static void FLASH_Program_HalfWord(uint32_t Address, uint16_t Data)
814
+{
815
+  /* Clean the error context */
816
+  pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
817
+  
818
+#if defined(FLASH_BANK2_END)
819
+  if(Address <= FLASH_BANK1_END)
820
+  {
821
+#endif /* FLASH_BANK2_END */
822
+    /* Proceed to program the new data */
823
+    SET_BIT(FLASH->CR, FLASH_CR_PG);
824
+#if defined(FLASH_BANK2_END)
825
+  }
826
+  else
827
+  {
828
+    /* Proceed to program the new data */
829
+    SET_BIT(FLASH->CR2, FLASH_CR2_PG);
830
+  }
831
+#endif /* FLASH_BANK2_END */
832
+
833
+  /* Write data in the address */
834
+  *(__IO uint16_t*)Address = Data;
835
+}
836
+
837
+/**
838
+  * @brief  Wait for a FLASH operation to complete.
839
+  * @param  Timeout  maximum flash operation timeout
840
+  * @retval HAL Status
841
+  */
842
+HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
843
+{
844
+  /* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
845
+     Even if the FLASH operation fails, the BUSY flag will be reset and an error
846
+     flag will be set */
847
+     
848
+  uint32_t tickstart = HAL_GetTick();
849
+     
850
+  while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY)) 
851
+  { 
852
+    if (Timeout != HAL_MAX_DELAY)
853
+    {
854
+      if((Timeout == 0U) || ((HAL_GetTick()-tickstart) > Timeout))
855
+      {
856
+        return HAL_TIMEOUT;
857
+      }
858
+    }
859
+  }
860
+  
861
+  /* Check FLASH End of Operation flag  */
862
+  if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP))
863
+  {
864
+    /* Clear FLASH End of Operation pending bit */
865
+    __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
866
+  }
867
+  
868
+  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR)  || 
869
+     __HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR) || 
870
+     __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR))
871
+  {
872
+    /*Save the error code*/
873
+    FLASH_SetErrorCode();
874
+    return HAL_ERROR;
875
+  }
876
+
877
+  /* There is no error flag set */
878
+  return HAL_OK;
879
+}
880
+
881
+#if defined(FLASH_BANK2_END)
882
+/**
883
+  * @brief  Wait for a FLASH BANK2 operation to complete.
884
+  * @param  Timeout maximum flash operation timeout
885
+  * @retval HAL_StatusTypeDef HAL Status
886
+  */
887
+HAL_StatusTypeDef FLASH_WaitForLastOperationBank2(uint32_t Timeout)
888
+{ 
889
+  /* Wait for the FLASH BANK2 operation to complete by polling on BUSY flag to be reset.
890
+     Even if the FLASH BANK2 operation fails, the BUSY flag will be reset and an error
891
+     flag will be set */
892
+     
893
+  uint32_t tickstart = HAL_GetTick();
894
+     
895
+  while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY_BANK2)) 
896
+  { 
897
+    if (Timeout != HAL_MAX_DELAY)
898
+    {
899
+      if((Timeout == 0U) || ((HAL_GetTick()-tickstart) > Timeout))
900
+      {
901
+        return HAL_TIMEOUT;
902
+      }
903
+    }
904
+  }
905
+  
906
+  /* Check FLASH End of Operation flag  */
907
+  if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP_BANK2))
908
+  {
909
+    /* Clear FLASH End of Operation pending bit */
910
+    __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP_BANK2);
911
+  }
912
+
913
+  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK2) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK2))
914
+  {
915
+    /*Save the error code*/
916
+    FLASH_SetErrorCode();
917
+    return HAL_ERROR;
918
+  }
919
+
920
+  /* If there is an error flag set */
921
+  return HAL_OK;
922
+  
923
+}
924
+#endif /* FLASH_BANK2_END */
925
+
926
+/**
927
+  * @brief  Set the specific FLASH error flag.
928
+  * @retval None
929
+  */
930
+static void FLASH_SetErrorCode(void)
931
+{
932
+  uint32_t flags = 0U;
933
+  
934
+#if defined(FLASH_BANK2_END)
935
+  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK2))
936
+#else
937
+  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR))
938
+#endif /* FLASH_BANK2_END */
939
+  {
940
+    pFlash.ErrorCode |= HAL_FLASH_ERROR_WRP;
941
+#if defined(FLASH_BANK2_END)
942
+    flags |= FLASH_FLAG_WRPERR | FLASH_FLAG_WRPERR_BANK2;
943
+#else
944
+    flags |= FLASH_FLAG_WRPERR;
945
+#endif /* FLASH_BANK2_END */
946
+  }
947
+#if defined(FLASH_BANK2_END)
948
+  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK2))
949
+#else
950
+  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR))
951
+#endif /* FLASH_BANK2_END */
952
+  {
953
+    pFlash.ErrorCode |= HAL_FLASH_ERROR_PROG;
954
+#if defined(FLASH_BANK2_END)
955
+    flags |= FLASH_FLAG_PGERR | FLASH_FLAG_PGERR_BANK2;
956
+#else
957
+    flags |= FLASH_FLAG_PGERR;
958
+#endif /* FLASH_BANK2_END */
959
+  }
960
+  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR))
961
+  {
962
+    pFlash.ErrorCode |= HAL_FLASH_ERROR_OPTV;
963
+  __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
964
+  }
965
+
966
+  /* Clear FLASH error pending bits */
967
+  __HAL_FLASH_CLEAR_FLAG(flags);
968
+}  
969
+/**
970
+  * @}
971
+  */
972
+
973
+/**
974
+  * @}
975
+  */
976
+
977
+#endif /* HAL_FLASH_MODULE_ENABLED */
978
+
979
+/**
980
+  * @}
981
+  */
982
+
983
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

Разлика између датотеке није приказан због своје велике величине
+ 1143 - 0
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c


+ 595 - 0
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c

@@ -0,0 +1,595 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_gpio.c
4
+  * @author  MCD Application Team
5
+  * @brief   GPIO HAL module driver.
6
+  *          This file provides firmware functions to manage the following
7
+  *          functionalities of the General Purpose Input/Output (GPIO) peripheral:
8
+  *           + Initialization and de-initialization functions
9
+  *           + IO operation functions
10
+  *
11
+  @verbatim
12
+  ==============================================================================
13
+                    ##### GPIO Peripheral features #####
14
+  ==============================================================================
15
+  [..]
16
+  Subject to the specific hardware characteristics of each I/O port listed in the datasheet, each
17
+  port bit of the General Purpose IO (GPIO) Ports, can be individually configured by software
18
+  in several modes:
19
+  (+) Input mode
20
+  (+) Analog mode
21
+  (+) Output mode
22
+  (+) Alternate function mode
23
+  (+) External interrupt/event lines
24
+
25
+  [..]
26
+  During and just after reset, the alternate functions and external interrupt
27
+  lines are not active and the I/O ports are configured in input floating mode.
28
+
29
+  [..]
30
+  All GPIO pins have weak internal pull-up and pull-down resistors, which can be
31
+  activated or not.
32
+
33
+  [..]
34
+  In Output or Alternate mode, each IO can be configured on open-drain or push-pull
35
+  type and the IO speed can be selected depending on the VDD value.
36
+
37
+  [..]
38
+  All ports have external interrupt/event capability. To use external interrupt
39
+  lines, the port must be configured in input mode. All available GPIO pins are
40
+  connected to the 16 external interrupt/event lines from EXTI0 to EXTI15.
41
+
42
+  [..]
43
+  The external interrupt/event controller consists of up to 20 edge detectors in connectivity
44
+  line devices, or 19 edge detectors in other devices for generating event/interrupt requests.
45
+  Each input line can be independently configured to select the type (event or interrupt) and
46
+  the corresponding trigger event (rising or falling or both). Each line can also masked
47
+  independently. A pending register maintains the status line of the interrupt requests
48
+
49
+                     ##### How to use this driver #####
50
+  ==============================================================================
51
+ [..]
52
+   (#) Enable the GPIO APB2 clock using the following function : __HAL_RCC_GPIOx_CLK_ENABLE().
53
+
54
+   (#) Configure the GPIO pin(s) using HAL_GPIO_Init().
55
+       (++) Configure the IO mode using "Mode" member from GPIO_InitTypeDef structure
56
+       (++) Activate Pull-up, Pull-down resistor using "Pull" member from GPIO_InitTypeDef
57
+            structure.
58
+       (++) In case of Output or alternate function mode selection: the speed is
59
+            configured through "Speed" member from GPIO_InitTypeDef structure
60
+       (++) Analog mode is required when a pin is to be used as ADC channel
61
+            or DAC output.
62
+       (++) In case of external interrupt/event selection the "Mode" member from
63
+            GPIO_InitTypeDef structure select the type (interrupt or event) and
64
+            the corresponding trigger event (rising or falling or both).
65
+
66
+   (#) In case of external interrupt/event mode selection, configure NVIC IRQ priority
67
+       mapped to the EXTI line using HAL_NVIC_SetPriority() and enable it using
68
+       HAL_NVIC_EnableIRQ().
69
+
70
+   (#) To get the level of a pin configured in input mode use HAL_GPIO_ReadPin().
71
+
72
+   (#) To set/reset the level of a pin configured in output mode use
73
+       HAL_GPIO_WritePin()/HAL_GPIO_TogglePin().
74
+
75
+   (#) To lock pin configuration until next reset use HAL_GPIO_LockPin().
76
+
77
+   (#) During and just after reset, the alternate functions are not
78
+       active and the GPIO pins are configured in input floating mode (except JTAG
79
+       pins).
80
+
81
+   (#) The LSE oscillator pins OSC32_IN and OSC32_OUT can be used as general purpose
82
+       (PC14 and PC15, respectively) when the LSE oscillator is off. The LSE has
83
+       priority over the GPIO function.
84
+
85
+   (#) The HSE oscillator pins OSC_IN/OSC_OUT can be used as
86
+       general purpose PD0 and PD1, respectively, when the HSE oscillator is off.
87
+       The HSE has priority over the GPIO function.
88
+
89
+  @endverbatim
90
+  ******************************************************************************
91
+  * @attention
92
+  *
93
+  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
94
+  *
95
+  * Redistribution and use in source and binary forms, with or without modification,
96
+  * are permitted provided that the following conditions are met:
97
+  *   1. Redistributions of source code must retain the above copyright notice,
98
+  *      this list of conditions and the following disclaimer.
99
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
100
+  *      this list of conditions and the following disclaimer in the documentation
101
+  *      and/or other materials provided with the distribution.
102
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
103
+  *      may be used to endorse or promote products derived from this software
104
+  *      without specific prior written permission.
105
+  *
106
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
107
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
108
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
109
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
110
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
111
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
112
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
113
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
114
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
115
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
116
+  *
117
+  ******************************************************************************
118
+  */
119
+
120
+/* Includes ------------------------------------------------------------------*/
121
+#include "stm32f1xx_hal.h"
122
+
123
+/** @addtogroup STM32F1xx_HAL_Driver
124
+  * @{
125
+  */
126
+
127
+/** @defgroup GPIO GPIO
128
+  * @brief GPIO HAL module driver
129
+  * @{
130
+  */
131
+
132
+#ifdef HAL_GPIO_MODULE_ENABLED
133
+
134
+/* Private typedef -----------------------------------------------------------*/
135
+/* Private define ------------------------------------------------------------*/
136
+/** @addtogroup GPIO_Private_Constants GPIO Private Constants
137
+  * @{
138
+  */
139
+#define GPIO_MODE             0x00000003U
140
+#define EXTI_MODE             0x10000000U
141
+#define GPIO_MODE_IT          0x00010000U
142
+#define GPIO_MODE_EVT         0x00020000U
143
+#define RISING_EDGE           0x00100000U
144
+#define FALLING_EDGE          0x00200000U
145
+#define GPIO_OUTPUT_TYPE      0x00000010U
146
+
147
+#define GPIO_NUMBER           16U
148
+
149
+/* Definitions for bit manipulation of CRL and CRH register */
150
+#define  GPIO_CR_MODE_INPUT         0x00000000U /*!< 00: Input mode (reset state)  */
151
+#define  GPIO_CR_CNF_ANALOG         0x00000000U /*!< 00: Analog mode  */
152
+#define  GPIO_CR_CNF_INPUT_FLOATING 0x00000004U /*!< 01: Floating input (reset state)  */
153
+#define  GPIO_CR_CNF_INPUT_PU_PD    0x00000008U /*!< 10: Input with pull-up / pull-down  */
154
+#define  GPIO_CR_CNF_GP_OUTPUT_PP   0x00000000U /*!< 00: General purpose output push-pull  */
155
+#define  GPIO_CR_CNF_GP_OUTPUT_OD   0x00000004U /*!< 01: General purpose output Open-drain  */
156
+#define  GPIO_CR_CNF_AF_OUTPUT_PP   0x00000008U /*!< 10: Alternate function output Push-pull  */
157
+#define  GPIO_CR_CNF_AF_OUTPUT_OD   0x0000000CU /*!< 11: Alternate function output Open-drain  */
158
+
159
+/**
160
+  * @}
161
+  */
162
+/* Private macro -------------------------------------------------------------*/
163
+/* Private variables ---------------------------------------------------------*/
164
+/* Private function prototypes -----------------------------------------------*/
165
+/* Private functions ---------------------------------------------------------*/
166
+/* Exported functions --------------------------------------------------------*/
167
+/** @defgroup GPIO_Exported_Functions GPIO Exported Functions
168
+  * @{
169
+  */
170
+
171
+/** @defgroup GPIO_Exported_Functions_Group1 Initialization and de-initialization functions
172
+ *  @brief    Initialization and Configuration functions
173
+ *
174
+@verbatim
175
+ ===============================================================================
176
+              ##### Initialization and de-initialization functions #####
177
+ ===============================================================================
178
+  [..]
179
+    This section provides functions allowing to initialize and de-initialize the GPIOs
180
+    to be ready for use.
181
+
182
+@endverbatim
183
+  * @{
184
+  */
185
+
186
+
187
+/**
188
+  * @brief  Initializes the GPIOx peripheral according to the specified parameters in the GPIO_Init.
189
+  * @param  GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral
190
+  * @param  GPIO_Init: pointer to a GPIO_InitTypeDef structure that contains
191
+  *         the configuration information for the specified GPIO peripheral.
192
+  * @retval None
193
+  */
194
+void HAL_GPIO_Init(GPIO_TypeDef  *GPIOx, GPIO_InitTypeDef *GPIO_Init)
195
+{
196
+  uint32_t position;
197
+  uint32_t ioposition = 0x00U;
198
+  uint32_t iocurrent = 0x00U;
199
+  uint32_t temp = 0x00U;
200
+  uint32_t config = 0x00U;
201
+  __IO uint32_t *configregister; /* Store the address of CRL or CRH register based on pin number */
202
+  uint32_t registeroffset = 0U; /* offset used during computation of CNF and MODE bits placement inside CRL or CRH register */
203
+
204
+  /* Check the parameters */
205
+  assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
206
+  assert_param(IS_GPIO_PIN(GPIO_Init->Pin));
207
+  assert_param(IS_GPIO_MODE(GPIO_Init->Mode));
208
+
209
+  /* Configure the port pins */
210
+  for (position = 0U; position < GPIO_NUMBER; position++)
211
+  {
212
+    /* Get the IO position */
213
+    ioposition = (0x01U << position);
214
+
215
+    /* Get the current IO position */
216
+    iocurrent = (uint32_t)(GPIO_Init->Pin) & ioposition;
217
+
218
+    if (iocurrent == ioposition)
219
+    {
220
+      /* Check the Alternate function parameters */
221
+      assert_param(IS_GPIO_AF_INSTANCE(GPIOx));
222
+
223
+      /* Based on the required mode, filling config variable with MODEy[1:0] and CNFy[3:2] corresponding bits */
224
+      switch (GPIO_Init->Mode)
225
+      {
226
+        /* If we are configuring the pin in OUTPUT push-pull mode */
227
+        case GPIO_MODE_OUTPUT_PP:
228
+          /* Check the GPIO speed parameter */
229
+          assert_param(IS_GPIO_SPEED(GPIO_Init->Speed));
230
+          config = GPIO_Init->Speed + GPIO_CR_CNF_GP_OUTPUT_PP;
231
+          break;
232
+
233
+        /* If we are configuring the pin in OUTPUT open-drain mode */
234
+        case GPIO_MODE_OUTPUT_OD:
235
+          /* Check the GPIO speed parameter */
236
+          assert_param(IS_GPIO_SPEED(GPIO_Init->Speed));
237
+          config = GPIO_Init->Speed + GPIO_CR_CNF_GP_OUTPUT_OD;
238
+          break;
239
+
240
+        /* If we are configuring the pin in ALTERNATE FUNCTION push-pull mode */
241
+        case GPIO_MODE_AF_PP:
242
+          /* Check the GPIO speed parameter */
243
+          assert_param(IS_GPIO_SPEED(GPIO_Init->Speed));
244
+          config = GPIO_Init->Speed + GPIO_CR_CNF_AF_OUTPUT_PP;
245
+          break;
246
+
247
+        /* If we are configuring the pin in ALTERNATE FUNCTION open-drain mode */
248
+        case GPIO_MODE_AF_OD:
249
+          /* Check the GPIO speed parameter */
250
+          assert_param(IS_GPIO_SPEED(GPIO_Init->Speed));
251
+          config = GPIO_Init->Speed + GPIO_CR_CNF_AF_OUTPUT_OD;
252
+          break;
253
+
254
+        /* If we are configuring the pin in INPUT (also applicable to EVENT and IT mode) */
255
+        case GPIO_MODE_INPUT:
256
+        case GPIO_MODE_IT_RISING:
257
+        case GPIO_MODE_IT_FALLING:
258
+        case GPIO_MODE_IT_RISING_FALLING:
259
+        case GPIO_MODE_EVT_RISING:
260
+        case GPIO_MODE_EVT_FALLING:
261
+        case GPIO_MODE_EVT_RISING_FALLING:
262
+          /* Check the GPIO pull parameter */
263
+          assert_param(IS_GPIO_PULL(GPIO_Init->Pull));
264
+          if (GPIO_Init->Pull == GPIO_NOPULL)
265
+          {
266
+            config = GPIO_CR_MODE_INPUT + GPIO_CR_CNF_INPUT_FLOATING;
267
+          }
268
+          else if (GPIO_Init->Pull == GPIO_PULLUP)
269
+          {
270
+            config = GPIO_CR_MODE_INPUT + GPIO_CR_CNF_INPUT_PU_PD;
271
+
272
+            /* Set the corresponding ODR bit */
273
+            GPIOx->BSRR = ioposition;
274
+          }
275
+          else /* GPIO_PULLDOWN */
276
+          {
277
+            config = GPIO_CR_MODE_INPUT + GPIO_CR_CNF_INPUT_PU_PD;
278
+
279
+            /* Reset the corresponding ODR bit */
280
+            GPIOx->BRR = ioposition;
281
+          }
282
+          break;
283
+
284
+        /* If we are configuring the pin in INPUT analog mode */
285
+        case GPIO_MODE_ANALOG:
286
+          config = GPIO_CR_MODE_INPUT + GPIO_CR_CNF_ANALOG;
287
+          break;
288
+
289
+        /* Parameters are checked with assert_param */
290
+        default:
291
+          break;
292
+      }
293
+
294
+      /* Check if the current bit belongs to first half or last half of the pin count number
295
+       in order to address CRH or CRL register*/
296
+      configregister = (iocurrent < GPIO_PIN_8) ? &GPIOx->CRL     : &GPIOx->CRH;
297
+      registeroffset = (iocurrent < GPIO_PIN_8) ? (position << 2U) : ((position - 8U) << 2U);
298
+
299
+      /* Apply the new configuration of the pin to the register */
300
+      MODIFY_REG((*configregister), ((GPIO_CRL_MODE0 | GPIO_CRL_CNF0) << registeroffset), (config << registeroffset));
301
+
302
+      /*--------------------- EXTI Mode Configuration ------------------------*/
303
+      /* Configure the External Interrupt or event for the current IO */
304
+      if ((GPIO_Init->Mode & EXTI_MODE) == EXTI_MODE)
305
+      {
306
+        /* Enable AFIO Clock */
307
+        __HAL_RCC_AFIO_CLK_ENABLE();
308
+        temp = AFIO->EXTICR[position >> 2U];
309
+        CLEAR_BIT(temp, (0x0FU) << (4U * (position & 0x03U)));
310
+        SET_BIT(temp, (GPIO_GET_INDEX(GPIOx)) << (4U * (position & 0x03U)));
311
+        AFIO->EXTICR[position >> 2U] = temp;
312
+
313
+
314
+        /* Configure the interrupt mask */
315
+        if ((GPIO_Init->Mode & GPIO_MODE_IT) == GPIO_MODE_IT)
316
+        {
317
+          SET_BIT(EXTI->IMR, iocurrent);
318
+        }
319
+        else
320
+        {
321
+          CLEAR_BIT(EXTI->IMR, iocurrent);
322
+        }
323
+
324
+        /* Configure the event mask */
325
+        if ((GPIO_Init->Mode & GPIO_MODE_EVT) == GPIO_MODE_EVT)
326
+        {
327
+          SET_BIT(EXTI->EMR, iocurrent);
328
+        }
329
+        else
330
+        {
331
+          CLEAR_BIT(EXTI->EMR, iocurrent);
332
+        }
333
+
334
+        /* Enable or disable the rising trigger */
335
+        if ((GPIO_Init->Mode & RISING_EDGE) == RISING_EDGE)
336
+        {
337
+          SET_BIT(EXTI->RTSR, iocurrent);
338
+        }
339
+        else
340
+        {
341
+          CLEAR_BIT(EXTI->RTSR, iocurrent);
342
+        }
343
+
344
+        /* Enable or disable the falling trigger */
345
+        if ((GPIO_Init->Mode & FALLING_EDGE) == FALLING_EDGE)
346
+        {
347
+          SET_BIT(EXTI->FTSR, iocurrent);
348
+        }
349
+        else
350
+        {
351
+          CLEAR_BIT(EXTI->FTSR, iocurrent);
352
+        }
353
+      }
354
+    }
355
+  }
356
+}
357
+
358
+/**
359
+  * @brief  De-initializes the GPIOx peripheral registers to their default reset values.
360
+  * @param  GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral
361
+  * @param  GPIO_Pin: specifies the port bit to be written.
362
+  *         This parameter can be one of GPIO_PIN_x where x can be (0..15).
363
+  * @retval None
364
+  */
365
+void HAL_GPIO_DeInit(GPIO_TypeDef  *GPIOx, uint32_t GPIO_Pin)
366
+{
367
+  uint32_t position = 0x00U;
368
+  uint32_t iocurrent = 0x00U;
369
+  uint32_t tmp = 0x00U;
370
+  __IO uint32_t *configregister; /* Store the address of CRL or CRH register based on pin number */
371
+  uint32_t registeroffset = 0U;
372
+
373
+  /* Check the parameters */
374
+  assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
375
+  assert_param(IS_GPIO_PIN(GPIO_Pin));
376
+
377
+  /* Configure the port pins */
378
+  while ((GPIO_Pin >> position) != 0U)
379
+  {
380
+    /* Get current io position */
381
+    iocurrent = (GPIO_Pin) & (1U << position);
382
+
383
+    if (iocurrent)
384
+    {
385
+      /*------------------------- GPIO Mode Configuration --------------------*/
386
+      /* Check if the current bit belongs to first half or last half of the pin count number
387
+       in order to address CRH or CRL register */
388
+      configregister = (iocurrent < GPIO_PIN_8) ? &GPIOx->CRL     : &GPIOx->CRH;
389
+      registeroffset = (iocurrent < GPIO_PIN_8) ? (position << 2U) : ((position - 8U) << 2U);
390
+
391
+      /* CRL/CRH default value is floating input(0x04) shifted to correct position */
392
+      MODIFY_REG(*configregister, ((GPIO_CRL_MODE0 | GPIO_CRL_CNF0) << registeroffset), GPIO_CRL_CNF0_0 << registeroffset);
393
+
394
+      /* ODR default value is 0 */
395
+      CLEAR_BIT(GPIOx->ODR, iocurrent);
396
+
397
+      /*------------------------- EXTI Mode Configuration --------------------*/
398
+      /* Clear the External Interrupt or Event for the current IO */
399
+
400
+      tmp = AFIO->EXTICR[position >> 2U];
401
+      tmp &= 0x0FU << (4U * (position & 0x03U));
402
+      if (tmp == (GPIO_GET_INDEX(GPIOx) << (4U * (position & 0x03U))))
403
+      {
404
+        tmp = 0x0FU << (4U * (position & 0x03U));
405
+        CLEAR_BIT(AFIO->EXTICR[position >> 2U], tmp);
406
+
407
+        /* Clear EXTI line configuration */
408
+        CLEAR_BIT(EXTI->IMR, (uint32_t)iocurrent);
409
+        CLEAR_BIT(EXTI->EMR, (uint32_t)iocurrent);
410
+
411
+        /* Clear Rising Falling edge configuration */
412
+        CLEAR_BIT(EXTI->RTSR, (uint32_t)iocurrent);
413
+        CLEAR_BIT(EXTI->FTSR, (uint32_t)iocurrent);
414
+      }
415
+    }
416
+
417
+    position++;
418
+  }
419
+}
420
+
421
+/**
422
+  * @}
423
+  */
424
+
425
+/** @defgroup GPIO_Exported_Functions_Group2 IO operation functions
426
+ *  @brief   GPIO Read and Write
427
+ *
428
+@verbatim
429
+ ===============================================================================
430
+                       ##### IO operation functions #####
431
+ ===============================================================================
432
+  [..]
433
+    This subsection provides a set of functions allowing to manage the GPIOs.
434
+
435
+@endverbatim
436
+  * @{
437
+  */
438
+
439
+/**
440
+  * @brief  Reads the specified input port pin.
441
+  * @param  GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral
442
+  * @param  GPIO_Pin: specifies the port bit to read.
443
+  *         This parameter can be GPIO_PIN_x where x can be (0..15).
444
+  * @retval The input port pin value.
445
+  */
446
+GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
447
+{
448
+  GPIO_PinState bitstatus;
449
+
450
+  /* Check the parameters */
451
+  assert_param(IS_GPIO_PIN(GPIO_Pin));
452
+
453
+  if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)GPIO_PIN_RESET)
454
+  {
455
+    bitstatus = GPIO_PIN_SET;
456
+  }
457
+  else
458
+  {
459
+    bitstatus = GPIO_PIN_RESET;
460
+  }
461
+  return bitstatus;
462
+}
463
+
464
+/**
465
+  * @brief  Sets or clears the selected data port bit.
466
+  *
467
+  * @note   This function uses GPIOx_BSRR register to allow atomic read/modify
468
+  *         accesses. In this way, there is no risk of an IRQ occurring between
469
+  *         the read and the modify access.
470
+  *
471
+  * @param  GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral
472
+  * @param  GPIO_Pin: specifies the port bit to be written.
473
+  *          This parameter can be one of GPIO_PIN_x where x can be (0..15).
474
+  * @param  PinState: specifies the value to be written to the selected bit.
475
+  *          This parameter can be one of the GPIO_PinState enum values:
476
+  *            @arg GPIO_PIN_RESET: to clear the port pin
477
+  *            @arg GPIO_PIN_SET: to set the port pin
478
+  * @retval None
479
+  */
480
+void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)
481
+{
482
+  /* Check the parameters */
483
+  assert_param(IS_GPIO_PIN(GPIO_Pin));
484
+  assert_param(IS_GPIO_PIN_ACTION(PinState));
485
+
486
+  if (PinState != GPIO_PIN_RESET)
487
+  {
488
+    GPIOx->BSRR = GPIO_Pin;
489
+  }
490
+  else
491
+  {
492
+    GPIOx->BSRR = (uint32_t)GPIO_Pin << 16U;
493
+  }
494
+}
495
+
496
+/**
497
+  * @brief  Toggles the specified GPIO pin
498
+  * @param  GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral
499
+  * @param  GPIO_Pin: Specifies the pins to be toggled.
500
+  * @retval None
501
+  */
502
+void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
503
+{
504
+  /* Check the parameters */
505
+  assert_param(IS_GPIO_PIN(GPIO_Pin));
506
+
507
+  GPIOx->ODR ^= GPIO_Pin;
508
+}
509
+
510
+/**
511
+* @brief  Locks GPIO Pins configuration registers.
512
+* @note   The locking mechanism allows the IO configuration to be frozen. When the LOCK sequence
513
+*         has been applied on a port bit, it is no longer possible to modify the value of the port bit until
514
+*         the next reset.
515
+* @param  GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral
516
+* @param  GPIO_Pin: specifies the port bit to be locked.
517
+*         This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
518
+* @retval None
519
+*/
520
+HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
521
+{
522
+  __IO uint32_t tmp = GPIO_LCKR_LCKK;
523
+
524
+  /* Check the parameters */
525
+  assert_param(IS_GPIO_LOCK_INSTANCE(GPIOx));
526
+  assert_param(IS_GPIO_PIN(GPIO_Pin));
527
+
528
+  /* Apply lock key write sequence */
529
+  SET_BIT(tmp, GPIO_Pin);
530
+  /* Set LCKx bit(s): LCKK='1' + LCK[15-0] */
531
+  GPIOx->LCKR = tmp;
532
+  /* Reset LCKx bit(s): LCKK='0' + LCK[15-0] */
533
+  GPIOx->LCKR = GPIO_Pin;
534
+  /* Set LCKx bit(s): LCKK='1' + LCK[15-0] */
535
+  GPIOx->LCKR = tmp;
536
+  /* Read LCKK bit*/
537
+  tmp = GPIOx->LCKR;
538
+
539
+  if ((uint32_t)(GPIOx->LCKR & GPIO_LCKR_LCKK))
540
+  {
541
+    return HAL_OK;
542
+  }
543
+  else
544
+  {
545
+    return HAL_ERROR;
546
+  }
547
+}
548
+
549
+/**
550
+  * @brief  This function handles EXTI interrupt request.
551
+  * @param  GPIO_Pin: Specifies the pins connected EXTI line
552
+  * @retval None
553
+  */
554
+void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
555
+{
556
+  /* EXTI line interrupt detected */
557
+  if (__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != RESET)
558
+  {
559
+    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
560
+    HAL_GPIO_EXTI_Callback(GPIO_Pin);
561
+  }
562
+}
563
+
564
+/**
565
+  * @brief  EXTI line detection callbacks.
566
+  * @param  GPIO_Pin: Specifies the pins connected EXTI line
567
+  * @retval None
568
+  */
569
+__weak void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
570
+{
571
+  /* Prevent unused argument(s) compilation warning */
572
+  UNUSED(GPIO_Pin);
573
+  /* NOTE: This function Should not be modified, when the callback is needed,
574
+           the HAL_GPIO_EXTI_Callback could be implemented in the user file
575
+   */
576
+}
577
+
578
+/**
579
+  * @}
580
+  */
581
+
582
+/**
583
+  * @}
584
+  */
585
+
586
+#endif /* HAL_GPIO_MODULE_ENABLED */
587
+/**
588
+  * @}
589
+  */
590
+
591
+/**
592
+  * @}
593
+  */
594
+
595
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 143 - 0
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c

@@ -0,0 +1,143 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_gpio_ex.c
4
+  * @author  MCD Application Team
5
+  * @brief   GPIO Extension HAL module driver.
6
+  *         This file provides firmware functions to manage the following
7
+  *          functionalities of the General Purpose Input/Output (GPIO) extension peripheral.
8
+  *           + Extended features functions
9
+  *
10
+  @verbatim
11
+  ==============================================================================
12
+                    ##### GPIO Peripheral extension features #####
13
+  ==============================================================================
14
+  [..] GPIO module on STM32F1 family, manage also the AFIO register:
15
+       (+) Possibility to use the EVENTOUT Cortex feature
16
+
17
+                     ##### How to use this driver #####
18
+  ==============================================================================
19
+  [..] This driver provides functions to use EVENTOUT Cortex feature
20
+    (#) Configure EVENTOUT Cortex feature using the function HAL_GPIOEx_ConfigEventout()
21
+    (#) Activate EVENTOUT Cortex feature using the HAL_GPIOEx_EnableEventout()
22
+    (#) Deactivate EVENTOUT Cortex feature using the HAL_GPIOEx_DisableEventout()
23
+
24
+  @endverbatim
25
+  ******************************************************************************
26
+  * @attention
27
+  *
28
+  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
29
+  *
30
+  * Redistribution and use in source and binary forms, with or without modification,
31
+  * are permitted provided that the following conditions are met:
32
+  *   1. Redistributions of source code must retain the above copyright notice,
33
+  *      this list of conditions and the following disclaimer.
34
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
35
+  *      this list of conditions and the following disclaimer in the documentation
36
+  *      and/or other materials provided with the distribution.
37
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
38
+  *      may be used to endorse or promote products derived from this software
39
+  *      without specific prior written permission.
40
+  *
41
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
42
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
44
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
45
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
47
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
48
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51
+  *
52
+  ******************************************************************************
53
+  */
54
+
55
+/* Includes ------------------------------------------------------------------*/
56
+#include "stm32f1xx_hal.h"
57
+
58
+/** @addtogroup STM32F1xx_HAL_Driver
59
+  * @{
60
+  */
61
+
62
+/** @defgroup GPIOEx GPIOEx
63
+  * @brief GPIO HAL module driver
64
+  * @{
65
+  */
66
+
67
+#ifdef HAL_GPIO_MODULE_ENABLED
68
+
69
+/** @defgroup GPIOEx_Exported_Functions GPIOEx Exported Functions
70
+  * @{
71
+  */
72
+
73
+/** @defgroup GPIOEx_Exported_Functions_Group1 Extended features functions
74
+ *  @brief    Extended features functions
75
+ *
76
+@verbatim
77
+  ==============================================================================
78
+                 ##### Extended features functions #####
79
+  ==============================================================================
80
+    [..]  This section provides functions allowing to:
81
+    (+) Configure EVENTOUT Cortex feature using the function HAL_GPIOEx_ConfigEventout()
82
+    (+) Activate EVENTOUT Cortex feature using the HAL_GPIOEx_EnableEventout()
83
+    (+) Deactivate EVENTOUT Cortex feature using the HAL_GPIOEx_DisableEventout()
84
+
85
+@endverbatim
86
+  * @{
87
+  */
88
+
89
+/**
90
+  * @brief  Configures the port and pin on which the EVENTOUT Cortex signal will be connected.
91
+  * @param  GPIO_PortSource Select the port used to output the Cortex EVENTOUT signal.
92
+  *   This parameter can be a value of @ref GPIOEx_EVENTOUT_PORT.
93
+  * @param  GPIO_PinSource Select the pin used to output the Cortex EVENTOUT signal.
94
+  *   This parameter can be a value of @ref GPIOEx_EVENTOUT_PIN.
95
+  * @retval None
96
+  */
97
+void HAL_GPIOEx_ConfigEventout(uint32_t GPIO_PortSource, uint32_t GPIO_PinSource)
98
+{
99
+  /* Verify the parameters */
100
+  assert_param(IS_AFIO_EVENTOUT_PORT(GPIO_PortSource));
101
+  assert_param(IS_AFIO_EVENTOUT_PIN(GPIO_PinSource));
102
+
103
+  /* Apply the new configuration */
104
+  MODIFY_REG(AFIO->EVCR, (AFIO_EVCR_PORT) | (AFIO_EVCR_PIN), (GPIO_PortSource) | (GPIO_PinSource));
105
+}
106
+
107
+/**
108
+  * @brief  Enables the Event Output.
109
+  * @retval None
110
+  */
111
+void HAL_GPIOEx_EnableEventout(void)
112
+{
113
+  SET_BIT(AFIO->EVCR, AFIO_EVCR_EVOE);
114
+}
115
+
116
+/**
117
+  * @brief  Disables the Event Output.
118
+  * @retval None
119
+  */
120
+void HAL_GPIOEx_DisableEventout(void)
121
+{
122
+  CLEAR_BIT(AFIO->EVCR, AFIO_EVCR_EVOE);
123
+}
124
+
125
+/**
126
+  * @}
127
+  */
128
+
129
+/**
130
+  * @}
131
+  */
132
+
133
+#endif /* HAL_GPIO_MODULE_ENABLED */
134
+
135
+/**
136
+  * @}
137
+  */
138
+
139
+/**
140
+  * @}
141
+  */
142
+
143
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 637 - 0
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c

@@ -0,0 +1,637 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_pwr.c
4
+  * @author  MCD Application Team
5
+  * @brief   PWR HAL module driver.
6
+  *
7
+  *          This file provides firmware functions to manage the following
8
+  *          functionalities of the Power Controller (PWR) peripheral:
9
+  *           + Initialization/de-initialization functions
10
+  *           + Peripheral Control functions 
11
+  *
12
+  ******************************************************************************
13
+  * @attention
14
+  *
15
+  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
16
+  *
17
+  * Redistribution and use in source and binary forms, with or without modification,
18
+  * are permitted provided that the following conditions are met:
19
+  *   1. Redistributions of source code must retain the above copyright notice,
20
+  *      this list of conditions and the following disclaimer.
21
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
22
+  *      this list of conditions and the following disclaimer in the documentation
23
+  *      and/or other materials provided with the distribution.
24
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
25
+  *      may be used to endorse or promote products derived from this software
26
+  *      without specific prior written permission.
27
+  *
28
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
32
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
34
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
+  *
39
+  ******************************************************************************
40
+  */
41
+
42
+/* Includes ------------------------------------------------------------------*/
43
+#include "stm32f1xx_hal.h"
44
+
45
+/** @addtogroup STM32F1xx_HAL_Driver
46
+  * @{
47
+  */
48
+
49
+/** @defgroup PWR PWR
50
+  * @brief    PWR HAL module driver
51
+  * @{
52
+  */
53
+
54
+#ifdef HAL_PWR_MODULE_ENABLED
55
+
56
+/* Private typedef -----------------------------------------------------------*/
57
+/* Private define ------------------------------------------------------------*/
58
+
59
+/** @defgroup PWR_Private_Constants PWR Private Constants
60
+  * @{
61
+  */
62
+  
63
+/** @defgroup PWR_PVD_Mode_Mask PWR PVD Mode Mask
64
+  * @{
65
+  */ 
66
+#define PVD_MODE_IT               0x00010000U
67
+#define PVD_MODE_EVT              0x00020000U
68
+#define PVD_RISING_EDGE           0x00000001U
69
+#define PVD_FALLING_EDGE          0x00000002U
70
+/**
71
+  * @}
72
+  */
73
+
74
+
75
+/** @defgroup PWR_register_alias_address PWR Register alias address
76
+  * @{
77
+  */ 
78
+/* ------------- PWR registers bit address in the alias region ---------------*/
79
+#define PWR_OFFSET               (PWR_BASE - PERIPH_BASE)
80
+#define PWR_CR_OFFSET            0x00U
81
+#define PWR_CSR_OFFSET           0x04U
82
+#define PWR_CR_OFFSET_BB         (PWR_OFFSET + PWR_CR_OFFSET)
83
+#define PWR_CSR_OFFSET_BB        (PWR_OFFSET + PWR_CSR_OFFSET)
84
+/**
85
+  * @}
86
+  */
87
+   
88
+/** @defgroup PWR_CR_register_alias PWR CR Register alias address
89
+  * @{
90
+  */  
91
+/* --- CR Register ---*/
92
+/* Alias word address of LPSDSR bit */
93
+#define LPSDSR_BIT_NUMBER        PWR_CR_LPDS_Pos
94
+#define CR_LPSDSR_BB             ((uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (LPSDSR_BIT_NUMBER * 4U)))
95
+
96
+/* Alias word address of DBP bit */
97
+#define DBP_BIT_NUMBER            PWR_CR_DBP_Pos
98
+#define CR_DBP_BB                ((uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (DBP_BIT_NUMBER * 4U)))
99
+
100
+/* Alias word address of PVDE bit */
101
+#define PVDE_BIT_NUMBER           PWR_CR_PVDE_Pos
102
+#define CR_PVDE_BB               ((uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (PVDE_BIT_NUMBER * 4U)))
103
+
104
+/**
105
+  * @}
106
+  */
107
+
108
+/** @defgroup PWR_CSR_register_alias PWR CSR Register alias address
109
+  * @{
110
+  */
111
+
112
+/* --- CSR Register ---*/
113
+/* Alias word address of EWUP1 bit */
114
+#define CSR_EWUP_BB(VAL)         ((uint32_t)(PERIPH_BB_BASE + (PWR_CSR_OFFSET_BB * 32U) + (POSITION_VAL(VAL) * 4U)))
115
+/**
116
+  * @}
117
+  */
118
+  
119
+/**
120
+  * @}
121
+  */
122
+
123
+/* Private variables ---------------------------------------------------------*/
124
+/* Private function prototypes -----------------------------------------------*/
125
+/** @defgroup PWR_Private_Functions PWR Private Functions
126
+ * brief   WFE cortex command overloaded for HAL_PWR_EnterSTOPMode usage only (see Workaround section)
127
+ * @{
128
+ */
129
+static void PWR_OverloadWfe(void);
130
+
131
+/* Private functions ---------------------------------------------------------*/
132
+__NOINLINE
133
+static void PWR_OverloadWfe(void)
134
+{
135
+  __asm volatile( "wfe" );
136
+  __asm volatile( "nop" );
137
+}
138
+
139
+/**
140
+  * @}
141
+  */
142
+
143
+
144
+/** @defgroup PWR_Exported_Functions PWR Exported Functions
145
+  * @{
146
+  */
147
+
148
+/** @defgroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions 
149
+  *  @brief   Initialization and de-initialization functions
150
+  *
151
+@verbatim
152
+ ===============================================================================
153
+              ##### Initialization and de-initialization functions #####
154
+ ===============================================================================
155
+    [..]
156
+      After reset, the backup domain (RTC registers, RTC backup data
157
+      registers) is protected against possible unwanted
158
+      write accesses.
159
+      To enable access to the RTC Domain and RTC registers, proceed as follows:
160
+        (+) Enable the Power Controller (PWR) APB1 interface clock using the
161
+            __HAL_RCC_PWR_CLK_ENABLE() macro.
162
+        (+) Enable access to RTC domain using the HAL_PWR_EnableBkUpAccess() function.
163
+
164
+@endverbatim
165
+  * @{
166
+  */
167
+
168
+/**
169
+  * @brief  Deinitializes the PWR peripheral registers to their default reset values.  
170
+  * @retval None
171
+  */
172
+void HAL_PWR_DeInit(void)
173
+{
174
+  __HAL_RCC_PWR_FORCE_RESET();
175
+  __HAL_RCC_PWR_RELEASE_RESET();
176
+}
177
+
178
+/**
179
+  * @brief  Enables access to the backup domain (RTC registers, RTC
180
+  *         backup data registers ).
181
+  * @note   If the HSE divided by 128 is used as the RTC clock, the
182
+  *         Backup Domain Access should be kept enabled.
183
+  * @retval None
184
+  */
185
+void HAL_PWR_EnableBkUpAccess(void)
186
+{
187
+  /* Enable access to RTC and backup registers */
188
+  *(__IO uint32_t *) CR_DBP_BB = (uint32_t)ENABLE;
189
+}
190
+
191
+/**
192
+  * @brief  Disables access to the backup domain (RTC registers, RTC
193
+  *         backup data registers).
194
+  * @note   If the HSE divided by 128 is used as the RTC clock, the
195
+  *         Backup Domain Access should be kept enabled.
196
+  * @retval None
197
+  */
198
+void HAL_PWR_DisableBkUpAccess(void)
199
+{
200
+  /* Disable access to RTC and backup registers */
201
+  *(__IO uint32_t *) CR_DBP_BB = (uint32_t)DISABLE;
202
+}
203
+
204
+/**
205
+  * @}
206
+  */
207
+
208
+/** @defgroup PWR_Exported_Functions_Group2 Peripheral Control functions 
209
+  * @brief    Low Power modes configuration functions
210
+  *
211
+@verbatim
212
+ ===============================================================================
213
+                 ##### Peripheral Control functions #####
214
+ ===============================================================================
215
+     
216
+    *** PVD configuration ***
217
+    =========================
218
+    [..]
219
+      (+) The PVD is used to monitor the VDD power supply by comparing it to a
220
+          threshold selected by the PVD Level (PLS[2:0] bits in the PWR_CR).
221
+
222
+      (+) A PVDO flag is available to indicate if VDD/VDDA is higher or lower
223
+          than the PVD threshold. This event is internally connected to the EXTI
224
+          line16 and can generate an interrupt if enabled. This is done through
225
+          __HAL_PVD_EXTI_ENABLE_IT() macro.
226
+      (+) The PVD is stopped in Standby mode.
227
+
228
+    *** WakeUp pin configuration ***
229
+    ================================
230
+    [..]
231
+      (+) WakeUp pin is used to wake up the system from Standby mode. This pin is
232
+          forced in input pull-down configuration and is active on rising edges.
233
+      (+) There is one WakeUp pin:
234
+          WakeUp Pin 1 on PA.00.
235
+
236
+    [..]
237
+
238
+    *** Low Power modes configuration ***
239
+    =====================================
240
+     [..]
241
+      The device features 3 low-power modes:
242
+      (+) Sleep mode: CPU clock off, all peripherals including Cortex-M3 core peripherals like 
243
+                      NVIC, SysTick, etc. are kept running
244
+      (+) Stop mode: All clocks are stopped
245
+      (+) Standby mode: 1.8V domain powered off
246
+  
247
+  
248
+   *** Sleep mode ***
249
+   ==================
250
+    [..]
251
+      (+) Entry:
252
+          The Sleep mode is entered by using the HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFx)
253
+              functions with
254
+          (++) PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction
255
+          (++) PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction
256
+     
257
+      (+) Exit:
258
+        (++) WFI entry mode, Any peripheral interrupt acknowledged by the nested vectored interrupt
259
+             controller (NVIC) can wake up the device from Sleep mode.
260
+        (++) WFE entry mode, Any wakeup event can wake up the device from Sleep mode.
261
+           (+++) Any peripheral interrupt w/o NVIC configuration & SEVONPEND bit set in the Cortex (HAL_PWR_EnableSEVOnPend)
262
+           (+++) Any EXTI Line (Internal or External) configured in Event mode
263
+
264
+   *** Stop mode ***
265
+   =================
266
+    [..]
267
+      The Stop mode is based on the Cortex-M3 deepsleep mode combined with peripheral
268
+      clock gating. The voltage regulator can be configured either in normal or low-power mode.
269
+      In Stop mode, all clocks in the 1.8 V domain are stopped, the PLL, the HSI and the HSE RC 
270
+      oscillators are disabled. SRAM and register contents are preserved.
271
+      In Stop mode, all I/O pins keep the same state as in Run mode.
272
+
273
+      (+) Entry:
274
+           The Stop mode is entered using the HAL_PWR_EnterSTOPMode(PWR_REGULATOR_VALUE, PWR_SLEEPENTRY_WFx )
275
+             function with:
276
+          (++) PWR_REGULATOR_VALUE= PWR_MAINREGULATOR_ON: Main regulator ON.
277
+          (++) PWR_REGULATOR_VALUE= PWR_LOWPOWERREGULATOR_ON: Low Power regulator ON.
278
+          (++) PWR_SLEEPENTRY_WFx= PWR_SLEEPENTRY_WFI: enter STOP mode with WFI instruction
279
+          (++) PWR_SLEEPENTRY_WFx= PWR_SLEEPENTRY_WFE: enter STOP mode with WFE instruction
280
+      (+) Exit:
281
+          (++) WFI entry mode, Any EXTI Line (Internal or External) configured in Interrupt mode with NVIC configured
282
+          (++) WFE entry mode, Any EXTI Line (Internal or External) configured in Event mode.
283
+
284
+   *** Standby mode ***
285
+   ====================
286
+     [..]
287
+      The Standby mode allows to achieve the lowest power consumption. It is based on the
288
+      Cortex-M3 deepsleep mode, with the voltage regulator disabled. The 1.8 V domain is 
289
+      consequently powered off. The PLL, the HSI oscillator and the HSE oscillator are also 
290
+      switched off. SRAM and register contents are lost except for registers in the Backup domain 
291
+      and Standby circuitry
292
+      
293
+      (+) Entry:
294
+        (++) The Standby mode is entered using the HAL_PWR_EnterSTANDBYMode() function.
295
+      (+) Exit:
296
+        (++) WKUP pin rising edge, RTC alarm event rising edge, external Reset in 
297
+             NRSTpin, IWDG Reset
298
+
299
+   *** Auto-wakeup (AWU) from low-power mode ***
300
+       =============================================
301
+       [..]
302
+        
303
+       (+) The MCU can be woken up from low-power mode by an RTC Alarm event, 
304
+           without depending on an external interrupt (Auto-wakeup mode).
305
+   
306
+       (+) RTC auto-wakeup (AWU) from the Stop and Standby modes
307
+
308
+           (++) To wake up from the Stop mode with an RTC alarm event, it is necessary to 
309
+                configure the RTC to generate the RTC alarm using the HAL_RTC_SetAlarm_IT() function.
310
+
311
+   *** PWR Workarounds linked to Silicon Limitation ***
312
+       ====================================================
313
+       [..]
314
+       Below the list of all silicon limitations known on STM32F1xx prouct.
315
+
316
+       (#)Workarounds Implemented inside PWR HAL Driver
317
+          (##)Debugging Stop mode with WFE entry - overloaded the WFE by an internal function    
318
+        
319
+@endverbatim
320
+  * @{
321
+  */
322
+
323
+/**
324
+  * @brief  Configures the voltage threshold detected by the Power Voltage Detector(PVD).
325
+  * @param  sConfigPVD: pointer to an PWR_PVDTypeDef structure that contains the configuration
326
+  *         information for the PVD.
327
+  * @note   Refer to the electrical characteristics of your device datasheet for
328
+  *         more details about the voltage threshold corresponding to each
329
+  *         detection level.
330
+  * @retval None
331
+  */
332
+void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD)
333
+{
334
+  /* Check the parameters */
335
+  assert_param(IS_PWR_PVD_LEVEL(sConfigPVD->PVDLevel));
336
+  assert_param(IS_PWR_PVD_MODE(sConfigPVD->Mode));
337
+
338
+  /* Set PLS[7:5] bits according to PVDLevel value */
339
+  MODIFY_REG(PWR->CR, PWR_CR_PLS, sConfigPVD->PVDLevel);
340
+  
341
+  /* Clear any previous config. Keep it clear if no event or IT mode is selected */
342
+  __HAL_PWR_PVD_EXTI_DISABLE_EVENT();
343
+  __HAL_PWR_PVD_EXTI_DISABLE_IT();
344
+  __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE(); 
345
+  __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE();
346
+
347
+  /* Configure interrupt mode */
348
+  if((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT)
349
+  {
350
+    __HAL_PWR_PVD_EXTI_ENABLE_IT();
351
+  }
352
+  
353
+  /* Configure event mode */
354
+  if((sConfigPVD->Mode & PVD_MODE_EVT) == PVD_MODE_EVT)
355
+  {
356
+    __HAL_PWR_PVD_EXTI_ENABLE_EVENT();
357
+  }
358
+  
359
+  /* Configure the edge */
360
+  if((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE)
361
+  {
362
+    __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE();
363
+  }
364
+  
365
+  if((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE)
366
+  {
367
+    __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE();
368
+  }
369
+}
370
+
371
+/**
372
+  * @brief  Enables the Power Voltage Detector(PVD).
373
+  * @retval None
374
+  */
375
+void HAL_PWR_EnablePVD(void)
376
+{
377
+  /* Enable the power voltage detector */
378
+  *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)ENABLE;
379
+}
380
+
381
+/**
382
+  * @brief  Disables the Power Voltage Detector(PVD).
383
+  * @retval None
384
+  */
385
+void HAL_PWR_DisablePVD(void)
386
+{
387
+  /* Disable the power voltage detector */
388
+  *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)DISABLE;
389
+}
390
+
391
+/**
392
+  * @brief Enables the WakeUp PINx functionality.
393
+  * @param WakeUpPinx: Specifies the Power Wake-Up pin to enable.
394
+  *        This parameter can be one of the following values:
395
+  *           @arg PWR_WAKEUP_PIN1
396
+  * @retval None
397
+  */
398
+void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx)
399
+{
400
+  /* Check the parameter */
401
+  assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));
402
+  /* Enable the EWUPx pin */
403
+  *(__IO uint32_t *) CSR_EWUP_BB(WakeUpPinx) = (uint32_t)ENABLE;
404
+}
405
+
406
+/**
407
+  * @brief Disables the WakeUp PINx functionality.
408
+  * @param WakeUpPinx: Specifies the Power Wake-Up pin to disable.
409
+  *        This parameter can be one of the following values:
410
+  *           @arg PWR_WAKEUP_PIN1
411
+  * @retval None
412
+  */
413
+void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx)
414
+{
415
+  /* Check the parameter */
416
+  assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));
417
+  /* Disable the EWUPx pin */
418
+  *(__IO uint32_t *) CSR_EWUP_BB(WakeUpPinx) = (uint32_t)DISABLE;
419
+}
420
+
421
+/**
422
+  * @brief Enters Sleep mode.
423
+  * @note  In Sleep mode, all I/O pins keep the same state as in Run mode.
424
+  * @param Regulator: Regulator state as no effect in SLEEP mode -  allows to support portability from legacy software
425
+  * @param SLEEPEntry: Specifies if SLEEP mode is entered with WFI or WFE instruction.
426
+  *           When WFI entry is used, tick interrupt have to be disabled if not desired as 
427
+  *           the interrupt wake up source.
428
+  *           This parameter can be one of the following values:
429
+  *            @arg PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction
430
+  *            @arg PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction
431
+  * @retval None
432
+  */
433
+void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry)
434
+{
435
+  /* Check the parameters */
436
+  /* No check on Regulator because parameter not used in SLEEP mode */
437
+  /* Prevent unused argument(s) compilation warning */
438
+  UNUSED(Regulator);
439
+
440
+  assert_param(IS_PWR_SLEEP_ENTRY(SLEEPEntry));
441
+
442
+  /* Clear SLEEPDEEP bit of Cortex System Control Register */
443
+  CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
444
+
445
+  /* Select SLEEP mode entry -------------------------------------------------*/
446
+  if(SLEEPEntry == PWR_SLEEPENTRY_WFI)
447
+  {
448
+    /* Request Wait For Interrupt */
449
+    __WFI();
450
+  }
451
+  else
452
+  {
453
+    /* Request Wait For Event */
454
+    __SEV();
455
+    __WFE();
456
+    __WFE();
457
+  }
458
+}
459
+
460
+/**
461
+  * @brief Enters Stop mode. 
462
+  * @note  In Stop mode, all I/O pins keep the same state as in Run mode.
463
+  * @note  When exiting Stop mode by using an interrupt or a wakeup event,
464
+  *        HSI RC oscillator is selected as system clock.
465
+  * @note  When the voltage regulator operates in low power mode, an additional
466
+  *         startup delay is incurred when waking up from Stop mode. 
467
+  *         By keeping the internal regulator ON during Stop mode, the consumption
468
+  *         is higher although the startup time is reduced.    
469
+  * @param Regulator: Specifies the regulator state in Stop mode.
470
+  *          This parameter can be one of the following values:
471
+  *            @arg PWR_MAINREGULATOR_ON: Stop mode with regulator ON
472
+  *            @arg PWR_LOWPOWERREGULATOR_ON: Stop mode with low power regulator ON
473
+  * @param STOPEntry: Specifies if Stop mode in entered with WFI or WFE instruction.
474
+  *          This parameter can be one of the following values:
475
+  *            @arg PWR_STOPENTRY_WFI: Enter Stop mode with WFI instruction
476
+  *            @arg PWR_STOPENTRY_WFE: Enter Stop mode with WFE instruction   
477
+  * @retval None
478
+  */
479
+void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
480
+{
481
+  /* Check the parameters */
482
+  assert_param(IS_PWR_REGULATOR(Regulator));
483
+  assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
484
+
485
+  /* Clear PDDS bit in PWR register to specify entering in STOP mode when CPU enter in Deepsleep */ 
486
+  CLEAR_BIT(PWR->CR,  PWR_CR_PDDS);
487
+
488
+  /* Select the voltage regulator mode by setting LPDS bit in PWR register according to Regulator parameter value */
489
+  MODIFY_REG(PWR->CR, PWR_CR_LPDS, Regulator);
490
+
491
+  /* Set SLEEPDEEP bit of Cortex System Control Register */
492
+  SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
493
+
494
+  /* Select Stop mode entry --------------------------------------------------*/
495
+  if(STOPEntry == PWR_STOPENTRY_WFI)
496
+  {
497
+    /* Request Wait For Interrupt */
498
+    __WFI();
499
+  }
500
+  else
501
+  {
502
+    /* Request Wait For Event */
503
+    __SEV();
504
+    PWR_OverloadWfe(); /* WFE redefine locally */
505
+    PWR_OverloadWfe(); /* WFE redefine locally */
506
+  }
507
+  /* Reset SLEEPDEEP bit of Cortex System Control Register */
508
+  CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
509
+}
510
+
511
+/**
512
+  * @brief Enters Standby mode.
513
+  * @note  In Standby mode, all I/O pins are high impedance except for:
514
+  *          - Reset pad (still available) 
515
+  *          - TAMPER pin if configured for tamper or calibration out.
516
+  *          - WKUP pin (PA0) if enabled.
517
+  * @retval None
518
+  */
519
+void HAL_PWR_EnterSTANDBYMode(void)
520
+{
521
+  /* Select Standby mode */
522
+  SET_BIT(PWR->CR, PWR_CR_PDDS);
523
+
524
+  /* Set SLEEPDEEP bit of Cortex System Control Register */
525
+  SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
526
+
527
+  /* This option is used to ensure that store operations are completed */
528
+#if defined ( __CC_ARM)
529
+  __force_stores();
530
+#endif
531
+  /* Request Wait For Interrupt */
532
+  __WFI();
533
+}
534
+
535
+
536
+/**
537
+  * @brief Indicates Sleep-On-Exit when returning from Handler mode to Thread mode. 
538
+  * @note Set SLEEPONEXIT bit of SCR register. When this bit is set, the processor 
539
+  *       re-enters SLEEP mode when an interruption handling is over.
540
+  *       Setting this bit is useful when the processor is expected to run only on
541
+  *       interruptions handling.         
542
+  * @retval None
543
+  */
544
+void HAL_PWR_EnableSleepOnExit(void)
545
+{
546
+  /* Set SLEEPONEXIT bit of Cortex System Control Register */
547
+  SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
548
+}
549
+
550
+
551
+/**
552
+  * @brief Disables Sleep-On-Exit feature when returning from Handler mode to Thread mode. 
553
+  * @note Clears SLEEPONEXIT bit of SCR register. When this bit is set, the processor 
554
+  *       re-enters SLEEP mode when an interruption handling is over.          
555
+  * @retval None
556
+  */
557
+void HAL_PWR_DisableSleepOnExit(void)
558
+{
559
+  /* Clear SLEEPONEXIT bit of Cortex System Control Register */
560
+  CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
561
+}
562
+
563
+
564
+/**
565
+  * @brief Enables CORTEX M3 SEVONPEND bit. 
566
+  * @note Sets SEVONPEND bit of SCR register. When this bit is set, this causes 
567
+  *       WFE to wake up when an interrupt moves from inactive to pended.
568
+  * @retval None
569
+  */
570
+void HAL_PWR_EnableSEVOnPend(void)
571
+{
572
+  /* Set SEVONPEND bit of Cortex System Control Register */
573
+  SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
574
+}
575
+
576
+
577
+/**
578
+  * @brief Disables CORTEX M3 SEVONPEND bit. 
579
+  * @note Clears SEVONPEND bit of SCR register. When this bit is set, this causes 
580
+  *       WFE to wake up when an interrupt moves from inactive to pended.         
581
+  * @retval None
582
+  */
583
+void HAL_PWR_DisableSEVOnPend(void)
584
+{
585
+  /* Clear SEVONPEND bit of Cortex System Control Register */
586
+  CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
587
+}
588
+
589
+
590
+
591
+/**
592
+  * @brief  This function handles the PWR PVD interrupt request.
593
+  * @note   This API should be called under the PVD_IRQHandler().
594
+  * @retval None
595
+  */
596
+void HAL_PWR_PVD_IRQHandler(void)
597
+{
598
+  /* Check PWR exti flag */
599
+  if(__HAL_PWR_PVD_EXTI_GET_FLAG() != RESET)
600
+  {
601
+    /* PWR PVD interrupt user callback */
602
+    HAL_PWR_PVDCallback();
603
+
604
+    /* Clear PWR Exti pending bit */
605
+    __HAL_PWR_PVD_EXTI_CLEAR_FLAG();
606
+  }
607
+}
608
+
609
+/**
610
+  * @brief  PWR PVD interrupt callback
611
+  * @retval None
612
+  */
613
+__weak void HAL_PWR_PVDCallback(void)
614
+{
615
+  /* NOTE : This function Should not be modified, when the callback is needed,
616
+            the HAL_PWR_PVDCallback could be implemented in the user file
617
+   */ 
618
+}
619
+
620
+/**
621
+  * @}
622
+  */
623
+
624
+/**
625
+  * @}
626
+  */
627
+
628
+#endif /* HAL_PWR_MODULE_ENABLED */
629
+/**
630
+  * @}
631
+  */
632
+
633
+/**
634
+  * @}
635
+  */
636
+
637
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

Разлика између датотеке није приказан због своје велике величине
+ 1416 - 0
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c


+ 879 - 0
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c

@@ -0,0 +1,879 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_rcc_ex.c
4
+  * @author  MCD Application Team
5
+  * @brief   Extended RCC HAL module driver.
6
+  *          This file provides firmware functions to manage the following 
7
+  *          functionalities RCC extension peripheral:
8
+  *           + Extended Peripheral Control functions
9
+  *  
10
+  ******************************************************************************
11
+  * @attention
12
+  *
13
+  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
14
+  *
15
+  * Redistribution and use in source and binary forms, with or without modification,
16
+  * are permitted provided that the following conditions are met:
17
+  *   1. Redistributions of source code must retain the above copyright notice,
18
+  *      this list of conditions and the following disclaimer.
19
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
20
+  *      this list of conditions and the following disclaimer in the documentation
21
+  *      and/or other materials provided with the distribution.
22
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
23
+  *      may be used to endorse or promote products derived from this software
24
+  *      without specific prior written permission.
25
+  *
26
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
30
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
34
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
+  *
37
+  ******************************************************************************  
38
+  */ 
39
+
40
+/* Includes ------------------------------------------------------------------*/
41
+#include "stm32f1xx_hal.h"
42
+
43
+/** @addtogroup STM32F1xx_HAL_Driver
44
+  * @{
45
+  */
46
+
47
+#ifdef HAL_RCC_MODULE_ENABLED
48
+
49
+/** @defgroup RCCEx RCCEx
50
+  * @brief RCC Extension HAL module driver.
51
+  * @{
52
+  */
53
+
54
+/* Private typedef -----------------------------------------------------------*/
55
+/* Private define ------------------------------------------------------------*/
56
+/** @defgroup RCCEx_Private_Constants RCCEx Private Constants
57
+  * @{
58
+  */
59
+/**
60
+  * @}
61
+  */
62
+
63
+/* Private macro -------------------------------------------------------------*/
64
+/** @defgroup RCCEx_Private_Macros RCCEx Private Macros
65
+  * @{
66
+  */
67
+/**
68
+  * @}
69
+  */
70
+
71
+/* Private variables ---------------------------------------------------------*/
72
+/* Private function prototypes -----------------------------------------------*/
73
+/* Private functions ---------------------------------------------------------*/
74
+
75
+/** @defgroup RCCEx_Exported_Functions RCCEx Exported Functions
76
+  * @{
77
+  */
78
+
79
+/** @defgroup RCCEx_Exported_Functions_Group1 Peripheral Control functions 
80
+  *  @brief  Extended Peripheral Control functions  
81
+  *
82
+@verbatim   
83
+ ===============================================================================
84
+                ##### Extended Peripheral Control functions  #####
85
+ ===============================================================================  
86
+    [..]
87
+    This subsection provides a set of functions allowing to control the RCC Clocks 
88
+    frequencies.
89
+    [..] 
90
+    (@) Important note: Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to
91
+        select the RTC clock source; in this case the Backup domain will be reset in  
92
+        order to modify the RTC Clock source, as consequence RTC registers (including 
93
+        the backup registers) are set to their reset values.
94
+      
95
+@endverbatim
96
+  * @{
97
+  */
98
+
99
+/**
100
+  * @brief  Initializes the RCC extended peripherals clocks according to the specified parameters in the
101
+  *         RCC_PeriphCLKInitTypeDef.
102
+  * @param  PeriphClkInit pointer to an RCC_PeriphCLKInitTypeDef structure that
103
+  *         contains the configuration information for the Extended Peripherals clocks(RTC clock).
104
+  *
105
+  * @note   Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to select 
106
+  *         the RTC clock source; in this case the Backup domain will be reset in  
107
+  *         order to modify the RTC Clock source, as consequence RTC registers (including 
108
+  *         the backup registers) are set to their reset values.
109
+  *
110
+  * @note   In case of STM32F105xC or STM32F107xC devices, PLLI2S will be enabled if requested on 
111
+  *         one of 2 I2S interfaces. When PLLI2S is enabled, you need to call HAL_RCCEx_DisablePLLI2S to
112
+  *         manually disable it.
113
+  *
114
+  * @retval HAL status
115
+  */
116
+HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef  *PeriphClkInit)
117
+{
118
+  uint32_t tickstart = 0U, temp_reg = 0U;
119
+#if defined(STM32F105xC) || defined(STM32F107xC)
120
+  uint32_t  pllactive = 0U;
121
+#endif /* STM32F105xC || STM32F107xC */
122
+
123
+  /* Check the parameters */
124
+  assert_param(IS_RCC_PERIPHCLOCK(PeriphClkInit->PeriphClockSelection));
125
+  
126
+  /*------------------------------- RTC/LCD Configuration ------------------------*/ 
127
+  if ((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC))
128
+  {
129
+    /* check for RTC Parameters used to output RTCCLK */
130
+    assert_param(IS_RCC_RTCCLKSOURCE(PeriphClkInit->RTCClockSelection));
131
+
132
+    FlagStatus       pwrclkchanged = RESET;
133
+
134
+    /* As soon as function is called to change RTC clock source, activation of the 
135
+       power domain is done. */
136
+    /* Requires to enable write access to Backup Domain of necessary */
137
+    if(__HAL_RCC_PWR_IS_CLK_DISABLED())
138
+    {
139
+    __HAL_RCC_PWR_CLK_ENABLE();
140
+      pwrclkchanged = SET;
141
+    }
142
+    
143
+    if(HAL_IS_BIT_CLR(PWR->CR, PWR_CR_DBP))
144
+    {
145
+      /* Enable write access to Backup domain */
146
+      SET_BIT(PWR->CR, PWR_CR_DBP);
147
+      
148
+      /* Wait for Backup domain Write protection disable */
149
+      tickstart = HAL_GetTick();
150
+      
151
+      while(HAL_IS_BIT_CLR(PWR->CR, PWR_CR_DBP))
152
+      {
153
+        if((HAL_GetTick() - tickstart) > RCC_DBP_TIMEOUT_VALUE)
154
+        {
155
+          return HAL_TIMEOUT;
156
+        }
157
+      }
158
+    }
159
+      
160
+    /* Reset the Backup domain only if the RTC Clock source selection is modified from reset value */ 
161
+    temp_reg = (RCC->BDCR & RCC_BDCR_RTCSEL);
162
+    if((temp_reg != 0x00000000U) && (temp_reg != (PeriphClkInit->RTCClockSelection & RCC_BDCR_RTCSEL)))
163
+    {
164
+      /* Store the content of BDCR register before the reset of Backup Domain */
165
+      temp_reg = (RCC->BDCR & ~(RCC_BDCR_RTCSEL));
166
+      /* RTC Clock selection can be changed only if the Backup Domain is reset */
167
+      __HAL_RCC_BACKUPRESET_FORCE();
168
+      __HAL_RCC_BACKUPRESET_RELEASE();
169
+      /* Restore the Content of BDCR register */
170
+      RCC->BDCR = temp_reg;
171
+
172
+      /* Wait for LSERDY if LSE was enabled */
173
+      if (HAL_IS_BIT_SET(temp_reg, RCC_BDCR_LSEON))
174
+      {
175
+        /* Get Start Tick */
176
+        tickstart = HAL_GetTick();
177
+      
178
+        /* Wait till LSE is ready */  
179
+        while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET)
180
+        {
181
+          if((HAL_GetTick() - tickstart) > RCC_LSE_TIMEOUT_VALUE)
182
+          {
183
+            return HAL_TIMEOUT;
184
+          }      
185
+        }  
186
+      }
187
+    }
188
+    __HAL_RCC_RTC_CONFIG(PeriphClkInit->RTCClockSelection); 
189
+
190
+    /* Require to disable power clock if necessary */
191
+    if(pwrclkchanged == SET)
192
+    {
193
+      __HAL_RCC_PWR_CLK_DISABLE();
194
+    }
195
+  }
196
+
197
+  /*------------------------------ ADC clock Configuration ------------------*/ 
198
+  if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC)
199
+  {
200
+    /* Check the parameters */
201
+    assert_param(IS_RCC_ADCPLLCLK_DIV(PeriphClkInit->AdcClockSelection));
202
+    
203
+    /* Configure the ADC clock source */
204
+    __HAL_RCC_ADC_CONFIG(PeriphClkInit->AdcClockSelection);
205
+  }
206
+
207
+#if defined(STM32F105xC) || defined(STM32F107xC)
208
+  /*------------------------------ I2S2 Configuration ------------------------*/ 
209
+  if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S2) == RCC_PERIPHCLK_I2S2)
210
+  {
211
+    /* Check the parameters */
212
+    assert_param(IS_RCC_I2S2CLKSOURCE(PeriphClkInit->I2s2ClockSelection));
213
+
214
+    /* Configure the I2S2 clock source */
215
+    __HAL_RCC_I2S2_CONFIG(PeriphClkInit->I2s2ClockSelection);
216
+  }
217
+
218
+  /*------------------------------ I2S3 Configuration ------------------------*/ 
219
+  if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S3) == RCC_PERIPHCLK_I2S3)
220
+  {
221
+    /* Check the parameters */
222
+    assert_param(IS_RCC_I2S3CLKSOURCE(PeriphClkInit->I2s3ClockSelection));
223
+    
224
+    /* Configure the I2S3 clock source */
225
+    __HAL_RCC_I2S3_CONFIG(PeriphClkInit->I2s3ClockSelection);
226
+  }
227
+
228
+  /*------------------------------ PLL I2S Configuration ----------------------*/ 
229
+  /* Check that PLLI2S need to be enabled */
230
+  if (HAL_IS_BIT_SET(RCC->CFGR2, RCC_CFGR2_I2S2SRC) || HAL_IS_BIT_SET(RCC->CFGR2, RCC_CFGR2_I2S3SRC))
231
+  {
232
+    /* Update flag to indicate that PLL I2S should be active */
233
+    pllactive = 1;
234
+  }
235
+
236
+  /* Check if PLL I2S need to be enabled */
237
+  if (pllactive == 1)
238
+  {
239
+    /* Enable PLL I2S only if not active */
240
+    if (HAL_IS_BIT_CLR(RCC->CR, RCC_CR_PLL3ON))
241
+    {
242
+      /* Check the parameters */
243
+      assert_param(IS_RCC_PLLI2S_MUL(PeriphClkInit->PLLI2S.PLLI2SMUL));
244
+      assert_param(IS_RCC_HSE_PREDIV2(PeriphClkInit->PLLI2S.HSEPrediv2Value));
245
+
246
+      /* Prediv2 can be written only when the PLL2 is disabled. */
247
+      /* Return an error only if new value is different from the programmed value */
248
+      if (HAL_IS_BIT_SET(RCC->CR,RCC_CR_PLL2ON) && \
249
+        (__HAL_RCC_HSE_GET_PREDIV2() != PeriphClkInit->PLLI2S.HSEPrediv2Value))
250
+      {
251
+        return HAL_ERROR;
252
+      }
253
+
254
+      /* Configure the HSE prediv2 factor --------------------------------*/
255
+      __HAL_RCC_HSE_PREDIV2_CONFIG(PeriphClkInit->PLLI2S.HSEPrediv2Value);
256
+
257
+      /* Configure the main PLLI2S multiplication factors. */
258
+      __HAL_RCC_PLLI2S_CONFIG(PeriphClkInit->PLLI2S.PLLI2SMUL);
259
+      
260
+      /* Enable the main PLLI2S. */
261
+      __HAL_RCC_PLLI2S_ENABLE();
262
+      
263
+      /* Get Start Tick*/
264
+      tickstart = HAL_GetTick();
265
+      
266
+      /* Wait till PLLI2S is ready */
267
+      while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY)  == RESET)
268
+      {
269
+        if((HAL_GetTick() - tickstart ) > PLLI2S_TIMEOUT_VALUE)
270
+        {
271
+          return HAL_TIMEOUT;
272
+        }
273
+      }
274
+    }
275
+    else
276
+    {
277
+      /* Return an error only if user wants to change the PLLI2SMUL whereas PLLI2S is active */
278
+      if (READ_BIT(RCC->CFGR2, RCC_CFGR2_PLL3MUL) != PeriphClkInit->PLLI2S.PLLI2SMUL)
279
+      {
280
+          return HAL_ERROR;
281
+      }
282
+    }
283
+  }
284
+#endif /* STM32F105xC || STM32F107xC */
285
+
286
+#if defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6)\
287
+ || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG)\
288
+ || defined(STM32F105xC) || defined(STM32F107xC)
289
+  /*------------------------------ USB clock Configuration ------------------*/ 
290
+  if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USB) == RCC_PERIPHCLK_USB)
291
+  {
292
+    /* Check the parameters */
293
+    assert_param(IS_RCC_USBPLLCLK_DIV(PeriphClkInit->UsbClockSelection));
294
+    
295
+    /* Configure the USB clock source */
296
+    __HAL_RCC_USB_CONFIG(PeriphClkInit->UsbClockSelection);
297
+  }
298
+#endif /* STM32F102x6 || STM32F102xB || STM32F103x6 || STM32F103xB || STM32F103xE || STM32F103xG || STM32F105xC || STM32F107xC */
299
+
300
+  return HAL_OK;
301
+}
302
+
303
+/**
304
+  * @brief  Get the PeriphClkInit according to the internal
305
+  * RCC configuration registers.
306
+  * @param  PeriphClkInit pointer to an RCC_PeriphCLKInitTypeDef structure that 
307
+  *         returns the configuration information for the Extended Peripherals clocks(RTC, I2S, ADC clocks).
308
+  * @retval None
309
+  */
310
+void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef  *PeriphClkInit)
311
+{
312
+  uint32_t srcclk = 0U;
313
+  
314
+  /* Set all possible values for the extended clock type parameter------------*/
315
+  PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_RTC;
316
+
317
+  /* Get the RTC configuration -----------------------------------------------*/
318
+  srcclk = __HAL_RCC_GET_RTC_SOURCE();
319
+  /* Source clock is LSE or LSI*/
320
+  PeriphClkInit->RTCClockSelection = srcclk;
321
+
322
+  /* Get the ADC clock configuration -----------------------------------------*/
323
+  PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_ADC;
324
+  PeriphClkInit->AdcClockSelection = __HAL_RCC_GET_ADC_SOURCE();
325
+
326
+#if defined(STM32F105xC) || defined(STM32F107xC)
327
+  /* Get the I2S2 clock configuration -----------------------------------------*/
328
+  PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_I2S2;
329
+  PeriphClkInit->I2s2ClockSelection = __HAL_RCC_GET_I2S2_SOURCE();
330
+
331
+  /* Get the I2S3 clock configuration -----------------------------------------*/
332
+  PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_I2S3;
333
+  PeriphClkInit->I2s3ClockSelection = __HAL_RCC_GET_I2S3_SOURCE();
334
+
335
+#endif /* STM32F105xC || STM32F107xC */
336
+
337
+#if defined(STM32F103xE) || defined(STM32F103xG)
338
+  /* Get the I2S2 clock configuration -----------------------------------------*/
339
+  PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_I2S2;
340
+  PeriphClkInit->I2s2ClockSelection = RCC_I2S2CLKSOURCE_SYSCLK;
341
+
342
+  /* Get the I2S3 clock configuration -----------------------------------------*/
343
+  PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_I2S3;
344
+  PeriphClkInit->I2s3ClockSelection = RCC_I2S3CLKSOURCE_SYSCLK;
345
+
346
+#endif /* STM32F103xE || STM32F103xG */
347
+
348
+#if defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6)\
349
+ || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG)\
350
+ || defined(STM32F105xC) || defined(STM32F107xC)
351
+  /* Get the USB clock configuration -----------------------------------------*/
352
+  PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_USB;
353
+  PeriphClkInit->UsbClockSelection = __HAL_RCC_GET_USB_SOURCE();
354
+#endif /* STM32F102x6 || STM32F102xB || STM32F103x6 || STM32F103xB || STM32F103xE || STM32F103xG || STM32F105xC || STM32F107xC */
355
+}
356
+
357
+/**
358
+  * @brief  Returns the peripheral clock frequency
359
+  * @note   Returns 0 if peripheral clock is unknown
360
+  * @param  PeriphClk Peripheral clock identifier
361
+  *         This parameter can be one of the following values:
362
+  *            @arg @ref RCC_PERIPHCLK_RTC  RTC peripheral clock
363
+  *            @arg @ref RCC_PERIPHCLK_ADC  ADC peripheral clock
364
+  @if STM32F103xE
365
+  *            @arg @ref RCC_PERIPHCLK_I2S2 I2S2 peripheral clock
366
+  *            @arg @ref RCC_PERIPHCLK_I2S3 I2S3 peripheral clock
367
+  *            @arg @ref RCC_PERIPHCLK_I2S3 I2S3 peripheral clock
368
+  @endif
369
+  @if STM32F103xG
370
+  *            @arg @ref RCC_PERIPHCLK_I2S2 I2S2 peripheral clock
371
+  *            @arg @ref RCC_PERIPHCLK_I2S3 I2S3 peripheral clock
372
+  *            @arg @ref RCC_PERIPHCLK_I2S3 I2S3 peripheral clock
373
+  *            @arg @ref RCC_PERIPHCLK_I2S2 I2S2 peripheral clock
374
+  @endif
375
+  @if STM32F105xC
376
+  *            @arg @ref RCC_PERIPHCLK_I2S2 I2S2 peripheral clock
377
+  *            @arg @ref RCC_PERIPHCLK_I2S3 I2S3 peripheral clock
378
+  *            @arg @ref RCC_PERIPHCLK_I2S3 I2S3 peripheral clock
379
+  *            @arg @ref RCC_PERIPHCLK_I2S2 I2S2 peripheral clock
380
+  *            @arg @ref RCC_PERIPHCLK_I2S3 I2S3 peripheral clock
381
+  *            @arg @ref RCC_PERIPHCLK_I2S3 I2S3 peripheral clock
382
+  *            @arg @ref RCC_PERIPHCLK_I2S2 I2S2 peripheral clock
383
+  *            @arg @ref RCC_PERIPHCLK_USB  USB peripheral clock
384
+  @endif
385
+  @if STM32F107xC
386
+  *            @arg @ref RCC_PERIPHCLK_I2S2 I2S2 peripheral clock
387
+  *            @arg @ref RCC_PERIPHCLK_I2S3 I2S3 peripheral clock
388
+  *            @arg @ref RCC_PERIPHCLK_I2S3 I2S3 peripheral clock
389
+  *            @arg @ref RCC_PERIPHCLK_I2S2 I2S2 peripheral clock
390
+  *            @arg @ref RCC_PERIPHCLK_I2S3 I2S3 peripheral clock
391
+  *            @arg @ref RCC_PERIPHCLK_I2S3 I2S3 peripheral clock
392
+  *            @arg @ref RCC_PERIPHCLK_I2S2 I2S2 peripheral clock
393
+  *            @arg @ref RCC_PERIPHCLK_USB  USB peripheral clock
394
+  @endif
395
+  @if STM32F102xx
396
+  *            @arg @ref RCC_PERIPHCLK_USB  USB peripheral clock
397
+  @endif
398
+  @if STM32F103xx
399
+  *            @arg @ref RCC_PERIPHCLK_USB  USB peripheral clock
400
+  @endif
401
+  * @retval Frequency in Hz (0: means that no available frequency for the peripheral)
402
+  */
403
+uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
404
+{
405
+#if defined(STM32F105xC) || defined(STM32F107xC)
406
+  const uint8_t aPLLMULFactorTable[14] = {0, 0, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 13};
407
+  const uint8_t aPredivFactorTable[16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
408
+
409
+  uint32_t prediv1 = 0U, pllclk = 0U, pllmul = 0U;
410
+  uint32_t pll2mul = 0U, pll3mul = 0U, prediv2 = 0U;
411
+#endif /* STM32F105xC || STM32F107xC */
412
+#if defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6) || \
413
+    defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG)
414
+  const uint8_t aPLLMULFactorTable[16] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 16};
415
+  const uint8_t aPredivFactorTable[2] = {1, 2};
416
+
417
+  uint32_t prediv1 = 0U, pllclk = 0U, pllmul = 0U;
418
+#endif /* STM32F102x6 || STM32F102xB || STM32F103x6 || STM32F103xB || STM32F103xE || STM32F103xG */
419
+  uint32_t temp_reg = 0U, frequency = 0U;
420
+
421
+  /* Check the parameters */
422
+  assert_param(IS_RCC_PERIPHCLOCK(PeriphClk));
423
+  
424
+  switch (PeriphClk)
425
+  {
426
+#if defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6)\
427
+ || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG)\
428
+ || defined(STM32F105xC) || defined(STM32F107xC)
429
+  case RCC_PERIPHCLK_USB:  
430
+    {
431
+      /* Get RCC configuration ------------------------------------------------------*/
432
+      temp_reg = RCC->CFGR;
433
+  
434
+      /* Check if PLL is enabled */
435
+      if (HAL_IS_BIT_SET(RCC->CR,RCC_CR_PLLON))
436
+      {
437
+        pllmul = aPLLMULFactorTable[(uint32_t)(temp_reg & RCC_CFGR_PLLMULL) >> RCC_CFGR_PLLMULL_Pos];
438
+        if ((temp_reg & RCC_CFGR_PLLSRC) != RCC_PLLSOURCE_HSI_DIV2)
439
+        {
440
+#if defined(STM32F105xC) || defined(STM32F107xC) || defined(STM32F100xB)\
441
+ || defined(STM32F100xE)
442
+          prediv1 = aPredivFactorTable[(uint32_t)(RCC->CFGR2 & RCC_CFGR2_PREDIV1) >> RCC_CFGR2_PREDIV1_Pos];
443
+#else
444
+          prediv1 = aPredivFactorTable[(uint32_t)(RCC->CFGR & RCC_CFGR_PLLXTPRE) >> RCC_CFGR_PLLXTPRE_Pos];
445
+#endif /* STM32F105xC || STM32F107xC || STM32F100xB || STM32F100xE */
446
+
447
+#if defined(STM32F105xC) || defined(STM32F107xC)
448
+          if(HAL_IS_BIT_SET(RCC->CFGR2, RCC_CFGR2_PREDIV1SRC))
449
+          {
450
+            /* PLL2 selected as Prediv1 source */
451
+            /* PLLCLK = PLL2CLK / PREDIV1 * PLLMUL with PLL2CLK = HSE/PREDIV2 * PLL2MUL */
452
+            prediv2 = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> RCC_CFGR2_PREDIV2_Pos) + 1;
453
+            pll2mul = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> RCC_CFGR2_PLL2MUL_Pos) + 2;
454
+            pllclk = (uint32_t)((((HSE_VALUE / prediv2) * pll2mul) / prediv1) * pllmul);
455
+          }
456
+          else
457
+          {
458
+            /* HSE used as PLL clock source : PLLCLK = HSE/PREDIV1 * PLLMUL */
459
+            pllclk = (uint32_t)((HSE_VALUE / prediv1) * pllmul);
460
+          }
461
+          
462
+          /* If PLLMUL was set to 13 means that it was to cover the case PLLMUL 6.5 (avoid using float) */
463
+          /* In this case need to divide pllclk by 2 */
464
+          if (pllmul == aPLLMULFactorTable[(uint32_t)(RCC_CFGR_PLLMULL6_5) >> RCC_CFGR_PLLMULL_Pos])
465
+          {
466
+              pllclk = pllclk / 2;
467
+          }
468
+#else
469
+          if ((temp_reg & RCC_CFGR_PLLSRC) != RCC_PLLSOURCE_HSI_DIV2)
470
+          {
471
+            /* HSE used as PLL clock source : PLLCLK = HSE/PREDIV1 * PLLMUL */
472
+            pllclk = (uint32_t)((HSE_VALUE / prediv1) * pllmul);
473
+          }
474
+#endif /* STM32F105xC || STM32F107xC */
475
+        }
476
+        else
477
+        {
478
+          /* HSI used as PLL clock source : PLLCLK = HSI/2 * PLLMUL */
479
+          pllclk = (uint32_t)((HSI_VALUE >> 1) * pllmul);
480
+        }
481
+
482
+        /* Calcul of the USB frequency*/
483
+#if defined(STM32F105xC) || defined(STM32F107xC)
484
+        /* USBCLK = PLLVCO = (2 x PLLCLK) / USB prescaler */
485
+        if (__HAL_RCC_GET_USB_SOURCE() == RCC_USBCLKSOURCE_PLL_DIV2)
486
+        {
487
+          /* Prescaler of 2 selected for USB */ 
488
+          frequency = pllclk;
489
+        }
490
+        else
491
+        {
492
+          /* Prescaler of 3 selected for USB */ 
493
+          frequency = (2 * pllclk) / 3;
494
+        }
495
+#else
496
+        /* USBCLK = PLLCLK / USB prescaler */
497
+        if (__HAL_RCC_GET_USB_SOURCE() == RCC_USBCLKSOURCE_PLL)
498
+        {
499
+          /* No prescaler selected for USB */
500
+          frequency = pllclk;
501
+        }
502
+        else
503
+        {
504
+          /* Prescaler of 1.5 selected for USB */ 
505
+          frequency = (pllclk * 2) / 3;
506
+        }
507
+#endif
508
+      }
509
+      break;
510
+    }
511
+#endif /* STM32F102x6 || STM32F102xB || STM32F103x6 || STM32F103xB || STM32F103xE || STM32F103xG || STM32F105xC || STM32F107xC */
512
+#if defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC)
513
+  case RCC_PERIPHCLK_I2S2:  
514
+    {
515
+#if defined(STM32F103xE) || defined(STM32F103xG)
516
+      /* SYSCLK used as source clock for I2S2 */
517
+      frequency = HAL_RCC_GetSysClockFreq();
518
+#else
519
+      if (__HAL_RCC_GET_I2S2_SOURCE() == RCC_I2S2CLKSOURCE_SYSCLK)
520
+      {
521
+        /* SYSCLK used as source clock for I2S2 */
522
+        frequency = HAL_RCC_GetSysClockFreq();
523
+      }
524
+      else
525
+      {
526
+         /* Check if PLLI2S is enabled */
527
+        if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL3ON))
528
+        {
529
+          /* PLLI2SVCO = 2 * PLLI2SCLK = 2 * (HSE/PREDIV2 * PLL3MUL) */
530
+          prediv2 = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> RCC_CFGR2_PREDIV2_Pos) + 1;
531
+          pll3mul = ((RCC->CFGR2 & RCC_CFGR2_PLL3MUL) >> RCC_CFGR2_PLL3MUL_Pos) + 2;
532
+          frequency = (uint32_t)(2 * ((HSE_VALUE / prediv2) * pll3mul));
533
+        }
534
+      }
535
+#endif /* STM32F103xE || STM32F103xG */
536
+      break;
537
+    }
538
+  case RCC_PERIPHCLK_I2S3:
539
+    {
540
+#if defined(STM32F103xE) || defined(STM32F103xG)
541
+      /* SYSCLK used as source clock for I2S3 */
542
+      frequency = HAL_RCC_GetSysClockFreq();
543
+#else
544
+      if (__HAL_RCC_GET_I2S3_SOURCE() == RCC_I2S3CLKSOURCE_SYSCLK)
545
+      {
546
+        /* SYSCLK used as source clock for I2S3 */
547
+        frequency = HAL_RCC_GetSysClockFreq();
548
+      }
549
+      else
550
+      {
551
+         /* Check if PLLI2S is enabled */
552
+        if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL3ON))
553
+        {
554
+          /* PLLI2SVCO = 2 * PLLI2SCLK = 2 * (HSE/PREDIV2 * PLL3MUL) */
555
+          prediv2 = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> RCC_CFGR2_PREDIV2_Pos) + 1;
556
+          pll3mul = ((RCC->CFGR2 & RCC_CFGR2_PLL3MUL) >> RCC_CFGR2_PLL3MUL_Pos) + 2;
557
+          frequency = (uint32_t)(2 * ((HSE_VALUE / prediv2) * pll3mul));
558
+        }
559
+      }
560
+#endif /* STM32F103xE || STM32F103xG */
561
+      break;
562
+    }
563
+#endif /* STM32F103xE || STM32F103xG || STM32F105xC || STM32F107xC */
564
+  case RCC_PERIPHCLK_RTC:  
565
+    {
566
+      /* Get RCC BDCR configuration ------------------------------------------------------*/
567
+      temp_reg = RCC->BDCR;
568
+
569
+      /* Check if LSE is ready if RTC clock selection is LSE */
570
+      if (((temp_reg & RCC_BDCR_RTCSEL) == RCC_RTCCLKSOURCE_LSE) && (HAL_IS_BIT_SET(temp_reg, RCC_BDCR_LSERDY)))
571
+      {
572
+        frequency = LSE_VALUE;
573
+      }
574
+      /* Check if LSI is ready if RTC clock selection is LSI */
575
+      else if (((temp_reg & RCC_BDCR_RTCSEL) == RCC_RTCCLKSOURCE_LSI) && (HAL_IS_BIT_SET(RCC->CSR, RCC_CSR_LSIRDY)))
576
+      {
577
+        frequency = LSI_VALUE;
578
+      }
579
+      else if (((temp_reg & RCC_BDCR_RTCSEL) == RCC_RTCCLKSOURCE_HSE_DIV128) && (HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY)))
580
+      {
581
+        frequency = HSE_VALUE / 128U;
582
+      }
583
+      /* Clock not enabled for RTC*/
584
+      else
585
+      {
586
+        frequency = 0U;
587
+      }
588
+      break;
589
+    }
590
+  case RCC_PERIPHCLK_ADC:  
591
+    {
592
+      frequency = HAL_RCC_GetPCLK2Freq() / (((__HAL_RCC_GET_ADC_SOURCE() >> RCC_CFGR_ADCPRE_Pos) + 1) * 2);
593
+      break;
594
+    }
595
+  default: 
596
+    {
597
+      break;
598
+    }
599
+  }
600
+  return(frequency);
601
+}
602
+
603
+/**
604
+  * @}
605
+  */
606
+
607
+#if defined(STM32F105xC) || defined(STM32F107xC)
608
+/** @defgroup RCCEx_Exported_Functions_Group2 PLLI2S Management function
609
+  *  @brief  PLLI2S Management functions
610
+  *
611
+@verbatim   
612
+ ===============================================================================
613
+                ##### Extended PLLI2S Management functions  #####
614
+ ===============================================================================  
615
+    [..]
616
+    This subsection provides a set of functions allowing to control the PLLI2S
617
+    activation or deactivation
618
+@endverbatim
619
+  * @{
620
+  */
621
+
622
+/**
623
+  * @brief  Enable PLLI2S
624
+  * @param  PLLI2SInit pointer to an RCC_PLLI2SInitTypeDef structure that
625
+  *         contains the configuration information for the PLLI2S
626
+  * @note   The PLLI2S configuration not modified if used by I2S2 or I2S3 Interface.
627
+  * @retval HAL status
628
+  */
629
+HAL_StatusTypeDef HAL_RCCEx_EnablePLLI2S(RCC_PLLI2SInitTypeDef  *PLLI2SInit)
630
+{
631
+  uint32_t tickstart = 0U;
632
+
633
+  /* Check that PLL I2S has not been already enabled by I2S2 or I2S3*/
634
+  if (HAL_IS_BIT_CLR(RCC->CFGR2, RCC_CFGR2_I2S2SRC) && HAL_IS_BIT_CLR(RCC->CFGR2, RCC_CFGR2_I2S3SRC))
635
+  {
636
+    /* Check the parameters */
637
+    assert_param(IS_RCC_PLLI2S_MUL(PLLI2SInit->PLLI2SMUL));
638
+    assert_param(IS_RCC_HSE_PREDIV2(PLLI2SInit->HSEPrediv2Value));
639
+
640
+    /* Prediv2 can be written only when the PLL2 is disabled. */
641
+    /* Return an error only if new value is different from the programmed value */
642
+    if (HAL_IS_BIT_SET(RCC->CR,RCC_CR_PLL2ON) && \
643
+      (__HAL_RCC_HSE_GET_PREDIV2() != PLLI2SInit->HSEPrediv2Value))
644
+    {
645
+      return HAL_ERROR;
646
+    }
647
+
648
+    /* Disable the main PLLI2S. */
649
+    __HAL_RCC_PLLI2S_DISABLE();
650
+
651
+    /* Get Start Tick*/
652
+    tickstart = HAL_GetTick();
653
+    
654
+    /* Wait till PLLI2S is ready */  
655
+    while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY)  != RESET)
656
+    {
657
+      if((HAL_GetTick() - tickstart ) > PLLI2S_TIMEOUT_VALUE)
658
+      {
659
+        return HAL_TIMEOUT;
660
+      }
661
+    }
662
+
663
+    /* Configure the HSE prediv2 factor --------------------------------*/
664
+    __HAL_RCC_HSE_PREDIV2_CONFIG(PLLI2SInit->HSEPrediv2Value);
665
+    
666
+
667
+    /* Configure the main PLLI2S multiplication factors. */
668
+    __HAL_RCC_PLLI2S_CONFIG(PLLI2SInit->PLLI2SMUL);
669
+    
670
+    /* Enable the main PLLI2S. */
671
+    __HAL_RCC_PLLI2S_ENABLE();
672
+    
673
+    /* Get Start Tick*/
674
+    tickstart = HAL_GetTick();
675
+    
676
+    /* Wait till PLLI2S is ready */
677
+    while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY)  == RESET)
678
+    {
679
+      if((HAL_GetTick() - tickstart ) > PLLI2S_TIMEOUT_VALUE)
680
+      {
681
+        return HAL_TIMEOUT;
682
+      }
683
+    }
684
+  }
685
+  else
686
+  {
687
+    /* PLLI2S cannot be modified as already used by I2S2 or I2S3 */
688
+    return HAL_ERROR;
689
+  }
690
+
691
+  return HAL_OK;
692
+}
693
+
694
+/**
695
+  * @brief  Disable PLLI2S
696
+  * @note   PLLI2S is not disabled if used by I2S2 or I2S3 Interface.
697
+  * @retval HAL status
698
+  */
699
+HAL_StatusTypeDef HAL_RCCEx_DisablePLLI2S(void)
700
+{
701
+  uint32_t tickstart = 0U;
702
+
703
+  /* Disable PLL I2S as not requested by I2S2 or I2S3*/
704
+  if (HAL_IS_BIT_CLR(RCC->CFGR2, RCC_CFGR2_I2S2SRC) && HAL_IS_BIT_CLR(RCC->CFGR2, RCC_CFGR2_I2S3SRC))
705
+  {
706
+    /* Disable the main PLLI2S. */
707
+    __HAL_RCC_PLLI2S_DISABLE();
708
+
709
+    /* Get Start Tick*/
710
+    tickstart = HAL_GetTick();
711
+    
712
+    /* Wait till PLLI2S is ready */  
713
+    while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY)  != RESET)
714
+    {
715
+      if((HAL_GetTick() - tickstart ) > PLLI2S_TIMEOUT_VALUE)
716
+      {
717
+        return HAL_TIMEOUT;
718
+      }
719
+    }
720
+  }
721
+  else
722
+  {
723
+    /* PLLI2S is currently used by I2S2 or I2S3. Cannot be disabled.*/
724
+    return HAL_ERROR;
725
+  }
726
+  
727
+  return HAL_OK;
728
+}
729
+
730
+/**
731
+  * @}
732
+  */
733
+
734
+/** @defgroup RCCEx_Exported_Functions_Group3 PLL2 Management function
735
+  *  @brief  PLL2 Management functions
736
+  *
737
+@verbatim   
738
+ ===============================================================================
739
+                ##### Extended PLL2 Management functions  #####
740
+ ===============================================================================  
741
+    [..]
742
+    This subsection provides a set of functions allowing to control the PLL2
743
+    activation or deactivation
744
+@endverbatim
745
+  * @{
746
+  */
747
+
748
+/**
749
+  * @brief  Enable PLL2
750
+  * @param  PLL2Init pointer to an RCC_PLL2InitTypeDef structure that
751
+  *         contains the configuration information for the PLL2
752
+  * @note   The PLL2 configuration not modified if used indirectly as system clock.
753
+  * @retval HAL status
754
+  */
755
+HAL_StatusTypeDef HAL_RCCEx_EnablePLL2(RCC_PLL2InitTypeDef  *PLL2Init)
756
+{
757
+  uint32_t tickstart = 0U;
758
+
759
+  /* This bit can not be cleared if the PLL2 clock is used indirectly as system 
760
+    clock (i.e. it is used as PLL clock entry that is used as system clock). */
761
+  if((__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_HSE) && \
762
+        (__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_PLLCLK) && \
763
+        ((READ_BIT(RCC->CFGR2,RCC_CFGR2_PREDIV1SRC)) == RCC_CFGR2_PREDIV1SRC_PLL2))
764
+  {
765
+    return HAL_ERROR;
766
+  }
767
+  else
768
+  {
769
+    /* Check the parameters */
770
+    assert_param(IS_RCC_PLL2_MUL(PLL2Init->PLL2MUL));
771
+    assert_param(IS_RCC_HSE_PREDIV2(PLL2Init->HSEPrediv2Value));
772
+
773
+    /* Prediv2 can be written only when the PLLI2S is disabled. */
774
+    /* Return an error only if new value is different from the programmed value */
775
+    if (HAL_IS_BIT_SET(RCC->CR,RCC_CR_PLL3ON) && \
776
+      (__HAL_RCC_HSE_GET_PREDIV2() != PLL2Init->HSEPrediv2Value))
777
+    {
778
+      return HAL_ERROR;
779
+    }
780
+
781
+    /* Disable the main PLL2. */
782
+    __HAL_RCC_PLL2_DISABLE();
783
+    
784
+    /* Get Start Tick*/
785
+    tickstart = HAL_GetTick();
786
+    
787
+    /* Wait till PLL2 is disabled */
788
+    while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) != RESET)
789
+    {
790
+      if((HAL_GetTick() - tickstart ) > PLL2_TIMEOUT_VALUE)
791
+      {
792
+        return HAL_TIMEOUT;
793
+      }
794
+    }
795
+    
796
+    /* Configure the HSE prediv2 factor --------------------------------*/
797
+    __HAL_RCC_HSE_PREDIV2_CONFIG(PLL2Init->HSEPrediv2Value);
798
+
799
+    /* Configure the main PLL2 multiplication factors. */
800
+    __HAL_RCC_PLL2_CONFIG(PLL2Init->PLL2MUL);
801
+    
802
+    /* Enable the main PLL2. */
803
+    __HAL_RCC_PLL2_ENABLE();
804
+    
805
+    /* Get Start Tick*/
806
+    tickstart = HAL_GetTick();
807
+    
808
+    /* Wait till PLL2 is ready */
809
+    while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY)  == RESET)
810
+    {
811
+      if((HAL_GetTick() - tickstart ) > PLL2_TIMEOUT_VALUE)
812
+      {
813
+        return HAL_TIMEOUT;
814
+      }
815
+    }
816
+  }
817
+
818
+  return HAL_OK;
819
+}
820
+
821
+/**
822
+  * @brief  Disable PLL2
823
+  * @note   PLL2 is not disabled if used indirectly as system clock.
824
+  * @retval HAL status
825
+  */
826
+HAL_StatusTypeDef HAL_RCCEx_DisablePLL2(void)
827
+{
828
+  uint32_t tickstart = 0U;
829
+
830
+  /* This bit can not be cleared if the PLL2 clock is used indirectly as system 
831
+    clock (i.e. it is used as PLL clock entry that is used as system clock). */
832
+  if((__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_HSE) && \
833
+        (__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_PLLCLK) && \
834
+        ((READ_BIT(RCC->CFGR2,RCC_CFGR2_PREDIV1SRC)) == RCC_CFGR2_PREDIV1SRC_PLL2))
835
+  {
836
+    return HAL_ERROR;
837
+  }
838
+  else
839
+  {
840
+    /* Disable the main PLL2. */
841
+    __HAL_RCC_PLL2_DISABLE();
842
+
843
+    /* Get Start Tick*/
844
+    tickstart = HAL_GetTick();
845
+    
846
+    /* Wait till PLL2 is disabled */  
847
+    while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY)  != RESET)
848
+    {
849
+      if((HAL_GetTick() - tickstart ) > PLL2_TIMEOUT_VALUE)
850
+      {
851
+        return HAL_TIMEOUT;
852
+      }
853
+    }
854
+  }
855
+
856
+  return HAL_OK;
857
+}
858
+
859
+/**
860
+  * @}
861
+  */
862
+#endif /* STM32F105xC || STM32F107xC */
863
+
864
+/**
865
+  * @}
866
+  */
867
+
868
+/**
869
+  * @}
870
+  */
871
+
872
+#endif /* HAL_RCC_MODULE_ENABLED */
873
+
874
+/**
875
+  * @}
876
+  */
877
+
878
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
879
+

Разлика између датотеке није приказан због своје велике величине
+ 5419 - 0
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c


Разлика између датотеке није приказан због своје велике величине
+ 1773 - 0
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c


Разлика између датотеке није приказан због своје велике величине
+ 2556 - 0
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c


+ 209 - 0
Inc/main.h

@@ -0,0 +1,209 @@
1
+/* USER CODE BEGIN Header */
2
+/**
3
+  ******************************************************************************
4
+  * @file           : main.h
5
+  * @brief          : Header for main.c file.
6
+  *                   This file contains the common defines of the application.
7
+  ******************************************************************************
8
+  * @attention
9
+  *
10
+  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
11
+  * All rights reserved.</center></h2>
12
+  *
13
+  * This software component is licensed by ST under BSD 3-Clause license,
14
+  * the "License"; You may not use this file except in compliance with the
15
+  * License. You may obtain a copy of the License at:
16
+  *                        opensource.org/licenses/BSD-3-Clause
17
+  *
18
+  ******************************************************************************
19
+  */
20
+/* USER CODE END Header */
21
+
22
+/* Define to prevent recursive inclusion -------------------------------------*/
23
+#ifndef __MAIN_H
24
+#define __MAIN_H
25
+
26
+#ifdef __cplusplus
27
+extern "C" {
28
+#endif
29
+
30
+/* Includes ------------------------------------------------------------------*/
31
+#include "stm32f1xx_hal.h"
32
+
33
+/* Private includes ----------------------------------------------------------*/
34
+/* USER CODE BEGIN Includes */
35
+
36
+/* USER CODE END Includes */
37
+
38
+/* Exported types ------------------------------------------------------------*/
39
+/* USER CODE BEGIN ET */
40
+
41
+/* USER CODE END ET */
42
+
43
+/* Exported constants --------------------------------------------------------*/
44
+/* USER CODE BEGIN EC */
45
+
46
+/* USER CODE END EC */
47
+
48
+/* Exported macro ------------------------------------------------------------*/
49
+/* USER CODE BEGIN EM */
50
+
51
+/* USER CODE END EM */
52
+
53
+/* Exported functions prototypes ---------------------------------------------*/
54
+void Error_Handler(void);
55
+
56
+/* USER CODE BEGIN EFP */
57
+
58
+/* USER CODE END EFP */
59
+
60
+/* Private defines -----------------------------------------------------------*/
61
+#define ATT_EN_1_8G_DL1_Pin GPIO_PIN_2
62
+#define ATT_EN_1_8G_DL1_GPIO_Port GPIOE
63
+#define ATT_EN_1_8G_DL2_Pin GPIO_PIN_3
64
+#define ATT_EN_1_8G_DL2_GPIO_Port GPIOE
65
+#define ATT_EN_1_8G_UL1_Pin GPIO_PIN_4
66
+#define ATT_EN_1_8G_UL1_GPIO_Port GPIOE
67
+#define ATT_EN_1_8G_UL2_Pin GPIO_PIN_5
68
+#define ATT_EN_1_8G_UL2_GPIO_Port GPIOE
69
+#define ATT_EN_1_8G_UL3_Pin GPIO_PIN_6
70
+#define ATT_EN_1_8G_UL3_GPIO_Port GPIOE
71
+#define ATT_EN_1_8G_UL4_Pin GPIO_PIN_13
72
+#define ATT_EN_1_8G_UL4_GPIO_Port GPIOC
73
+#define PATH_EN_1_8G_DL_Pin GPIO_PIN_14
74
+#define PATH_EN_1_8G_DL_GPIO_Port GPIOC
75
+#define PATH_EN_1_8G_UL_Pin GPIO_PIN_15
76
+#define PATH_EN_1_8G_UL_GPIO_Port GPIOC
77
+#define DET_3_5G_UL_IN_Pin GPIO_PIN_0
78
+#define DET_3_5G_UL_IN_GPIO_Port GPIOC
79
+#define DET_3_5G_UL_OUT_Pin GPIO_PIN_1
80
+#define DET_3_5G_UL_OUT_GPIO_Port GPIOC
81
+#define RFU_TEMP_Pin GPIO_PIN_2
82
+#define RFU_TEMP_GPIO_Port GPIOC
83
+#define _28V_DET_Pin GPIO_PIN_3
84
+#define _28V_DET_GPIO_Port GPIOC
85
+#define DET_1_8G_DL_IN_Pin GPIO_PIN_0
86
+#define DET_1_8G_DL_IN_GPIO_Port GPIOA
87
+#define DET_1_8G_DL_OUT_Pin GPIO_PIN_1
88
+#define DET_1_8G_DL_OUT_GPIO_Port GPIOA
89
+#define DET_1_8G_UL_IN_Pin GPIO_PIN_2
90
+#define DET_1_8G_UL_IN_GPIO_Port GPIOA
91
+#define DET_1_8G_UL_OUT_Pin GPIO_PIN_3
92
+#define DET_1_8G_UL_OUT_GPIO_Port GPIOA
93
+#define DET_2_1G_DL_IN_Pin GPIO_PIN_4
94
+#define DET_2_1G_DL_IN_GPIO_Port GPIOA
95
+#define DET_2_1G_DL_OUT_Pin GPIO_PIN_5
96
+#define DET_2_1G_DL_OUT_GPIO_Port GPIOA
97
+#define DET_2_1G_UL_IN_Pin GPIO_PIN_6
98
+#define DET_2_1G_UL_IN_GPIO_Port GPIOA
99
+#define DET_2_1G_UL_OUT_Pin GPIO_PIN_7
100
+#define DET_2_1G_UL_OUT_GPIO_Port GPIOA
101
+#define DET_3_5G_DL_IN_Pin GPIO_PIN_0
102
+#define DET_3_5G_DL_IN_GPIO_Port GPIOB
103
+#define DET_3_5G_DL_OUT_Pin GPIO_PIN_1
104
+#define DET_3_5G_DL_OUT_GPIO_Port GPIOB
105
+#define ATT_CLK_Pin GPIO_PIN_11
106
+#define ATT_CLK_GPIO_Port GPIOE
107
+#define ATT_DATA_Pin GPIO_PIN_12
108
+#define ATT_DATA_GPIO_Port GPIOE
109
+#define PLL_CLK_Pin GPIO_PIN_13
110
+#define PLL_CLK_GPIO_Port GPIOE
111
+#define PLL_DATA_Pin GPIO_PIN_14
112
+#define PLL_DATA_GPIO_Port GPIOE
113
+#define ALARM_DC_Pin GPIO_PIN_15
114
+#define ALARM_DC_GPIO_Port GPIOE
115
+#define ALARM_AC_Pin GPIO_PIN_10
116
+#define ALARM_AC_GPIO_Port GPIOB
117
+#define DA_LDAC_Pin GPIO_PIN_11
118
+#define DA_LDAC_GPIO_Port GPIOB
119
+#define DA_SYNC_Pin GPIO_PIN_12
120
+#define DA_SYNC_GPIO_Port GPIOB
121
+#define DA_SCLK_Pin GPIO_PIN_13
122
+#define DA_SCLK_GPIO_Port GPIOB
123
+#define DA_DIN_Pin GPIO_PIN_14
124
+#define DA_DIN_GPIO_Port GPIOB
125
+#define _T_SYNC_UL_Pin GPIO_PIN_15
126
+#define _T_SYNC_UL_GPIO_Port GPIOB
127
+#define T_SYNC_UL_Pin GPIO_PIN_8
128
+#define T_SYNC_UL_GPIO_Port GPIOD
129
+#define _T_SYNC_DL_Pin GPIO_PIN_9
130
+#define _T_SYNC_DL_GPIO_Port GPIOD
131
+#define T_SYNC_DL_Pin GPIO_PIN_10
132
+#define T_SYNC_DL_GPIO_Port GPIOD
133
+#define PLL_LD_3_5G_H_Pin GPIO_PIN_11
134
+#define PLL_LD_3_5G_H_GPIO_Port GPIOD
135
+#define PLL_LD_3_5G_L_Pin GPIO_PIN_12
136
+#define PLL_LD_3_5G_L_GPIO_Port GPIOD
137
+#define PLL_EN_3_5G_H_Pin GPIO_PIN_13
138
+#define PLL_EN_3_5G_H_GPIO_Port GPIOD
139
+#define PLL_EN_3_5G_L_Pin GPIO_PIN_14
140
+#define PLL_EN_3_5G_L_GPIO_Port GPIOD
141
+#define PLL_ON_OFF_3_5G_H_Pin GPIO_PIN_15
142
+#define PLL_ON_OFF_3_5G_H_GPIO_Port GPIOD
143
+#define PLL_ON_OFF_3_5G_L_Pin GPIO_PIN_6
144
+#define PLL_ON_OFF_3_5G_L_GPIO_Port GPIOC
145
+#define PATH_EN_3_5G_UL_Pin GPIO_PIN_7
146
+#define PATH_EN_3_5G_UL_GPIO_Port GPIOC
147
+#define PATH_EN_3_5G_DL_Pin GPIO_PIN_8
148
+#define PATH_EN_3_5G_DL_GPIO_Port GPIOC
149
+#define PATH_EN_3_5G_H_Pin GPIO_PIN_9
150
+#define PATH_EN_3_5G_H_GPIO_Port GPIOC
151
+#define PATH_EN_3_5G_L_Pin GPIO_PIN_8
152
+#define PATH_EN_3_5G_L_GPIO_Port GPIOA
153
+#define ATT_DATA_3_5G_COM3_Pin GPIO_PIN_12
154
+#define ATT_DATA_3_5G_COM3_GPIO_Port GPIOA
155
+#define ATT_DATA_3_5G_COM2_Pin GPIO_PIN_13
156
+#define ATT_DATA_3_5G_COM2_GPIO_Port GPIOA
157
+#define ATT_DATA_3_5G_COM1_Pin GPIO_PIN_14
158
+#define ATT_DATA_3_5G_COM1_GPIO_Port GPIOA
159
+#define ATT_DATA_3_5G_UL_Pin GPIO_PIN_15
160
+#define ATT_DATA_3_5G_UL_GPIO_Port GPIOA
161
+#define ATT_DATA_3_5G_DL_Pin GPIO_PIN_10
162
+#define ATT_DATA_3_5G_DL_GPIO_Port GPIOC
163
+#define ATT_EN_3_5G_Pin GPIO_PIN_11
164
+#define ATT_EN_3_5G_GPIO_Port GPIOC
165
+#define ATT_CLK_3_5G_Pin GPIO_PIN_12
166
+#define ATT_CLK_3_5G_GPIO_Port GPIOC
167
+#define PLL_LD_2_1G_UL_Pin GPIO_PIN_1
168
+#define PLL_LD_2_1G_UL_GPIO_Port GPIOD
169
+#define PLL_LD_2_1G_DL_Pin GPIO_PIN_2
170
+#define PLL_LD_2_1G_DL_GPIO_Port GPIOD
171
+#define PLL_EN_2_1G_UL_Pin GPIO_PIN_3
172
+#define PLL_EN_2_1G_UL_GPIO_Port GPIOD
173
+#define PLL_EN_2_1G_DL_Pin GPIO_PIN_4
174
+#define PLL_EN_2_1G_DL_GPIO_Port GPIOD
175
+#define PATH_EN_2_1G_UL_Pin GPIO_PIN_5
176
+#define PATH_EN_2_1G_UL_GPIO_Port GPIOD
177
+#define PATH_EN_2_1G_DL_Pin GPIO_PIN_6
178
+#define PATH_EN_2_1G_DL_GPIO_Port GPIOD
179
+#define ATT_EN_2_1G_UL4_Pin GPIO_PIN_7
180
+#define ATT_EN_2_1G_UL4_GPIO_Port GPIOD
181
+#define ATT_EN_2_1G_UL3_Pin GPIO_PIN_3
182
+#define ATT_EN_2_1G_UL3_GPIO_Port GPIOB
183
+#define ATT_EN_2_1G_UL2_Pin GPIO_PIN_4
184
+#define ATT_EN_2_1G_UL2_GPIO_Port GPIOB
185
+#define ATT_EN_2_1G_UL1_Pin GPIO_PIN_5
186
+#define ATT_EN_2_1G_UL1_GPIO_Port GPIOB
187
+#define ATT_EN_2_1G_DL2_Pin GPIO_PIN_6
188
+#define ATT_EN_2_1G_DL2_GPIO_Port GPIOB
189
+#define ATT_EN_2_1G_DL1_Pin GPIO_PIN_7
190
+#define ATT_EN_2_1G_DL1_GPIO_Port GPIOB
191
+#define PLL_LD_1_8G_UL_Pin GPIO_PIN_8
192
+#define PLL_LD_1_8G_UL_GPIO_Port GPIOB
193
+#define PLL_LD_1_8G_DL_Pin GPIO_PIN_9
194
+#define PLL_LD_1_8G_DL_GPIO_Port GPIOB
195
+#define PLL_EN_1_8G_UL_Pin GPIO_PIN_0
196
+#define PLL_EN_1_8G_UL_GPIO_Port GPIOE
197
+#define PLL_EN_1_8G_DL_Pin GPIO_PIN_1
198
+#define PLL_EN_1_8G_DL_GPIO_Port GPIOE
199
+/* USER CODE BEGIN Private defines */
200
+
201
+/* USER CODE END Private defines */
202
+
203
+#ifdef __cplusplus
204
+}
205
+#endif
206
+
207
+#endif /* __MAIN_H */
208
+
209
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 370 - 0
Inc/stm32f1xx_hal_conf.h

@@ -0,0 +1,370 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_conf.h
4
+  * @brief   HAL configuration file.
5
+  ******************************************************************************
6
+  * @attention
7
+  *
8
+  * <h2><center>&copy; COPYRIGHT(c) 2019 STMicroelectronics</center></h2>
9
+  *
10
+  * Redistribution and use in source and binary forms, with or without modification,
11
+  * are permitted provided that the following conditions are met:
12
+  *   1. Redistributions of source code must retain the above copyright notice,
13
+  *      this list of conditions and the following disclaimer.
14
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
15
+  *      this list of conditions and the following disclaimer in the documentation
16
+  *      and/or other materials provided with the distribution.
17
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
18
+  *      may be used to endorse or promote products derived from this software
19
+  *      without specific prior written permission.
20
+  *
21
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+  *
32
+  ******************************************************************************
33
+  */ 
34
+
35
+/* Define to prevent recursive inclusion -------------------------------------*/
36
+#ifndef __STM32F1xx_HAL_CONF_H
37
+#define __STM32F1xx_HAL_CONF_H
38
+
39
+#ifdef __cplusplus
40
+ extern "C" {
41
+#endif
42
+
43
+/* Exported types ------------------------------------------------------------*/
44
+/* Exported constants --------------------------------------------------------*/
45
+
46
+/* ########################## Module Selection ############################## */
47
+/**
48
+  * @brief This is the list of modules to be used in the HAL driver 
49
+  */
50
+  
51
+#define HAL_MODULE_ENABLED  
52
+#define HAL_ADC_MODULE_ENABLED
53
+/*#define HAL_CRYP_MODULE_ENABLED   */
54
+/*#define HAL_CAN_MODULE_ENABLED   */
55
+/*#define HAL_CEC_MODULE_ENABLED   */
56
+/*#define HAL_CORTEX_MODULE_ENABLED   */
57
+/*#define HAL_CRC_MODULE_ENABLED   */
58
+/*#define HAL_DAC_MODULE_ENABLED   */
59
+/*#define HAL_DMA_MODULE_ENABLED   */
60
+/*#define HAL_ETH_MODULE_ENABLED   */
61
+/*#define HAL_FLASH_MODULE_ENABLED   */
62
+#define HAL_GPIO_MODULE_ENABLED
63
+/*#define HAL_I2C_MODULE_ENABLED   */
64
+/*#define HAL_I2S_MODULE_ENABLED   */
65
+/*#define HAL_IRDA_MODULE_ENABLED   */
66
+/*#define HAL_IWDG_MODULE_ENABLED   */
67
+/*#define HAL_NOR_MODULE_ENABLED   */
68
+/*#define HAL_NAND_MODULE_ENABLED   */
69
+/*#define HAL_PCCARD_MODULE_ENABLED   */
70
+/*#define HAL_PCD_MODULE_ENABLED   */
71
+/*#define HAL_HCD_MODULE_ENABLED   */
72
+/*#define HAL_PWR_MODULE_ENABLED   */
73
+/*#define HAL_RCC_MODULE_ENABLED   */
74
+/*#define HAL_RTC_MODULE_ENABLED   */
75
+/*#define HAL_SD_MODULE_ENABLED   */
76
+/*#define HAL_MMC_MODULE_ENABLED   */
77
+/*#define HAL_SDRAM_MODULE_ENABLED   */
78
+/*#define HAL_SMARTCARD_MODULE_ENABLED   */
79
+/*#define HAL_SPI_MODULE_ENABLED   */
80
+/*#define HAL_SRAM_MODULE_ENABLED   */
81
+/*#define HAL_TIM_MODULE_ENABLED   */
82
+#define HAL_UART_MODULE_ENABLED
83
+/*#define HAL_USART_MODULE_ENABLED   */
84
+/*#define HAL_WWDG_MODULE_ENABLED   */
85
+/*#define HAL_EXTI_MODULE_ENABLED   */
86
+
87
+#define HAL_CORTEX_MODULE_ENABLED
88
+#define HAL_DMA_MODULE_ENABLED
89
+#define HAL_FLASH_MODULE_ENABLED
90
+#define HAL_GPIO_MODULE_ENABLED
91
+#define HAL_PWR_MODULE_ENABLED
92
+#define HAL_RCC_MODULE_ENABLED
93
+
94
+/* ########################## Oscillator Values adaptation ####################*/
95
+/**
96
+  * @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
97
+  *        This value is used by the RCC HAL module to compute the system frequency
98
+  *        (when HSE is used as system clock source, directly or through the PLL).  
99
+  */
100
+#if !defined  (HSE_VALUE) 
101
+  #define HSE_VALUE    ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
102
+#endif /* HSE_VALUE */
103
+
104
+#if !defined  (HSE_STARTUP_TIMEOUT)
105
+  #define HSE_STARTUP_TIMEOUT    ((uint32_t)100)   /*!< Time out for HSE start up, in ms */
106
+#endif /* HSE_STARTUP_TIMEOUT */
107
+
108
+/**
109
+  * @brief Internal High Speed oscillator (HSI) value.
110
+  *        This value is used by the RCC HAL module to compute the system frequency
111
+  *        (when HSI is used as system clock source, directly or through the PLL). 
112
+  */
113
+#if !defined  (HSI_VALUE)
114
+  #define HSI_VALUE    ((uint32_t)8000000) /*!< Value of the Internal oscillator in Hz*/
115
+#endif /* HSI_VALUE */
116
+
117
+/**
118
+  * @brief Internal Low Speed oscillator (LSI) value.
119
+  */
120
+#if !defined  (LSI_VALUE) 
121
+ #define LSI_VALUE               40000U    /*!< LSI Typical Value in Hz */
122
+#endif /* LSI_VALUE */                     /*!< Value of the Internal Low Speed oscillator in Hz
123
+                                                The real value may vary depending on the variations
124
+                                                in voltage and temperature. */
125
+
126
+/**
127
+  * @brief External Low Speed oscillator (LSE) value.
128
+  *        This value is used by the UART, RTC HAL module to compute the system frequency
129
+  */
130
+#if !defined  (LSE_VALUE)
131
+  #define LSE_VALUE    ((uint32_t)32768) /*!< Value of the External oscillator in Hz*/
132
+#endif /* LSE_VALUE */
133
+
134
+#if !defined  (LSE_STARTUP_TIMEOUT)
135
+  #define LSE_STARTUP_TIMEOUT    ((uint32_t)5000)   /*!< Time out for LSE start up, in ms */
136
+#endif /* LSE_STARTUP_TIMEOUT */
137
+
138
+/* Tip: To avoid modifying this file each time you need to use different HSE,
139
+   ===  you can define the HSE value in your toolchain compiler preprocessor. */
140
+
141
+/* ########################### System Configuration ######################### */
142
+/**
143
+  * @brief This is the HAL system configuration section
144
+  */     
145
+#define  VDD_VALUE                    ((uint32_t)3300) /*!< Value of VDD in mv */           
146
+#define  TICK_INT_PRIORITY            ((uint32_t)0)    /*!< tick interrupt priority (lowest by default)  */            
147
+#define  USE_RTOS                     0
148
+#define  PREFETCH_ENABLE              1
149
+
150
+/* ########################## Assert Selection ############################## */
151
+/**
152
+  * @brief Uncomment the line below to expanse the "assert_param" macro in the 
153
+  *        HAL drivers code
154
+  */
155
+/* #define USE_FULL_ASSERT    1U */
156
+
157
+/* ################## Ethernet peripheral configuration ##################### */
158
+
159
+/* Section 1 : Ethernet peripheral configuration */
160
+
161
+/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
162
+#define MAC_ADDR0   2
163
+#define MAC_ADDR1   0
164
+#define MAC_ADDR2   0
165
+#define MAC_ADDR3   0
166
+#define MAC_ADDR4   0
167
+#define MAC_ADDR5   0
168
+
169
+/* Definition of the Ethernet driver buffers size and count */   
170
+#define ETH_RX_BUF_SIZE                ETH_MAX_PACKET_SIZE /* buffer size for receive               */
171
+#define ETH_TX_BUF_SIZE                ETH_MAX_PACKET_SIZE /* buffer size for transmit              */
172
+#define ETH_RXBUFNB                    ((uint32_t)8)       /* 4 Rx buffers of size ETH_RX_BUF_SIZE  */
173
+#define ETH_TXBUFNB                    ((uint32_t)4)       /* 4 Tx buffers of size ETH_TX_BUF_SIZE  */
174
+
175
+/* Section 2: PHY configuration section */
176
+
177
+/* DP83848_PHY_ADDRESS Address*/ 
178
+#define DP83848_PHY_ADDRESS           0x01U
179
+/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/ 
180
+#define PHY_RESET_DELAY                 ((uint32_t)0x000000FF)
181
+/* PHY Configuration delay */
182
+#define PHY_CONFIG_DELAY                ((uint32_t)0x00000FFF)
183
+
184
+#define PHY_READ_TO                     ((uint32_t)0x0000FFFF)
185
+#define PHY_WRITE_TO                    ((uint32_t)0x0000FFFF)
186
+
187
+/* Section 3: Common PHY Registers */
188
+
189
+#define PHY_BCR                         ((uint16_t)0x00)    /*!< Transceiver Basic Control Register   */
190
+#define PHY_BSR                         ((uint16_t)0x01)    /*!< Transceiver Basic Status Register    */
191
+ 
192
+#define PHY_RESET                       ((uint16_t)0x8000)  /*!< PHY Reset */
193
+#define PHY_LOOPBACK                    ((uint16_t)0x4000)  /*!< Select loop-back mode */
194
+#define PHY_FULLDUPLEX_100M             ((uint16_t)0x2100)  /*!< Set the full-duplex mode at 100 Mb/s */
195
+#define PHY_HALFDUPLEX_100M             ((uint16_t)0x2000)  /*!< Set the half-duplex mode at 100 Mb/s */
196
+#define PHY_FULLDUPLEX_10M              ((uint16_t)0x0100)  /*!< Set the full-duplex mode at 10 Mb/s  */
197
+#define PHY_HALFDUPLEX_10M              ((uint16_t)0x0000)  /*!< Set the half-duplex mode at 10 Mb/s  */
198
+#define PHY_AUTONEGOTIATION             ((uint16_t)0x1000)  /*!< Enable auto-negotiation function     */
199
+#define PHY_RESTART_AUTONEGOTIATION     ((uint16_t)0x0200)  /*!< Restart auto-negotiation function    */
200
+#define PHY_POWERDOWN                   ((uint16_t)0x0800)  /*!< Select the power down mode           */
201
+#define PHY_ISOLATE                     ((uint16_t)0x0400)  /*!< Isolate PHY from MII                 */
202
+
203
+#define PHY_AUTONEGO_COMPLETE           ((uint16_t)0x0020)  /*!< Auto-Negotiation process completed   */
204
+#define PHY_LINKED_STATUS               ((uint16_t)0x0004)  /*!< Valid link established               */
205
+#define PHY_JABBER_DETECTION            ((uint16_t)0x0002)  /*!< Jabber condition detected            */
206
+  
207
+/* Section 4: Extended PHY Registers */
208
+#define PHY_SR                          ((uint16_t)0x10U)    /*!< PHY status register Offset                      */
209
+
210
+#define PHY_SPEED_STATUS                ((uint16_t)0x0002U)  /*!< PHY Speed mask                                  */
211
+#define PHY_DUPLEX_STATUS               ((uint16_t)0x0004U)  /*!< PHY Duplex mask                                 */
212
+
213
+/* Includes ------------------------------------------------------------------*/
214
+/**
215
+  * @brief Include module's header file 
216
+  */
217
+
218
+#ifdef HAL_RCC_MODULE_ENABLED
219
+ #include "stm32f1xx_hal_rcc.h"
220
+#endif /* HAL_RCC_MODULE_ENABLED */
221
+
222
+#ifdef HAL_EXTI_MODULE_ENABLED
223
+ #include "stm32f1xx_hal_exti.h"
224
+#endif /* HAL_EXTI_MODULE_ENABLED */
225
+
226
+#ifdef HAL_GPIO_MODULE_ENABLED
227
+ #include "stm32f1xx_hal_gpio.h"
228
+#endif /* HAL_GPIO_MODULE_ENABLED */
229
+   
230
+#ifdef HAL_DMA_MODULE_ENABLED
231
+  #include "stm32f1xx_hal_dma.h"
232
+#endif /* HAL_DMA_MODULE_ENABLED */
233
+   
234
+#ifdef HAL_ETH_MODULE_ENABLED
235
+  #include "stm32f1xx_hal_eth.h"
236
+#endif /* HAL_ETH_MODULE_ENABLED */  
237
+   
238
+#ifdef HAL_CAN_MODULE_ENABLED
239
+ #include "stm32f1xx_hal_can.h"
240
+#endif /* HAL_CAN_MODULE_ENABLED */
241
+
242
+#ifdef HAL_CEC_MODULE_ENABLED
243
+ #include "stm32f1xx_hal_cec.h"
244
+#endif /* HAL_CEC_MODULE_ENABLED */
245
+
246
+#ifdef HAL_CORTEX_MODULE_ENABLED
247
+ #include "stm32f1xx_hal_cortex.h"
248
+#endif /* HAL_CORTEX_MODULE_ENABLED */
249
+
250
+#ifdef HAL_ADC_MODULE_ENABLED
251
+ #include "stm32f1xx_hal_adc.h"
252
+#endif /* HAL_ADC_MODULE_ENABLED */
253
+
254
+#ifdef HAL_CRC_MODULE_ENABLED
255
+ #include "stm32f1xx_hal_crc.h"
256
+#endif /* HAL_CRC_MODULE_ENABLED */
257
+
258
+#ifdef HAL_DAC_MODULE_ENABLED
259
+ #include "stm32f1xx_hal_dac.h"
260
+#endif /* HAL_DAC_MODULE_ENABLED */
261
+
262
+#ifdef HAL_FLASH_MODULE_ENABLED
263
+ #include "stm32f1xx_hal_flash.h"
264
+#endif /* HAL_FLASH_MODULE_ENABLED */
265
+
266
+#ifdef HAL_SRAM_MODULE_ENABLED
267
+ #include "stm32f1xx_hal_sram.h"
268
+#endif /* HAL_SRAM_MODULE_ENABLED */
269
+
270
+#ifdef HAL_NOR_MODULE_ENABLED
271
+ #include "stm32f1xx_hal_nor.h"
272
+#endif /* HAL_NOR_MODULE_ENABLED */
273
+
274
+#ifdef HAL_I2C_MODULE_ENABLED
275
+ #include "stm32f1xx_hal_i2c.h"
276
+#endif /* HAL_I2C_MODULE_ENABLED */
277
+
278
+#ifdef HAL_I2S_MODULE_ENABLED
279
+ #include "stm32f1xx_hal_i2s.h"
280
+#endif /* HAL_I2S_MODULE_ENABLED */
281
+
282
+#ifdef HAL_IWDG_MODULE_ENABLED
283
+ #include "stm32f1xx_hal_iwdg.h"
284
+#endif /* HAL_IWDG_MODULE_ENABLED */
285
+
286
+#ifdef HAL_PWR_MODULE_ENABLED
287
+ #include "stm32f1xx_hal_pwr.h"
288
+#endif /* HAL_PWR_MODULE_ENABLED */
289
+
290
+#ifdef HAL_RTC_MODULE_ENABLED
291
+ #include "stm32f1xx_hal_rtc.h"
292
+#endif /* HAL_RTC_MODULE_ENABLED */
293
+
294
+#ifdef HAL_PCCARD_MODULE_ENABLED
295
+ #include "stm32f1xx_hal_pccard.h"
296
+#endif /* HAL_PCCARD_MODULE_ENABLED */ 
297
+
298
+#ifdef HAL_SD_MODULE_ENABLED
299
+ #include "stm32f1xx_hal_sd.h"
300
+#endif /* HAL_SD_MODULE_ENABLED */  
301
+
302
+#ifdef HAL_MMC_MODULE_ENABLED
303
+ #include "stm32f1xx_hal_mmc.h"
304
+#endif /* HAL_MMC_MODULE_ENABLED */
305
+
306
+#ifdef HAL_NAND_MODULE_ENABLED
307
+ #include "stm32f1xx_hal_nand.h"
308
+#endif /* HAL_NAND_MODULE_ENABLED */     
309
+
310
+#ifdef HAL_SPI_MODULE_ENABLED
311
+ #include "stm32f1xx_hal_spi.h"
312
+#endif /* HAL_SPI_MODULE_ENABLED */
313
+
314
+#ifdef HAL_TIM_MODULE_ENABLED
315
+ #include "stm32f1xx_hal_tim.h"
316
+#endif /* HAL_TIM_MODULE_ENABLED */
317
+
318
+#ifdef HAL_UART_MODULE_ENABLED
319
+ #include "stm32f1xx_hal_uart.h"
320
+#endif /* HAL_UART_MODULE_ENABLED */
321
+
322
+#ifdef HAL_USART_MODULE_ENABLED
323
+ #include "stm32f1xx_hal_usart.h"
324
+#endif /* HAL_USART_MODULE_ENABLED */
325
+
326
+#ifdef HAL_IRDA_MODULE_ENABLED
327
+ #include "stm32f1xx_hal_irda.h"
328
+#endif /* HAL_IRDA_MODULE_ENABLED */
329
+
330
+#ifdef HAL_SMARTCARD_MODULE_ENABLED
331
+ #include "stm32f1xx_hal_smartcard.h"
332
+#endif /* HAL_SMARTCARD_MODULE_ENABLED */
333
+
334
+#ifdef HAL_WWDG_MODULE_ENABLED
335
+ #include "stm32f1xx_hal_wwdg.h"
336
+#endif /* HAL_WWDG_MODULE_ENABLED */
337
+
338
+#ifdef HAL_PCD_MODULE_ENABLED
339
+ #include "stm32f1xx_hal_pcd.h"
340
+#endif /* HAL_PCD_MODULE_ENABLED */
341
+
342
+#ifdef HAL_HCD_MODULE_ENABLED
343
+ #include "stm32f1xx_hal_hcd.h"
344
+#endif /* HAL_HCD_MODULE_ENABLED */   
345
+   
346
+
347
+/* Exported macro ------------------------------------------------------------*/
348
+#ifdef  USE_FULL_ASSERT
349
+/**
350
+  * @brief  The assert_param macro is used for function's parameters check.
351
+  * @param  expr: If expr is false, it calls assert_failed function
352
+  *         which reports the name of the source file and the source
353
+  *         line number of the call that failed. 
354
+  *         If expr is true, it returns no value.
355
+  * @retval None
356
+  */
357
+  #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
358
+/* Exported functions ------------------------------------------------------- */
359
+  void assert_failed(uint8_t* file, uint32_t line);
360
+#else
361
+  #define assert_param(expr) ((void)0U)
362
+#endif /* USE_FULL_ASSERT */
363
+
364
+#ifdef __cplusplus
365
+}
366
+#endif
367
+
368
+#endif /* __STM32F1xx_HAL_CONF_H */
369
+
370
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 69 - 0
Inc/stm32f1xx_it.h

@@ -0,0 +1,69 @@
1
+/* USER CODE BEGIN Header */
2
+/**
3
+  ******************************************************************************
4
+  * @file    stm32f1xx_it.h
5
+  * @brief   This file contains the headers of the interrupt handlers.
6
+  ******************************************************************************
7
+  * @attention
8
+  *
9
+  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
10
+  * All rights reserved.</center></h2>
11
+  *
12
+  * This software component is licensed by ST under BSD 3-Clause license,
13
+  * the "License"; You may not use this file except in compliance with the
14
+  * License. You may obtain a copy of the License at:
15
+  *                        opensource.org/licenses/BSD-3-Clause
16
+  *
17
+ ******************************************************************************
18
+  */
19
+/* USER CODE END Header */
20
+
21
+/* Define to prevent recursive inclusion -------------------------------------*/
22
+#ifndef __STM32F1xx_IT_H
23
+#define __STM32F1xx_IT_H
24
+
25
+#ifdef __cplusplus
26
+ extern "C" {
27
+#endif 
28
+
29
+/* Private includes ----------------------------------------------------------*/
30
+/* USER CODE BEGIN Includes */
31
+
32
+/* USER CODE END Includes */
33
+
34
+/* Exported types ------------------------------------------------------------*/
35
+/* USER CODE BEGIN ET */
36
+
37
+/* USER CODE END ET */
38
+
39
+/* Exported constants --------------------------------------------------------*/
40
+/* USER CODE BEGIN EC */
41
+
42
+/* USER CODE END EC */
43
+
44
+/* Exported macro ------------------------------------------------------------*/
45
+/* USER CODE BEGIN EM */
46
+
47
+/* USER CODE END EM */
48
+
49
+/* Exported functions prototypes ---------------------------------------------*/
50
+void NMI_Handler(void);
51
+void HardFault_Handler(void);
52
+void MemManage_Handler(void);
53
+void BusFault_Handler(void);
54
+void UsageFault_Handler(void);
55
+void SVC_Handler(void);
56
+void DebugMon_Handler(void);
57
+void PendSV_Handler(void);
58
+void SysTick_Handler(void);
59
+/* USER CODE BEGIN EFP */
60
+
61
+/* USER CODE END EFP */
62
+
63
+#ifdef __cplusplus
64
+}
65
+#endif
66
+
67
+#endif /* __STM32F1xx_IT_H */
68
+
69
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 168 - 0
STM32F103VG_FLASH.ld

@@ -0,0 +1,168 @@
1
+/*
2
+*****************************************************************************
3
+**
4
+
5
+**  File        : stm32_flash.ld
6
+**
7
+**  Abstract    : Linker script for STM32F103VG Device with
8
+**                1024KByte FLASH, 96KByte RAM
9
+**
10
+**                Set heap size, stack size and stack location according
11
+**                to application requirements.
12
+**
13
+**                Set memory bank area and size if external memory is used.
14
+**
15
+**  Target      : STMicroelectronics STM32
16
+**
17
+**  Environment : Atollic TrueSTUDIO(R)
18
+**
19
+**  Distribution: The file is distributed as is, without any warranty
20
+**                of any kind.
21
+**
22
+**  (c)Copyright Atollic AB.
23
+**  You may use this file as-is or modify it according to the needs of your
24
+**  project. This file may only be built (assembled or compiled and linked)
25
+**  using the Atollic TrueSTUDIO(R) product. The use of this file together
26
+**  with other tools than Atollic TrueSTUDIO(R) is not permitted.
27
+**
28
+*****************************************************************************
29
+*/
30
+
31
+/* Entry Point */
32
+ENTRY(Reset_Handler)
33
+
34
+/* Highest address of the user mode stack */
35
+_estack = 0x20018000;    /* end of RAM */
36
+/* Generate a link error if heap and stack don't fit into RAM */
37
+_Min_Heap_Size = 0x200;      /* required amount of heap  */
38
+_Min_Stack_Size = 0x400; /* required amount of stack */
39
+
40
+/* Specify the memory areas */
41
+MEMORY
42
+{
43
+RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 96K
44
+FLASH (rx)      : ORIGIN = 0x8000000, LENGTH = 1024K
45
+}
46
+
47
+/* Define output sections */
48
+SECTIONS
49
+{
50
+  /* The startup code goes first into FLASH */
51
+  .isr_vector :
52
+  {
53
+    . = ALIGN(4);
54
+    KEEP(*(.isr_vector)) /* Startup code */
55
+    . = ALIGN(4);
56
+  } >FLASH
57
+
58
+  /* The program code and other data goes into FLASH */
59
+  .text :
60
+  {
61
+    . = ALIGN(4);
62
+    *(.text)           /* .text sections (code) */
63
+    *(.text*)          /* .text* sections (code) */
64
+    *(.glue_7)         /* glue arm to thumb code */
65
+    *(.glue_7t)        /* glue thumb to arm code */
66
+    *(.eh_frame)
67
+
68
+    KEEP (*(.init))
69
+    KEEP (*(.fini))
70
+
71
+    . = ALIGN(4);
72
+    _etext = .;        /* define a global symbols at end of code */
73
+  } >FLASH
74
+
75
+  /* Constant data goes into FLASH */
76
+  .rodata :
77
+  {
78
+    . = ALIGN(4);
79
+    *(.rodata)         /* .rodata sections (constants, strings, etc.) */
80
+    *(.rodata*)        /* .rodata* sections (constants, strings, etc.) */
81
+    . = ALIGN(4);
82
+  } >FLASH
83
+
84
+  .ARM.extab   : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
85
+  .ARM : {
86
+    __exidx_start = .;
87
+    *(.ARM.exidx*)
88
+    __exidx_end = .;
89
+  } >FLASH
90
+
91
+  .preinit_array     :
92
+  {
93
+    PROVIDE_HIDDEN (__preinit_array_start = .);
94
+    KEEP (*(.preinit_array*))
95
+    PROVIDE_HIDDEN (__preinit_array_end = .);
96
+  } >FLASH
97
+  .init_array :
98
+  {
99
+    PROVIDE_HIDDEN (__init_array_start = .);
100
+    KEEP (*(SORT(.init_array.*)))
101
+    KEEP (*(.init_array*))
102
+    PROVIDE_HIDDEN (__init_array_end = .);
103
+  } >FLASH
104
+  .fini_array :
105
+  {
106
+    PROVIDE_HIDDEN (__fini_array_start = .);
107
+    KEEP (*(SORT(.fini_array.*)))
108
+    KEEP (*(.fini_array*))
109
+    PROVIDE_HIDDEN (__fini_array_end = .);
110
+  } >FLASH
111
+
112
+  /* used by the startup to initialize data */
113
+  _sidata = LOADADDR(.data);
114
+
115
+  /* Initialized data sections goes into RAM, load LMA copy after code */
116
+  .data : 
117
+  {
118
+    . = ALIGN(4);
119
+    _sdata = .;        /* create a global symbol at data start */
120
+    *(.data)           /* .data sections */
121
+    *(.data*)          /* .data* sections */
122
+
123
+    . = ALIGN(4);
124
+    _edata = .;        /* define a global symbol at data end */
125
+  } >RAM AT> FLASH
126
+
127
+  
128
+  /* Uninitialized data section */
129
+  . = ALIGN(4);
130
+  .bss :
131
+  {
132
+    /* This is used by the startup in order to initialize the .bss secion */
133
+    _sbss = .;         /* define a global symbol at bss start */
134
+    __bss_start__ = _sbss;
135
+    *(.bss)
136
+    *(.bss*)
137
+    *(COMMON)
138
+
139
+    . = ALIGN(4);
140
+    _ebss = .;         /* define a global symbol at bss end */
141
+    __bss_end__ = _ebss;
142
+  } >RAM
143
+
144
+  /* User_heap_stack section, used to check that there is enough RAM left */
145
+  ._user_heap_stack :
146
+  {
147
+    . = ALIGN(4);
148
+    PROVIDE ( end = . );
149
+    PROVIDE ( _end = . );
150
+    . = . + _Min_Heap_Size;
151
+    . = . + _Min_Stack_Size;
152
+    . = ALIGN(4);
153
+  } >RAM
154
+
155
+  
156
+
157
+  /* Remove information from the standard libraries */
158
+  /DISCARD/ :
159
+  {
160
+    libc.a ( * )
161
+    libm.a ( * )
162
+    libgcc.a ( * )
163
+  }
164
+
165
+  .ARM.attributes 0 : { *(.ARM.attributes) }
166
+}
167
+
168
+

Разлика између датотеке није приказан због своје велике величине
+ 46 - 0
STM32F103_ATTEN_PLL_Zig.elf.launch


+ 451 - 0
STM32F103_ATTEN_PLL_Zig.ioc

@@ -0,0 +1,451 @@
1
+#MicroXplorer Configuration settings - do not modify
2
+ADC1.Channel-1\#ChannelRegularConversion=ADC_CHANNEL_0
3
+ADC1.IPParameters=Rank-1\#ChannelRegularConversion,Channel-1\#ChannelRegularConversion,SamplingTime-1\#ChannelRegularConversion,NbrOfConversionFlag,master
4
+ADC1.NbrOfConversionFlag=1
5
+ADC1.Rank-1\#ChannelRegularConversion=1
6
+ADC1.SamplingTime-1\#ChannelRegularConversion=ADC_SAMPLETIME_1CYCLE_5
7
+ADC1.master=1
8
+File.Version=6
9
+KeepUserPlacement=false
10
+Mcu.Family=STM32F1
11
+Mcu.IP0=ADC1
12
+Mcu.IP1=NVIC
13
+Mcu.IP2=RCC
14
+Mcu.IP3=SYS
15
+Mcu.IP4=USART1
16
+Mcu.IPNb=5
17
+Mcu.Name=STM32F103V(F-G)Tx
18
+Mcu.Package=LQFP100
19
+Mcu.Pin0=PE2
20
+Mcu.Pin1=PE3
21
+Mcu.Pin10=PC2
22
+Mcu.Pin11=PC3
23
+Mcu.Pin12=PA0-WKUP
24
+Mcu.Pin13=PA1
25
+Mcu.Pin14=PA2
26
+Mcu.Pin15=PA3
27
+Mcu.Pin16=PA4
28
+Mcu.Pin17=PA5
29
+Mcu.Pin18=PA6
30
+Mcu.Pin19=PA7
31
+Mcu.Pin2=PE4
32
+Mcu.Pin20=PB0
33
+Mcu.Pin21=PB1
34
+Mcu.Pin22=PE11
35
+Mcu.Pin23=PE12
36
+Mcu.Pin24=PE13
37
+Mcu.Pin25=PE14
38
+Mcu.Pin26=PE15
39
+Mcu.Pin27=PB10
40
+Mcu.Pin28=PB11
41
+Mcu.Pin29=PB12
42
+Mcu.Pin3=PE5
43
+Mcu.Pin30=PB13
44
+Mcu.Pin31=PB14
45
+Mcu.Pin32=PB15
46
+Mcu.Pin33=PD8
47
+Mcu.Pin34=PD9
48
+Mcu.Pin35=PD10
49
+Mcu.Pin36=PD11
50
+Mcu.Pin37=PD12
51
+Mcu.Pin38=PD13
52
+Mcu.Pin39=PD14
53
+Mcu.Pin4=PE6
54
+Mcu.Pin40=PD15
55
+Mcu.Pin41=PC6
56
+Mcu.Pin42=PC7
57
+Mcu.Pin43=PC8
58
+Mcu.Pin44=PC9
59
+Mcu.Pin45=PA8
60
+Mcu.Pin46=PA9
61
+Mcu.Pin47=PA10
62
+Mcu.Pin48=PA12
63
+Mcu.Pin49=PA13
64
+Mcu.Pin5=PC13-TAMPER-RTC
65
+Mcu.Pin50=PA14
66
+Mcu.Pin51=PA15
67
+Mcu.Pin52=PC10
68
+Mcu.Pin53=PC11
69
+Mcu.Pin54=PC12
70
+Mcu.Pin55=PD1
71
+Mcu.Pin56=PD2
72
+Mcu.Pin57=PD3
73
+Mcu.Pin58=PD4
74
+Mcu.Pin59=PD5
75
+Mcu.Pin6=PC14-OSC32_IN
76
+Mcu.Pin60=PD6
77
+Mcu.Pin61=PD7
78
+Mcu.Pin62=PB3
79
+Mcu.Pin63=PB4
80
+Mcu.Pin64=PB5
81
+Mcu.Pin65=PB6
82
+Mcu.Pin66=PB7
83
+Mcu.Pin67=PB8
84
+Mcu.Pin68=PB9
85
+Mcu.Pin69=PE0
86
+Mcu.Pin7=PC15-OSC32_OUT
87
+Mcu.Pin70=PE1
88
+Mcu.Pin71=VP_SYS_VS_ND
89
+Mcu.Pin72=VP_SYS_VS_Systick
90
+Mcu.Pin8=PC0
91
+Mcu.Pin9=PC1
92
+Mcu.PinsNb=73
93
+Mcu.ThirdPartyNb=0
94
+Mcu.UserConstants=
95
+Mcu.UserName=STM32F103VGTx
96
+MxCube.Version=5.2.1
97
+MxDb.Version=DB.5.0.21
98
+NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false
99
+NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false
100
+NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false
101
+NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false
102
+NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false
103
+NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false
104
+NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
105
+NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false
106
+NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false\:true
107
+NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false
108
+PA0-WKUP.GPIOParameters=GPIO_Label
109
+PA0-WKUP.GPIO_Label=DET_1.8G_DL_IN
110
+PA0-WKUP.Signal=ADCx_IN0
111
+PA1.GPIOParameters=GPIO_Label
112
+PA1.GPIO_Label=DET_1.8G_DL_OUT
113
+PA1.Signal=ADCx_IN1
114
+PA10.Mode=Asynchronous
115
+PA10.Signal=USART1_RX
116
+PA12.GPIOParameters=GPIO_Label
117
+PA12.GPIO_Label=ATT_DATA_3.5G_COM3
118
+PA12.Locked=true
119
+PA12.Signal=GPIO_Output
120
+PA13.GPIOParameters=GPIO_Label
121
+PA13.GPIO_Label=ATT_DATA_3.5G_COM2
122
+PA13.Locked=true
123
+PA13.Signal=GPIO_Output
124
+PA14.GPIOParameters=GPIO_Label
125
+PA14.GPIO_Label=ATT_DATA_3.5G_COM1
126
+PA14.Locked=true
127
+PA14.Signal=GPIO_Output
128
+PA15.GPIOParameters=GPIO_Label
129
+PA15.GPIO_Label=ATT_DATA_3.5G_UL
130
+PA15.Locked=true
131
+PA15.Signal=GPIO_Output
132
+PA2.GPIOParameters=GPIO_Label
133
+PA2.GPIO_Label=DET_1.8G_UL_IN
134
+PA2.Signal=ADCx_IN2
135
+PA3.GPIOParameters=GPIO_Label
136
+PA3.GPIO_Label=DET_1.8G_UL_OUT
137
+PA3.Signal=ADCx_IN3
138
+PA4.GPIOParameters=GPIO_Label
139
+PA4.GPIO_Label=DET_2.1G_DL_IN
140
+PA4.Signal=ADCx_IN4
141
+PA5.GPIOParameters=GPIO_Label
142
+PA5.GPIO_Label=DET_2.1G_DL_OUT
143
+PA5.Signal=ADCx_IN5
144
+PA6.GPIOParameters=GPIO_Label
145
+PA6.GPIO_Label=DET_2.1G_UL_IN
146
+PA6.Signal=ADCx_IN6
147
+PA7.GPIOParameters=GPIO_Label
148
+PA7.GPIO_Label=DET_2.1G_UL_OUT
149
+PA7.Signal=ADCx_IN7
150
+PA8.GPIOParameters=GPIO_Label
151
+PA8.GPIO_Label=PATH_EN_3.5G_L
152
+PA8.Locked=true
153
+PA8.Signal=GPIO_Output
154
+PA9.Mode=Asynchronous
155
+PA9.Signal=USART1_TX
156
+PB0.GPIOParameters=GPIO_Label
157
+PB0.GPIO_Label=DET_3.5G_DL_IN
158
+PB0.Signal=ADCx_IN8
159
+PB1.GPIOParameters=GPIO_Label
160
+PB1.GPIO_Label=DET_3.5G_DL_OUT
161
+PB1.Signal=ADCx_IN9
162
+PB10.GPIOParameters=GPIO_Label
163
+PB10.GPIO_Label=ALARM_AC
164
+PB10.Locked=true
165
+PB10.Signal=GPIO_Input
166
+PB11.GPIOParameters=GPIO_Label
167
+PB11.GPIO_Label=DA_LDAC
168
+PB11.Locked=true
169
+PB11.Signal=GPIO_Output
170
+PB12.GPIOParameters=GPIO_Label
171
+PB12.GPIO_Label=DA_SYNC
172
+PB12.Locked=true
173
+PB12.Signal=GPIO_Output
174
+PB13.GPIOParameters=GPIO_Label
175
+PB13.GPIO_Label=DA_SCLK
176
+PB13.Locked=true
177
+PB13.Signal=GPIO_Output
178
+PB14.GPIOParameters=GPIO_Label
179
+PB14.GPIO_Label=DA_DIN
180
+PB14.Locked=true
181
+PB14.Signal=GPIO_Output
182
+PB15.GPIOParameters=GPIO_Label
183
+PB15.GPIO_Label=_T-SYNC_UL
184
+PB15.Locked=true
185
+PB15.Signal=GPIO_Output
186
+PB3.GPIOParameters=GPIO_Label
187
+PB3.GPIO_Label=ATT_EN_2.1G_UL3
188
+PB3.Locked=true
189
+PB3.Signal=GPIO_Output
190
+PB4.GPIOParameters=GPIO_Label
191
+PB4.GPIO_Label=ATT_EN_2.1G_UL2
192
+PB4.Locked=true
193
+PB4.Signal=GPIO_Output
194
+PB5.GPIOParameters=GPIO_Label
195
+PB5.GPIO_Label=ATT_EN_2.1G_UL1
196
+PB5.Locked=true
197
+PB5.Signal=GPIO_Output
198
+PB6.GPIOParameters=GPIO_Label
199
+PB6.GPIO_Label=ATT_EN_2.1G_DL2
200
+PB6.Locked=true
201
+PB6.Signal=GPIO_Output
202
+PB7.GPIOParameters=GPIO_Label
203
+PB7.GPIO_Label=ATT_EN_2.1G_DL1
204
+PB7.Locked=true
205
+PB7.Signal=GPIO_Output
206
+PB8.GPIOParameters=GPIO_Label
207
+PB8.GPIO_Label=PLL_LD_1.8G_UL
208
+PB8.Locked=true
209
+PB8.Signal=GPIO_Input
210
+PB9.GPIOParameters=GPIO_Label
211
+PB9.GPIO_Label=PLL_LD_1.8G_DL
212
+PB9.Locked=true
213
+PB9.Signal=GPIO_Input
214
+PC0.GPIOParameters=GPIO_Label
215
+PC0.GPIO_Label=DET_3.5G_UL_IN
216
+PC0.Signal=ADCx_IN10
217
+PC1.GPIOParameters=GPIO_Label
218
+PC1.GPIO_Label=DET_3.5G_UL_OUT
219
+PC1.Signal=ADCx_IN11
220
+PC10.GPIOParameters=GPIO_Label
221
+PC10.GPIO_Label=ATT_DATA_3.5G_DL
222
+PC10.Locked=true
223
+PC10.Signal=GPIO_Output
224
+PC11.GPIOParameters=GPIO_Label
225
+PC11.GPIO_Label=ATT_EN_3.5G
226
+PC11.Locked=true
227
+PC11.Signal=GPIO_Output
228
+PC12.GPIOParameters=GPIO_Label
229
+PC12.GPIO_Label=ATT_CLK_3.5G
230
+PC12.Locked=true
231
+PC12.Signal=GPIO_Output
232
+PC13-TAMPER-RTC.GPIOParameters=GPIO_Label
233
+PC13-TAMPER-RTC.GPIO_Label=ATT_EN_1.8G_UL4
234
+PC13-TAMPER-RTC.Locked=true
235
+PC13-TAMPER-RTC.Signal=GPIO_Output
236
+PC14-OSC32_IN.GPIOParameters=GPIO_Label
237
+PC14-OSC32_IN.GPIO_Label=PATH_EN_1.8G_DL
238
+PC14-OSC32_IN.Locked=true
239
+PC14-OSC32_IN.Signal=GPIO_Output
240
+PC15-OSC32_OUT.GPIOParameters=GPIO_Label
241
+PC15-OSC32_OUT.GPIO_Label=PATH_EN_1.8G_UL
242
+PC15-OSC32_OUT.Locked=true
243
+PC15-OSC32_OUT.Signal=GPIO_Output
244
+PC2.GPIOParameters=GPIO_Label
245
+PC2.GPIO_Label=RFU_TEMP
246
+PC2.Signal=ADCx_IN12
247
+PC3.GPIOParameters=GPIO_Label
248
+PC3.GPIO_Label=_28V_DET
249
+PC3.Signal=ADCx_IN13
250
+PC6.GPIOParameters=GPIO_Label
251
+PC6.GPIO_Label=PLL_ON/OFF_3.5G_L
252
+PC6.Locked=true
253
+PC6.Signal=GPIO_Output
254
+PC7.GPIOParameters=GPIO_Label
255
+PC7.GPIO_Label=PATH_EN_3.5G_UL
256
+PC7.Locked=true
257
+PC7.Signal=GPIO_Output
258
+PC8.GPIOParameters=GPIO_Label
259
+PC8.GPIO_Label=PATH_EN_3.5G_DL
260
+PC8.Locked=true
261
+PC8.Signal=GPIO_Output
262
+PC9.GPIOParameters=GPIO_Label
263
+PC9.GPIO_Label=PATH_EN_3.5G_H
264
+PC9.Locked=true
265
+PC9.Signal=GPIO_Output
266
+PCC.Checker=false
267
+PCC.Line=STM32F103
268
+PCC.MCU=STM32F103V(F-G)Tx
269
+PCC.PartNumber=STM32F103VGTx
270
+PCC.Seq0=0
271
+PCC.Series=STM32F1
272
+PCC.Temperature=25
273
+PCC.Vdd=3.3
274
+PD1.GPIOParameters=GPIO_Label
275
+PD1.GPIO_Label=PLL_LD_2.1G_UL
276
+PD1.Locked=true
277
+PD1.Signal=GPIO_Input
278
+PD10.GPIOParameters=GPIO_Label
279
+PD10.GPIO_Label=T-SYNC_DL
280
+PD10.Locked=true
281
+PD10.Signal=GPIO_Output
282
+PD11.GPIOParameters=GPIO_Label
283
+PD11.GPIO_Label=PLL_LD_3.5G_H
284
+PD11.Locked=true
285
+PD11.Signal=GPIO_Input
286
+PD12.GPIOParameters=GPIO_Label
287
+PD12.GPIO_Label=PLL_LD_3.5G_L
288
+PD12.Locked=true
289
+PD12.Signal=GPIO_Input
290
+PD13.GPIOParameters=GPIO_Label
291
+PD13.GPIO_Label=PLL_EN_3.5G_H
292
+PD13.Locked=true
293
+PD13.Signal=GPIO_Output
294
+PD14.GPIOParameters=GPIO_Label
295
+PD14.GPIO_Label=PLL_EN_3.5G_L
296
+PD14.Locked=true
297
+PD14.Signal=GPIO_Output
298
+PD15.GPIOParameters=GPIO_Label
299
+PD15.GPIO_Label=PLL_ON/OFF_3.5G_H
300
+PD15.Locked=true
301
+PD15.Signal=GPIO_Output
302
+PD2.GPIOParameters=GPIO_Label
303
+PD2.GPIO_Label=PLL_LD_2.1G_DL
304
+PD2.Locked=true
305
+PD2.Signal=GPIO_Input
306
+PD3.GPIOParameters=GPIO_Label
307
+PD3.GPIO_Label=PLL_EN_2.1G_UL
308
+PD3.Locked=true
309
+PD3.Signal=GPIO_Output
310
+PD4.GPIOParameters=GPIO_Label
311
+PD4.GPIO_Label=PLL_EN_2.1G_DL
312
+PD4.Locked=true
313
+PD4.Signal=GPIO_Output
314
+PD5.GPIOParameters=GPIO_Label
315
+PD5.GPIO_Label=PATH_EN_2.1G_UL
316
+PD5.Locked=true
317
+PD5.Signal=GPIO_Output
318
+PD6.GPIOParameters=GPIO_Label
319
+PD6.GPIO_Label=PATH_EN_2.1G_DL
320
+PD6.Locked=true
321
+PD6.Signal=GPIO_Output
322
+PD7.GPIOParameters=GPIO_Label
323
+PD7.GPIO_Label=ATT_EN_2.1G_UL4
324
+PD7.Locked=true
325
+PD7.Signal=GPIO_Output
326
+PD8.GPIOParameters=GPIO_Label
327
+PD8.GPIO_Label=T-SYNC_UL
328
+PD8.Locked=true
329
+PD8.Signal=GPIO_Output
330
+PD9.GPIOParameters=GPIO_Label
331
+PD9.GPIO_Label=_T-SYNC_DL
332
+PD9.Locked=true
333
+PD9.Signal=GPIO_Output
334
+PE0.GPIOParameters=GPIO_Label
335
+PE0.GPIO_Label=PLL_EN_1.8G_UL
336
+PE0.Locked=true
337
+PE0.Signal=GPIO_Output
338
+PE1.GPIOParameters=GPIO_Label
339
+PE1.GPIO_Label=PLL_EN_1.8G_DL
340
+PE1.Locked=true
341
+PE1.Signal=GPIO_Output
342
+PE11.GPIOParameters=GPIO_Label
343
+PE11.GPIO_Label=ATT_CLK
344
+PE11.Locked=true
345
+PE11.Signal=GPIO_Output
346
+PE12.GPIOParameters=GPIO_Label
347
+PE12.GPIO_Label=ATT_DATA
348
+PE12.Locked=true
349
+PE12.Signal=GPIO_Output
350
+PE13.GPIOParameters=GPIO_Label
351
+PE13.GPIO_Label=PLL_CLK
352
+PE13.Locked=true
353
+PE13.Signal=GPIO_Output
354
+PE14.GPIOParameters=GPIO_Label
355
+PE14.GPIO_Label=PLL_DATA
356
+PE14.Locked=true
357
+PE14.Signal=GPIO_Output
358
+PE15.GPIOParameters=GPIO_Label
359
+PE15.GPIO_Label=ALARM_DC
360
+PE15.Locked=true
361
+PE15.Signal=GPIO_Input
362
+PE2.GPIOParameters=GPIO_Label
363
+PE2.GPIO_Label=ATT_EN_1.8G_DL1
364
+PE2.Locked=true
365
+PE2.Signal=GPIO_Output
366
+PE3.GPIOParameters=GPIO_Label
367
+PE3.GPIO_Label=ATT_EN_1.8G_DL2
368
+PE3.Locked=true
369
+PE3.Signal=GPIO_Output
370
+PE4.GPIOParameters=GPIO_Label
371
+PE4.GPIO_Label=ATT_EN_1.8G_UL1
372
+PE4.Locked=true
373
+PE4.Signal=GPIO_Output
374
+PE5.GPIOParameters=GPIO_Label
375
+PE5.GPIO_Label=ATT_EN_1.8G_UL2
376
+PE5.Locked=true
377
+PE5.Signal=GPIO_Output
378
+PE6.GPIOParameters=GPIO_Label
379
+PE6.GPIO_Label=ATT_EN_1.8G_UL3
380
+PE6.Locked=true
381
+PE6.Signal=GPIO_Output
382
+PinOutPanel.RotationAngle=0
383
+ProjectManager.AskForMigrate=true
384
+ProjectManager.BackupPrevious=false
385
+ProjectManager.CompilerOptimize=6
386
+ProjectManager.ComputerToolchain=false
387
+ProjectManager.CoupleFile=false
388
+ProjectManager.CustomerFirmwarePackage=
389
+ProjectManager.DefaultFWLocation=true
390
+ProjectManager.DeletePrevious=true
391
+ProjectManager.DeviceId=STM32F103VGTx
392
+ProjectManager.FirmwarePackage=STM32Cube FW_F1 V1.7.0
393
+ProjectManager.FreePins=false
394
+ProjectManager.HalAssertFull=false
395
+ProjectManager.HeapSize=0x200
396
+ProjectManager.KeepUserCode=true
397
+ProjectManager.LastFirmware=true
398
+ProjectManager.LibraryCopy=1
399
+ProjectManager.MainLocation=Src
400
+ProjectManager.NoMain=false
401
+ProjectManager.PreviousToolchain=TrueSTUDIO
402
+ProjectManager.ProjectBuild=false
403
+ProjectManager.ProjectFileName=STM32F103_ATTEN_PLL_Zig.ioc
404
+ProjectManager.ProjectName=STM32F103_ATTEN_PLL_Zig
405
+ProjectManager.StackSize=0x400
406
+ProjectManager.TargetToolchain=TrueSTUDIO
407
+ProjectManager.ToolChainLocation=
408
+ProjectManager.UnderRoot=true
409
+ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_ADC1_Init-ADC1-false-HAL-true,4-MX_USART1_UART_Init-USART1-false-HAL-true
410
+RCC.APB1Freq_Value=8000000
411
+RCC.APB2Freq_Value=8000000
412
+RCC.FamilyName=M
413
+RCC.IPParameters=APB1Freq_Value,APB2Freq_Value,FamilyName,PLLCLKFreq_Value,PLLMCOFreq_Value,TimSysFreq_Value
414
+RCC.PLLCLKFreq_Value=8000000
415
+RCC.PLLMCOFreq_Value=4000000
416
+RCC.TimSysFreq_Value=8000000
417
+SH.ADCx_IN0.0=ADC1_IN0,IN0
418
+SH.ADCx_IN0.ConfNb=1
419
+SH.ADCx_IN1.0=ADC1_IN1,IN1
420
+SH.ADCx_IN1.ConfNb=1
421
+SH.ADCx_IN10.0=ADC1_IN10,IN10
422
+SH.ADCx_IN10.ConfNb=1
423
+SH.ADCx_IN11.0=ADC1_IN11,IN11
424
+SH.ADCx_IN11.ConfNb=1
425
+SH.ADCx_IN12.0=ADC1_IN12,IN12
426
+SH.ADCx_IN12.ConfNb=1
427
+SH.ADCx_IN13.0=ADC1_IN13,IN13
428
+SH.ADCx_IN13.ConfNb=1
429
+SH.ADCx_IN2.0=ADC1_IN2,IN2
430
+SH.ADCx_IN2.ConfNb=1
431
+SH.ADCx_IN3.0=ADC1_IN3,IN3
432
+SH.ADCx_IN3.ConfNb=1
433
+SH.ADCx_IN4.0=ADC1_IN4,IN4
434
+SH.ADCx_IN4.ConfNb=1
435
+SH.ADCx_IN5.0=ADC1_IN5,IN5
436
+SH.ADCx_IN5.ConfNb=1
437
+SH.ADCx_IN6.0=ADC1_IN6,IN6
438
+SH.ADCx_IN6.ConfNb=1
439
+SH.ADCx_IN7.0=ADC1_IN7,IN7
440
+SH.ADCx_IN7.ConfNb=1
441
+SH.ADCx_IN8.0=ADC1_IN8,IN8
442
+SH.ADCx_IN8.ConfNb=1
443
+SH.ADCx_IN9.0=ADC1_IN9,IN9
444
+SH.ADCx_IN9.ConfNb=1
445
+USART1.IPParameters=VirtualMode
446
+USART1.VirtualMode=VM_ASYNC
447
+VP_SYS_VS_ND.Mode=No_Debug
448
+VP_SYS_VS_ND.Signal=SYS_VS_ND
449
+VP_SYS_VS_Systick.Mode=SysTick
450
+VP_SYS_VS_Systick.Signal=SYS_VS_Systick
451
+board=custom

+ 378 - 0
Src/main.c

@@ -0,0 +1,378 @@
1
+/* USER CODE BEGIN Header */
2
+/**
3
+  ******************************************************************************
4
+  * @file           : main.c
5
+  * @brief          : Main program body
6
+  ******************************************************************************
7
+  * @attention
8
+  *
9
+  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
10
+  * All rights reserved.</center></h2>
11
+  *
12
+  * This software component is licensed by ST under BSD 3-Clause license,
13
+  * the "License"; You may not use this file except in compliance with the
14
+  * License. You may obtain a copy of the License at:
15
+  *                        opensource.org/licenses/BSD-3-Clause
16
+  *
17
+  ******************************************************************************
18
+  */
19
+/* USER CODE END Header */
20
+
21
+/* Includes ------------------------------------------------------------------*/
22
+#include "main.h"
23
+
24
+/* Private includes ----------------------------------------------------------*/
25
+/* USER CODE BEGIN Includes */
26
+
27
+/* USER CODE END Includes */
28
+
29
+/* Private typedef -----------------------------------------------------------*/
30
+/* USER CODE BEGIN PTD */
31
+
32
+/* USER CODE END PTD */
33
+
34
+/* Private define ------------------------------------------------------------*/
35
+/* USER CODE BEGIN PD */
36
+
37
+/* USER CODE END PD */
38
+
39
+/* Private macro -------------------------------------------------------------*/
40
+/* USER CODE BEGIN PM */
41
+
42
+/* USER CODE END PM */
43
+
44
+/* Private variables ---------------------------------------------------------*/
45
+ADC_HandleTypeDef hadc1;
46
+
47
+UART_HandleTypeDef huart1;
48
+
49
+/* USER CODE BEGIN PV */
50
+
51
+/* USER CODE END PV */
52
+
53
+/* Private function prototypes -----------------------------------------------*/
54
+void SystemClock_Config(void);
55
+static void MX_GPIO_Init(void);
56
+static void MX_ADC1_Init(void);
57
+static void MX_USART1_UART_Init(void);
58
+/* USER CODE BEGIN PFP */
59
+
60
+/* USER CODE END PFP */
61
+
62
+/* Private user code ---------------------------------------------------------*/
63
+/* USER CODE BEGIN 0 */
64
+
65
+/* USER CODE END 0 */
66
+
67
+/**
68
+  * @brief  The application entry point.
69
+  * @retval int
70
+  */
71
+int main(void)
72
+{
73
+  /* USER CODE BEGIN 1 */
74
+
75
+  /* USER CODE END 1 */
76
+  
77
+
78
+  /* MCU Configuration--------------------------------------------------------*/
79
+
80
+  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
81
+  HAL_Init();
82
+
83
+  /* USER CODE BEGIN Init */
84
+
85
+  /* USER CODE END Init */
86
+
87
+  /* Configure the system clock */
88
+  SystemClock_Config();
89
+
90
+  /* USER CODE BEGIN SysInit */
91
+
92
+  /* USER CODE END SysInit */
93
+
94
+  /* Initialize all configured peripherals */
95
+  MX_GPIO_Init();
96
+  MX_ADC1_Init();
97
+  MX_USART1_UART_Init();
98
+  /* USER CODE BEGIN 2 */
99
+
100
+  /* USER CODE END 2 */
101
+
102
+  /* Infinite loop */
103
+  /* USER CODE BEGIN WHILE */
104
+  while (1)
105
+  {
106
+    /* USER CODE END WHILE */
107
+
108
+    /* USER CODE BEGIN 3 */
109
+  }
110
+  /* USER CODE END 3 */
111
+}
112
+
113
+/**
114
+  * @brief System Clock Configuration
115
+  * @retval None
116
+  */
117
+void SystemClock_Config(void)
118
+{
119
+  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
120
+  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
121
+  RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
122
+
123
+  /** Initializes the CPU, AHB and APB busses clocks 
124
+  */
125
+  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
126
+  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
127
+  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
128
+  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
129
+  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
130
+  {
131
+    Error_Handler();
132
+  }
133
+  /** Initializes the CPU, AHB and APB busses clocks 
134
+  */
135
+  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
136
+                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
137
+  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
138
+  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
139
+  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
140
+  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
141
+
142
+  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
143
+  {
144
+    Error_Handler();
145
+  }
146
+  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
147
+  PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV2;
148
+  if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
149
+  {
150
+    Error_Handler();
151
+  }
152
+}
153
+
154
+/**
155
+  * @brief ADC1 Initialization Function
156
+  * @param None
157
+  * @retval None
158
+  */
159
+static void MX_ADC1_Init(void)
160
+{
161
+
162
+  /* USER CODE BEGIN ADC1_Init 0 */
163
+
164
+  /* USER CODE END ADC1_Init 0 */
165
+
166
+  ADC_ChannelConfTypeDef sConfig = {0};
167
+
168
+  /* USER CODE BEGIN ADC1_Init 1 */
169
+
170
+  /* USER CODE END ADC1_Init 1 */
171
+  /** Common config 
172
+  */
173
+  hadc1.Instance = ADC1;
174
+  hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
175
+  hadc1.Init.ContinuousConvMode = DISABLE;
176
+  hadc1.Init.DiscontinuousConvMode = DISABLE;
177
+  hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
178
+  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
179
+  hadc1.Init.NbrOfConversion = 1;
180
+  if (HAL_ADC_Init(&hadc1) != HAL_OK)
181
+  {
182
+    Error_Handler();
183
+  }
184
+  /** Configure Regular Channel 
185
+  */
186
+  sConfig.Channel = ADC_CHANNEL_0;
187
+  sConfig.Rank = ADC_REGULAR_RANK_1;
188
+  sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
189
+  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
190
+  {
191
+    Error_Handler();
192
+  }
193
+  /* USER CODE BEGIN ADC1_Init 2 */
194
+
195
+  /* USER CODE END ADC1_Init 2 */
196
+
197
+}
198
+
199
+/**
200
+  * @brief USART1 Initialization Function
201
+  * @param None
202
+  * @retval None
203
+  */
204
+static void MX_USART1_UART_Init(void)
205
+{
206
+
207
+  /* USER CODE BEGIN USART1_Init 0 */
208
+
209
+  /* USER CODE END USART1_Init 0 */
210
+
211
+  /* USER CODE BEGIN USART1_Init 1 */
212
+
213
+  /* USER CODE END USART1_Init 1 */
214
+  huart1.Instance = USART1;
215
+  huart1.Init.BaudRate = 115200;
216
+  huart1.Init.WordLength = UART_WORDLENGTH_8B;
217
+  huart1.Init.StopBits = UART_STOPBITS_1;
218
+  huart1.Init.Parity = UART_PARITY_NONE;
219
+  huart1.Init.Mode = UART_MODE_TX_RX;
220
+  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
221
+  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
222
+  if (HAL_UART_Init(&huart1) != HAL_OK)
223
+  {
224
+    Error_Handler();
225
+  }
226
+  /* USER CODE BEGIN USART1_Init 2 */
227
+
228
+  /* USER CODE END USART1_Init 2 */
229
+
230
+}
231
+
232
+/**
233
+  * @brief GPIO Initialization Function
234
+  * @param None
235
+  * @retval None
236
+  */
237
+static void MX_GPIO_Init(void)
238
+{
239
+  GPIO_InitTypeDef GPIO_InitStruct = {0};
240
+
241
+  /* GPIO Ports Clock Enable */
242
+  __HAL_RCC_GPIOE_CLK_ENABLE();
243
+  __HAL_RCC_GPIOC_CLK_ENABLE();
244
+  __HAL_RCC_GPIOA_CLK_ENABLE();
245
+  __HAL_RCC_GPIOB_CLK_ENABLE();
246
+  __HAL_RCC_GPIOD_CLK_ENABLE();
247
+
248
+  /*Configure GPIO pin Output Level */
249
+  HAL_GPIO_WritePin(GPIOE, ATT_EN_1_8G_DL1_Pin|ATT_EN_1_8G_DL2_Pin|ATT_EN_1_8G_UL1_Pin|ATT_EN_1_8G_UL2_Pin 
250
+                          |ATT_EN_1_8G_UL3_Pin|ATT_CLK_Pin|ATT_DATA_Pin|PLL_CLK_Pin 
251
+                          |PLL_DATA_Pin|PLL_EN_1_8G_UL_Pin|PLL_EN_1_8G_DL_Pin, GPIO_PIN_RESET);
252
+
253
+  /*Configure GPIO pin Output Level */
254
+  HAL_GPIO_WritePin(GPIOC, ATT_EN_1_8G_UL4_Pin|PATH_EN_1_8G_DL_Pin|PATH_EN_1_8G_UL_Pin|PLL_ON_OFF_3_5G_L_Pin 
255
+                          |PATH_EN_3_5G_UL_Pin|PATH_EN_3_5G_DL_Pin|PATH_EN_3_5G_H_Pin|ATT_DATA_3_5G_DL_Pin 
256
+                          |ATT_EN_3_5G_Pin|ATT_CLK_3_5G_Pin, GPIO_PIN_RESET);
257
+
258
+  /*Configure GPIO pin Output Level */
259
+  HAL_GPIO_WritePin(GPIOB, DA_LDAC_Pin|DA_SYNC_Pin|DA_SCLK_Pin|DA_DIN_Pin 
260
+                          |_T_SYNC_UL_Pin|ATT_EN_2_1G_UL3_Pin|ATT_EN_2_1G_UL2_Pin|ATT_EN_2_1G_UL1_Pin 
261
+                          |ATT_EN_2_1G_DL2_Pin|ATT_EN_2_1G_DL1_Pin, GPIO_PIN_RESET);
262
+
263
+  /*Configure GPIO pin Output Level */
264
+  HAL_GPIO_WritePin(GPIOD, T_SYNC_UL_Pin|_T_SYNC_DL_Pin|T_SYNC_DL_Pin|PLL_EN_3_5G_H_Pin 
265
+                          |PLL_EN_3_5G_L_Pin|PLL_ON_OFF_3_5G_H_Pin|PLL_EN_2_1G_UL_Pin|PLL_EN_2_1G_DL_Pin 
266
+                          |PATH_EN_2_1G_UL_Pin|PATH_EN_2_1G_DL_Pin|ATT_EN_2_1G_UL4_Pin, GPIO_PIN_RESET);
267
+
268
+  /*Configure GPIO pin Output Level */
269
+  HAL_GPIO_WritePin(GPIOA, PATH_EN_3_5G_L_Pin|ATT_DATA_3_5G_COM3_Pin|ATT_DATA_3_5G_COM2_Pin|ATT_DATA_3_5G_COM1_Pin 
270
+                          |ATT_DATA_3_5G_UL_Pin, GPIO_PIN_RESET);
271
+
272
+  /*Configure GPIO pins : ATT_EN_1_8G_DL1_Pin ATT_EN_1_8G_DL2_Pin ATT_EN_1_8G_UL1_Pin ATT_EN_1_8G_UL2_Pin 
273
+                           ATT_EN_1_8G_UL3_Pin ATT_CLK_Pin ATT_DATA_Pin PLL_CLK_Pin 
274
+                           PLL_DATA_Pin PLL_EN_1_8G_UL_Pin PLL_EN_1_8G_DL_Pin */
275
+  GPIO_InitStruct.Pin = ATT_EN_1_8G_DL1_Pin|ATT_EN_1_8G_DL2_Pin|ATT_EN_1_8G_UL1_Pin|ATT_EN_1_8G_UL2_Pin 
276
+                          |ATT_EN_1_8G_UL3_Pin|ATT_CLK_Pin|ATT_DATA_Pin|PLL_CLK_Pin 
277
+                          |PLL_DATA_Pin|PLL_EN_1_8G_UL_Pin|PLL_EN_1_8G_DL_Pin;
278
+  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
279
+  GPIO_InitStruct.Pull = GPIO_NOPULL;
280
+  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
281
+  HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
282
+
283
+  /*Configure GPIO pins : ATT_EN_1_8G_UL4_Pin PATH_EN_1_8G_DL_Pin PATH_EN_1_8G_UL_Pin PLL_ON_OFF_3_5G_L_Pin 
284
+                           PATH_EN_3_5G_UL_Pin PATH_EN_3_5G_DL_Pin PATH_EN_3_5G_H_Pin ATT_DATA_3_5G_DL_Pin 
285
+                           ATT_EN_3_5G_Pin ATT_CLK_3_5G_Pin */
286
+  GPIO_InitStruct.Pin = ATT_EN_1_8G_UL4_Pin|PATH_EN_1_8G_DL_Pin|PATH_EN_1_8G_UL_Pin|PLL_ON_OFF_3_5G_L_Pin 
287
+                          |PATH_EN_3_5G_UL_Pin|PATH_EN_3_5G_DL_Pin|PATH_EN_3_5G_H_Pin|ATT_DATA_3_5G_DL_Pin 
288
+                          |ATT_EN_3_5G_Pin|ATT_CLK_3_5G_Pin;
289
+  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
290
+  GPIO_InitStruct.Pull = GPIO_NOPULL;
291
+  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
292
+  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
293
+
294
+  /*Configure GPIO pin : ALARM_DC_Pin */
295
+  GPIO_InitStruct.Pin = ALARM_DC_Pin;
296
+  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
297
+  GPIO_InitStruct.Pull = GPIO_NOPULL;
298
+  HAL_GPIO_Init(ALARM_DC_GPIO_Port, &GPIO_InitStruct);
299
+
300
+  /*Configure GPIO pins : ALARM_AC_Pin PLL_LD_1_8G_UL_Pin PLL_LD_1_8G_DL_Pin */
301
+  GPIO_InitStruct.Pin = ALARM_AC_Pin|PLL_LD_1_8G_UL_Pin|PLL_LD_1_8G_DL_Pin;
302
+  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
303
+  GPIO_InitStruct.Pull = GPIO_NOPULL;
304
+  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
305
+
306
+  /*Configure GPIO pins : DA_LDAC_Pin DA_SYNC_Pin DA_SCLK_Pin DA_DIN_Pin 
307
+                           _T_SYNC_UL_Pin ATT_EN_2_1G_UL3_Pin ATT_EN_2_1G_UL2_Pin ATT_EN_2_1G_UL1_Pin 
308
+                           ATT_EN_2_1G_DL2_Pin ATT_EN_2_1G_DL1_Pin */
309
+  GPIO_InitStruct.Pin = DA_LDAC_Pin|DA_SYNC_Pin|DA_SCLK_Pin|DA_DIN_Pin 
310
+                          |_T_SYNC_UL_Pin|ATT_EN_2_1G_UL3_Pin|ATT_EN_2_1G_UL2_Pin|ATT_EN_2_1G_UL1_Pin 
311
+                          |ATT_EN_2_1G_DL2_Pin|ATT_EN_2_1G_DL1_Pin;
312
+  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
313
+  GPIO_InitStruct.Pull = GPIO_NOPULL;
314
+  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
315
+  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
316
+
317
+  /*Configure GPIO pins : T_SYNC_UL_Pin _T_SYNC_DL_Pin T_SYNC_DL_Pin PLL_EN_3_5G_H_Pin 
318
+                           PLL_EN_3_5G_L_Pin PLL_ON_OFF_3_5G_H_Pin PLL_EN_2_1G_UL_Pin PLL_EN_2_1G_DL_Pin 
319
+                           PATH_EN_2_1G_UL_Pin PATH_EN_2_1G_DL_Pin ATT_EN_2_1G_UL4_Pin */
320
+  GPIO_InitStruct.Pin = T_SYNC_UL_Pin|_T_SYNC_DL_Pin|T_SYNC_DL_Pin|PLL_EN_3_5G_H_Pin 
321
+                          |PLL_EN_3_5G_L_Pin|PLL_ON_OFF_3_5G_H_Pin|PLL_EN_2_1G_UL_Pin|PLL_EN_2_1G_DL_Pin 
322
+                          |PATH_EN_2_1G_UL_Pin|PATH_EN_2_1G_DL_Pin|ATT_EN_2_1G_UL4_Pin;
323
+  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
324
+  GPIO_InitStruct.Pull = GPIO_NOPULL;
325
+  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
326
+  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
327
+
328
+  /*Configure GPIO pins : PLL_LD_3_5G_H_Pin PLL_LD_3_5G_L_Pin PLL_LD_2_1G_UL_Pin PLL_LD_2_1G_DL_Pin */
329
+  GPIO_InitStruct.Pin = PLL_LD_3_5G_H_Pin|PLL_LD_3_5G_L_Pin|PLL_LD_2_1G_UL_Pin|PLL_LD_2_1G_DL_Pin;
330
+  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
331
+  GPIO_InitStruct.Pull = GPIO_NOPULL;
332
+  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
333
+
334
+  /*Configure GPIO pins : PATH_EN_3_5G_L_Pin ATT_DATA_3_5G_COM3_Pin ATT_DATA_3_5G_COM2_Pin ATT_DATA_3_5G_COM1_Pin 
335
+                           ATT_DATA_3_5G_UL_Pin */
336
+  GPIO_InitStruct.Pin = PATH_EN_3_5G_L_Pin|ATT_DATA_3_5G_COM3_Pin|ATT_DATA_3_5G_COM2_Pin|ATT_DATA_3_5G_COM1_Pin 
337
+                          |ATT_DATA_3_5G_UL_Pin;
338
+  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
339
+  GPIO_InitStruct.Pull = GPIO_NOPULL;
340
+  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
341
+  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
342
+
343
+}
344
+
345
+/* USER CODE BEGIN 4 */
346
+
347
+/* USER CODE END 4 */
348
+
349
+/**
350
+  * @brief  This function is executed in case of error occurrence.
351
+  * @retval None
352
+  */
353
+void Error_Handler(void)
354
+{
355
+  /* USER CODE BEGIN Error_Handler_Debug */
356
+  /* User can add his own implementation to report the HAL error return state */
357
+
358
+  /* USER CODE END Error_Handler_Debug */
359
+}
360
+
361
+#ifdef  USE_FULL_ASSERT
362
+/**
363
+  * @brief  Reports the name of the source file and the source line number
364
+  *         where the assert_param error has occurred.
365
+  * @param  file: pointer to the source file name
366
+  * @param  line: assert_param error line source number
367
+  * @retval None
368
+  */
369
+void assert_failed(uint8_t *file, uint32_t line)
370
+{ 
371
+  /* USER CODE BEGIN 6 */
372
+  /* User can add his own implementation to report the file name and line number,
373
+     tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
374
+  /* USER CODE END 6 */
375
+}
376
+#endif /* USE_FULL_ASSERT */
377
+
378
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 258 - 0
Src/stm32f1xx_hal_msp.c

@@ -0,0 +1,258 @@
1
+/* USER CODE BEGIN Header */
2
+/**
3
+  ******************************************************************************
4
+  * File Name          : stm32f1xx_hal_msp.c
5
+  * Description        : This file provides code for the MSP Initialization 
6
+  *                      and de-Initialization codes.
7
+  ******************************************************************************
8
+  * @attention
9
+  *
10
+  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
11
+  * All rights reserved.</center></h2>
12
+  *
13
+  * This software component is licensed by ST under BSD 3-Clause license,
14
+  * the "License"; You may not use this file except in compliance with the
15
+  * License. You may obtain a copy of the License at:
16
+  *                        opensource.org/licenses/BSD-3-Clause
17
+  *
18
+  ******************************************************************************
19
+  */
20
+/* USER CODE END Header */
21
+
22
+/* Includes ------------------------------------------------------------------*/
23
+#include "main.h"
24
+/* USER CODE BEGIN Includes */
25
+
26
+/* USER CODE END Includes */
27
+
28
+/* Private typedef -----------------------------------------------------------*/
29
+/* USER CODE BEGIN TD */
30
+
31
+/* USER CODE END TD */
32
+
33
+/* Private define ------------------------------------------------------------*/
34
+/* USER CODE BEGIN Define */
35
+ 
36
+/* USER CODE END Define */
37
+
38
+/* Private macro -------------------------------------------------------------*/
39
+/* USER CODE BEGIN Macro */
40
+
41
+/* USER CODE END Macro */
42
+
43
+/* Private variables ---------------------------------------------------------*/
44
+/* USER CODE BEGIN PV */
45
+
46
+/* USER CODE END PV */
47
+
48
+/* Private function prototypes -----------------------------------------------*/
49
+/* USER CODE BEGIN PFP */
50
+
51
+/* USER CODE END PFP */
52
+
53
+/* External functions --------------------------------------------------------*/
54
+/* USER CODE BEGIN ExternalFunctions */
55
+
56
+/* USER CODE END ExternalFunctions */
57
+
58
+/* USER CODE BEGIN 0 */
59
+
60
+/* USER CODE END 0 */
61
+/**
62
+  * Initializes the Global MSP.
63
+  */
64
+void HAL_MspInit(void)
65
+{
66
+  /* USER CODE BEGIN MspInit 0 */
67
+
68
+  /* USER CODE END MspInit 0 */
69
+
70
+  __HAL_RCC_AFIO_CLK_ENABLE();
71
+  __HAL_RCC_PWR_CLK_ENABLE();
72
+
73
+  /* System interrupt init*/
74
+
75
+  /** DISABLE: JTAG-DP Disabled and SW-DP Disabled 
76
+  */
77
+  __HAL_AFIO_REMAP_SWJ_DISABLE();
78
+
79
+  /* USER CODE BEGIN MspInit 1 */
80
+
81
+  /* USER CODE END MspInit 1 */
82
+}
83
+
84
+/**
85
+* @brief ADC MSP Initialization
86
+* This function configures the hardware resources used in this example
87
+* @param hadc: ADC handle pointer
88
+* @retval None
89
+*/
90
+void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
91
+{
92
+  GPIO_InitTypeDef GPIO_InitStruct = {0};
93
+  if(hadc->Instance==ADC1)
94
+  {
95
+  /* USER CODE BEGIN ADC1_MspInit 0 */
96
+
97
+  /* USER CODE END ADC1_MspInit 0 */
98
+    /* Peripheral clock enable */
99
+    __HAL_RCC_ADC1_CLK_ENABLE();
100
+  
101
+    __HAL_RCC_GPIOC_CLK_ENABLE();
102
+    __HAL_RCC_GPIOA_CLK_ENABLE();
103
+    __HAL_RCC_GPIOB_CLK_ENABLE();
104
+    /**ADC1 GPIO Configuration    
105
+    PC0     ------> ADC1_IN10
106
+    PC1     ------> ADC1_IN11
107
+    PC2     ------> ADC1_IN12
108
+    PC3     ------> ADC1_IN13
109
+    PA0-WKUP     ------> ADC1_IN0
110
+    PA1     ------> ADC1_IN1
111
+    PA2     ------> ADC1_IN2
112
+    PA3     ------> ADC1_IN3
113
+    PA4     ------> ADC1_IN4
114
+    PA5     ------> ADC1_IN5
115
+    PA6     ------> ADC1_IN6
116
+    PA7     ------> ADC1_IN7
117
+    PB0     ------> ADC1_IN8
118
+    PB1     ------> ADC1_IN9 
119
+    */
120
+    GPIO_InitStruct.Pin = DET_3_5G_UL_IN_Pin|DET_3_5G_UL_OUT_Pin|RFU_TEMP_Pin|_28V_DET_Pin;
121
+    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
122
+    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
123
+
124
+    GPIO_InitStruct.Pin = DET_1_8G_DL_IN_Pin|DET_1_8G_DL_OUT_Pin|DET_1_8G_UL_IN_Pin|DET_1_8G_UL_OUT_Pin 
125
+                          |DET_2_1G_DL_IN_Pin|DET_2_1G_DL_OUT_Pin|DET_2_1G_UL_IN_Pin|DET_2_1G_UL_OUT_Pin;
126
+    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
127
+    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
128
+
129
+    GPIO_InitStruct.Pin = DET_3_5G_DL_IN_Pin|DET_3_5G_DL_OUT_Pin;
130
+    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
131
+    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
132
+
133
+  /* USER CODE BEGIN ADC1_MspInit 1 */
134
+
135
+  /* USER CODE END ADC1_MspInit 1 */
136
+  }
137
+
138
+}
139
+
140
+/**
141
+* @brief ADC MSP De-Initialization
142
+* This function freeze the hardware resources used in this example
143
+* @param hadc: ADC handle pointer
144
+* @retval None
145
+*/
146
+void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
147
+{
148
+  if(hadc->Instance==ADC1)
149
+  {
150
+  /* USER CODE BEGIN ADC1_MspDeInit 0 */
151
+
152
+  /* USER CODE END ADC1_MspDeInit 0 */
153
+    /* Peripheral clock disable */
154
+    __HAL_RCC_ADC1_CLK_DISABLE();
155
+  
156
+    /**ADC1 GPIO Configuration    
157
+    PC0     ------> ADC1_IN10
158
+    PC1     ------> ADC1_IN11
159
+    PC2     ------> ADC1_IN12
160
+    PC3     ------> ADC1_IN13
161
+    PA0-WKUP     ------> ADC1_IN0
162
+    PA1     ------> ADC1_IN1
163
+    PA2     ------> ADC1_IN2
164
+    PA3     ------> ADC1_IN3
165
+    PA4     ------> ADC1_IN4
166
+    PA5     ------> ADC1_IN5
167
+    PA6     ------> ADC1_IN6
168
+    PA7     ------> ADC1_IN7
169
+    PB0     ------> ADC1_IN8
170
+    PB1     ------> ADC1_IN9 
171
+    */
172
+    HAL_GPIO_DeInit(GPIOC, DET_3_5G_UL_IN_Pin|DET_3_5G_UL_OUT_Pin|RFU_TEMP_Pin|_28V_DET_Pin);
173
+
174
+    HAL_GPIO_DeInit(GPIOA, DET_1_8G_DL_IN_Pin|DET_1_8G_DL_OUT_Pin|DET_1_8G_UL_IN_Pin|DET_1_8G_UL_OUT_Pin 
175
+                          |DET_2_1G_DL_IN_Pin|DET_2_1G_DL_OUT_Pin|DET_2_1G_UL_IN_Pin|DET_2_1G_UL_OUT_Pin);
176
+
177
+    HAL_GPIO_DeInit(GPIOB, DET_3_5G_DL_IN_Pin|DET_3_5G_DL_OUT_Pin);
178
+
179
+  /* USER CODE BEGIN ADC1_MspDeInit 1 */
180
+
181
+  /* USER CODE END ADC1_MspDeInit 1 */
182
+  }
183
+
184
+}
185
+
186
+/**
187
+* @brief UART MSP Initialization
188
+* This function configures the hardware resources used in this example
189
+* @param huart: UART handle pointer
190
+* @retval None
191
+*/
192
+void HAL_UART_MspInit(UART_HandleTypeDef* huart)
193
+{
194
+  GPIO_InitTypeDef GPIO_InitStruct = {0};
195
+  if(huart->Instance==USART1)
196
+  {
197
+  /* USER CODE BEGIN USART1_MspInit 0 */
198
+
199
+  /* USER CODE END USART1_MspInit 0 */
200
+    /* Peripheral clock enable */
201
+    __HAL_RCC_USART1_CLK_ENABLE();
202
+  
203
+    __HAL_RCC_GPIOA_CLK_ENABLE();
204
+    /**USART1 GPIO Configuration    
205
+    PA9     ------> USART1_TX
206
+    PA10     ------> USART1_RX 
207
+    */
208
+    GPIO_InitStruct.Pin = GPIO_PIN_9;
209
+    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
210
+    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
211
+    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
212
+
213
+    GPIO_InitStruct.Pin = GPIO_PIN_10;
214
+    GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
215
+    GPIO_InitStruct.Pull = GPIO_NOPULL;
216
+    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
217
+
218
+  /* USER CODE BEGIN USART1_MspInit 1 */
219
+
220
+  /* USER CODE END USART1_MspInit 1 */
221
+  }
222
+
223
+}
224
+
225
+/**
226
+* @brief UART MSP De-Initialization
227
+* This function freeze the hardware resources used in this example
228
+* @param huart: UART handle pointer
229
+* @retval None
230
+*/
231
+void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
232
+{
233
+  if(huart->Instance==USART1)
234
+  {
235
+  /* USER CODE BEGIN USART1_MspDeInit 0 */
236
+
237
+  /* USER CODE END USART1_MspDeInit 0 */
238
+    /* Peripheral clock disable */
239
+    __HAL_RCC_USART1_CLK_DISABLE();
240
+  
241
+    /**USART1 GPIO Configuration    
242
+    PA9     ------> USART1_TX
243
+    PA10     ------> USART1_RX 
244
+    */
245
+    HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
246
+
247
+  /* USER CODE BEGIN USART1_MspDeInit 1 */
248
+
249
+  /* USER CODE END USART1_MspDeInit 1 */
250
+  }
251
+
252
+}
253
+
254
+/* USER CODE BEGIN 1 */
255
+
256
+/* USER CODE END 1 */
257
+
258
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 203 - 0
Src/stm32f1xx_it.c

@@ -0,0 +1,203 @@
1
+/* USER CODE BEGIN Header */
2
+/**
3
+  ******************************************************************************
4
+  * @file    stm32f1xx_it.c
5
+  * @brief   Interrupt Service Routines.
6
+  ******************************************************************************
7
+  * @attention
8
+  *
9
+  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
10
+  * All rights reserved.</center></h2>
11
+  *
12
+  * This software component is licensed by ST under BSD 3-Clause license,
13
+  * the "License"; You may not use this file except in compliance with the
14
+  * License. You may obtain a copy of the License at:
15
+  *                        opensource.org/licenses/BSD-3-Clause
16
+  *
17
+  ******************************************************************************
18
+  */
19
+/* USER CODE END Header */
20
+
21
+/* Includes ------------------------------------------------------------------*/
22
+#include "main.h"
23
+#include "stm32f1xx_it.h"
24
+/* Private includes ----------------------------------------------------------*/
25
+/* USER CODE BEGIN Includes */
26
+/* USER CODE END Includes */
27
+
28
+/* Private typedef -----------------------------------------------------------*/
29
+/* USER CODE BEGIN TD */
30
+
31
+/* USER CODE END TD */
32
+
33
+/* Private define ------------------------------------------------------------*/
34
+/* USER CODE BEGIN PD */
35
+ 
36
+/* USER CODE END PD */
37
+
38
+/* Private macro -------------------------------------------------------------*/
39
+/* USER CODE BEGIN PM */
40
+
41
+/* USER CODE END PM */
42
+
43
+/* Private variables ---------------------------------------------------------*/
44
+/* USER CODE BEGIN PV */
45
+
46
+/* USER CODE END PV */
47
+
48
+/* Private function prototypes -----------------------------------------------*/
49
+/* USER CODE BEGIN PFP */
50
+
51
+/* USER CODE END PFP */
52
+
53
+/* Private user code ---------------------------------------------------------*/
54
+/* USER CODE BEGIN 0 */
55
+
56
+/* USER CODE END 0 */
57
+
58
+/* External variables --------------------------------------------------------*/
59
+
60
+/* USER CODE BEGIN EV */
61
+
62
+/* USER CODE END EV */
63
+
64
+/******************************************************************************/
65
+/*           Cortex-M3 Processor Interruption and Exception Handlers          */ 
66
+/******************************************************************************/
67
+/**
68
+  * @brief This function handles Non maskable interrupt.
69
+  */
70
+void NMI_Handler(void)
71
+{
72
+  /* USER CODE BEGIN NonMaskableInt_IRQn 0 */
73
+
74
+  /* USER CODE END NonMaskableInt_IRQn 0 */
75
+  /* USER CODE BEGIN NonMaskableInt_IRQn 1 */
76
+
77
+  /* USER CODE END NonMaskableInt_IRQn 1 */
78
+}
79
+
80
+/**
81
+  * @brief This function handles Hard fault interrupt.
82
+  */
83
+void HardFault_Handler(void)
84
+{
85
+  /* USER CODE BEGIN HardFault_IRQn 0 */
86
+
87
+  /* USER CODE END HardFault_IRQn 0 */
88
+  while (1)
89
+  {
90
+    /* USER CODE BEGIN W1_HardFault_IRQn 0 */
91
+    /* USER CODE END W1_HardFault_IRQn 0 */
92
+  }
93
+}
94
+
95
+/**
96
+  * @brief This function handles Memory management fault.
97
+  */
98
+void MemManage_Handler(void)
99
+{
100
+  /* USER CODE BEGIN MemoryManagement_IRQn 0 */
101
+
102
+  /* USER CODE END MemoryManagement_IRQn 0 */
103
+  while (1)
104
+  {
105
+    /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
106
+    /* USER CODE END W1_MemoryManagement_IRQn 0 */
107
+  }
108
+}
109
+
110
+/**
111
+  * @brief This function handles Prefetch fault, memory access fault.
112
+  */
113
+void BusFault_Handler(void)
114
+{
115
+  /* USER CODE BEGIN BusFault_IRQn 0 */
116
+
117
+  /* USER CODE END BusFault_IRQn 0 */
118
+  while (1)
119
+  {
120
+    /* USER CODE BEGIN W1_BusFault_IRQn 0 */
121
+    /* USER CODE END W1_BusFault_IRQn 0 */
122
+  }
123
+}
124
+
125
+/**
126
+  * @brief This function handles Undefined instruction or illegal state.
127
+  */
128
+void UsageFault_Handler(void)
129
+{
130
+  /* USER CODE BEGIN UsageFault_IRQn 0 */
131
+
132
+  /* USER CODE END UsageFault_IRQn 0 */
133
+  while (1)
134
+  {
135
+    /* USER CODE BEGIN W1_UsageFault_IRQn 0 */
136
+    /* USER CODE END W1_UsageFault_IRQn 0 */
137
+  }
138
+}
139
+
140
+/**
141
+  * @brief This function handles System service call via SWI instruction.
142
+  */
143
+void SVC_Handler(void)
144
+{
145
+  /* USER CODE BEGIN SVCall_IRQn 0 */
146
+
147
+  /* USER CODE END SVCall_IRQn 0 */
148
+  /* USER CODE BEGIN SVCall_IRQn 1 */
149
+
150
+  /* USER CODE END SVCall_IRQn 1 */
151
+}
152
+
153
+/**
154
+  * @brief This function handles Debug monitor.
155
+  */
156
+void DebugMon_Handler(void)
157
+{
158
+  /* USER CODE BEGIN DebugMonitor_IRQn 0 */
159
+
160
+  /* USER CODE END DebugMonitor_IRQn 0 */
161
+  /* USER CODE BEGIN DebugMonitor_IRQn 1 */
162
+
163
+  /* USER CODE END DebugMonitor_IRQn 1 */
164
+}
165
+
166
+/**
167
+  * @brief This function handles Pendable request for system service.
168
+  */
169
+void PendSV_Handler(void)
170
+{
171
+  /* USER CODE BEGIN PendSV_IRQn 0 */
172
+
173
+  /* USER CODE END PendSV_IRQn 0 */
174
+  /* USER CODE BEGIN PendSV_IRQn 1 */
175
+
176
+  /* USER CODE END PendSV_IRQn 1 */
177
+}
178
+
179
+/**
180
+  * @brief This function handles System tick timer.
181
+  */
182
+void SysTick_Handler(void)
183
+{
184
+  /* USER CODE BEGIN SysTick_IRQn 0 */
185
+
186
+  /* USER CODE END SysTick_IRQn 0 */
187
+  HAL_IncTick();
188
+  /* USER CODE BEGIN SysTick_IRQn 1 */
189
+
190
+  /* USER CODE END SysTick_IRQn 1 */
191
+}
192
+
193
+/******************************************************************************/
194
+/* STM32F1xx Peripheral Interrupt Handlers                                    */
195
+/* Add here the Interrupt Handlers for the used peripherals.                  */
196
+/* For the available peripheral interrupt handler names,                      */
197
+/* please refer to the startup file (startup_stm32f1xx.s).                    */
198
+/******************************************************************************/
199
+
200
+/* USER CODE BEGIN 1 */
201
+
202
+/* USER CODE END 1 */
203
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 204 - 0
Src/syscalls.c

@@ -0,0 +1,204 @@
1
+/**
2
+*****************************************************************************
3
+**
4
+**  File        : syscalls.c
5
+**
6
+**  Abstract    : System Workbench Minimal System calls file
7
+**
8
+** 		          For more information about which c-functions
9
+**                need which of these lowlevel functions
10
+**                please consult the Newlib libc-manual
11
+**
12
+**  Environment : System Workbench for MCU
13
+**
14
+**  Distribution: The file is distributed ¡°as is,¡± without any warranty
15
+**                of any kind.
16
+**
17
+*****************************************************************************
18
+**
19
+** <h2><center>&copy; COPYRIGHT(c) 2014 Ac6</center></h2>
20
+**
21
+** Redistribution and use in source and binary forms, with or without modification,
22
+** are permitted provided that the following conditions are met:
23
+**   1. Redistributions of source code must retain the above copyright notice,
24
+**      this list of conditions and the following disclaimer.
25
+**   2. Redistributions in binary form must reproduce the above copyright notice,
26
+**      this list of conditions and the following disclaimer in the documentation
27
+**      and/or other materials provided with the distribution.
28
+**   3. Neither the name of Ac6 nor the names of its contributors
29
+**      may be used to endorse or promote products derived from this software
30
+**      without specific prior written permission.
31
+**
32
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
33
+** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34
+** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
35
+** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
36
+** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37
+** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
38
+** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
39
+** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
40
+** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
41
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42
+**
43
+*****************************************************************************
44
+*/
45
+
46
+/* Includes */
47
+#include <sys/stat.h>
48
+#include <stdlib.h>
49
+#include <errno.h>
50
+#include <stdio.h>
51
+#include <signal.h>
52
+#include <time.h>
53
+#include <sys/time.h>
54
+#include <sys/times.h>
55
+
56
+
57
+/* Variables */
58
+//#undef errno
59
+extern int errno;
60
+extern int __io_putchar(int ch) __attribute__((weak));
61
+extern int __io_getchar(void) __attribute__((weak));
62
+
63
+register char * stack_ptr asm("sp");
64
+
65
+char *__env[1] = { 0 };
66
+char **environ = __env;
67
+
68
+
69
+/* Functions */
70
+void initialise_monitor_handles()
71
+{
72
+}
73
+
74
+int _getpid(void)
75
+{
76
+	return 1;
77
+}
78
+
79
+int _kill(int pid, int sig)
80
+{
81
+	errno = EINVAL;
82
+	return -1;
83
+}
84
+
85
+void _exit (int status)
86
+{
87
+	_kill(status, -1);
88
+	while (1) {}		/* Make sure we hang here */
89
+}
90
+
91
+__attribute__((weak)) int _read(int file, char *ptr, int len)
92
+{
93
+	int DataIdx;
94
+
95
+	for (DataIdx = 0; DataIdx < len; DataIdx++)
96
+	{
97
+		*ptr++ = __io_getchar();
98
+	}
99
+
100
+return len;
101
+}
102
+
103
+__attribute__((weak)) int _write(int file, char *ptr, int len)
104
+{
105
+	int DataIdx;
106
+
107
+	for (DataIdx = 0; DataIdx < len; DataIdx++)
108
+	{
109
+		__io_putchar(*ptr++);
110
+	}
111
+	return len;
112
+}
113
+
114
+caddr_t _sbrk(int incr)
115
+{
116
+	extern char end asm("end");
117
+	static char *heap_end;
118
+	char *prev_heap_end;
119
+
120
+	if (heap_end == 0)
121
+		heap_end = &end;
122
+
123
+	prev_heap_end = heap_end;
124
+	if (heap_end + incr > stack_ptr)
125
+	{
126
+//		write(1, "Heap and stack collision\n", 25);
127
+//		abort();
128
+		errno = ENOMEM;
129
+		return (caddr_t) -1;
130
+	}
131
+
132
+	heap_end += incr;
133
+
134
+	return (caddr_t) prev_heap_end;
135
+}
136
+
137
+int _close(int file)
138
+{
139
+	return -1;
140
+}
141
+
142
+
143
+int _fstat(int file, struct stat *st)
144
+{
145
+	st->st_mode = S_IFCHR;
146
+	return 0;
147
+}
148
+
149
+int _isatty(int file)
150
+{
151
+	return 1;
152
+}
153
+
154
+int _lseek(int file, int ptr, int dir)
155
+{
156
+	return 0;
157
+}
158
+
159
+int _open(char *path, int flags, ...)
160
+{
161
+	/* Pretend like we always fail */
162
+	return -1;
163
+}
164
+
165
+int _wait(int *status)
166
+{
167
+	errno = ECHILD;
168
+	return -1;
169
+}
170
+
171
+int _unlink(char *name)
172
+{
173
+	errno = ENOENT;
174
+	return -1;
175
+}
176
+
177
+int _times(struct tms *buf)
178
+{
179
+	return -1;
180
+}
181
+
182
+int _stat(char *file, struct stat *st)
183
+{
184
+	st->st_mode = S_IFCHR;
185
+	return 0;
186
+}
187
+
188
+int _link(char *old, char *new)
189
+{
190
+	errno = EMLINK;
191
+	return -1;
192
+}
193
+
194
+int _fork(void)
195
+{
196
+	errno = EAGAIN;
197
+	return -1;
198
+}
199
+
200
+int _execve(char *name, char **argv, char **env)
201
+{
202
+	errno = ENOMEM;
203
+	return -1;
204
+}

+ 448 - 0
Src/system_stm32f1xx.c

@@ -0,0 +1,448 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    system_stm32f1xx.c
4
+  * @author  MCD Application Team
5
+  * @version V4.2.0
6
+  * @date    31-March-2017
7
+  * @brief   CMSIS Cortex-M3 Device Peripheral Access Layer System Source File.
8
+  * 
9
+  * 1.  This file provides two functions and one global variable to be called from 
10
+  *     user application:
11
+  *      - SystemInit(): Setups the system clock (System clock source, PLL Multiplier
12
+  *                      factors, AHB/APBx prescalers and Flash settings). 
13
+  *                      This function is called at startup just after reset and 
14
+  *                      before branch to main program. This call is made inside
15
+  *                      the "startup_stm32f1xx_xx.s" file.
16
+  *
17
+  *      - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
18
+  *                                  by the user application to setup the SysTick 
19
+  *                                  timer or configure other parameters.
20
+  *                                     
21
+  *      - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
22
+  *                                 be called whenever the core clock is changed
23
+  *                                 during program execution.
24
+  *
25
+  * 2. After each device reset the HSI (8 MHz) is used as system clock source.
26
+  *    Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to
27
+  *    configure the system clock before to branch to main program.
28
+  *
29
+  * 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on
30
+  *    the product used), refer to "HSE_VALUE". 
31
+  *    When HSE is used as system clock source, directly or through PLL, and you
32
+  *    are using different crystal you have to adapt the HSE value to your own
33
+  *    configuration.
34
+  *        
35
+  ******************************************************************************
36
+  * @attention
37
+  *
38
+  * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
39
+  *
40
+  * Redistribution and use in source and binary forms, with or without modification,
41
+  * are permitted provided that the following conditions are met:
42
+  *   1. Redistributions of source code must retain the above copyright notice,
43
+  *      this list of conditions and the following disclaimer.
44
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
45
+  *      this list of conditions and the following disclaimer in the documentation
46
+  *      and/or other materials provided with the distribution.
47
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
48
+  *      may be used to endorse or promote products derived from this software
49
+  *      without specific prior written permission.
50
+  *
51
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
52
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
54
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
55
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
57
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
58
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
59
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61
+  *
62
+  ******************************************************************************
63
+  */
64
+
65
+/** @addtogroup CMSIS
66
+  * @{
67
+  */
68
+
69
+/** @addtogroup stm32f1xx_system
70
+  * @{
71
+  */  
72
+  
73
+/** @addtogroup STM32F1xx_System_Private_Includes
74
+  * @{
75
+  */
76
+
77
+#include "stm32f1xx.h"
78
+
79
+/**
80
+  * @}
81
+  */
82
+
83
+/** @addtogroup STM32F1xx_System_Private_TypesDefinitions
84
+  * @{
85
+  */
86
+
87
+/**
88
+  * @}
89
+  */
90
+
91
+/** @addtogroup STM32F1xx_System_Private_Defines
92
+  * @{
93
+  */
94
+
95
+#if !defined  (HSE_VALUE) 
96
+  #define HSE_VALUE               8000000U /*!< Default value of the External oscillator in Hz.
97
+                                                This value can be provided and adapted by the user application. */
98
+#endif /* HSE_VALUE */
99
+
100
+#if !defined  (HSI_VALUE)
101
+  #define HSI_VALUE               8000000U /*!< Default value of the Internal oscillator in Hz.
102
+                                                This value can be provided and adapted by the user application. */
103
+#endif /* HSI_VALUE */
104
+
105
+/*!< Uncomment the following line if you need to use external SRAM  */ 
106
+#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
107
+/* #define DATA_IN_ExtSRAM */
108
+#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
109
+
110
+/*!< Uncomment the following line if you need to relocate your vector Table in
111
+     Internal SRAM. */ 
112
+/* #define VECT_TAB_SRAM */
113
+#define VECT_TAB_OFFSET  0x00000000U /*!< Vector Table base offset field. 
114
+                                  This value must be a multiple of 0x200. */
115
+
116
+
117
+/**
118
+  * @}
119
+  */
120
+
121
+/** @addtogroup STM32F1xx_System_Private_Macros
122
+  * @{
123
+  */
124
+
125
+/**
126
+  * @}
127
+  */
128
+
129
+/** @addtogroup STM32F1xx_System_Private_Variables
130
+  * @{
131
+  */
132
+
133
+/*******************************************************************************
134
+*  Clock Definitions
135
+*******************************************************************************/
136
+#if defined(STM32F100xB) ||defined(STM32F100xE)
137
+  uint32_t SystemCoreClock         = 24000000U;        /*!< System Clock Frequency (Core Clock) */
138
+#else /*!< HSI Selected as System Clock source */
139
+  uint32_t SystemCoreClock         = 72000000U;        /*!< System Clock Frequency (Core Clock) */
140
+#endif
141
+
142
+const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
143
+const uint8_t APBPrescTable[8U] =  {0, 0, 0, 0, 1, 2, 3, 4};
144
+
145
+/**
146
+  * @}
147
+  */
148
+
149
+/** @addtogroup STM32F1xx_System_Private_FunctionPrototypes
150
+  * @{
151
+  */
152
+
153
+#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
154
+#ifdef DATA_IN_ExtSRAM
155
+  static void SystemInit_ExtMemCtl(void); 
156
+#endif /* DATA_IN_ExtSRAM */
157
+#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
158
+
159
+/**
160
+  * @}
161
+  */
162
+
163
+/** @addtogroup STM32F1xx_System_Private_Functions
164
+  * @{
165
+  */
166
+
167
+/**
168
+  * @brief  Setup the microcontroller system
169
+  *         Initialize the Embedded Flash Interface, the PLL and update the 
170
+  *         SystemCoreClock variable.
171
+  * @note   This function should be used only after reset.
172
+  * @param  None
173
+  * @retval None
174
+  */
175
+void SystemInit (void)
176
+{
177
+  /* Reset the RCC clock configuration to the default reset state(for debug purpose) */
178
+  /* Set HSION bit */
179
+  RCC->CR |= 0x00000001U;
180
+
181
+  /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */
182
+#if !defined(STM32F105xC) && !defined(STM32F107xC)
183
+  RCC->CFGR &= 0xF8FF0000U;
184
+#else
185
+  RCC->CFGR &= 0xF0FF0000U;
186
+#endif /* STM32F105xC */   
187
+  
188
+  /* Reset HSEON, CSSON and PLLON bits */
189
+  RCC->CR &= 0xFEF6FFFFU;
190
+
191
+  /* Reset HSEBYP bit */
192
+  RCC->CR &= 0xFFFBFFFFU;
193
+
194
+  /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */
195
+  RCC->CFGR &= 0xFF80FFFFU;
196
+
197
+#if defined(STM32F105xC) || defined(STM32F107xC)
198
+  /* Reset PLL2ON and PLL3ON bits */
199
+  RCC->CR &= 0xEBFFFFFFU;
200
+
201
+  /* Disable all interrupts and clear pending bits  */
202
+  RCC->CIR = 0x00FF0000U;
203
+
204
+  /* Reset CFGR2 register */
205
+  RCC->CFGR2 = 0x00000000U;
206
+#elif defined(STM32F100xB) || defined(STM32F100xE)
207
+  /* Disable all interrupts and clear pending bits  */
208
+  RCC->CIR = 0x009F0000U;
209
+
210
+  /* Reset CFGR2 register */
211
+  RCC->CFGR2 = 0x00000000U;      
212
+#else
213
+  /* Disable all interrupts and clear pending bits  */
214
+  RCC->CIR = 0x009F0000U;
215
+#endif /* STM32F105xC */
216
+    
217
+#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
218
+  #ifdef DATA_IN_ExtSRAM
219
+    SystemInit_ExtMemCtl(); 
220
+  #endif /* DATA_IN_ExtSRAM */
221
+#endif 
222
+
223
+#ifdef VECT_TAB_SRAM
224
+  SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
225
+#else
226
+  SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
227
+#endif 
228
+}
229
+
230
+/**
231
+  * @brief  Update SystemCoreClock variable according to Clock Register Values.
232
+  *         The SystemCoreClock variable contains the core clock (HCLK), it can
233
+  *         be used by the user application to setup the SysTick timer or configure
234
+  *         other parameters.
235
+  *           
236
+  * @note   Each time the core clock (HCLK) changes, this function must be called
237
+  *         to update SystemCoreClock variable value. Otherwise, any configuration
238
+  *         based on this variable will be incorrect.         
239
+  *     
240
+  * @note   - The system frequency computed by this function is not the real 
241
+  *           frequency in the chip. It is calculated based on the predefined 
242
+  *           constant and the selected clock source:
243
+  *             
244
+  *           - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
245
+  *                                              
246
+  *           - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
247
+  *                          
248
+  *           - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) 
249
+  *             or HSI_VALUE(*) multiplied by the PLL factors.
250
+  *         
251
+  *         (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value
252
+  *             8 MHz) but the real value may vary depending on the variations
253
+  *             in voltage and temperature.   
254
+  *    
255
+  *         (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value
256
+  *              8 MHz or 25 MHz, depending on the product used), user has to ensure
257
+  *              that HSE_VALUE is same as the real frequency of the crystal used.
258
+  *              Otherwise, this function may have wrong result.
259
+  *                
260
+  *         - The result of this function could be not correct when using fractional
261
+  *           value for HSE crystal.
262
+  * @param  None
263
+  * @retval None
264
+  */
265
+void SystemCoreClockUpdate (void)
266
+{
267
+  uint32_t tmp = 0U, pllmull = 0U, pllsource = 0U;
268
+
269
+#if defined(STM32F105xC) || defined(STM32F107xC)
270
+  uint32_t prediv1source = 0U, prediv1factor = 0U, prediv2factor = 0U, pll2mull = 0U;
271
+#endif /* STM32F105xC */
272
+
273
+#if defined(STM32F100xB) || defined(STM32F100xE)
274
+  uint32_t prediv1factor = 0U;
275
+#endif /* STM32F100xB or STM32F100xE */
276
+    
277
+  /* Get SYSCLK source -------------------------------------------------------*/
278
+  tmp = RCC->CFGR & RCC_CFGR_SWS;
279
+  
280
+  switch (tmp)
281
+  {
282
+    case 0x00U:  /* HSI used as system clock */
283
+      SystemCoreClock = HSI_VALUE;
284
+      break;
285
+    case 0x04U:  /* HSE used as system clock */
286
+      SystemCoreClock = HSE_VALUE;
287
+      break;
288
+    case 0x08U:  /* PLL used as system clock */
289
+
290
+      /* Get PLL clock source and multiplication factor ----------------------*/
291
+      pllmull = RCC->CFGR & RCC_CFGR_PLLMULL;
292
+      pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;
293
+      
294
+#if !defined(STM32F105xC) && !defined(STM32F107xC)      
295
+      pllmull = ( pllmull >> 18U) + 2U;
296
+      
297
+      if (pllsource == 0x00U)
298
+      {
299
+        /* HSI oscillator clock divided by 2 selected as PLL clock entry */
300
+        SystemCoreClock = (HSI_VALUE >> 1U) * pllmull;
301
+      }
302
+      else
303
+      {
304
+ #if defined(STM32F100xB) || defined(STM32F100xE)
305
+       prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U;
306
+       /* HSE oscillator clock selected as PREDIV1 clock entry */
307
+       SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; 
308
+ #else
309
+        /* HSE selected as PLL clock entry */
310
+        if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET)
311
+        {/* HSE oscillator clock divided by 2 */
312
+          SystemCoreClock = (HSE_VALUE >> 1U) * pllmull;
313
+        }
314
+        else
315
+        {
316
+          SystemCoreClock = HSE_VALUE * pllmull;
317
+        }
318
+ #endif
319
+      }
320
+#else
321
+      pllmull = pllmull >> 18U;
322
+      
323
+      if (pllmull != 0x0DU)
324
+      {
325
+         pllmull += 2U;
326
+      }
327
+      else
328
+      { /* PLL multiplication factor = PLL input clock * 6.5 */
329
+        pllmull = 13U / 2U; 
330
+      }
331
+            
332
+      if (pllsource == 0x00U)
333
+      {
334
+        /* HSI oscillator clock divided by 2 selected as PLL clock entry */
335
+        SystemCoreClock = (HSI_VALUE >> 1U) * pllmull;
336
+      }
337
+      else
338
+      {/* PREDIV1 selected as PLL clock entry */
339
+        
340
+        /* Get PREDIV1 clock source and division factor */
341
+        prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC;
342
+        prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U;
343
+        
344
+        if (prediv1source == 0U)
345
+        { 
346
+          /* HSE oscillator clock selected as PREDIV1 clock entry */
347
+          SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;          
348
+        }
349
+        else
350
+        {/* PLL2 clock selected as PREDIV1 clock entry */
351
+          
352
+          /* Get PREDIV2 division factor and PLL2 multiplication factor */
353
+          prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U;
354
+          pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8U) + 2U; 
355
+          SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull;                         
356
+        }
357
+      }
358
+#endif /* STM32F105xC */ 
359
+      break;
360
+
361
+    default:
362
+      SystemCoreClock = HSI_VALUE;
363
+      break;
364
+  }
365
+  
366
+  /* Compute HCLK clock frequency ----------------*/
367
+  /* Get HCLK prescaler */
368
+  tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)];
369
+  /* HCLK clock frequency */
370
+  SystemCoreClock >>= tmp;  
371
+}
372
+
373
+#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
374
+/**
375
+  * @brief  Setup the external memory controller. Called in startup_stm32f1xx.s 
376
+  *          before jump to __main
377
+  * @param  None
378
+  * @retval None
379
+  */ 
380
+#ifdef DATA_IN_ExtSRAM
381
+/**
382
+  * @brief  Setup the external memory controller. 
383
+  *         Called in startup_stm32f1xx_xx.s/.c before jump to main.
384
+  *         This function configures the external SRAM mounted on STM3210E-EVAL
385
+  *         board (STM32 High density devices). This SRAM will be used as program
386
+  *         data memory (including heap and stack).
387
+  * @param  None
388
+  * @retval None
389
+  */ 
390
+void SystemInit_ExtMemCtl(void) 
391
+{
392
+  __IO uint32_t tmpreg;
393
+  /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is 
394
+    required, then adjust the Register Addresses */
395
+
396
+  /* Enable FSMC clock */
397
+  RCC->AHBENR = 0x00000114U;
398
+
399
+  /* Delay after an RCC peripheral clock enabling */
400
+  tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN);
401
+  
402
+  /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */
403
+  RCC->APB2ENR = 0x000001E0U;
404
+  
405
+  /* Delay after an RCC peripheral clock enabling */
406
+  tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN);
407
+
408
+  (void)(tmpreg);
409
+  
410
+/* ---------------  SRAM Data lines, NOE and NWE configuration ---------------*/
411
+/*----------------  SRAM Address lines configuration -------------------------*/
412
+/*----------------  NOE and NWE configuration --------------------------------*/  
413
+/*----------------  NE3 configuration ----------------------------------------*/
414
+/*----------------  NBL0, NBL1 configuration ---------------------------------*/
415
+  
416
+  GPIOD->CRL = 0x44BB44BBU;  
417
+  GPIOD->CRH = 0xBBBBBBBBU;
418
+
419
+  GPIOE->CRL = 0xB44444BBU;  
420
+  GPIOE->CRH = 0xBBBBBBBBU;
421
+
422
+  GPIOF->CRL = 0x44BBBBBBU;  
423
+  GPIOF->CRH = 0xBBBB4444U;
424
+
425
+  GPIOG->CRL = 0x44BBBBBBU;  
426
+  GPIOG->CRH = 0x444B4B44U;
427
+   
428
+/*----------------  FSMC Configuration ---------------------------------------*/  
429
+/*----------------  Enable FSMC Bank1_SRAM Bank ------------------------------*/
430
+  
431
+  FSMC_Bank1->BTCR[4U] = 0x00001091U;
432
+  FSMC_Bank1->BTCR[5U] = 0x00110212U;
433
+}
434
+#endif /* DATA_IN_ExtSRAM */
435
+#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
436
+
437
+/**
438
+  * @}
439
+  */
440
+
441
+/**
442
+  * @}
443
+  */
444
+  
445
+/**
446
+  * @}
447
+  */    
448
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 482 - 0
startup/startup_stm32f103xg.s

@@ -0,0 +1,482 @@
1
+/**
2
+  *************** (C) COPYRIGHT 2017 STMicroelectronics ************************
3
+  * @file      startup_stm32f103xb.s
4
+  * @author    MCD Application Team
5
+  * @version   V4.2.0
6
+  * @date      31-March-2017
7
+  * @brief     STM32F103xB Devices vector table for Atollic toolchain.
8
+  *            This module performs:
9
+  *                - Set the initial SP
10
+  *                - Set the initial PC == Reset_Handler,
11
+  *                - Set the vector table entries with the exceptions ISR address
12
+  *                - Configure the clock system   
13
+  *                - Branches to main in the C library (which eventually
14
+  *                  calls main()).
15
+  *            After Reset the Cortex-M3 processor is in Thread mode,
16
+  *            priority is Privileged, and the Stack is set to Main.
17
+  ******************************************************************************
18
+  *
19
+  * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
20
+  *
21
+  * Redistribution and use in source and binary forms, with or without modification,
22
+  * are permitted provided that the following conditions are met:
23
+  *   1. Redistributions of source code must retain the above copyright notice,
24
+  *      this list of conditions and the following disclaimer.
25
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
26
+  *      this list of conditions and the following disclaimer in the documentation
27
+  *      and/or other materials provided with the distribution.
28
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
29
+  *      may be used to endorse or promote products derived from this software
30
+  *      without specific prior written permission.
31
+  *
32
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
33
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
35
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
36
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
38
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
39
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
40
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
41
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42
+  *
43
+  ******************************************************************************
44
+  */
45
+
46
+  .syntax unified
47
+  .cpu cortex-m3
48
+  .fpu softvfp
49
+  .thumb
50
+
51
+.global g_pfnVectors
52
+.global Default_Handler
53
+
54
+/* start address for the initialization values of the .data section.
55
+defined in linker script */
56
+.word _sidata
57
+/* start address for the .data section. defined in linker script */
58
+.word _sdata
59
+/* end address for the .data section. defined in linker script */
60
+.word _edata
61
+/* start address for the .bss section. defined in linker script */
62
+.word _sbss
63
+/* end address for the .bss section. defined in linker script */
64
+.word _ebss
65
+
66
+.equ  BootRAM,        0xF1E0F85F
67
+/**
68
+ * @brief  This is the code that gets called when the processor first
69
+ *          starts execution following a reset event. Only the absolutely
70
+ *          necessary set is performed, after which the application
71
+ *          supplied main() routine is called.
72
+ * @param  None
73
+ * @retval : None
74
+*/
75
+
76
+  .section .text.Reset_Handler
77
+  .weak Reset_Handler
78
+  .type Reset_Handler, %function
79
+Reset_Handler:
80
+
81
+/* Copy the data segment initializers from flash to SRAM */
82
+  movs r1, #0
83
+  b LoopCopyDataInit
84
+
85
+CopyDataInit:
86
+  ldr r3, =_sidata
87
+  ldr r3, [r3, r1]
88
+  str r3, [r0, r1]
89
+  adds r1, r1, #4
90
+
91
+LoopCopyDataInit:
92
+  ldr r0, =_sdata
93
+  ldr r3, =_edata
94
+  adds r2, r0, r1
95
+  cmp r2, r3
96
+  bcc CopyDataInit
97
+  ldr r2, =_sbss
98
+  b LoopFillZerobss
99
+
100
+/* Zero fill the bss segment. */
101
+FillZerobss:
102
+  movs r3, #0
103
+  str r3, [r2], #4
104
+
105
+LoopFillZerobss:
106
+  ldr r3, = _ebss
107
+  cmp r2, r3
108
+  bcc FillZerobss
109
+
110
+/* Call the clock system intitialization function.*/
111
+    bl  SystemInit
112
+/* Call static constructors */
113
+    bl __libc_init_array
114
+/* Call the application's entry point.*/
115
+  bl main
116
+  bx lr
117
+.size Reset_Handler, .-Reset_Handler
118
+
119
+/**
120
+ * @brief  This is the code that gets called when the processor receives an
121
+ *         unexpected interrupt.  This simply enters an infinite loop, preserving
122
+ *         the system state for examination by a debugger.
123
+ * @param  None
124
+ * @retval None       
125
+*/
126
+    .section .text.Default_Handler,"ax",%progbits
127
+Default_Handler:
128
+Infinite_Loop:
129
+  b Infinite_Loop
130
+  .size Default_Handler, .-Default_Handler
131
+/******************************************************************************
132
+*
133
+* The minimal vector table for a Cortex M3.  Note that the proper constructs
134
+* must be placed on this to ensure that it ends up at physical address
135
+* 0x0000.0000.
136
+*
137
+*******************************************************************************/
138
+  .section .isr_vector,"a",%progbits
139
+  .type g_pfnVectors, %object
140
+  .size g_pfnVectors, .-g_pfnVectors
141
+
142
+
143
+g_pfnVectors:
144
+
145
+  .word  _estack
146
+  .word  Reset_Handler
147
+  .word  NMI_Handler
148
+  .word  HardFault_Handler
149
+  .word  MemManage_Handler
150
+  .word  BusFault_Handler
151
+  .word  UsageFault_Handler
152
+  .word  0
153
+  .word  0
154
+  .word  0
155
+  .word  0
156
+  .word  SVC_Handler
157
+  .word  DebugMon_Handler
158
+  .word  0
159
+  .word  PendSV_Handler
160
+  .word  SysTick_Handler
161
+  .word  WWDG_IRQHandler
162
+  .word  PVD_IRQHandler
163
+  .word  TAMPER_IRQHandler
164
+  .word  RTC_IRQHandler
165
+  .word  FLASH_IRQHandler
166
+  .word  RCC_IRQHandler
167
+  .word  EXTI0_IRQHandler
168
+  .word  EXTI1_IRQHandler
169
+  .word  EXTI2_IRQHandler
170
+  .word  EXTI3_IRQHandler
171
+  .word  EXTI4_IRQHandler
172
+  .word  DMA1_Channel1_IRQHandler
173
+  .word  DMA1_Channel2_IRQHandler
174
+  .word  DMA1_Channel3_IRQHandler
175
+  .word  DMA1_Channel4_IRQHandler
176
+  .word  DMA1_Channel5_IRQHandler
177
+  .word  DMA1_Channel6_IRQHandler
178
+  .word  DMA1_Channel7_IRQHandler
179
+  .word  ADC1_2_IRQHandler
180
+  .word  USB_HP_CAN1_TX_IRQHandler
181
+  .word  USB_LP_CAN1_RX0_IRQHandler
182
+  .word  CAN1_RX1_IRQHandler
183
+  .word  CAN1_SCE_IRQHandler
184
+  .word  EXTI9_5_IRQHandler
185
+  .word  TIM1_BRK_TIM9_IRQHandler
186
+  .word  TIM1_UP_TIM10_IRQHandler
187
+  .word  TIM1_TRG_COM_TIM11_IRQHandler
188
+  .word  TIM1_CC_IRQHandler
189
+  .word  TIM2_IRQHandler
190
+  .word  TIM3_IRQHandler
191
+  .word  TIM4_IRQHandler
192
+  .word  I2C1_EV_IRQHandler
193
+  .word  I2C1_ER_IRQHandler
194
+  .word  I2C2_EV_IRQHandler
195
+  .word  I2C2_ER_IRQHandler
196
+  .word  SPI1_IRQHandler
197
+  .word  SPI2_IRQHandler
198
+  .word  USART1_IRQHandler
199
+  .word  USART2_IRQHandler
200
+  .word  USART3_IRQHandler
201
+  .word  EXTI15_10_IRQHandler
202
+  .word  RTC_Alarm_IRQHandler
203
+  .word  USBWakeUp_IRQHandler
204
+  .word  TIM8_BRK_TIM12_IRQHandler
205
+  .word  TIM8_UP_TIM13_IRQHandler
206
+  .word  TIM8_TRG_COM_TIM14_IRQHandler
207
+  .word  TIM8_CC_IRQHandler
208
+  .word  ADC3_IRQHandler
209
+  .word  FSMC_IRQHandler
210
+  .word  SDIO_IRQHandler
211
+  .word  TIM5_IRQHandler
212
+  .word  SPI3_IRQHandler
213
+  .word  UART4_IRQHandler
214
+  .word  UART5_IRQHandler
215
+  .word  TIM6_IRQHandler
216
+  .word  TIM7_IRQHandler
217
+  .word  DMA2_Channel1_IRQHandler
218
+  .word  DMA2_Channel2_IRQHandler
219
+  .word  DMA2_Channel3_IRQHandler
220
+  .word  DMA2_Channel4_5_IRQHandler
221
+  .word  0
222
+  .word  0
223
+  .word  0
224
+  .word  0
225
+  .word  0
226
+  .word  0
227
+  .word  0
228
+  .word  0
229
+  .word  0
230
+  .word  0
231
+  .word  0
232
+  .word  0
233
+  .word  0
234
+  .word  0
235
+  .word  0
236
+  .word  0
237
+  .word  0
238
+  .word  0
239
+  .word  0
240
+  .word  0
241
+  .word  0
242
+  .word  0
243
+  .word  0
244
+  .word  0
245
+  .word  0
246
+  .word  0
247
+  .word  0
248
+  .word  0
249
+  .word  0
250
+  .word  0
251
+  .word  0
252
+  .word  0
253
+  .word  0
254
+  .word  0
255
+  .word  0
256
+  .word  0
257
+  .word  0
258
+  .word  0
259
+  .word  0
260
+  .word  0
261
+  .word  0
262
+  .word  0
263
+  .word  0
264
+  .word  0
265
+  .word  BootRAM       /* @0x1E0. This is for boot in RAM mode for 
266
+                         STM32F10x XL-Density devices. */
267
+/*******************************************************************************
268
+*
269
+* Provide weak aliases for each Exception handler to the Default_Handler. 
270
+* As they are weak aliases, any function with the same name will override 
271
+* this definition.
272
+* 
273
+*******************************************************************************/
274
+    
275
+  .weak  NMI_Handler
276
+  .thumb_set NMI_Handler,Default_Handler
277
+  
278
+  .weak  HardFault_Handler
279
+  .thumb_set HardFault_Handler,Default_Handler
280
+  
281
+  .weak  MemManage_Handler
282
+  .thumb_set MemManage_Handler,Default_Handler
283
+  
284
+  .weak  BusFault_Handler
285
+  .thumb_set BusFault_Handler,Default_Handler
286
+
287
+  .weak  UsageFault_Handler
288
+  .thumb_set UsageFault_Handler,Default_Handler
289
+
290
+  .weak  SVC_Handler
291
+  .thumb_set SVC_Handler,Default_Handler
292
+
293
+  .weak  DebugMon_Handler
294
+  .thumb_set DebugMon_Handler,Default_Handler
295
+
296
+  .weak  PendSV_Handler
297
+  .thumb_set PendSV_Handler,Default_Handler
298
+
299
+  .weak  SysTick_Handler
300
+  .thumb_set SysTick_Handler,Default_Handler
301
+
302
+  .weak  WWDG_IRQHandler
303
+  .thumb_set WWDG_IRQHandler,Default_Handler
304
+
305
+  .weak  PVD_IRQHandler
306
+  .thumb_set PVD_IRQHandler,Default_Handler
307
+
308
+  .weak  TAMPER_IRQHandler
309
+  .thumb_set TAMPER_IRQHandler,Default_Handler
310
+
311
+  .weak  RTC_IRQHandler
312
+  .thumb_set RTC_IRQHandler,Default_Handler
313
+
314
+  .weak  FLASH_IRQHandler
315
+  .thumb_set FLASH_IRQHandler,Default_Handler
316
+
317
+  .weak  RCC_IRQHandler
318
+  .thumb_set RCC_IRQHandler,Default_Handler
319
+
320
+  .weak  EXTI0_IRQHandler
321
+  .thumb_set EXTI0_IRQHandler,Default_Handler
322
+
323
+  .weak  EXTI1_IRQHandler
324
+  .thumb_set EXTI1_IRQHandler,Default_Handler
325
+
326
+  .weak  EXTI2_IRQHandler
327
+  .thumb_set EXTI2_IRQHandler,Default_Handler
328
+
329
+  .weak  EXTI3_IRQHandler
330
+  .thumb_set EXTI3_IRQHandler,Default_Handler
331
+
332
+  .weak  EXTI4_IRQHandler
333
+  .thumb_set EXTI4_IRQHandler,Default_Handler
334
+
335
+  .weak  DMA1_Channel1_IRQHandler
336
+  .thumb_set DMA1_Channel1_IRQHandler,Default_Handler
337
+
338
+  .weak  DMA1_Channel2_IRQHandler
339
+  .thumb_set DMA1_Channel2_IRQHandler,Default_Handler
340
+
341
+  .weak  DMA1_Channel3_IRQHandler
342
+  .thumb_set DMA1_Channel3_IRQHandler,Default_Handler
343
+
344
+  .weak  DMA1_Channel4_IRQHandler
345
+  .thumb_set DMA1_Channel4_IRQHandler,Default_Handler
346
+
347
+  .weak  DMA1_Channel5_IRQHandler
348
+  .thumb_set DMA1_Channel5_IRQHandler,Default_Handler
349
+
350
+  .weak  DMA1_Channel6_IRQHandler
351
+  .thumb_set DMA1_Channel6_IRQHandler,Default_Handler
352
+
353
+  .weak  DMA1_Channel7_IRQHandler
354
+  .thumb_set DMA1_Channel7_IRQHandler,Default_Handler
355
+
356
+  .weak  ADC1_2_IRQHandler
357
+  .thumb_set ADC1_2_IRQHandler,Default_Handler
358
+
359
+  .weak  USB_HP_CAN1_TX_IRQHandler
360
+  .thumb_set USB_HP_CAN1_TX_IRQHandler,Default_Handler
361
+
362
+  .weak  USB_LP_CAN1_RX0_IRQHandler
363
+  .thumb_set USB_LP_CAN1_RX0_IRQHandler,Default_Handler
364
+
365
+  .weak  CAN1_RX1_IRQHandler
366
+  .thumb_set CAN1_RX1_IRQHandler,Default_Handler
367
+
368
+  .weak  CAN1_SCE_IRQHandler
369
+  .thumb_set CAN1_SCE_IRQHandler,Default_Handler
370
+
371
+  .weak  EXTI9_5_IRQHandler
372
+  .thumb_set EXTI9_5_IRQHandler,Default_Handler
373
+
374
+  .weak  TIM1_BRK_TIM9_IRQHandler
375
+  .thumb_set TIM1_BRK_TIM9_IRQHandler,Default_Handler
376
+
377
+  .weak  TIM1_UP_TIM10_IRQHandler
378
+  .thumb_set TIM1_UP_TIM10_IRQHandler,Default_Handler
379
+
380
+  .weak  TIM1_TRG_COM_TIM11_IRQHandler
381
+  .thumb_set TIM1_TRG_COM_TIM11_IRQHandler,Default_Handler
382
+
383
+  .weak  TIM1_CC_IRQHandler
384
+  .thumb_set TIM1_CC_IRQHandler,Default_Handler
385
+
386
+  .weak  TIM2_IRQHandler
387
+  .thumb_set TIM2_IRQHandler,Default_Handler
388
+
389
+  .weak  TIM3_IRQHandler
390
+  .thumb_set TIM3_IRQHandler,Default_Handler
391
+
392
+  .weak  TIM4_IRQHandler
393
+  .thumb_set TIM4_IRQHandler,Default_Handler
394
+
395
+  .weak  I2C1_EV_IRQHandler
396
+  .thumb_set I2C1_EV_IRQHandler,Default_Handler
397
+
398
+  .weak  I2C1_ER_IRQHandler
399
+  .thumb_set I2C1_ER_IRQHandler,Default_Handler
400
+
401
+  .weak  I2C2_EV_IRQHandler
402
+  .thumb_set I2C2_EV_IRQHandler,Default_Handler
403
+
404
+  .weak  I2C2_ER_IRQHandler
405
+  .thumb_set I2C2_ER_IRQHandler,Default_Handler
406
+
407
+  .weak  SPI1_IRQHandler
408
+  .thumb_set SPI1_IRQHandler,Default_Handler
409
+
410
+  .weak  SPI2_IRQHandler
411
+  .thumb_set SPI2_IRQHandler,Default_Handler
412
+
413
+  .weak  USART1_IRQHandler
414
+  .thumb_set USART1_IRQHandler,Default_Handler
415
+
416
+  .weak  USART2_IRQHandler
417
+  .thumb_set USART2_IRQHandler,Default_Handler
418
+
419
+  .weak  USART3_IRQHandler
420
+  .thumb_set USART3_IRQHandler,Default_Handler
421
+
422
+  .weak  EXTI15_10_IRQHandler
423
+  .thumb_set EXTI15_10_IRQHandler,Default_Handler
424
+
425
+  .weak  RTC_Alarm_IRQHandler
426
+  .thumb_set RTC_Alarm_IRQHandler,Default_Handler
427
+
428
+  .weak  USBWakeUp_IRQHandler
429
+  .thumb_set USBWakeUp_IRQHandler,Default_Handler
430
+
431
+  .weak  TIM8_BRK_TIM12_IRQHandler
432
+  .thumb_set TIM8_BRK_TIM12_IRQHandler,Default_Handler
433
+
434
+  .weak  TIM8_UP_TIM13_IRQHandler
435
+  .thumb_set TIM8_UP_TIM13_IRQHandler,Default_Handler
436
+
437
+  .weak  TIM8_TRG_COM_TIM14_IRQHandler
438
+  .thumb_set TIM8_TRG_COM_TIM14_IRQHandler,Default_Handler
439
+
440
+  .weak  TIM8_CC_IRQHandler
441
+  .thumb_set TIM8_CC_IRQHandler,Default_Handler
442
+
443
+  .weak  ADC3_IRQHandler
444
+  .thumb_set ADC3_IRQHandler,Default_Handler
445
+
446
+  .weak  FSMC_IRQHandler
447
+  .thumb_set FSMC_IRQHandler,Default_Handler
448
+
449
+  .weak  SDIO_IRQHandler
450
+  .thumb_set SDIO_IRQHandler,Default_Handler
451
+
452
+  .weak  TIM5_IRQHandler
453
+  .thumb_set TIM5_IRQHandler,Default_Handler
454
+
455
+  .weak  SPI3_IRQHandler
456
+  .thumb_set SPI3_IRQHandler,Default_Handler
457
+
458
+  .weak  UART4_IRQHandler
459
+  .thumb_set UART4_IRQHandler,Default_Handler
460
+
461
+  .weak  UART5_IRQHandler
462
+  .thumb_set UART5_IRQHandler,Default_Handler
463
+
464
+  .weak  TIM6_IRQHandler
465
+  .thumb_set TIM6_IRQHandler,Default_Handler
466
+
467
+  .weak  TIM7_IRQHandler
468
+  .thumb_set TIM7_IRQHandler,Default_Handler
469
+
470
+  .weak  DMA2_Channel1_IRQHandler
471
+  .thumb_set DMA2_Channel1_IRQHandler,Default_Handler
472
+
473
+  .weak  DMA2_Channel2_IRQHandler
474
+  .thumb_set DMA2_Channel2_IRQHandler,Default_Handler
475
+
476
+  .weak  DMA2_Channel3_IRQHandler
477
+  .thumb_set DMA2_Channel3_IRQHandler,Default_Handler
478
+
479
+  .weak  DMA2_Channel4_5_IRQHandler
480
+  .thumb_set DMA2_Channel4_5_IRQHandler,Default_Handler
481
+
482
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/