1
10
11
12
13
14
15
16
17
18
19
20
21
22
23
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
52
53
54
55
56
57
58
59
60
64
65
66
67
68
69
70
71
72
77
78
79
80
81
82
83
84
85
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
145
146
147
148
149
150
151
152
153
158
159
160
161
162
163
164
165
166
167
168
169
170
171
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
...
#include "fx_stm32_sd_driver.h"
TX_SEMAPHORE transfer_semaphore;
extern SD_HandleTypeDef hsd;
extern void MX_SDIO_SD_Init(void);
/* ... */
INT fx_stm32_sd_init(UINT instance)
{
INT ret = 0;
UNUSED(instance);
#if (FX_STM32_SD_INIT == 1)
MX_SDIO_SD_Init();
#endif
return ret;
}{ ... }
/* ... */
INT fx_stm32_sd_deinit(UINT instance)
{
INT ret = 0;
UNUSED(instance);
if(HAL_SD_DeInit(&hsd) != HAL_OK)
{
ret = 1;
}if (HAL_SD_DeInit(&hsd) != HAL_OK) { ... }
return ret;
}{ ... }
/* ... */
INT fx_stm32_sd_get_status(UINT instance)
{
INT ret = 0;
UNUSED(instance);
if(HAL_SD_GetCardState(&hsd) != HAL_SD_CARD_TRANSFER)
{
ret = 1;
}if (HAL_SD_GetCardState(&hsd) != HAL_SD_CARD_TRANSFER) { ... }
return ret;
}{ ... }
/* ... */
INT fx_stm32_sd_read_blocks(UINT instance, UINT *buffer, UINT start_block, UINT total_blocks)
{
INT ret = 0;
UNUSED(instance);
if(HAL_SD_ReadBlocks_DMA(&hsd, (uint8_t *)buffer, start_block, total_blocks) != HAL_OK)
{
ret = 1;
}if (HAL_SD_ReadBlocks_DMA(&hsd, (uint8_t *)buffer, start_block, total_blocks) != HAL_OK) { ... }
return ret;
}{ ... }
/* ... */
INT fx_stm32_sd_write_blocks(UINT instance, UINT *buffer, UINT start_block, UINT total_blocks)
{
INT ret = 0;
UNUSED(instance);
if(HAL_SD_WriteBlocks_DMA(&hsd, (uint8_t *)buffer, start_block, total_blocks) != HAL_OK)
{
ret = 1;
}if (HAL_SD_WriteBlocks_DMA(&hsd, (uint8_t *)buffer, start_block, total_blocks) != HAL_OK) { ... }
return ret;
}{ ... }
/* ... */
void HAL_SD_TxCpltCallback(SD_HandleTypeDef *hsd)
{
tx_semaphore_put(&transfer_semaphore);
}{ ... }
/* ... */
void HAL_SD_RxCpltCallback(SD_HandleTypeDef *hsd)
{
tx_semaphore_put(&transfer_semaphore);
}{ ... }
...