1 | /**
|
2 | ******************************************************************************
|
3 | * File Name : main.c
|
4 | * Description : Main program body
|
5 | ******************************************************************************
|
6 | *
|
7 | * COPYRIGHT(c) 2016 STMicroelectronics
|
8 | *
|
9 | * Redistribution and use in source and binary forms, with or without modification,
|
10 | * are permitted provided that the following conditions are met:
|
11 | * 1. Redistributions of source code must retain the above copyright notice,
|
12 | * this list of conditions and the following disclaimer.
|
13 | * 2. Redistributions in binary form must reproduce the above copyright notice,
|
14 | * this list of conditions and the following disclaimer in the documentation
|
15 | * and/or other materials provided with the distribution.
|
16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
|
17 | * may be used to endorse or promote products derived from this software
|
18 | * without specific prior written permission.
|
19 | *
|
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 | *
|
31 | ******************************************************************************
|
32 | */
|
33 | /* Includes ------------------------------------------------------------------*/
|
34 | #include "main.h"
|
35 | #include "stm32f4xx_hal.h"
|
36 |
|
37 | /* USER CODE BEGIN Includes */
|
38 |
|
39 | #include "WaveData.h"
|
40 |
|
41 |
|
42 |
|
43 | #define CORE_I2C_ADDRESS 0x33
|
44 | #define CODEC_I2C_ADDRESS 0x94
|
45 |
|
46 | #define CODEC_MAPBYTE_INC 0x80
|
47 |
|
48 | //register map bytes for CS42L22 (see page 35)
|
49 | #define CODEC_MAP_CHIP_ID 0x01
|
50 | #define CODEC_MAP_PWR_CTRL1 0x02
|
51 | #define CODEC_MAP_PWR_CTRL2 0x04
|
52 | #define CODEC_MAP_CLK_CTRL 0x05
|
53 | #define CODEC_MAP_IF_CTRL1 0x06
|
54 | #define CODEC_MAP_IF_CTRL2 0x07
|
55 | #define CODEC_MAP_PASSTHROUGH_A_SELECT 0x08
|
56 | #define CODEC_MAP_PASSTHROUGH_B_SELECT 0x09
|
57 | #define CODEC_MAP_ANALOG_SET 0x0A
|
58 | #define CODEC_MAP_PASSTHROUGH_GANG_CTRL 0x0C
|
59 | #define CODEC_MAP_PLAYBACK_CTRL1 0x0D
|
60 | #define CODEC_MAP_MISC_CTRL 0x0E
|
61 | #define CODEC_MAP_PLAYBACK_CTRL2 0x0F
|
62 | #define CODEC_MAP_PASSTHROUGH_A_VOL 0x14
|
63 | #define CODEC_MAP_PASSTHROUGH_B_VOL 0x15
|
64 | #define CODEC_MAP_PCMA_VOL 0x1A
|
65 | #define CODEC_MAP_PCMB_VOL 0x1B
|
66 | #define CODEC_MAP_BEEP_FREQ_ONTIME 0x1C
|
67 | #define CODEC_MAP_BEEP_VOL_OFFTIME 0x1D
|
68 | #define CODEC_MAP_BEEP_TONE_CFG 0x1E
|
69 | #define CODEC_MAP_TONE_CTRL 0x1F
|
70 | #define CODEC_MAP_MASTER_A_VOL 0x20
|
71 | #define CODEC_MAP_MASTER_B_VOL 0x21
|
72 | #define CODEC_MAP_HP_A_VOL 0x22
|
73 | #define CODEC_MAP_HP_B_VOL 0x23
|
74 | #define CODEC_MAP_SPEAK_A_VOL 0x24
|
75 | #define CODEC_MAP_SPEAK_B_VOL 0x25
|
76 | #define CODEC_MAP_CH_MIX_SWAP 0x26
|
77 | #define CODEC_MAP_LIMIT_CTRL1 0x27
|
78 | #define CODEC_MAP_LIMIT_CTRL2 0x28
|
79 | #define CODEC_MAP_LIMIT_ATTACK 0x29
|
80 | #define CODEC_MAP_OVFL_CLK_STATUS 0x2E
|
81 | #define CODEC_MAP_BATT_COMP 0x2F
|
82 | #define CODEC_MAP_VP_BATT_LEVEL 0x30
|
83 | #define CODEC_MAP_SPEAK_STATUS 0x31
|
84 | #define CODEC_MAP_CHARGE_PUMP_FREQ 0x34
|
85 |
|
86 | /* USER CODE END Includes */
|
87 |
|
88 | /* Private variables ---------------------------------------------------------*/
|
89 | I2C_HandleTypeDef hi2c1;
|
90 |
|
91 | I2S_HandleTypeDef hi2s3;
|
92 | DMA_HandleTypeDef hdma_spi3_tx;
|
93 |
|
94 | /* USER CODE BEGIN PV */
|
95 | /* Private variables ---------------------------------------------------------*/
|
96 |
|
97 | /* USER CODE END PV */
|
98 |
|
99 | /* Private function prototypes -----------------------------------------------*/
|
100 | void SystemClock_Config(void);
|
101 | void Error_Handler(void);
|
102 | static void MX_GPIO_Init(void);
|
103 | static void MX_DMA_Init(void);
|
104 | static void MX_I2C1_Init(void);
|
105 | static void MX_I2S3_Init(void);
|
106 |
|
107 | /* USER CODE BEGIN PFP */
|
108 | /* Private function prototypes -----------------------------------------------*/
|
109 |
|
110 | /* USER CODE END PFP */
|
111 |
|
112 | /* USER CODE BEGIN 0 */
|
113 |
|
114 | void send_codec_ctrl(uint8_t *werte, uint8_t laenge)
|
115 | {
|
116 | while( HAL_I2C_Master_Transmit(&hi2c1, CODEC_I2C_ADDRESS, werte, laenge, 1000) !=HAL_OK){}
|
117 |
|
118 | }
|
119 |
|
120 | uint8_t read_codec_register(uint8_t regValue)
|
121 | {
|
122 | uint8_t RxBuffer[1];
|
123 | HAL_I2C_Mem_Read(&hi2c1, CODEC_I2C_ADDRESS, regValue, I2C_MEMADD_SIZE_8BIT, RxBuffer, 1, 10000);
|
124 | return RxBuffer[0];
|
125 | }
|
126 |
|
127 | void codec_ctrl_init()
|
128 | {
|
129 |
|
130 | uint8_t CodecCommandBuffer[5];
|
131 |
|
132 | uint8_t regValue = 0xFF;
|
133 | HAL_GPIO_WritePin(GPIOD, LD4_Pin|Audio_RST_Pin, GPIO_PIN_SET);
|
134 |
|
135 | HAL_Delay(1000);
|
136 |
|
137 | //keep codec OFF
|
138 | CodecCommandBuffer[0] = CODEC_MAP_PLAYBACK_CTRL1;
|
139 | CodecCommandBuffer[1] = 0x01;
|
140 | send_codec_ctrl(CodecCommandBuffer, 2);
|
141 |
|
142 | //begin initialization sequence (p. 32)
|
143 | CodecCommandBuffer[0] = 0x00;
|
144 | CodecCommandBuffer[1] = 0x99;
|
145 | send_codec_ctrl(CodecCommandBuffer, 2);
|
146 |
|
147 | CodecCommandBuffer[0] = 0x47;
|
148 | CodecCommandBuffer[1] = 0x80;
|
149 | send_codec_ctrl(CodecCommandBuffer, 2);
|
150 |
|
151 | regValue = read_codec_register(0x32);
|
152 |
|
153 | CodecCommandBuffer[0] = 0x32;
|
154 | CodecCommandBuffer[1] = regValue | 0x80;
|
155 | send_codec_ctrl(CodecCommandBuffer, 2);
|
156 |
|
157 | regValue = read_codec_register(0x32);
|
158 |
|
159 | CodecCommandBuffer[0] = 0x32;
|
160 | CodecCommandBuffer[1] = regValue & (~0x80);
|
161 | send_codec_ctrl(CodecCommandBuffer, 2);
|
162 |
|
163 | CodecCommandBuffer[0] = 0x00;
|
164 | CodecCommandBuffer[1] = 0x00;
|
165 | send_codec_ctrl(CodecCommandBuffer, 2);
|
166 | //end of initialization sequence
|
167 |
|
168 | CodecCommandBuffer[0] = CODEC_MAP_PWR_CTRL2;
|
169 | CodecCommandBuffer[1] = 0xAF;
|
170 | send_codec_ctrl(CodecCommandBuffer, 2);
|
171 |
|
172 | CodecCommandBuffer[0] = CODEC_MAP_PLAYBACK_CTRL1;
|
173 | CodecCommandBuffer[1] = 0x70;
|
174 | send_codec_ctrl(CodecCommandBuffer, 2);
|
175 |
|
176 | CodecCommandBuffer[0] = CODEC_MAP_CLK_CTRL;
|
177 | CodecCommandBuffer[1] = 0x81; //auto detect clock
|
178 | send_codec_ctrl(CodecCommandBuffer, 2);
|
179 |
|
180 | CodecCommandBuffer[0] = CODEC_MAP_IF_CTRL1;
|
181 | CodecCommandBuffer[1] = 0x07;
|
182 | send_codec_ctrl(CodecCommandBuffer, 2);
|
183 |
|
184 | CodecCommandBuffer[0] = 0x0A;
|
185 | CodecCommandBuffer[1] = 0x00;
|
186 | send_codec_ctrl(CodecCommandBuffer, 2);
|
187 |
|
188 | CodecCommandBuffer[0] = 0x27;
|
189 | CodecCommandBuffer[1] = 0x00;
|
190 | send_codec_ctrl(CodecCommandBuffer, 2);
|
191 |
|
192 | CodecCommandBuffer[0] = 0x1A | CODEC_MAPBYTE_INC;
|
193 | CodecCommandBuffer[1] = 0x0A;
|
194 | CodecCommandBuffer[2] = 0x0A;
|
195 | send_codec_ctrl(CodecCommandBuffer, 3);
|
196 |
|
197 | CodecCommandBuffer[0] = 0x1F;
|
198 | CodecCommandBuffer[1] = 0x0F;
|
199 | send_codec_ctrl(CodecCommandBuffer, 2);
|
200 |
|
201 | CodecCommandBuffer[0] = CODEC_MAP_PWR_CTRL1;
|
202 | CodecCommandBuffer[1] = 0x9E;
|
203 | send_codec_ctrl(CodecCommandBuffer, 2);
|
204 |
|
205 | /*
|
206 | CodecCommandBuffer[0] = CODEC_MAP_HP_A_VOL;
|
207 | CodecCommandBuffer[1] = 0x34;
|
208 | send_codec_ctrl(CodecCommandBuffer, 2);
|
209 |
|
210 | CodecCommandBuffer[0] = CODEC_MAP_HP_B_VOL;
|
211 | CodecCommandBuffer[1] = 0x34;
|
212 | send_codec_ctrl(CodecCommandBuffer, 2);
|
213 | */
|
214 | HAL_GPIO_WritePin(GPIOD, LD4_Pin, GPIO_PIN_RESET);
|
215 | }
|
216 |
|
217 | /* USER CODE END 0 */
|
218 |
|
219 | int main(void)
|
220 | {
|
221 |
|
222 | /* USER CODE BEGIN 1 */
|
223 |
|
224 | /* USER CODE END 1 */
|
225 |
|
226 | /* MCU Configuration----------------------------------------------------------*/
|
227 |
|
228 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
229 | HAL_Init();
|
230 |
|
231 | /* Configure the system clock */
|
232 | SystemClock_Config();
|
233 |
|
234 | /* Initialize all configured peripherals */
|
235 | MX_GPIO_Init();
|
236 | MX_DMA_Init();
|
237 | MX_I2C1_Init();
|
238 | MX_I2S3_Init();
|
239 |
|
240 | /* USER CODE BEGIN 2 */
|
241 | codec_ctrl_init();
|
242 |
|
243 |
|
244 | /* USER CODE END 2 */
|
245 |
|
246 | /* Infinite loop */
|
247 | /* USER CODE BEGIN WHILE */
|
248 | while (1)
|
249 | {
|
250 | HAL_I2S_Transmit(&hi2s3,(uint16_t *)sound0,2048,100);
|
251 | //HAL_I2S_Transmit(&hi2s3,(uint16_t *)result_sound,2048,100);
|
252 |
|
253 |
|
254 |
|
255 | /* USER CODE END WHILE */
|
256 |
|
257 | /* USER CODE BEGIN 3 */
|
258 |
|
259 | }
|
260 | /* USER CODE END 3 */
|
261 |
|
262 | }
|
263 |
|
264 | /** System Clock Configuration
|
265 | */
|
266 | void SystemClock_Config(void)
|
267 | {
|
268 |
|
269 | RCC_OscInitTypeDef RCC_OscInitStruct;
|
270 | RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
271 | RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
|
272 |
|
273 | /**Configure the main internal regulator output voltage
|
274 | */
|
275 | __HAL_RCC_PWR_CLK_ENABLE();
|
276 |
|
277 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
|
278 |
|
279 | /**Initializes the CPU, AHB and APB busses clocks
|
280 | */
|
281 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
282 | RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
283 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
284 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
285 | RCC_OscInitStruct.PLL.PLLM = 8;
|
286 | RCC_OscInitStruct.PLL.PLLN = 336;
|
287 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
288 | RCC_OscInitStruct.PLL.PLLQ = 7;
|
289 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
290 | {
|
291 | Error_Handler();
|
292 | }
|
293 |
|
294 | /**Initializes the CPU, AHB and APB busses clocks
|
295 | */
|
296 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
297 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
298 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
299 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
300 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
|
301 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
302 |
|
303 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
|
304 | {
|
305 | Error_Handler();
|
306 | }
|
307 |
|
308 | PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2S;
|
309 | PeriphClkInitStruct.PLLI2S.PLLI2SN = 352;
|
310 | PeriphClkInitStruct.PLLI2S.PLLI2SR = 2;
|
311 | if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
312 | {
|
313 | Error_Handler();
|
314 | }
|
315 |
|
316 | /**Configure the Systick interrupt time
|
317 | */
|
318 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
|
319 |
|
320 | /**Configure the Systick
|
321 | */
|
322 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
|
323 |
|
324 | /* SysTick_IRQn interrupt configuration */
|
325 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
|
326 | }
|
327 |
|
328 | /* I2C1 init function */
|
329 | static void MX_I2C1_Init(void)
|
330 | {
|
331 |
|
332 | hi2c1.Instance = I2C1;
|
333 | hi2c1.Init.ClockSpeed = 100000;
|
334 | hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
|
335 | hi2c1.Init.OwnAddress1 = 0;
|
336 | hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
337 | hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
338 | hi2c1.Init.OwnAddress2 = 0;
|
339 | hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
340 | hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
341 | if (HAL_I2C_Init(&hi2c1) != HAL_OK)
|
342 | {
|
343 | Error_Handler();
|
344 | }
|
345 |
|
346 | }
|
347 |
|
348 | /* I2S3 init function */
|
349 | static void MX_I2S3_Init(void)
|
350 | {
|
351 |
|
352 | hi2s3.Instance = SPI3;
|
353 | hi2s3.Init.Mode = I2S_MODE_MASTER_TX;
|
354 | hi2s3.Init.Standard = I2S_STANDARD_PHILIPS;
|
355 | hi2s3.Init.DataFormat = I2S_DATAFORMAT_16B;
|
356 | hi2s3.Init.MCLKOutput = I2S_MCLKOUTPUT_ENABLE;
|
357 | hi2s3.Init.AudioFreq = I2S_AUDIOFREQ_8K;
|
358 | hi2s3.Init.CPOL = I2S_CPOL_LOW;
|
359 | hi2s3.Init.ClockSource = I2S_CLOCK_PLL;
|
360 | hi2s3.Init.FullDuplexMode = I2S_FULLDUPLEXMODE_ENABLE;
|
361 | if (HAL_I2S_Init(&hi2s3) != HAL_OK)
|
362 | {
|
363 | Error_Handler();
|
364 | }
|
365 |
|
366 | }
|
367 |
|
368 | /**
|
369 | * Enable DMA controller clock
|
370 | */
|
371 | static void MX_DMA_Init(void)
|
372 | {
|
373 | /* DMA controller clock enable */
|
374 | __HAL_RCC_DMA1_CLK_ENABLE();
|
375 |
|
376 | /* DMA interrupt init */
|
377 | /* DMA1_Stream5_IRQn interrupt configuration */
|
378 | HAL_NVIC_SetPriority(DMA1_Stream5_IRQn, 0, 0);
|
379 | HAL_NVIC_EnableIRQ(DMA1_Stream5_IRQn);
|
380 |
|
381 | }
|
382 |
|
383 | /** Configure pins as
|
384 | * Analog
|
385 | * Input
|
386 | * Output
|
387 | * EVENT_OUT
|
388 | * EXTI
|
389 | PC3 ------> I2S2_SD
|
390 | PA5 ------> SPI1_SCK
|
391 | PA6 ------> SPI1_MISO
|
392 | PA7 ------> SPI1_MOSI
|
393 | PB10 ------> I2S2_CK
|
394 | PA9 ------> USB_OTG_FS_VBUS
|
395 | PA10 ------> USB_OTG_FS_ID
|
396 | PA11 ------> USB_OTG_FS_DM
|
397 | PA12 ------> USB_OTG_FS_DP
|
398 | */
|
399 | static void MX_GPIO_Init(void)
|
400 | {
|
401 |
|
402 | GPIO_InitTypeDef GPIO_InitStruct;
|
403 |
|
404 | /* GPIO Ports Clock Enable */
|
405 | __HAL_RCC_GPIOE_CLK_ENABLE();
|
406 | __HAL_RCC_GPIOC_CLK_ENABLE();
|
407 | __HAL_RCC_GPIOH_CLK_ENABLE();
|
408 | __HAL_RCC_GPIOA_CLK_ENABLE();
|
409 | __HAL_RCC_GPIOB_CLK_ENABLE();
|
410 | __HAL_RCC_GPIOD_CLK_ENABLE();
|
411 |
|
412 | /*Configure GPIO pin Output Level */
|
413 | HAL_GPIO_WritePin(CS_I2C_SPI_GPIO_Port, CS_I2C_SPI_Pin, GPIO_PIN_RESET);
|
414 |
|
415 | /*Configure GPIO pin Output Level */
|
416 | HAL_GPIO_WritePin(OTG_FS_PowerSwitchOn_GPIO_Port, OTG_FS_PowerSwitchOn_Pin, GPIO_PIN_SET);
|
417 |
|
418 | /*Configure GPIO pin Output Level */
|
419 | HAL_GPIO_WritePin(GPIOD, LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin
|
420 | |Audio_RST_Pin, GPIO_PIN_RESET);
|
421 |
|
422 | /*Configure GPIO pin : CS_I2C_SPI_Pin */
|
423 | GPIO_InitStruct.Pin = CS_I2C_SPI_Pin;
|
424 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
425 | GPIO_InitStruct.Pull = GPIO_NOPULL;
|
426 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
427 | HAL_GPIO_Init(CS_I2C_SPI_GPIO_Port, &GPIO_InitStruct);
|
428 |
|
429 | /*Configure GPIO pin : OTG_FS_PowerSwitchOn_Pin */
|
430 | GPIO_InitStruct.Pin = OTG_FS_PowerSwitchOn_Pin;
|
431 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
432 | GPIO_InitStruct.Pull = GPIO_NOPULL;
|
433 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
434 | HAL_GPIO_Init(OTG_FS_PowerSwitchOn_GPIO_Port, &GPIO_InitStruct);
|
435 |
|
436 | /*Configure GPIO pin : PDM_OUT_Pin */
|
437 | GPIO_InitStruct.Pin = PDM_OUT_Pin;
|
438 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
439 | GPIO_InitStruct.Pull = GPIO_NOPULL;
|
440 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
441 | GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
|
442 | HAL_GPIO_Init(PDM_OUT_GPIO_Port, &GPIO_InitStruct);
|
443 |
|
444 | /*Configure GPIO pins : PA5 PA6 PA7 */
|
445 | GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
|
446 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
447 | GPIO_InitStruct.Pull = GPIO_NOPULL;
|
448 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
449 | GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
|
450 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
451 |
|
452 | /*Configure GPIO pin : BOOT1_Pin */
|
453 | GPIO_InitStruct.Pin = BOOT1_Pin;
|
454 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
455 | GPIO_InitStruct.Pull = GPIO_NOPULL;
|
456 | HAL_GPIO_Init(BOOT1_GPIO_Port, &GPIO_InitStruct);
|
457 |
|
458 | /*Configure GPIO pin : CLK_IN_Pin */
|
459 | GPIO_InitStruct.Pin = CLK_IN_Pin;
|
460 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
461 | GPIO_InitStruct.Pull = GPIO_NOPULL;
|
462 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
463 | GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
|
464 | HAL_GPIO_Init(CLK_IN_GPIO_Port, &GPIO_InitStruct);
|
465 |
|
466 | /*Configure GPIO pins : LD4_Pin LD3_Pin LD5_Pin LD6_Pin
|
467 | Audio_RST_Pin */
|
468 | GPIO_InitStruct.Pin = LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin
|
469 | |Audio_RST_Pin;
|
470 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
471 | GPIO_InitStruct.Pull = GPIO_NOPULL;
|
472 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
473 | HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
474 |
|
475 | /*Configure GPIO pin : VBUS_FS_Pin */
|
476 | GPIO_InitStruct.Pin = VBUS_FS_Pin;
|
477 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
478 | GPIO_InitStruct.Pull = GPIO_NOPULL;
|
479 | HAL_GPIO_Init(VBUS_FS_GPIO_Port, &GPIO_InitStruct);
|
480 |
|
481 | /*Configure GPIO pins : OTG_FS_ID_Pin OTG_FS_DM_Pin OTG_FS_DP_Pin */
|
482 | GPIO_InitStruct.Pin = OTG_FS_ID_Pin|OTG_FS_DM_Pin|OTG_FS_DP_Pin;
|
483 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
484 | GPIO_InitStruct.Pull = GPIO_NOPULL;
|
485 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
486 | GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
|
487 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
488 |
|
489 | /*Configure GPIO pin : OTG_FS_OverCurrent_Pin */
|
490 | GPIO_InitStruct.Pin = OTG_FS_OverCurrent_Pin;
|
491 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
492 | GPIO_InitStruct.Pull = GPIO_NOPULL;
|
493 | HAL_GPIO_Init(OTG_FS_OverCurrent_GPIO_Port, &GPIO_InitStruct);
|
494 |
|
495 | /*Configure GPIO pin : MEMS_INT1_Pin */
|
496 | GPIO_InitStruct.Pin = MEMS_INT1_Pin;
|
497 | GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
498 | GPIO_InitStruct.Pull = GPIO_NOPULL;
|
499 | HAL_GPIO_Init(MEMS_INT1_GPIO_Port, &GPIO_InitStruct);
|
500 |
|
501 | /*Configure GPIO pin : MEMS_INT2_Pin */
|
502 | GPIO_InitStruct.Pin = MEMS_INT2_Pin;
|
503 | GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
|
504 | GPIO_InitStruct.Pull = GPIO_NOPULL;
|
505 | HAL_GPIO_Init(MEMS_INT2_GPIO_Port, &GPIO_InitStruct);
|
506 |
|
507 | }
|
508 |
|
509 | /* USER CODE BEGIN 4 */
|
510 |
|
511 | /* USER CODE END 4 */
|
512 |
|
513 | /**
|
514 | * @brief This function is executed in case of error occurrence.
|
515 | * @param None
|
516 | * @retval None
|
517 | */
|
518 | void Error_Handler(void)
|
519 | {
|
520 | /* USER CODE BEGIN Error_Handler */
|
521 | /* User can add his own implementation to report the HAL error return state */
|
522 | while(1)
|
523 | {
|
524 | }
|
525 | /* USER CODE END Error_Handler */
|
526 | }
|
527 |
|
528 | #ifdef USE_FULL_ASSERT
|
529 |
|
530 | /**
|
531 | * @brief Reports the name of the source file and the source line number
|
532 | * where the assert_param error has occurred.
|
533 | * @param file: pointer to the source file name
|
534 | * @param line: assert_param error line source number
|
535 | * @retval None
|
536 | */
|
537 | void assert_failed(uint8_t* file, uint32_t line)
|
538 | {
|
539 | /* USER CODE BEGIN 6 */
|
540 | /* User can add his own implementation to report the file name and line number,
|
541 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
542 | /* USER CODE END 6 */
|
543 |
|
544 | }
|
545 |
|
546 | #endif
|
547 |
|
548 | /**
|
549 | * @}
|
550 | */
|
551 |
|
552 | /**
|
553 | * @}
|
554 | */
|
555 |
|
556 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|