@@ -47,6 +47,15 @@ package body SDCard is
47
47
(Interrupt_ID => SD_Interrupt,
48
48
Priority => System.Interrupt_Priority'Last);
49
49
50
+ -- ---------------------
51
+ -- Has_SD_Detect_Pin --
52
+ -- ---------------------
53
+
54
+ function Has_SD_Detect_Pin return Boolean is
55
+ begin
56
+ return (for all Pin of SD_Pins => Pin.Pin /= SD_Detect_Pin.Pin);
57
+ end Has_SD_Detect_Pin ;
58
+
50
59
-- --------------
51
60
-- Initialize --
52
61
-- --------------
@@ -78,12 +87,19 @@ package body SDCard is
78
87
Resistors => Pull_Up));
79
88
80
89
-- GPIO configuration for the SD-Detect pin
81
- Configure_IO
82
- (SD_Detect_Pin,
83
- (Mode => Mode_In,
84
- -- Output_Type => Open_Drain,
85
- -- Speed => Speed_High,
86
- Resistors => Pull_Up));
90
+ if Has_SD_Detect_Pin then
91
+ Configure_IO
92
+ (SD_Detect_Pin,
93
+ (Mode => Mode_In,
94
+ Resistors => Pull_Up));
95
+ else
96
+ Configure_IO
97
+ (SD_Detect_Pin,
98
+ (Mode => Mode_In,
99
+ Resistors => Pull_Down));
100
+
101
+ This.Card_Detected := False;
102
+ end if ;
87
103
88
104
-- Enable the SDIO clock
89
105
STM32.Device.Enable_Clock (This.Device.all );
@@ -140,8 +156,30 @@ package body SDCard is
140
156
function Card_Present
141
157
(This : in out SDCard_Controller) return Boolean
142
158
is
159
+ function Card_Detect return Boolean;
160
+ -- Check SD_Detect_Pin depending on the presence of a dedicated pin
161
+
162
+ -- ---------------
163
+ -- Card_Detect --
164
+ -- ---------------
165
+
166
+ function Card_Detect return Boolean is
167
+ begin
168
+ if Has_SD_Detect_Pin then
169
+ -- We have a dedicated pin.
170
+ return not STM32.GPIO.Set (SD_Detect_Pin);
171
+ elsif This.Card_Detected then
172
+ -- We have no dedicated pin.
173
+ -- In normal operation mode no detection is possible.
174
+ return True;
175
+ else
176
+ -- We have no dedicated pin. Check DAT3 pin
177
+ return STM32.GPIO.Set (SD_Detect_Pin);
178
+ end if ;
179
+ end Card_Detect ;
180
+
143
181
begin
144
- if STM32.GPIO.Set (SD_Detect_Pin) then
182
+ if not Card_Detect then
145
183
-- No card
146
184
This.Device.Clear_Card_Information;
147
185
This.Card_Detected := False;
@@ -152,7 +190,21 @@ package body SDCard is
152
190
delay until Clock + Milliseconds (50 );
153
191
end if ;
154
192
155
- This.Card_Detected := not STM32.GPIO.Set (SD_Detect_Pin);
193
+ if Has_SD_Detect_Pin then
194
+ This.Card_Detected := Card_Detect;
195
+
196
+ elsif not This.Card_Detected and Card_Detect then
197
+ -- Reconfigure the SD_Detect_Pin pin to SDIO function
198
+ Configure_IO
199
+ (SD_Detect_Pin,
200
+ (Mode => Mode_AF,
201
+ AF => SD_Pins_AF,
202
+ AF_Output_Type => Push_Pull,
203
+ AF_Speed => Speed_High,
204
+ Resistors => Pull_Up));
205
+
206
+ This.Card_Detected := True;
207
+ end if ;
156
208
end if ;
157
209
158
210
return This.Card_Detected;
0 commit comments