1 | /* USER CODE BEGIN Header */ |
---|
2 | /** |
---|
3 | ****************************************************************************** |
---|
4 | * @file sdmmc.c |
---|
5 | * @brief This file provides code for the configuration |
---|
6 | * of the SDMMC instances. |
---|
7 | ****************************************************************************** |
---|
8 | * @attention |
---|
9 | * |
---|
10 | * Copyright (c) 2024 STMicroelectronics. |
---|
11 | * All rights reserved. |
---|
12 | * |
---|
13 | * This software is licensed under terms that can be found in the LICENSE file |
---|
14 | * in the root directory of this software component. |
---|
15 | * If no LICENSE file comes with this software, it is provided AS-IS. |
---|
16 | * |
---|
17 | ****************************************************************************** |
---|
18 | */ |
---|
19 | /* USER CODE END Header */ |
---|
20 | /* Includes ------------------------------------------------------------------*/ |
---|
21 | #include "sdmmc.h" |
---|
22 | |
---|
23 | /* USER CODE BEGIN 0 */ |
---|
24 | |
---|
25 | #include <stdio.h> |
---|
26 | |
---|
27 | /* USER CODE END 0 */ |
---|
28 | |
---|
29 | SD_HandleTypeDef hsd1; |
---|
30 | |
---|
31 | /* SDMMC1 init function */ |
---|
32 | |
---|
33 | void MX_SDMMC1_SD_Init(void) |
---|
34 | { |
---|
35 | |
---|
36 | /* USER CODE BEGIN SDMMC1_Init 0 */ |
---|
37 | |
---|
38 | /* USER CODE END SDMMC1_Init 0 */ |
---|
39 | |
---|
40 | /* USER CODE BEGIN SDMMC1_Init 1 */ |
---|
41 | |
---|
42 | /* USER CODE END SDMMC1_Init 1 */ |
---|
43 | hsd1.Instance = SDMMC1; |
---|
44 | hsd1.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING; |
---|
45 | hsd1.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_ENABLE; |
---|
46 | hsd1.Init.BusWide = SDMMC_BUS_WIDE_4B; |
---|
47 | hsd1.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_ENABLE; |
---|
48 | hsd1.Init.ClockDiv = 2; |
---|
49 | /* USER CODE BEGIN SDMMC1_Init 2 */ |
---|
50 | |
---|
51 | /* USER CODE END SDMMC1_Init 2 */ |
---|
52 | |
---|
53 | } |
---|
54 | |
---|
55 | void HAL_SD_MspInit(SD_HandleTypeDef* sdHandle) |
---|
56 | { |
---|
57 | |
---|
58 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
---|
59 | if(sdHandle->Instance==SDMMC1) |
---|
60 | { |
---|
61 | /* USER CODE BEGIN SDMMC1_MspInit 0 */ |
---|
62 | |
---|
63 | /* USER CODE END SDMMC1_MspInit 0 */ |
---|
64 | /* SDMMC1 clock enable */ |
---|
65 | __HAL_RCC_SDMMC1_CLK_ENABLE(); |
---|
66 | |
---|
67 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
---|
68 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
---|
69 | /**SDMMC1 GPIO Configuration |
---|
70 | PC8 ------> SDMMC1_D0 |
---|
71 | PC9 ------> SDMMC1_D1 |
---|
72 | PC10 ------> SDMMC1_D2 |
---|
73 | PC11 ------> SDMMC1_D3 |
---|
74 | PC12 ------> SDMMC1_CK |
---|
75 | PD2 ------> SDMMC1_CMD |
---|
76 | */ |
---|
77 | GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11 |
---|
78 | |GPIO_PIN_12; |
---|
79 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
---|
80 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
---|
81 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
---|
82 | GPIO_InitStruct.Alternate = GPIO_AF12_SDMMC1; |
---|
83 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
---|
84 | |
---|
85 | GPIO_InitStruct.Pin = GPIO_PIN_2; |
---|
86 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
---|
87 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
---|
88 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
---|
89 | GPIO_InitStruct.Alternate = GPIO_AF12_SDMMC1; |
---|
90 | HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); |
---|
91 | |
---|
92 | /* SDMMC1 interrupt Init */ |
---|
93 | HAL_NVIC_SetPriority(SDMMC1_IRQn, 5, 0); |
---|
94 | HAL_NVIC_EnableIRQ(SDMMC1_IRQn); |
---|
95 | /* USER CODE BEGIN SDMMC1_MspInit 1 */ |
---|
96 | |
---|
97 | /* USER CODE END SDMMC1_MspInit 1 */ |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | void HAL_SD_MspDeInit(SD_HandleTypeDef* sdHandle) |
---|
102 | { |
---|
103 | |
---|
104 | if(sdHandle->Instance==SDMMC1) |
---|
105 | { |
---|
106 | /* USER CODE BEGIN SDMMC1_MspDeInit 0 */ |
---|
107 | |
---|
108 | /* USER CODE END SDMMC1_MspDeInit 0 */ |
---|
109 | /* Peripheral clock disable */ |
---|
110 | __HAL_RCC_SDMMC1_CLK_DISABLE(); |
---|
111 | |
---|
112 | /**SDMMC1 GPIO Configuration |
---|
113 | PC8 ------> SDMMC1_D0 |
---|
114 | PC9 ------> SDMMC1_D1 |
---|
115 | PC10 ------> SDMMC1_D2 |
---|
116 | PC11 ------> SDMMC1_D3 |
---|
117 | PC12 ------> SDMMC1_CK |
---|
118 | PD2 ------> SDMMC1_CMD |
---|
119 | */ |
---|
120 | HAL_GPIO_DeInit(GPIOC, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11 |
---|
121 | |GPIO_PIN_12); |
---|
122 | |
---|
123 | HAL_GPIO_DeInit(GPIOD, GPIO_PIN_2); |
---|
124 | |
---|
125 | /* SDMMC1 interrupt Deinit */ |
---|
126 | HAL_NVIC_DisableIRQ(SDMMC1_IRQn); |
---|
127 | /* USER CODE BEGIN SDMMC1_MspDeInit 1 */ |
---|
128 | |
---|
129 | /* USER CODE END SDMMC1_MspDeInit 1 */ |
---|
130 | } |
---|
131 | } |
---|
132 | |
---|
133 | /* USER CODE BEGIN 1 */ |
---|
134 | |
---|
135 | /* USER CODE END 1 */ |
---|