@@ -127,7 +127,7 @@ static SD_CardInfo uSdCardInfo;
127127
128128
129129/**
130- * @brief Initializes the SD card device without CS initialization .
130+ * @brief Initializes the SD card device with CS check if any .
131131 * @retval SD status
132132 */
133133uint8_t BSP_SD_Init (void )
@@ -146,6 +146,15 @@ uint8_t BSP_SD_Init(void)
146146 uSdHandle .Init .HardwareFlowControl = SD_HW_FLOW_CTRL ;
147147 uSdHandle .Init .ClockDiv = SD_CLK_DIV ;
148148
149+ if (SD_detect_gpio_pin != GPIO_PIN_All ) {
150+ /* Msp SD Detect pin initialization */
151+ BSP_SD_Detect_MspInit (& uSdHandle , NULL );
152+ if (BSP_SD_IsDetected () != SD_PRESENT ) /* Check if SD card is present */
153+ {
154+ return MSD_ERROR_SD_NOT_PRESENT ;
155+ }
156+ }
157+
149158 /* Msp SD initialization */
150159 BSP_SD_MspInit (& uSdHandle , NULL );
151160
@@ -176,60 +185,19 @@ uint8_t BSP_SD_Init(void)
176185}
177186
178187/**
179- * @brief Initializes the SD card device with CS initialization.
188+ * @brief Set the SD card device detect pin and port.
189+ * @param csport one of the gpio port
190+ * @param cspin one of the gpio pin
180191 * @retval SD status
181192 */
182- uint8_t BSP_SD_CSInit (GPIO_TypeDef * csport , uint32_t cspin )
193+ uint8_t BSP_SD_CSSet (GPIO_TypeDef * csport , uint32_t cspin )
183194{
184- uint8_t sd_state = MSD_OK ;
185- SD_detect_gpio_pin = cspin ;
186- SD_detect_gpio_port = csport ;
187- /* PLLSAI is dedicated to LCD periph. Do not use it to get 48MHz*/
188-
189- /* uSD device interface configuration */
190- uSdHandle .Instance = SD_INSTANCE ;
191-
192- uSdHandle .Init .ClockEdge = SD_CLK_EDGE ;
193- uSdHandle .Init .ClockBypass = SD_CLK_BYPASS ;
194- uSdHandle .Init .ClockPowerSave = SD_CLK_PWR_SAVE ;
195- uSdHandle .Init .BusWide = SD_BUS_WIDE_1B ;
196- uSdHandle .Init .HardwareFlowControl = SD_HW_FLOW_CTRL ;
197- uSdHandle .Init .ClockDiv = SD_CLK_DIV ;
198-
199- /* Msp SD Detect pin initialization */
200- BSP_SD_Detect_MspInit (& uSdHandle , NULL );
201- if (BSP_SD_IsDetected () != SD_PRESENT ) /* Check if SD card is present */
202- {
203- return MSD_ERROR_SD_NOT_PRESENT ;
204- }
205-
206- /* Msp SD initialization */
207- BSP_SD_MspInit (& uSdHandle , NULL );
208-
209- /* HAL SD initialization */
210- #if defined (STM32F4xx ) || defined(STM32F7xx ) || defined(STM32L4xx )
211- if (HAL_SD_Init (& uSdHandle ) != SD_OK )
212- #else /* (STM32F1xx) || defined(STM32F2xx) || defined(STM32L1xx) */
213- if (HAL_SD_Init (& uSdHandle , & uSdCardInfo ) != SD_OK )
214- #endif
215- {
216- sd_state = MSD_ERROR ;
195+ if (csport != 0 ) {
196+ SD_detect_gpio_pin = cspin ;
197+ SD_detect_gpio_port = csport ;
198+ return MSD_OK ;
217199 }
218-
219- /* Configure SD Bus width */
220- if (sd_state == MSD_OK )
221- {
222- /* Enable wide operation */
223- if (HAL_SD_WideBusOperation_Config (& uSdHandle , SD_BUS_WIDE_4B ) != SD_OK )
224- {
225- sd_state = MSD_ERROR ;
226- }
227- else
228- {
229- sd_state = MSD_OK ;
230- }
231- }
232- return sd_state ;
200+ return MSD_ERROR ;
233201}
234202
235203/**
0 commit comments