|
@@ -34,23 +34,59 @@
|
34
|
34
|
#include "HAL.h"
|
35
|
35
|
#include <STM32ADC.h>
|
36
|
36
|
|
37
|
|
-//#include <Wire.h>
|
38
|
|
-
|
39
|
37
|
// --------------------------------------------------------------------------
|
40
|
38
|
// Externals
|
41
|
39
|
// --------------------------------------------------------------------------
|
42
|
40
|
|
43
|
41
|
// --------------------------------------------------------------------------
|
44
|
|
-// Local defines
|
|
42
|
+// Types
|
45
|
43
|
// --------------------------------------------------------------------------
|
46
|
44
|
|
|
45
|
+#define __I
|
|
46
|
+#define __IO
|
|
47
|
+ typedef struct
|
|
48
|
+ {
|
|
49
|
+ __I uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */
|
|
50
|
+ __IO uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */
|
|
51
|
+ __IO uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */
|
|
52
|
+ __IO uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */
|
|
53
|
+ __IO uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */
|
|
54
|
+ __IO uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */
|
|
55
|
+ __IO uint8_t SHP[12]; /*!< Offset: 0x018 (R/W) System Handlers Priority Registers (4-7, 8-11, 12-15) */
|
|
56
|
+ __IO uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */
|
|
57
|
+ __IO uint32_t CFSR; /*!< Offset: 0x028 (R/W) Configurable Fault Status Register */
|
|
58
|
+ __IO uint32_t HFSR; /*!< Offset: 0x02C (R/W) HardFault Status Register */
|
|
59
|
+ __IO uint32_t DFSR; /*!< Offset: 0x030 (R/W) Debug Fault Status Register */
|
|
60
|
+ __IO uint32_t MMFAR; /*!< Offset: 0x034 (R/W) MemManage Fault Address Register */
|
|
61
|
+ __IO uint32_t BFAR; /*!< Offset: 0x038 (R/W) BusFault Address Register */
|
|
62
|
+ __IO uint32_t AFSR; /*!< Offset: 0x03C (R/W) Auxiliary Fault Status Register */
|
|
63
|
+ __I uint32_t PFR[2]; /*!< Offset: 0x040 (R/ ) Processor Feature Register */
|
|
64
|
+ __I uint32_t DFR; /*!< Offset: 0x048 (R/ ) Debug Feature Register */
|
|
65
|
+ __I uint32_t ADR; /*!< Offset: 0x04C (R/ ) Auxiliary Feature Register */
|
|
66
|
+ __I uint32_t MMFR[4]; /*!< Offset: 0x050 (R/ ) Memory Model Feature Register */
|
|
67
|
+ __I uint32_t ISAR[5]; /*!< Offset: 0x060 (R/ ) Instruction Set Attributes Register */
|
|
68
|
+ uint32_t RESERVED0[5];
|
|
69
|
+ __IO uint32_t CPACR; /*!< Offset: 0x088 (R/W) Coprocessor Access Control Register */
|
|
70
|
+ } SCB_Type;
|
|
71
|
+
|
47
|
72
|
// --------------------------------------------------------------------------
|
48
|
|
-// Types
|
|
73
|
+// Variables
|
49
|
74
|
// --------------------------------------------------------------------------
|
50
|
75
|
|
51
|
76
|
// --------------------------------------------------------------------------
|
52
|
|
-// Variables
|
|
77
|
+// Local defines
|
53
|
78
|
// --------------------------------------------------------------------------
|
|
79
|
+#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
|
|
80
|
+#define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */
|
|
81
|
+
|
|
82
|
+#define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */
|
|
83
|
+
|
|
84
|
+/* SCB Application Interrupt and Reset Control Register Definitions */
|
|
85
|
+#define SCB_AIRCR_VECTKEY_Pos 16 /*!< SCB AIRCR: VECTKEY Position */
|
|
86
|
+#define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */
|
|
87
|
+
|
|
88
|
+#define SCB_AIRCR_PRIGROUP_Pos 8 /*!< SCB AIRCR: PRIGROUP Position */
|
|
89
|
+#define SCB_AIRCR_PRIGROUP_Msk (7UL << SCB_AIRCR_PRIGROUP_Pos) /*!< SCB AIRCR: PRIGROUP Mask */
|
54
|
90
|
|
55
|
91
|
// --------------------------------------------------------------------------
|
56
|
92
|
// Public Variables
|
|
@@ -123,11 +159,26 @@ uint16_t HAL_adc_results[ADC_PIN_COUNT];
|
123
|
159
|
// --------------------------------------------------------------------------
|
124
|
160
|
// Private functions
|
125
|
161
|
// --------------------------------------------------------------------------
|
|
162
|
+static void NVIC_SetPriorityGrouping(uint32_t PriorityGroup) {
|
|
163
|
+ uint32_t reg_value;
|
|
164
|
+ uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07); /* only values 0..7 are used */
|
|
165
|
+
|
|
166
|
+ reg_value = SCB->AIRCR; /* read old register configuration */
|
|
167
|
+ reg_value &= ~(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk); /* clear bits to change */
|
|
168
|
+ reg_value = (reg_value |
|
|
169
|
+ ((uint32_t)0x5FA << SCB_AIRCR_VECTKEY_Pos) |
|
|
170
|
+ (PriorityGroupTmp << 8)); /* Insert write key and priorty group */
|
|
171
|
+ SCB->AIRCR = reg_value;
|
|
172
|
+}
|
126
|
173
|
|
127
|
174
|
// --------------------------------------------------------------------------
|
128
|
175
|
// Public functions
|
129
|
176
|
// --------------------------------------------------------------------------
|
130
|
177
|
|
|
178
|
+void HAL_init(void) {
|
|
179
|
+ NVIC_SetPriorityGrouping(0x3);
|
|
180
|
+}
|
|
181
|
+
|
131
|
182
|
/* VGPV Done with defines
|
132
|
183
|
// disable interrupts
|
133
|
184
|
void cli(void) { noInterrupts(); }
|