Skip to content

Commit 6132155

Browse files
committed
fix: STM32L1xx support
is now aligned with other series Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 703f41d commit 6132155

File tree

3 files changed

+8
-100
lines changed

3 files changed

+8
-100
lines changed

src/Sd2Card.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ bool Sd2Card::init(uint32_t detectpin)
6767
uint8_t Sd2Card::type(void) const
6868
{
6969
uint8_t cardType = SD_CARD_TYPE_UKN;
70-
#ifndef STM32L1xx
7170
switch (_SdCardInfo.CardType) {
7271
case CARD_SDSC:
7372
switch (_SdCardInfo.CardVersion) {
@@ -90,21 +89,6 @@ uint8_t Sd2Card::type(void) const
9089
default:
9190
cardType = SD_CARD_TYPE_UKN;
9291
}
93-
#else /* STM32L1xx */
94-
switch (_SdCardInfo.CardType) {
95-
case STD_CAPACITY_SD_CARD_V1_1:
96-
cardType = SD_CARD_TYPE_SD1;
97-
break;
98-
case STD_CAPACITY_SD_CARD_V2_0:
99-
cardType = SD_CARD_TYPE_SD2;
100-
break;
101-
case HIGH_CAPACITY_SD_CARD:
102-
cardType = SD_CARD_TYPE_SDHC;
103-
break;
104-
default:
105-
cardType = SD_CARD_TYPE_UKN;
106-
}
107-
#endif
10892
return cardType;
10993
}
11094

src/bsp_sd.c

Lines changed: 6 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,8 @@ static GPIO_TypeDef *SD_detect_gpio_port = GPIOA;
116116
static uint32_t SD_trans_sel_ll_gpio_pin = LL_GPIO_PIN_ALL;
117117
static GPIO_TypeDef *SD_trans_sel_gpio_port = GPIOA;
118118
#endif
119-
#ifndef STM32L1xx
120-
#define SD_OK HAL_OK
121-
#define SD_TRANSFER_OK ((uint8_t)0x00)
122-
#define SD_TRANSFER_BUSY ((uint8_t)0x01)
123-
#else /* STM32L1xx */
124-
static SD_CardInfo uSdCardInfo;
125-
#endif
119+
#define SD_TRANSFER_OK ((uint8_t)0x00)
120+
#define SD_TRANSFER_BUSY ((uint8_t)0x01)
126121

127122

128123
/**
@@ -165,19 +160,14 @@ uint8_t BSP_SD_Init(void)
165160
BSP_SD_MspInit(&uSdHandle, NULL);
166161

167162
/* HAL SD initialization */
168-
#ifndef STM32L1xx
169-
if (HAL_SD_Init(&uSdHandle) != SD_OK)
170-
#else /* STM32L1xx */
171-
if (HAL_SD_Init(&uSdHandle, &uSdCardInfo) != SD_OK)
172-
#endif
173-
{
163+
if (HAL_SD_Init(&uSdHandle) != HAL_OK) {
174164
sd_state = MSD_ERROR;
175165
}
176166

177167
/* Configure SD Bus width */
178168
if (sd_state == MSD_OK) {
179169
/* Enable wide operation */
180-
if (HAL_SD_WideBusOperation_Config(&uSdHandle, SD_BUS_WIDE) != SD_OK) {
170+
if (HAL_SD_ConfigWideBusOperation(&uSdHandle, SD_BUS_WIDE) != HAL_OK) {
181171
sd_state = MSD_ERROR;
182172
} else {
183173
sd_state = MSD_OK;
@@ -328,7 +318,6 @@ uint8_t BSP_SD_IsDetected(void)
328318
return status;
329319
}
330320

331-
#ifndef STM32L1xx
332321
/**
333322
* @brief Reads block(s) from a specified address in an SD card, in polling mode.
334323
* @param pData: Pointer to the buffer that will contain the data to transmit
@@ -362,41 +351,6 @@ uint8_t BSP_SD_WriteBlocks(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBl
362351
return MSD_OK;
363352
}
364353
}
365-
#else /* STM32L1xx */
366-
/**
367-
* @brief Reads block(s) from a specified address in an SD card, in polling mode.
368-
* @param pData: Pointer to the buffer that will contain the data to transmit
369-
* @param ReadAddr: Address from where data is to be read
370-
* @param BlockSize: SD card data block size, that should be 512
371-
* @param NumOfBlocks: Number of SD blocks to read
372-
* @retval SD status
373-
*/
374-
uint8_t BSP_SD_ReadBlocks(uint32_t *pData, uint64_t ReadAddr, uint32_t BlockSize, uint32_t NumOfBlocks)
375-
{
376-
if (HAL_SD_ReadBlocks(&uSdHandle, (uint8_t *)pData, ReadAddr, BlockSize, NumOfBlocks) != SD_OK) {
377-
return MSD_ERROR;
378-
} else {
379-
return MSD_OK;
380-
}
381-
}
382-
383-
/**
384-
* @brief Writes block(s) to a specified address in an SD card, in polling mode.
385-
* @param pData: Pointer to the buffer that will contain the data to transmit
386-
* @param WriteAddr: Address from where data is to be written
387-
* @param BlockSize: SD card data block size, that should be 512
388-
* @param NumOfBlocks: Number of SD blocks to write
389-
* @retval SD status
390-
*/
391-
uint8_t BSP_SD_WriteBlocks(uint32_t *pData, uint64_t WriteAddr, uint32_t BlockSize, uint32_t NumOfBlocks)
392-
{
393-
if (HAL_SD_WriteBlocks(&uSdHandle, (uint8_t *)pData, WriteAddr, BlockSize, NumOfBlocks) != SD_OK) {
394-
return MSD_ERROR;
395-
} else {
396-
return MSD_OK;
397-
}
398-
}
399-
#endif /* !STM32L1xx */
400354

401355
/**
402356
* @brief Erases the specified memory area of the given SD card.
@@ -406,7 +360,7 @@ uint8_t BSP_SD_WriteBlocks(uint32_t *pData, uint64_t WriteAddr, uint32_t BlockSi
406360
*/
407361
uint8_t BSP_SD_Erase(uint64_t StartAddr, uint64_t EndAddr)
408362
{
409-
if (HAL_SD_Erase(&uSdHandle, StartAddr, EndAddr) != SD_OK) {
363+
if (HAL_SD_Erase(&uSdHandle, StartAddr, EndAddr) != HAL_OK) {
410364
return MSD_ERROR;
411365
} else {
412366
return MSD_OK;
@@ -532,7 +486,6 @@ __weak void BSP_SD_Transceiver_MspInit(SD_HandleTypeDef *hsd, void *Params)
532486
}
533487
#endif /* USE_SD_TRANSCEIVER && (USE_SD_TRANSCEIVER != 0U) */
534488

535-
#ifndef STM32L1xx
536489
/**
537490
* @brief Gets the current SD card data status.
538491
* @retval Data transfer state.
@@ -544,20 +497,6 @@ uint8_t BSP_SD_GetCardState(void)
544497
{
545498
return ((HAL_SD_GetCardState(&uSdHandle) == HAL_SD_CARD_TRANSFER) ? SD_TRANSFER_OK : SD_TRANSFER_BUSY);
546499
}
547-
#else /* STM32L1xx */
548-
/**
549-
* @brief Gets the current SD card data status.
550-
* @retval Data transfer state.
551-
* This value can be one of the following values:
552-
* @arg SD_TRANSFER_OK: No data transfer is acting
553-
* @arg SD_TRANSFER_BUSY: Data transfer is acting
554-
* @arg SD_TRANSFER_ERROR: Data transfer error
555-
*/
556-
HAL_SD_TransferStateTypedef BSP_SD_GetStatus(void)
557-
{
558-
return (HAL_SD_GetStatus(&uSdHandle));
559-
}
560-
#endif
561500

562501
/**
563502
* @brief Get SD information about specific SD card.
@@ -566,7 +505,7 @@ HAL_SD_TransferStateTypedef BSP_SD_GetStatus(void)
566505
void BSP_SD_GetCardInfo(HAL_SD_CardInfoTypeDef *CardInfo)
567506
{
568507
/* Get SD card Information */
569-
HAL_SD_Get_CardInfo(&uSdHandle, CardInfo);
508+
HAL_SD_GetCardInfo(&uSdHandle, CardInfo);
570509
}
571510

572511
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

src/bsp_sd.h

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,8 @@ Please update the core or install previous library version."
5959
#endif
6060

6161
/*SD Card information structure */
62-
#ifndef STM32L1xx
63-
#define HAL_SD_CardInfoTypedef HAL_SD_CardInfoTypeDef
64-
#define BSP_SD_CardInfo HAL_SD_CardInfoTypeDef
65-
#define HAL_SD_WideBusOperation_Config HAL_SD_ConfigWideBusOperation
66-
#define HAL_SD_Get_CardInfo HAL_SD_GetCardInfo
67-
#endif
6862

69-
#define SD_CardInfo HAL_SD_CardInfoTypedef
63+
#define SD_CardInfo HAL_SD_CardInfoTypeDef
7064

7165
/*SD status structure definition */
7266
#define MSD_OK ((uint8_t)0x00)
@@ -105,20 +99,11 @@ uint8_t BSP_SD_TransceiverPin(GPIO_TypeDef *enport, uint32_t enpin, GPIO_TypeDef
10599
#endif
106100
uint8_t BSP_SD_DetectPin(GPIO_TypeDef *port, uint32_t pin);
107101
uint8_t BSP_SD_DetectITConfig(void (*callback)(void));
108-
#ifndef STM32L1xx
109102
uint8_t BSP_SD_ReadBlocks(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks, uint32_t Timeout);
110103
uint8_t BSP_SD_WriteBlocks(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks, uint32_t Timeout);
111-
#else
112-
uint8_t BSP_SD_ReadBlocks(uint32_t *pData, uint64_t ReadAddr, uint32_t BlockSize, uint32_t NumOfBlocks);
113-
uint8_t BSP_SD_WriteBlocks(uint32_t *pData, uint64_t WriteAddr, uint32_t BlockSize, uint32_t NumOfBlocks);
114-
#endif
115104
uint8_t BSP_SD_Erase(uint64_t StartAddr, uint64_t EndAddr);
116-
#ifndef STM32L1xx
117105
uint8_t BSP_SD_GetCardState(void);
118-
#else /* STM32L1xx */
119-
HAL_SD_TransferStateTypedef BSP_SD_GetStatus(void);
120-
#endif
121-
void BSP_SD_GetCardInfo(HAL_SD_CardInfoTypedef *CardInfo);
106+
void BSP_SD_GetCardInfo(HAL_SD_CardInfoTypeDef *CardInfo);
122107
uint8_t BSP_SD_IsDetected(void);
123108

124109
/* These __weak function can be surcharged by application code in case the current settings (e.g. DMA stream)

0 commit comments

Comments
 (0)