STM32F469NI Discovery board drivers
Dependents: DISCO-F469NI_LCDTS_GUI_demo Configurable_Robots DISCO-F469NI_LCD_demo DISCO-F469NI_SD_demo ... more
Drivers/BSP/STM32469I-Discovery/stm32469i_discovery_sd.c@4:27609b3a44ed, 2021-06-09 (annotated)
- Committer:
- aa6164
- Date:
- Wed Jun 09 12:45:23 2021 +0000
- Revision:
- 4:27609b3a44ed
- Parent:
- 3:3cdfcc4f7c9d
Updated wait_ms() to thread_sleep_for() for Mbed OS 6+
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jerome Coutant
2:123b894b49dd
|
1
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
2
|
******************************************************************************
|
|
Jerome Coutant
2:123b894b49dd
|
3
|
* @file stm32469i_discovery_sd.c
|
|
Jerome Coutant
2:123b894b49dd
|
4
|
* @author MCD Application Team
|
|
Jerome Coutant
2:123b894b49dd
|
5
|
* @brief This file includes the uSD card driver mounted on STM32469I-Discovery
|
|
Jerome Coutant
2:123b894b49dd
|
6
|
* board.
|
|
Jerome Coutant
2:123b894b49dd
|
7
|
******************************************************************************
|
|
Jerome Coutant
2:123b894b49dd
|
8
|
* @attention
|
|
Jerome Coutant
2:123b894b49dd
|
9
|
*
|
|
Jerome Coutant
2:123b894b49dd
|
10
|
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
|
Jerome Coutant
2:123b894b49dd
|
11
|
*
|
|
Jerome Coutant
2:123b894b49dd
|
12
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
Jerome Coutant
2:123b894b49dd
|
13
|
* are permitted provided that the following conditions are met:
|
|
Jerome Coutant
2:123b894b49dd
|
14
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
Jerome Coutant
2:123b894b49dd
|
15
|
* this list of conditions and the following disclaimer.
|
|
Jerome Coutant
2:123b894b49dd
|
16
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
Jerome Coutant
2:123b894b49dd
|
17
|
* this list of conditions and the following disclaimer in the documentation
|
|
Jerome Coutant
2:123b894b49dd
|
18
|
* and/or other materials provided with the distribution.
|
|
Jerome Coutant
2:123b894b49dd
|
19
|
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
|
Jerome Coutant
2:123b894b49dd
|
20
|
* may be used to endorse or promote products derived from this software
|
|
Jerome Coutant
2:123b894b49dd
|
21
|
* without specific prior written permission.
|
|
Jerome Coutant
2:123b894b49dd
|
22
|
*
|
|
Jerome Coutant
2:123b894b49dd
|
23
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
Jerome Coutant
2:123b894b49dd
|
24
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
Jerome Coutant
2:123b894b49dd
|
25
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
Jerome Coutant
2:123b894b49dd
|
26
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
Jerome Coutant
2:123b894b49dd
|
27
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
Jerome Coutant
2:123b894b49dd
|
28
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
Jerome Coutant
2:123b894b49dd
|
29
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
Jerome Coutant
2:123b894b49dd
|
30
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
Jerome Coutant
2:123b894b49dd
|
31
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
Jerome Coutant
2:123b894b49dd
|
32
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Jerome Coutant
2:123b894b49dd
|
33
|
*
|
|
Jerome Coutant
2:123b894b49dd
|
34
|
******************************************************************************
|
|
Jerome Coutant
2:123b894b49dd
|
35
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
36
|
|
|
Jerome Coutant
2:123b894b49dd
|
37
|
/* File Info : -----------------------------------------------------------------
|
|
Jerome Coutant
2:123b894b49dd
|
38
|
User NOTES
|
|
Jerome Coutant
2:123b894b49dd
|
39
|
1. How To use this driver:
|
|
Jerome Coutant
2:123b894b49dd
|
40
|
--------------------------
|
|
Jerome Coutant
2:123b894b49dd
|
41
|
- This driver is used to drive the micro SD external card mounted on STM32469I-Discovery
|
|
Jerome Coutant
2:123b894b49dd
|
42
|
board.
|
|
Jerome Coutant
2:123b894b49dd
|
43
|
- This driver does not need a specific component driver for the micro SD device
|
|
Jerome Coutant
2:123b894b49dd
|
44
|
to be included with.
|
|
Jerome Coutant
2:123b894b49dd
|
45
|
|
|
Jerome Coutant
2:123b894b49dd
|
46
|
2. Driver description:
|
|
Jerome Coutant
2:123b894b49dd
|
47
|
---------------------
|
|
Jerome Coutant
2:123b894b49dd
|
48
|
+ Initialization steps:
|
|
Jerome Coutant
2:123b894b49dd
|
49
|
o Initialize the micro SD card using the BSP_SD_Init() function. This
|
|
Jerome Coutant
2:123b894b49dd
|
50
|
function includes the MSP layer hardware resources initialization and the
|
|
Jerome Coutant
2:123b894b49dd
|
51
|
SDIO interface configuration to interface with the external micro SD. It
|
|
Jerome Coutant
2:123b894b49dd
|
52
|
also includes the micro SD initialization sequence.
|
|
Jerome Coutant
2:123b894b49dd
|
53
|
o To check the SD card presence you can use the function BSP_SD_IsDetected() which
|
|
Jerome Coutant
2:123b894b49dd
|
54
|
returns the detection status
|
|
Jerome Coutant
2:123b894b49dd
|
55
|
o If SD presence detection interrupt mode is desired, you must configure the
|
|
Jerome Coutant
2:123b894b49dd
|
56
|
SD detection interrupt mode by calling the function BSP_SD_ITConfig(). The interrupt
|
|
Jerome Coutant
2:123b894b49dd
|
57
|
is generated as an external interrupt whenever the micro SD card is
|
|
Jerome Coutant
2:123b894b49dd
|
58
|
plugged/unplugged in/from the board.
|
|
Jerome Coutant
2:123b894b49dd
|
59
|
o The function BSP_SD_GetCardInfo() is used to get the micro SD card information
|
|
Jerome Coutant
2:123b894b49dd
|
60
|
which is stored in the structure "HAL_SD_CardInfoTypeDef".
|
|
Jerome Coutant
2:123b894b49dd
|
61
|
|
|
Jerome Coutant
2:123b894b49dd
|
62
|
+ Micro SD card operations
|
|
Jerome Coutant
2:123b894b49dd
|
63
|
o The micro SD card can be accessed with read/write block(s) operations once
|
|
Jerome Coutant
2:123b894b49dd
|
64
|
it is ready for access. The access can be performed whether using the polling
|
|
Jerome Coutant
2:123b894b49dd
|
65
|
mode by calling the functions BSP_SD_ReadBlocks()/BSP_SD_WriteBlocks(), or by DMA
|
|
Jerome Coutant
2:123b894b49dd
|
66
|
transfer using the functions BSP_SD_ReadBlocks_DMA()/BSP_SD_WriteBlocks_DMA()
|
|
Jerome Coutant
2:123b894b49dd
|
67
|
o The DMA transfer complete is used with interrupt mode. Once the SD transfer
|
|
Jerome Coutant
2:123b894b49dd
|
68
|
is complete, the SD interrupt is handled using the function BSP_SD_IRQHandler(),
|
|
Jerome Coutant
2:123b894b49dd
|
69
|
the DMA Tx/Rx transfer complete are handled using the functions
|
|
Jerome Coutant
2:123b894b49dd
|
70
|
BSP_SD_DMA_Tx_IRQHandler()/BSP_SD_DMA_Rx_IRQHandler(). The corresponding user callbacks
|
|
Jerome Coutant
2:123b894b49dd
|
71
|
are implemented by the user at application level.
|
|
Jerome Coutant
2:123b894b49dd
|
72
|
o The SD erase block(s) is performed using the function BSP_SD_Erase() with specifying
|
|
Jerome Coutant
2:123b894b49dd
|
73
|
the number of blocks to erase.
|
|
Jerome Coutant
2:123b894b49dd
|
74
|
o The SD runtime status is returned when calling the function BSP_SD_GetCardState().
|
|
Jerome Coutant
2:123b894b49dd
|
75
|
|
|
Jerome Coutant
2:123b894b49dd
|
76
|
------------------------------------------------------------------------------*/
|
|
Jerome Coutant
2:123b894b49dd
|
77
|
|
|
Jerome Coutant
2:123b894b49dd
|
78
|
/* Includes ------------------------------------------------------------------*/
|
|
Jerome Coutant
2:123b894b49dd
|
79
|
#include "stm32469i_discovery_sd.h"
|
|
Jerome Coutant
2:123b894b49dd
|
80
|
|
|
Jerome Coutant
2:123b894b49dd
|
81
|
/** @addtogroup BSP
|
|
Jerome Coutant
2:123b894b49dd
|
82
|
* @{
|
|
Jerome Coutant
2:123b894b49dd
|
83
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
84
|
|
|
Jerome Coutant
2:123b894b49dd
|
85
|
/** @addtogroup STM32469I_Discovery
|
|
Jerome Coutant
2:123b894b49dd
|
86
|
* @{
|
|
Jerome Coutant
2:123b894b49dd
|
87
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
88
|
|
|
Jerome Coutant
2:123b894b49dd
|
89
|
/** @defgroup STM32469I-Discovery_SD STM32469I Discovery SD
|
|
Jerome Coutant
2:123b894b49dd
|
90
|
* @{
|
|
Jerome Coutant
2:123b894b49dd
|
91
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
92
|
|
|
Jerome Coutant
2:123b894b49dd
|
93
|
|
|
Jerome Coutant
2:123b894b49dd
|
94
|
/** @defgroup STM32469I-Discovery_SD_Private_TypesDefinitions STM32469I Discovery SD Private TypesDef
|
|
Jerome Coutant
2:123b894b49dd
|
95
|
* @{
|
|
Jerome Coutant
2:123b894b49dd
|
96
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
97
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
98
|
* @}
|
|
Jerome Coutant
2:123b894b49dd
|
99
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
100
|
|
|
Jerome Coutant
2:123b894b49dd
|
101
|
/** @defgroup STM32469I-Discovery_SD_Private_Defines STM32469I Discovery SD Private Defines
|
|
Jerome Coutant
2:123b894b49dd
|
102
|
* @{
|
|
Jerome Coutant
2:123b894b49dd
|
103
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
104
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
105
|
* @}
|
|
Jerome Coutant
2:123b894b49dd
|
106
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
107
|
|
|
Jerome Coutant
2:123b894b49dd
|
108
|
/** @defgroup STM32469I-Discovery_SD_Private_Macros STM32469I Discovery SD Private Macro
|
|
Jerome Coutant
2:123b894b49dd
|
109
|
* @{
|
|
Jerome Coutant
2:123b894b49dd
|
110
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
111
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
112
|
* @}
|
|
Jerome Coutant
2:123b894b49dd
|
113
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
114
|
|
|
Jerome Coutant
2:123b894b49dd
|
115
|
/** @defgroup STM32469I-Discovery_SD_Private_Variables STM32469I Discovery SD Private Variables
|
|
Jerome Coutant
2:123b894b49dd
|
116
|
* @{
|
|
Jerome Coutant
2:123b894b49dd
|
117
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
118
|
SD_HandleTypeDef uSdHandle;
|
|
Jerome Coutant
2:123b894b49dd
|
119
|
|
|
Jerome Coutant
2:123b894b49dd
|
120
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
121
|
* @}
|
|
Jerome Coutant
2:123b894b49dd
|
122
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
123
|
|
|
Jerome Coutant
2:123b894b49dd
|
124
|
/** @defgroup STM32469I-Discovery_SD_Private_FunctionPrototypes STM32469I Discovery SD Private Prototypes
|
|
Jerome Coutant
2:123b894b49dd
|
125
|
* @{
|
|
Jerome Coutant
2:123b894b49dd
|
126
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
127
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
128
|
* @}
|
|
Jerome Coutant
2:123b894b49dd
|
129
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
130
|
|
|
Jerome Coutant
2:123b894b49dd
|
131
|
/** @defgroup STM32469I-Discovery_SD_Private_Functions STM32469I Discovery SD Private Functions
|
|
Jerome Coutant
2:123b894b49dd
|
132
|
* @{
|
|
Jerome Coutant
2:123b894b49dd
|
133
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
134
|
|
|
Jerome Coutant
2:123b894b49dd
|
135
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
136
|
* @brief Initializes the SD card device.
|
|
Jerome Coutant
2:123b894b49dd
|
137
|
* @retval SD status
|
|
Jerome Coutant
2:123b894b49dd
|
138
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
139
|
uint8_t BSP_SD_Init(void)
|
|
Jerome Coutant
2:123b894b49dd
|
140
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
141
|
uint8_t sd_state = MSD_OK;
|
|
Jerome Coutant
2:123b894b49dd
|
142
|
|
|
Jerome Coutant
2:123b894b49dd
|
143
|
/* PLLSAI is dedicated to LCD periph. Do not use it to get 48MHz*/
|
|
Jerome Coutant
2:123b894b49dd
|
144
|
|
|
Jerome Coutant
2:123b894b49dd
|
145
|
/* uSD device interface configuration */
|
|
Jerome Coutant
2:123b894b49dd
|
146
|
uSdHandle.Instance = SDIO;
|
|
Jerome Coutant
2:123b894b49dd
|
147
|
|
|
Jerome Coutant
2:123b894b49dd
|
148
|
uSdHandle.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;
|
|
Jerome Coutant
2:123b894b49dd
|
149
|
uSdHandle.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE;
|
|
Jerome Coutant
2:123b894b49dd
|
150
|
uSdHandle.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE;
|
|
Jerome Coutant
2:123b894b49dd
|
151
|
uSdHandle.Init.BusWide = SDIO_BUS_WIDE_1B;
|
|
Jerome Coutant
2:123b894b49dd
|
152
|
uSdHandle.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_ENABLE;
|
|
Jerome Coutant
2:123b894b49dd
|
153
|
uSdHandle.Init.ClockDiv = SDIO_TRANSFER_CLK_DIV;
|
|
Jerome Coutant
2:123b894b49dd
|
154
|
|
|
Jerome Coutant
2:123b894b49dd
|
155
|
/* Msp SD Detect pin initialization */
|
|
Jerome Coutant
2:123b894b49dd
|
156
|
BSP_SD_Detect_MspInit(&uSdHandle, NULL);
|
|
Jerome Coutant
2:123b894b49dd
|
157
|
if(BSP_SD_IsDetected() != SD_PRESENT) /* Check if SD card is present */
|
|
Jerome Coutant
2:123b894b49dd
|
158
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
159
|
return MSD_ERROR_SD_NOT_PRESENT;
|
|
Jerome Coutant
2:123b894b49dd
|
160
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
161
|
|
|
Jerome Coutant
2:123b894b49dd
|
162
|
/* Msp SD initialization */
|
|
Jerome Coutant
2:123b894b49dd
|
163
|
BSP_SD_MspInit(&uSdHandle, NULL);
|
|
Jerome Coutant
2:123b894b49dd
|
164
|
|
|
Jerome Coutant
2:123b894b49dd
|
165
|
/* HAL SD initialization */
|
|
Jerome Coutant
2:123b894b49dd
|
166
|
if(HAL_SD_Init(&uSdHandle) != HAL_OK)
|
|
Jerome Coutant
2:123b894b49dd
|
167
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
168
|
sd_state = MSD_ERROR;
|
|
Jerome Coutant
2:123b894b49dd
|
169
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
170
|
|
|
Jerome Coutant
2:123b894b49dd
|
171
|
/* Configure SD Bus width */
|
|
Jerome Coutant
2:123b894b49dd
|
172
|
if(sd_state == MSD_OK)
|
|
Jerome Coutant
2:123b894b49dd
|
173
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
174
|
/* Enable wide operation */
|
|
Jerome Coutant
2:123b894b49dd
|
175
|
if(HAL_SD_ConfigWideBusOperation(&uSdHandle, SDIO_BUS_WIDE_4B) != HAL_OK)
|
|
Jerome Coutant
2:123b894b49dd
|
176
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
177
|
sd_state = MSD_ERROR;
|
|
Jerome Coutant
2:123b894b49dd
|
178
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
179
|
else
|
|
Jerome Coutant
2:123b894b49dd
|
180
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
181
|
sd_state = MSD_OK;
|
|
Jerome Coutant
2:123b894b49dd
|
182
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
183
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
184
|
return sd_state;
|
|
Jerome Coutant
2:123b894b49dd
|
185
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
186
|
|
|
Jerome Coutant
2:123b894b49dd
|
187
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
188
|
* @brief DeInitializes the SD card device.
|
|
Jerome Coutant
2:123b894b49dd
|
189
|
* @retval SD status
|
|
Jerome Coutant
2:123b894b49dd
|
190
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
191
|
uint8_t BSP_SD_DeInit(void)
|
|
Jerome Coutant
2:123b894b49dd
|
192
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
193
|
uint8_t sd_state = MSD_OK;
|
|
Jerome Coutant
2:123b894b49dd
|
194
|
|
|
Jerome Coutant
2:123b894b49dd
|
195
|
uSdHandle.Instance = SDIO;
|
|
Jerome Coutant
2:123b894b49dd
|
196
|
|
|
Jerome Coutant
2:123b894b49dd
|
197
|
/* HAL SD deinitialization */
|
|
Jerome Coutant
2:123b894b49dd
|
198
|
if(HAL_SD_DeInit(&uSdHandle) != HAL_OK)
|
|
Jerome Coutant
2:123b894b49dd
|
199
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
200
|
sd_state = MSD_ERROR;
|
|
Jerome Coutant
2:123b894b49dd
|
201
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
202
|
|
|
Jerome Coutant
2:123b894b49dd
|
203
|
/* Msp SD deinitialization */
|
|
Jerome Coutant
2:123b894b49dd
|
204
|
uSdHandle.Instance = SDIO;
|
|
Jerome Coutant
2:123b894b49dd
|
205
|
BSP_SD_MspDeInit(&uSdHandle, NULL);
|
|
Jerome Coutant
2:123b894b49dd
|
206
|
|
|
Jerome Coutant
2:123b894b49dd
|
207
|
return sd_state;
|
|
Jerome Coutant
2:123b894b49dd
|
208
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
209
|
|
|
Jerome Coutant
2:123b894b49dd
|
210
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
211
|
* @brief Configures Interrupt mode for SD detection pin.
|
|
Jerome Coutant
2:123b894b49dd
|
212
|
* @retval Returns 0
|
|
Jerome Coutant
2:123b894b49dd
|
213
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
214
|
uint8_t BSP_SD_ITConfig(void)
|
|
Jerome Coutant
2:123b894b49dd
|
215
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
216
|
GPIO_InitTypeDef gpio_init_structure;
|
|
Jerome Coutant
2:123b894b49dd
|
217
|
|
|
Jerome Coutant
2:123b894b49dd
|
218
|
/* Configure Interrupt mode for SD detection pin */
|
|
Jerome Coutant
2:123b894b49dd
|
219
|
gpio_init_structure.Pin = SD_DETECT_PIN;
|
|
Jerome Coutant
2:123b894b49dd
|
220
|
gpio_init_structure.Pull = GPIO_PULLUP;
|
|
Jerome Coutant
2:123b894b49dd
|
221
|
gpio_init_structure.Speed = GPIO_SPEED_FAST;
|
|
Jerome Coutant
2:123b894b49dd
|
222
|
gpio_init_structure.Mode = GPIO_MODE_IT_RISING_FALLING;
|
|
Jerome Coutant
2:123b894b49dd
|
223
|
HAL_GPIO_Init(SD_DETECT_GPIO_PORT, &gpio_init_structure);
|
|
Jerome Coutant
2:123b894b49dd
|
224
|
|
|
Jerome Coutant
2:123b894b49dd
|
225
|
/* Enable and set SD detect EXTI Interrupt to the lowest priority */
|
|
Jerome Coutant
2:123b894b49dd
|
226
|
HAL_NVIC_SetPriority((IRQn_Type)(SD_DETECT_EXTI_IRQn), 0x0F, 0x00);
|
|
Jerome Coutant
2:123b894b49dd
|
227
|
HAL_NVIC_EnableIRQ((IRQn_Type)(SD_DETECT_EXTI_IRQn));
|
|
Jerome Coutant
2:123b894b49dd
|
228
|
|
|
Jerome Coutant
2:123b894b49dd
|
229
|
return MSD_OK;
|
|
Jerome Coutant
2:123b894b49dd
|
230
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
231
|
|
|
Jerome Coutant
2:123b894b49dd
|
232
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
233
|
* @brief Detects if SD card is correctly plugged in the memory slot or not.
|
|
Jerome Coutant
2:123b894b49dd
|
234
|
* @retval Returns if SD is detected or not
|
|
Jerome Coutant
2:123b894b49dd
|
235
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
236
|
uint8_t BSP_SD_IsDetected(void)
|
|
Jerome Coutant
2:123b894b49dd
|
237
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
238
|
__IO uint8_t status = SD_PRESENT;
|
|
Jerome Coutant
2:123b894b49dd
|
239
|
|
|
Jerome Coutant
2:123b894b49dd
|
240
|
/* Check SD card detect pin */
|
|
Jerome Coutant
2:123b894b49dd
|
241
|
if (HAL_GPIO_ReadPin(SD_DETECT_GPIO_PORT, SD_DETECT_PIN) == GPIO_PIN_SET)
|
|
Jerome Coutant
2:123b894b49dd
|
242
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
243
|
status = SD_NOT_PRESENT;
|
|
Jerome Coutant
2:123b894b49dd
|
244
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
245
|
|
|
Jerome Coutant
2:123b894b49dd
|
246
|
return status;
|
|
Jerome Coutant
2:123b894b49dd
|
247
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
248
|
|
|
Jerome Coutant
2:123b894b49dd
|
249
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
250
|
* @brief Reads block(s) from a specified address in an SD card, in polling mode.
|
|
Jerome Coutant
2:123b894b49dd
|
251
|
* @param pData: Pointer to the buffer that will contain the data to transmit
|
|
Jerome Coutant
2:123b894b49dd
|
252
|
* @param ReadAddr: Address from where data is to be read
|
|
Jerome Coutant
2:123b894b49dd
|
253
|
* @param NumOfBlocks: Number of SD blocks to read
|
|
Jerome Coutant
2:123b894b49dd
|
254
|
* @param Timeout: Timeout for read operation
|
|
Jerome Coutant
2:123b894b49dd
|
255
|
* @retval SD status
|
|
Jerome Coutant
2:123b894b49dd
|
256
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
257
|
uint8_t BSP_SD_ReadBlocks(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks, uint32_t Timeout)
|
|
Jerome Coutant
2:123b894b49dd
|
258
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
259
|
if(HAL_SD_ReadBlocks(&uSdHandle, (uint8_t *)pData, ReadAddr, NumOfBlocks, Timeout) != HAL_OK)
|
|
Jerome Coutant
2:123b894b49dd
|
260
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
261
|
return MSD_ERROR;
|
|
Jerome Coutant
2:123b894b49dd
|
262
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
263
|
else
|
|
Jerome Coutant
2:123b894b49dd
|
264
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
265
|
return MSD_OK;
|
|
Jerome Coutant
2:123b894b49dd
|
266
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
267
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
268
|
|
|
Jerome Coutant
2:123b894b49dd
|
269
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
270
|
* @brief Writes block(s) to a specified address in an SD card, in polling mode.
|
|
Jerome Coutant
2:123b894b49dd
|
271
|
* @param pData: Pointer to the buffer that will contain the data to transmit
|
|
Jerome Coutant
2:123b894b49dd
|
272
|
* @param WriteAddr: Address from where data is to be written
|
|
Jerome Coutant
2:123b894b49dd
|
273
|
* @param NumOfBlocks: Number of SD blocks to write
|
|
Jerome Coutant
2:123b894b49dd
|
274
|
* @param Timeout: Timeout for write operation
|
|
Jerome Coutant
2:123b894b49dd
|
275
|
* @retval SD status
|
|
Jerome Coutant
2:123b894b49dd
|
276
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
277
|
uint8_t BSP_SD_WriteBlocks(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks, uint32_t Timeout)
|
|
Jerome Coutant
2:123b894b49dd
|
278
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
279
|
if(HAL_SD_WriteBlocks(&uSdHandle, (uint8_t *)pData, WriteAddr, NumOfBlocks, Timeout) != HAL_OK)
|
|
Jerome Coutant
2:123b894b49dd
|
280
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
281
|
return MSD_ERROR;
|
|
Jerome Coutant
2:123b894b49dd
|
282
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
283
|
else
|
|
Jerome Coutant
2:123b894b49dd
|
284
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
285
|
return MSD_OK;
|
|
Jerome Coutant
2:123b894b49dd
|
286
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
287
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
288
|
|
|
Jerome Coutant
2:123b894b49dd
|
289
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
290
|
* @brief Reads block(s) from a specified address in an SD card, in DMA mode.
|
|
Jerome Coutant
2:123b894b49dd
|
291
|
* @param pData: Pointer to the buffer that will contain the data to transmit
|
|
Jerome Coutant
2:123b894b49dd
|
292
|
* @param ReadAddr: Address from where data is to be read
|
|
Jerome Coutant
2:123b894b49dd
|
293
|
* @param NumOfBlocks: Number of SD blocks to read
|
|
Jerome Coutant
2:123b894b49dd
|
294
|
* @retval SD status
|
|
Jerome Coutant
2:123b894b49dd
|
295
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
296
|
uint8_t BSP_SD_ReadBlocks_DMA(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks)
|
|
Jerome Coutant
2:123b894b49dd
|
297
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
298
|
/* Read block(s) in DMA transfer mode */
|
|
Jerome Coutant
2:123b894b49dd
|
299
|
if(HAL_SD_ReadBlocks_DMA(&uSdHandle, (uint8_t *)pData, ReadAddr, NumOfBlocks) != HAL_OK)
|
|
Jerome Coutant
2:123b894b49dd
|
300
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
301
|
return MSD_ERROR;
|
|
Jerome Coutant
2:123b894b49dd
|
302
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
303
|
else
|
|
Jerome Coutant
2:123b894b49dd
|
304
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
305
|
return MSD_OK;
|
|
Jerome Coutant
2:123b894b49dd
|
306
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
307
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
308
|
|
|
Jerome Coutant
2:123b894b49dd
|
309
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
310
|
* @brief Writes block(s) to a specified address in an SD card, in DMA mode.
|
|
Jerome Coutant
2:123b894b49dd
|
311
|
* @param pData: Pointer to the buffer that will contain the data to transmit
|
|
Jerome Coutant
2:123b894b49dd
|
312
|
* @param WriteAddr: Address from where data is to be written
|
|
Jerome Coutant
2:123b894b49dd
|
313
|
* @param NumOfBlocks: Number of SD blocks to write
|
|
Jerome Coutant
2:123b894b49dd
|
314
|
* @retval SD status
|
|
Jerome Coutant
2:123b894b49dd
|
315
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
316
|
uint8_t BSP_SD_WriteBlocks_DMA(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks)
|
|
Jerome Coutant
2:123b894b49dd
|
317
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
318
|
/* Write block(s) in DMA transfer mode */
|
|
Jerome Coutant
2:123b894b49dd
|
319
|
if(HAL_SD_WriteBlocks_DMA(&uSdHandle, (uint8_t *)pData, WriteAddr, NumOfBlocks) != HAL_OK)
|
|
Jerome Coutant
2:123b894b49dd
|
320
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
321
|
return MSD_ERROR;
|
|
Jerome Coutant
2:123b894b49dd
|
322
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
323
|
else
|
|
Jerome Coutant
2:123b894b49dd
|
324
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
325
|
return MSD_OK;
|
|
Jerome Coutant
2:123b894b49dd
|
326
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
327
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
328
|
|
|
Jerome Coutant
2:123b894b49dd
|
329
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
330
|
* @brief Erases the specified memory area of the given SD card.
|
|
Jerome Coutant
2:123b894b49dd
|
331
|
* @param StartAddr: Start byte address
|
|
Jerome Coutant
2:123b894b49dd
|
332
|
* @param EndAddr: End byte address
|
|
Jerome Coutant
2:123b894b49dd
|
333
|
* @retval SD status
|
|
Jerome Coutant
2:123b894b49dd
|
334
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
335
|
uint8_t BSP_SD_Erase(uint32_t StartAddr, uint32_t EndAddr)
|
|
Jerome Coutant
2:123b894b49dd
|
336
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
337
|
if(HAL_SD_Erase(&uSdHandle, StartAddr, EndAddr) != HAL_OK)
|
|
Jerome Coutant
2:123b894b49dd
|
338
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
339
|
return MSD_ERROR;
|
|
Jerome Coutant
2:123b894b49dd
|
340
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
341
|
else
|
|
Jerome Coutant
2:123b894b49dd
|
342
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
343
|
return MSD_OK;
|
|
Jerome Coutant
2:123b894b49dd
|
344
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
345
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
346
|
|
|
Jerome Coutant
2:123b894b49dd
|
347
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
348
|
* @brief Initializes the SD MSP.
|
|
Jerome Coutant
2:123b894b49dd
|
349
|
* @param hsd: SD handle
|
|
Jerome Coutant
2:123b894b49dd
|
350
|
* @param Params : pointer on additional configuration parameters, can be NULL.
|
|
Jerome Coutant
2:123b894b49dd
|
351
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
352
|
__weak void BSP_SD_MspInit(SD_HandleTypeDef *hsd, void *Params)
|
|
Jerome Coutant
2:123b894b49dd
|
353
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
354
|
static DMA_HandleTypeDef dma_rx_handle;
|
|
Jerome Coutant
2:123b894b49dd
|
355
|
static DMA_HandleTypeDef dma_tx_handle;
|
|
Jerome Coutant
2:123b894b49dd
|
356
|
GPIO_InitTypeDef gpio_init_structure;
|
|
Jerome Coutant
2:123b894b49dd
|
357
|
|
|
Jerome Coutant
2:123b894b49dd
|
358
|
/* Enable SDIO clock */
|
|
Jerome Coutant
2:123b894b49dd
|
359
|
__HAL_RCC_SDIO_CLK_ENABLE();
|
|
Jerome Coutant
2:123b894b49dd
|
360
|
|
|
Jerome Coutant
2:123b894b49dd
|
361
|
/* Enable DMA2 clocks */
|
|
Jerome Coutant
2:123b894b49dd
|
362
|
__DMAx_TxRx_CLK_ENABLE();
|
|
Jerome Coutant
2:123b894b49dd
|
363
|
|
|
Jerome Coutant
2:123b894b49dd
|
364
|
/* Enable GPIOs clock */
|
|
Jerome Coutant
2:123b894b49dd
|
365
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
Jerome Coutant
2:123b894b49dd
|
366
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
|
Jerome Coutant
2:123b894b49dd
|
367
|
|
|
Jerome Coutant
2:123b894b49dd
|
368
|
/* Common GPIO configuration */
|
|
Jerome Coutant
2:123b894b49dd
|
369
|
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
|
|
Jerome Coutant
2:123b894b49dd
|
370
|
gpio_init_structure.Pull = GPIO_PULLUP;
|
|
Jerome Coutant
2:123b894b49dd
|
371
|
gpio_init_structure.Speed = GPIO_SPEED_HIGH;
|
|
Jerome Coutant
2:123b894b49dd
|
372
|
gpio_init_structure.Alternate = GPIO_AF12_SDIO;
|
|
Jerome Coutant
2:123b894b49dd
|
373
|
|
|
Jerome Coutant
2:123b894b49dd
|
374
|
/* GPIOC configuration */
|
|
Jerome Coutant
2:123b894b49dd
|
375
|
gpio_init_structure.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12;
|
|
Jerome Coutant
2:123b894b49dd
|
376
|
|
|
Jerome Coutant
2:123b894b49dd
|
377
|
HAL_GPIO_Init(GPIOC, &gpio_init_structure);
|
|
Jerome Coutant
2:123b894b49dd
|
378
|
|
|
Jerome Coutant
2:123b894b49dd
|
379
|
/* GPIOD configuration */
|
|
Jerome Coutant
2:123b894b49dd
|
380
|
gpio_init_structure.Pin = GPIO_PIN_2;
|
|
Jerome Coutant
2:123b894b49dd
|
381
|
HAL_GPIO_Init(GPIOD, &gpio_init_structure);
|
|
Jerome Coutant
2:123b894b49dd
|
382
|
|
|
Jerome Coutant
2:123b894b49dd
|
383
|
/* NVIC configuration for SDIO interrupts */
|
|
Jerome Coutant
2:123b894b49dd
|
384
|
HAL_NVIC_SetPriority(SDIO_IRQn, 0x0E, 0);
|
|
Jerome Coutant
2:123b894b49dd
|
385
|
HAL_NVIC_EnableIRQ(SDIO_IRQn);
|
|
Jerome Coutant
2:123b894b49dd
|
386
|
|
|
Jerome Coutant
2:123b894b49dd
|
387
|
/* Configure DMA Rx parameters */
|
|
Jerome Coutant
2:123b894b49dd
|
388
|
dma_rx_handle.Init.Channel = SD_DMAx_Rx_CHANNEL;
|
|
Jerome Coutant
2:123b894b49dd
|
389
|
dma_rx_handle.Init.Direction = DMA_PERIPH_TO_MEMORY;
|
|
Jerome Coutant
2:123b894b49dd
|
390
|
dma_rx_handle.Init.PeriphInc = DMA_PINC_DISABLE;
|
|
Jerome Coutant
2:123b894b49dd
|
391
|
dma_rx_handle.Init.MemInc = DMA_MINC_ENABLE;
|
|
Jerome Coutant
2:123b894b49dd
|
392
|
dma_rx_handle.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
|
|
Jerome Coutant
2:123b894b49dd
|
393
|
dma_rx_handle.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
|
|
Jerome Coutant
2:123b894b49dd
|
394
|
dma_rx_handle.Init.Mode = DMA_PFCTRL;
|
|
Jerome Coutant
2:123b894b49dd
|
395
|
dma_rx_handle.Init.Priority = DMA_PRIORITY_VERY_HIGH;
|
|
Jerome Coutant
2:123b894b49dd
|
396
|
dma_rx_handle.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
|
|
Jerome Coutant
2:123b894b49dd
|
397
|
dma_rx_handle.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
|
|
Jerome Coutant
2:123b894b49dd
|
398
|
dma_rx_handle.Init.MemBurst = DMA_MBURST_INC4;
|
|
Jerome Coutant
2:123b894b49dd
|
399
|
dma_rx_handle.Init.PeriphBurst = DMA_PBURST_INC4;
|
|
Jerome Coutant
2:123b894b49dd
|
400
|
|
|
Jerome Coutant
2:123b894b49dd
|
401
|
dma_rx_handle.Instance = SD_DMAx_Rx_STREAM;
|
|
Jerome Coutant
2:123b894b49dd
|
402
|
|
|
Jerome Coutant
2:123b894b49dd
|
403
|
/* Associate the DMA handle */
|
|
Jerome Coutant
2:123b894b49dd
|
404
|
__HAL_LINKDMA(hsd, hdmarx, dma_rx_handle);
|
|
Jerome Coutant
2:123b894b49dd
|
405
|
|
|
Jerome Coutant
2:123b894b49dd
|
406
|
/* Deinitialize the stream for new transfer */
|
|
Jerome Coutant
2:123b894b49dd
|
407
|
HAL_DMA_DeInit(&dma_rx_handle);
|
|
Jerome Coutant
2:123b894b49dd
|
408
|
|
|
Jerome Coutant
2:123b894b49dd
|
409
|
/* Configure the DMA stream */
|
|
Jerome Coutant
2:123b894b49dd
|
410
|
HAL_DMA_Init(&dma_rx_handle);
|
|
Jerome Coutant
2:123b894b49dd
|
411
|
|
|
Jerome Coutant
2:123b894b49dd
|
412
|
/* Configure DMA Tx parameters */
|
|
Jerome Coutant
2:123b894b49dd
|
413
|
dma_tx_handle.Init.Channel = SD_DMAx_Tx_CHANNEL;
|
|
Jerome Coutant
2:123b894b49dd
|
414
|
dma_tx_handle.Init.Direction = DMA_MEMORY_TO_PERIPH;
|
|
Jerome Coutant
2:123b894b49dd
|
415
|
dma_tx_handle.Init.PeriphInc = DMA_PINC_DISABLE;
|
|
Jerome Coutant
2:123b894b49dd
|
416
|
dma_tx_handle.Init.MemInc = DMA_MINC_ENABLE;
|
|
Jerome Coutant
2:123b894b49dd
|
417
|
dma_tx_handle.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
|
|
Jerome Coutant
2:123b894b49dd
|
418
|
dma_tx_handle.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
|
|
Jerome Coutant
2:123b894b49dd
|
419
|
dma_tx_handle.Init.Mode = DMA_PFCTRL;
|
|
Jerome Coutant
2:123b894b49dd
|
420
|
dma_tx_handle.Init.Priority = DMA_PRIORITY_VERY_HIGH;
|
|
Jerome Coutant
2:123b894b49dd
|
421
|
dma_tx_handle.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
|
|
Jerome Coutant
2:123b894b49dd
|
422
|
dma_tx_handle.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
|
|
Jerome Coutant
2:123b894b49dd
|
423
|
dma_tx_handle.Init.MemBurst = DMA_MBURST_INC4;
|
|
Jerome Coutant
2:123b894b49dd
|
424
|
dma_tx_handle.Init.PeriphBurst = DMA_PBURST_INC4;
|
|
Jerome Coutant
2:123b894b49dd
|
425
|
|
|
Jerome Coutant
2:123b894b49dd
|
426
|
dma_tx_handle.Instance = SD_DMAx_Tx_STREAM;
|
|
Jerome Coutant
2:123b894b49dd
|
427
|
|
|
Jerome Coutant
2:123b894b49dd
|
428
|
/* Associate the DMA handle */
|
|
Jerome Coutant
2:123b894b49dd
|
429
|
__HAL_LINKDMA(hsd, hdmatx, dma_tx_handle);
|
|
Jerome Coutant
2:123b894b49dd
|
430
|
|
|
Jerome Coutant
2:123b894b49dd
|
431
|
/* Deinitialize the stream for new transfer */
|
|
Jerome Coutant
2:123b894b49dd
|
432
|
HAL_DMA_DeInit(&dma_tx_handle);
|
|
Jerome Coutant
2:123b894b49dd
|
433
|
|
|
Jerome Coutant
2:123b894b49dd
|
434
|
/* Configure the DMA stream */
|
|
Jerome Coutant
2:123b894b49dd
|
435
|
HAL_DMA_Init(&dma_tx_handle);
|
|
Jerome Coutant
2:123b894b49dd
|
436
|
|
|
Jerome Coutant
2:123b894b49dd
|
437
|
/* NVIC configuration for DMA transfer complete interrupt */
|
|
Jerome Coutant
2:123b894b49dd
|
438
|
HAL_NVIC_SetPriority(SD_DMAx_Rx_IRQn, 0x0F, 0);
|
|
Jerome Coutant
2:123b894b49dd
|
439
|
HAL_NVIC_EnableIRQ(SD_DMAx_Rx_IRQn);
|
|
Jerome Coutant
2:123b894b49dd
|
440
|
|
|
Jerome Coutant
2:123b894b49dd
|
441
|
/* NVIC configuration for DMA transfer complete interrupt */
|
|
Jerome Coutant
2:123b894b49dd
|
442
|
HAL_NVIC_SetPriority(SD_DMAx_Tx_IRQn, 0x0F, 0);
|
|
Jerome Coutant
2:123b894b49dd
|
443
|
HAL_NVIC_EnableIRQ(SD_DMAx_Tx_IRQn);
|
|
Jerome Coutant
2:123b894b49dd
|
444
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
445
|
|
|
Jerome Coutant
2:123b894b49dd
|
446
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
447
|
* @brief Initializes the SD Detect pin MSP.
|
|
Jerome Coutant
2:123b894b49dd
|
448
|
* @param hsd: SD handle
|
|
Jerome Coutant
2:123b894b49dd
|
449
|
* @param Params : pointer on additional configuration parameters, can be NULL.
|
|
Jerome Coutant
2:123b894b49dd
|
450
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
451
|
__weak void BSP_SD_Detect_MspInit(SD_HandleTypeDef *hsd, void *Params)
|
|
Jerome Coutant
2:123b894b49dd
|
452
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
453
|
GPIO_InitTypeDef gpio_init_structure;
|
|
Jerome Coutant
2:123b894b49dd
|
454
|
|
|
Jerome Coutant
2:123b894b49dd
|
455
|
SD_DETECT_GPIO_CLK_ENABLE();
|
|
Jerome Coutant
2:123b894b49dd
|
456
|
|
|
Jerome Coutant
2:123b894b49dd
|
457
|
/* GPIO configuration in input for uSD_Detect signal */
|
|
Jerome Coutant
2:123b894b49dd
|
458
|
gpio_init_structure.Pin = SD_DETECT_PIN;
|
|
Jerome Coutant
2:123b894b49dd
|
459
|
gpio_init_structure.Mode = GPIO_MODE_INPUT;
|
|
Jerome Coutant
2:123b894b49dd
|
460
|
gpio_init_structure.Pull = GPIO_PULLUP;
|
|
Jerome Coutant
2:123b894b49dd
|
461
|
gpio_init_structure.Speed = GPIO_SPEED_HIGH;
|
|
Jerome Coutant
2:123b894b49dd
|
462
|
HAL_GPIO_Init(SD_DETECT_GPIO_PORT, &gpio_init_structure);
|
|
Jerome Coutant
2:123b894b49dd
|
463
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
464
|
|
|
Jerome Coutant
2:123b894b49dd
|
465
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
466
|
* @brief DeInitializes the SD MSP.
|
|
Jerome Coutant
2:123b894b49dd
|
467
|
* @param hsd: SD handle
|
|
Jerome Coutant
2:123b894b49dd
|
468
|
* @param Params : pointer on additional configuration parameters, can be NULL.
|
|
Jerome Coutant
2:123b894b49dd
|
469
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
470
|
__weak void BSP_SD_MspDeInit(SD_HandleTypeDef *hsd, void *Params)
|
|
Jerome Coutant
2:123b894b49dd
|
471
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
472
|
static DMA_HandleTypeDef dma_rx_handle;
|
|
Jerome Coutant
2:123b894b49dd
|
473
|
static DMA_HandleTypeDef dma_tx_handle;
|
|
Jerome Coutant
2:123b894b49dd
|
474
|
|
|
Jerome Coutant
2:123b894b49dd
|
475
|
/* Disable NVIC for DMA transfer complete interrupts */
|
|
Jerome Coutant
2:123b894b49dd
|
476
|
HAL_NVIC_DisableIRQ(SD_DMAx_Rx_IRQn);
|
|
Jerome Coutant
2:123b894b49dd
|
477
|
HAL_NVIC_DisableIRQ(SD_DMAx_Tx_IRQn);
|
|
Jerome Coutant
2:123b894b49dd
|
478
|
|
|
Jerome Coutant
2:123b894b49dd
|
479
|
/* Deinitialize the stream for new transfer */
|
|
Jerome Coutant
2:123b894b49dd
|
480
|
dma_rx_handle.Instance = SD_DMAx_Rx_STREAM;
|
|
Jerome Coutant
2:123b894b49dd
|
481
|
HAL_DMA_DeInit(&dma_rx_handle);
|
|
Jerome Coutant
2:123b894b49dd
|
482
|
|
|
Jerome Coutant
2:123b894b49dd
|
483
|
/* Deinitialize the stream for new transfer */
|
|
Jerome Coutant
2:123b894b49dd
|
484
|
dma_tx_handle.Instance = SD_DMAx_Tx_STREAM;
|
|
Jerome Coutant
2:123b894b49dd
|
485
|
HAL_DMA_DeInit(&dma_tx_handle);
|
|
Jerome Coutant
2:123b894b49dd
|
486
|
|
|
Jerome Coutant
2:123b894b49dd
|
487
|
/* Disable NVIC for SDIO interrupts */
|
|
Jerome Coutant
2:123b894b49dd
|
488
|
HAL_NVIC_DisableIRQ(SDIO_IRQn);
|
|
Jerome Coutant
2:123b894b49dd
|
489
|
|
|
Jerome Coutant
2:123b894b49dd
|
490
|
/* DeInit GPIO pins can be done in the application
|
|
Jerome Coutant
2:123b894b49dd
|
491
|
(by surcharging this __weak function) */
|
|
Jerome Coutant
2:123b894b49dd
|
492
|
|
|
Jerome Coutant
2:123b894b49dd
|
493
|
/* Disable SDIO clock */
|
|
Jerome Coutant
2:123b894b49dd
|
494
|
__HAL_RCC_SDIO_CLK_DISABLE();
|
|
Jerome Coutant
2:123b894b49dd
|
495
|
|
|
Jerome Coutant
2:123b894b49dd
|
496
|
/* GPOI pins clock and DMA cloks can be shut down in the applic
|
|
Jerome Coutant
2:123b894b49dd
|
497
|
by surcgarging this __weak function */
|
|
Jerome Coutant
2:123b894b49dd
|
498
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
499
|
|
|
Jerome Coutant
2:123b894b49dd
|
500
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
501
|
* @brief Gets the current SD card data status.
|
|
Jerome Coutant
2:123b894b49dd
|
502
|
* @retval Data transfer state.
|
|
Jerome Coutant
2:123b894b49dd
|
503
|
* This value can be one of the following values:
|
|
Jerome Coutant
2:123b894b49dd
|
504
|
* @arg SD_TRANSFER_OK: No data transfer is acting
|
|
Jerome Coutant
2:123b894b49dd
|
505
|
* @arg SD_TRANSFER_BUSY: Data transfer is acting
|
|
Jerome Coutant
2:123b894b49dd
|
506
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
507
|
uint8_t BSP_SD_GetCardState(void)
|
|
Jerome Coutant
2:123b894b49dd
|
508
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
509
|
return((HAL_SD_GetCardState(&uSdHandle) == HAL_SD_CARD_TRANSFER ) ? SD_TRANSFER_OK : SD_TRANSFER_BUSY);
|
|
Jerome Coutant
2:123b894b49dd
|
510
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
511
|
|
|
Jerome Coutant
2:123b894b49dd
|
512
|
|
|
Jerome Coutant
2:123b894b49dd
|
513
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
514
|
* @brief Get SD information about specific SD card.
|
|
Jerome Coutant
2:123b894b49dd
|
515
|
* @param CardInfo: Pointer to HAL_SD_CardInfoTypedef structure
|
|
Jerome Coutant
2:123b894b49dd
|
516
|
* @retval None
|
|
Jerome Coutant
2:123b894b49dd
|
517
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
518
|
void BSP_SD_GetCardInfo(HAL_SD_CardInfoTypeDef *CardInfo)
|
|
Jerome Coutant
2:123b894b49dd
|
519
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
520
|
/* Get SD card Information */
|
|
Jerome Coutant
2:123b894b49dd
|
521
|
HAL_SD_GetCardInfo(&uSdHandle, CardInfo);
|
|
Jerome Coutant
2:123b894b49dd
|
522
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
523
|
|
|
Jerome Coutant
2:123b894b49dd
|
524
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
525
|
* @brief SD Abort callbacks
|
|
Jerome Coutant
2:123b894b49dd
|
526
|
* @param hsd: SD handle
|
|
Jerome Coutant
2:123b894b49dd
|
527
|
* @retval None
|
|
Jerome Coutant
2:123b894b49dd
|
528
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
529
|
void HAL_SD_AbortCallback(SD_HandleTypeDef *hsd)
|
|
Jerome Coutant
2:123b894b49dd
|
530
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
531
|
BSP_SD_AbortCallback();
|
|
Jerome Coutant
2:123b894b49dd
|
532
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
533
|
|
|
Jerome Coutant
2:123b894b49dd
|
534
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
535
|
* @brief Tx Transfer completed callbacks
|
|
Jerome Coutant
2:123b894b49dd
|
536
|
* @param hsd: SD handle
|
|
Jerome Coutant
2:123b894b49dd
|
537
|
* @retval None
|
|
Jerome Coutant
2:123b894b49dd
|
538
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
539
|
void HAL_SD_TxCpltCallback(SD_HandleTypeDef *hsd)
|
|
Jerome Coutant
2:123b894b49dd
|
540
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
541
|
BSP_SD_WriteCpltCallback();
|
|
Jerome Coutant
2:123b894b49dd
|
542
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
543
|
|
|
Jerome Coutant
2:123b894b49dd
|
544
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
545
|
* @brief Rx Transfer completed callbacks
|
|
Jerome Coutant
2:123b894b49dd
|
546
|
* @param hsd: SD handle
|
|
Jerome Coutant
2:123b894b49dd
|
547
|
* @retval None
|
|
Jerome Coutant
2:123b894b49dd
|
548
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
549
|
void HAL_SD_RxCpltCallback(SD_HandleTypeDef *hsd)
|
|
Jerome Coutant
2:123b894b49dd
|
550
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
551
|
BSP_SD_ReadCpltCallback();
|
|
Jerome Coutant
2:123b894b49dd
|
552
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
553
|
|
|
Jerome Coutant
2:123b894b49dd
|
554
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
555
|
* @brief BSP SD Abort callbacks
|
|
Jerome Coutant
2:123b894b49dd
|
556
|
* @retval None
|
|
Jerome Coutant
2:123b894b49dd
|
557
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
558
|
__weak void BSP_SD_AbortCallback(void)
|
|
Jerome Coutant
2:123b894b49dd
|
559
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
560
|
|
|
Jerome Coutant
2:123b894b49dd
|
561
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
562
|
|
|
Jerome Coutant
2:123b894b49dd
|
563
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
564
|
* @brief BSP Tx Transfer completed callbacks
|
|
Jerome Coutant
2:123b894b49dd
|
565
|
* @retval None
|
|
Jerome Coutant
2:123b894b49dd
|
566
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
567
|
__weak void BSP_SD_WriteCpltCallback(void)
|
|
Jerome Coutant
2:123b894b49dd
|
568
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
569
|
|
|
Jerome Coutant
2:123b894b49dd
|
570
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
571
|
|
|
Jerome Coutant
2:123b894b49dd
|
572
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
573
|
* @brief BSP Rx Transfer completed callbacks
|
|
Jerome Coutant
2:123b894b49dd
|
574
|
* @retval None
|
|
Jerome Coutant
2:123b894b49dd
|
575
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
576
|
__weak void BSP_SD_ReadCpltCallback(void)
|
|
Jerome Coutant
2:123b894b49dd
|
577
|
{
|
|
Jerome Coutant
2:123b894b49dd
|
578
|
|
|
Jerome Coutant
2:123b894b49dd
|
579
|
}
|
|
Jerome Coutant
2:123b894b49dd
|
580
|
|
|
Jerome Coutant
2:123b894b49dd
|
581
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
582
|
* @}
|
|
Jerome Coutant
2:123b894b49dd
|
583
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
584
|
|
|
Jerome Coutant
2:123b894b49dd
|
585
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
586
|
* @}
|
|
Jerome Coutant
2:123b894b49dd
|
587
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
588
|
|
|
Jerome Coutant
2:123b894b49dd
|
589
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
590
|
* @}
|
|
Jerome Coutant
2:123b894b49dd
|
591
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
592
|
|
|
Jerome Coutant
2:123b894b49dd
|
593
|
/**
|
|
Jerome Coutant
2:123b894b49dd
|
594
|
* @}
|
|
Jerome Coutant
2:123b894b49dd
|
595
|
*/
|
|
Jerome Coutant
2:123b894b49dd
|
596
|
|
|
Jerome Coutant
2:123b894b49dd
|
597
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
|