1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
30
31
32
33
34
35
41
42
43
44
45
46
47
48
49
50
53
54
55
60
61
62
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
141
142
143
144
145
146
147
148
149
150
151
152
153
154
156
157
158
159
160
161
162
163
164
169
193
194
199
200
201
202
203
204
205
206
207
208
209
210
211
216
224
225
226
245
246
249
250
/* ... */
#include "main.h"
/* ... */
/* ... */
Includes
uint8_t DemoIndex = 0;
BSP_DemoTypedef BSP_examples[]={
{ACCELERO_MEMS_Test, "LSM303DLHC", 0},
{GYRO_MEMS_Test, "L3GD20", 1},
{AudioPlay_Test, "CS43L22", 2},
{AudioRecord_Test, "MP45DT02", 3},
...};
__IO uint8_t UserPressButton = 0;
__IO uint32_t PauseResumeStatus = IDLE_STATUS;
__IO uint32_t PressCount = 0;
Private variables
static void SystemClock_Config(void);
Private function prototypes
/* ... */
int main(void)
{
/* ... */
HAL_Init();
BSP_LED_Init(LED3);
BSP_LED_Init(LED4);
BSP_LED_Init(LED5);
BSP_LED_Init(LED6);
SystemClock_Config();
BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI);
while (!UserPressButton) Toggle_Leds();
BSP_LED_Off(LED3);
BSP_LED_Off(LED4);
BSP_LED_Off(LED5);
BSP_LED_Off(LED6);
while (1)
{
UserPressButton = 0;
BSP_examples[DemoIndex++].DemoFunc();
if(DemoIndex >= COUNT_OF_EXAMPLE(BSP_examples))
{
DemoIndex = 0;
}if (DemoIndex >= COUNT_OF_EXAMPLE(BSP_examples)) { ... }
UserPressButton = 0;
while (!UserPressButton) Toggle_Leds();
BSP_LED_Off(LED3);
BSP_LED_Off(LED4);
BSP_LED_Off(LED5);
BSP_LED_Off(LED6);
}while (1) { ... }
}{ ... }
/* ... */
static void SystemClock_Config(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
__HAL_RCC_PWR_CLK_ENABLE();
/* ... */
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 8;
RCC_OscInitStruct.PLL.PLLN = 336;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
RCC_OscInitStruct.PLL.PLLQ = 7;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
/* ... */
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
}{ ... }
/* ... */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if (KEY_BUTTON_PIN == GPIO_Pin)
{
while (BSP_PB_GetState(BUTTON_KEY) != RESET);
UserPressButton = 1;
}if (KEY_BUTTON_PIN == GPIO_Pin) { ... }
if(ACCELERO_INT1_PIN == GPIO_Pin)
{
if (PressCount == 1)
{
PauseResumeStatus = RESUME_STATUS;
PressCount = 0;
}if (PressCount == 1) { ... }
else
{
PauseResumeStatus = PAUSE_STATUS;
PressCount = 1;
}else { ... }
}if (ACCELERO_INT1_PIN == GPIO_Pin) { ... }
}{ ... }
/* ... */
void Toggle_Leds(void)
{
BSP_LED_Toggle(LED3);
HAL_Delay(100);
BSP_LED_Toggle(LED4);
HAL_Delay(100);
BSP_LED_Toggle(LED5);
HAL_Delay(100);
BSP_LED_Toggle(LED6);
HAL_Delay(100);
}{ ... }
/* ... */
void Error_Handler(void)
{
BSP_LED_On(LED5);
while(1)
{
}while (1) { ... }
}{ ... }
#ifdef USE_FULL_ASSERT
/* ... */
void assert_failed(uint8_t* file, uint32_t line)
{
/* ... */
while (1)
{
}while (1) { ... }
}assert_failed (uint8_t* file, uint32_t line) { ... }
/* ... */#endif
/* ... */
/* ... */