Skip to content

Commit b60bbe5

Browse files
committed
Clean up code
Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
1 parent 0877845 commit b60bbe5

File tree

6 files changed

+29
-95
lines changed

6 files changed

+29
-95
lines changed

src/SD.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ SDClass SD;
6262
* @param None
6363
* @retval TRUE or FALSE
6464
*/
65-
uint8_t SDClass::begin(uint32_t cspin)
65+
uint8_t SDClass::begin(uint32_t detectpin)
6666
{
6767
/*##-1- Initializes SD IOs #############################################*/
68-
if (_card.init(cspin)) {
68+
if (_card.init(detectpin)) {
6969
return _fatFs.init();
7070
}
7171
return FALSE;

src/STM32SD.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class SDClass {
8181
public:
8282

8383
/* Initialize the SD peripheral */
84-
uint8_t begin(uint32_t cspin = SD_DETECT_NONE);
84+
uint8_t begin(uint32_t detectpin = SD_DETECT_NONE);
8585
static File open(const char *filepath, uint8_t mode);
8686
static File open(const char *filepath);
8787
static uint8_t exists(const char *filepath);

src/Sd2Card.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
#include <Arduino.h>
3838
#include "Sd2Card.h"
3939

40-
uint8_t Sd2Card::init(uint32_t cspin)
40+
uint8_t Sd2Card::init(uint32_t detectpin)
4141
{
42-
if (cspin != SD_DETECT_NONE) {
43-
PinName p = digitalPinToPinName(cspin);
42+
if (detectpin != SD_DETECT_NONE) {
43+
PinName p = digitalPinToPinName(detectpin);
4444
if ((p == NC) || \
45-
BSP_SD_CSSet(set_GPIO_Port_Clock(STM_PORT(p)),
46-
STM_GPIO_PIN(p)) != MSD_OK) {
45+
BSP_SD_DetectPin(set_GPIO_Port_Clock(STM_PORT(p)),
46+
STM_GPIO_PIN(p)) != MSD_OK) {
4747
return FALSE;
4848
}
4949
}

src/Sd2Card.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
class Sd2Card {
5757
public:
5858

59-
uint8_t init(uint32_t cspin = SD_DETECT_NONE);
59+
uint8_t init(uint32_t detectpin = SD_DETECT_NONE);
6060

6161
/** Return the card type: SD V1, SD V2 or SDHC */
6262
uint8_t type(void) const;

src/bsp_sd.c

+18-84
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
/**
22
******************************************************************************
33
* @file bsp_sd.c
4-
* @author MCD Application Team
5-
* @version V1.0.0
6-
* @date 10-June-2016
74
* @brief This file includes the uSD card driver mounted on stm32
85
* board.
96
******************************************************************************
@@ -36,48 +33,6 @@
3633
******************************************************************************
3734
*/
3835

39-
/* File Info : -----------------------------------------------------------------
40-
User NOTES
41-
1. How To use this driver:
42-
--------------------------
43-
- This driver is used to drive the micro SD external card mounted on a board.
44-
- This driver does not need a specific component driver for the micro SD device
45-
to be included with.
46-
47-
2. Driver description:
48-
---------------------
49-
+ Initialization steps:
50-
o Initialize the micro SD card using the BSP_SD_Init() function. This
51-
function includes the MSP layer hardware resources initialization and the
52-
SDIO interface configuration to interface with the external micro SD. It
53-
also includes the micro SD initialization sequence.
54-
o To check the SD card presence you can use the function BSP_SD_IsDetected() which
55-
returns the detection status
56-
o If SD presence detection interrupt mode is desired, you must configure the
57-
SD detection interrupt mode by calling the function BSP_SD_ITConfig(). The interrupt
58-
is generated as an external interrupt whenever the micro SD card is
59-
plugged/unplugged in/from the board. The SD detection interrupt
60-
is handled by calling the function BSP_SD_DetectIT() which is called in the IRQ
61-
handler file, the user callback is implemented in the function BSP_SD_DetectCallback().
62-
o The function BSP_SD_GetCardInfo() is used to get the micro SD card information
63-
which is stored in the structure "HAL_SD_CardInfoTypedef".
64-
65-
+ Micro SD card operations
66-
o The micro SD card can be accessed with read/write block(s) operations once
67-
it is reay for access. The access cand be performed whether using the polling
68-
mode by calling the functions BSP_SD_ReadBlocks()/BSP_SD_WriteBlocks(), or by DMA
69-
transfer using the functions BSP_SD_ReadBlocks_DMA()/BSP_SD_WriteBlocks_DMA()
70-
o The DMA transfer complete is used with interrupt mode. Once the SD transfer
71-
is complete, the SD interrupt is handeled using the function BSP_SD_IRQHandler(),
72-
the DMA Tx/Rx transfer complete are handeled using the functions
73-
BSP_SD_DMA_Tx_IRQHandler()/BSP_SD_DMA_Rx_IRQHandler(). The corresponding user callbacks
74-
are implemented by the user at application level.
75-
o The SD erase block(s) is performed using the function BSP_SD_Erase() with specifying
76-
the number of blocks to erase.
77-
o The SD runtime status is returned when calling the function BSP_SD_GetStatus().
78-
79-
------------------------------------------------------------------------------*/
80-
8136
/* Includes ------------------------------------------------------------------*/
8237
#include "bsp_sd.h"
8338
#include "PeripheralPins.h"
@@ -139,8 +94,6 @@ uint8_t BSP_SD_Init(void)
13994
{
14095
uint8_t sd_state = MSD_OK;
14196

142-
/* PLLSAI is dedicated to LCD periph. Do not use it to get 48MHz*/
143-
14497
/* uSD device interface configuration */
14598
uSdHandle.Instance = SD_INSTANCE;
14699

@@ -186,22 +139,6 @@ uint8_t BSP_SD_Init(void)
186139
return sd_state;
187140
}
188141

189-
/**
190-
* @brief Set the SD card device detect pin and port.
191-
* @param csport one of the gpio port
192-
* @param cspin one of the gpio pin
193-
* @retval SD status
194-
*/
195-
uint8_t BSP_SD_CSSet(GPIO_TypeDef *csport, uint32_t cspin)
196-
{
197-
if (csport != 0) {
198-
SD_detect_gpio_pin = cspin;
199-
SD_detect_gpio_port = csport;
200-
return MSD_OK;
201-
}
202-
return MSD_ERROR;
203-
}
204-
205142
/**
206143
* @brief DeInitializes the SD card device.
207144
* @retval SD status
@@ -224,11 +161,27 @@ uint8_t BSP_SD_DeInit(void)
224161
return sd_state;
225162
}
226163

164+
/**
165+
* @brief Set the SD card device detect pin and port.
166+
* @param port one of the gpio port
167+
* @param pin one of the gpio pin
168+
* @retval SD status
169+
*/
170+
uint8_t BSP_SD_DetectPin(GPIO_TypeDef *port, uint32_t pin)
171+
{
172+
if (port != 0) {
173+
SD_detect_gpio_pin = pin;
174+
SD_detect_gpio_port = port;
175+
return MSD_OK;
176+
}
177+
return MSD_ERROR;
178+
}
179+
227180
/**
228181
* @brief Configures Interrupt mode for SD detection pin.
229-
* @retval Returns 0
182+
* @retval Status
230183
*/
231-
uint8_t BSP_SD_ITConfig(void)
184+
uint8_t BSP_SD_DetectITConfig(void)
232185
{
233186
uint8_t sd_state = MSD_OK;
234187
GPIO_InitTypeDef gpio_init_structure;
@@ -443,9 +396,6 @@ __weak void BSP_SD_MspDeInit(SD_HandleTypeDef *hsd, void *Params)
443396

444397
/* Disable SDIO clock */
445398
SD_CLK_DISABLE();
446-
447-
/* GPOI pins clock and DMA cloks can be shut down in the applic
448-
by surcgarging this __weak function */
449399
}
450400

451401
#ifndef STM32L1xx
@@ -485,20 +435,4 @@ void BSP_SD_GetCardInfo(HAL_SD_CardInfoTypeDef *CardInfo)
485435
HAL_SD_Get_CardInfo(&uSdHandle, CardInfo);
486436
}
487437

488-
/**
489-
* @}
490-
*/
491-
492-
/**
493-
* @}
494-
*/
495-
496-
/**
497-
* @}
498-
*/
499-
500-
/**
501-
* @}
502-
*/
503-
504438
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

src/bsp_sd.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ Please update the core or install previous libray version."
7979

8080
/* SD Exported Functions */
8181
uint8_t BSP_SD_Init(void);
82-
uint8_t BSP_SD_CSSet(GPIO_TypeDef *csport, uint32_t cspin);
8382
uint8_t BSP_SD_DeInit(void);
84-
uint8_t BSP_SD_ITConfig(void);
83+
uint8_t BSP_SD_DetectPin(GPIO_TypeDef *port, uint32_t pin);
84+
uint8_t BSP_SD_DetectITConfig(void);
8585
#ifndef STM32L1xx
8686
uint8_t BSP_SD_ReadBlocks(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks, uint32_t Timeout);
8787
uint8_t BSP_SD_WriteBlocks(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks, uint32_t Timeout);

0 commit comments

Comments
 (0)