This commit is contained in:
thomas committed 2026-10-18 14:06:40 +02:00
commit 2c2202e60d
2491 files changed
+1295990

No files matched your search

@@ -0,0 +1,236 @@
/**
******************************************************************************
* @file stm32_sal_sd.c
* @author MCD Application Team
* @brief This file implements the software adaptation layer for SD.
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32_extmem.h"
#include "stm32_extmem_conf.h"
#if EXTMEM_SAL_SD_DEBUG_LEVEL != 0 && defined(EXTMEM_MACRO_DEBUG)
#include <stdio.h>
#endif /* EXTMEM_SAL_SD_DEBUG_LEVEL != 0 && EXTMEM_MACRO_DEBUG */
#if EXTMEM_SAL_SD == 1
#include "stm32_sal_sd_type.h"
#include "stm32_sal_sd_api.h"
/** @defgroup SAL_SD SAL_SD : Software adaptation layer for the HAL_SD
* @ingroup EXTMEM_SAL
* @{
*/
/**
* @brief Ready timeout value
*/
#define READY_TIMEOUT 1000u
/* Private Macros ------------------------------------------------------------*/
/** @defgroup SAL_SD_Private_Macros SAL SD Private Macros
* @{
*/
#if EXTMEM_SAL_SD_DEBUG_LEVEL == 0 || !defined(EXTMEM_MACRO_DEBUG)
#define DEBUG_PARAM_BEGIN()
#define DEBUG_PARAM_DATA(_STR_)
#define DEBUG_PARAM_INT(_INT_ )
#define DEBUG_PARAM_END()
#else
/**
* @brief Trace header macro.
*/
#define DEBUG_PARAM_BEGIN() EXTMEM_MACRO_DEBUG("\t\tSALSD::");
/**
* @brief Trace data string macro.
*/
#define DEBUG_PARAM_DATA(_STR_) EXTMEM_MACRO_DEBUG(_STR_);
/**
* @brief Trace data integer macro
*/
#define DEBUG_PARAM_INT(_INT_ ) { \
char str[10]; \
(void)snprintf(str, sizeof(str), "0x%x", _INT_);\
EXTMEM_MACRO_DEBUG(str); \
}
/**
* @brief Trace close macro
*/
#define DEBUG_PARAM_END() EXTMEM_MACRO_DEBUG("\n");
#endif /* EXTMEM_SFDP_DEBUG */
/**
* @}
*/
/* Private typedefs ---------------------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/** @defgroup SAL_SD_Private_Functions SAL XSP Private Functions
* @{
*/
/**
* @}
*/
/* Exported variables ---------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/** @defgroup SAL_SD_Exported_Functions SAL XSP Exported Functions
* @{
*/
/**
* @brief This function initializes the SD SAL context
* @param SalSD SAL SD Object
* @param HALHandle HAL handle
* @param Info Information on the SD card
* @return @ref HAL_StatusTypeDef
**/
HAL_StatusTypeDef SAL_SD_Init(SAL_SD_ObjectTypeDef *SalSD, void *HALHandle, EXTMEM_DRIVER_SDCARD_InfoTypeDef *Info)
{
SalSD->hSD = (SD_HandleTypeDef *)HALHandle;
Info->BlockNbr = SalSD->hSD->SdCard.BlockNbr;
Info->BlockSize = SalSD->hSD->SdCard.BlockSize;
/* Switch to the highest Speed mode supported by the sd-card */
return HAL_SD_ConfigSpeedBusOperation(SalSD->hSD, SDMMC_SPEED_MODE_AUTO);
}
/**
* @brief This function un-initializes the SD SAL context
* @param SalSD SAL SD Object
* @return @ref HAL_StatusTypeDef
**/
HAL_StatusTypeDef SAL_SD_DeInit(SAL_SD_ObjectTypeDef *SalSD)
{
SalSD->hSD->SdCard.BlockNbr = 0;
return HAL_OK;
}
/**
* @brief This function reads data from the SD
* @param SalSD SAL SD Object
* @param BlockIdx Block index
* @param Data Data pointer
* @param NumberOfBlock Number of block
* @return @ref HAL_StatusTypeDef
**/
HAL_StatusTypeDef SAL_SD_ReadData(SAL_SD_ObjectTypeDef *SalSD, uint32_t BlockIdx, uint8_t *Data, uint32_t NumberOfBlock)
{
uint32_t timeout = 100UL * NumberOfBlock;
HAL_StatusTypeDef retr = HAL_SD_ReadBlocks(SalSD->hSD, (uint8_t *)Data, BlockIdx, NumberOfBlock, timeout);
if (HAL_OK == retr)
{
timeout = HAL_GetTick();
/* Check the SD status */
while (HAL_SD_GetCardState(SalSD->hSD) != HAL_SD_CARD_TRANSFER)
{
if ((HAL_GetTick() - timeout) > READY_TIMEOUT)
{
retr = HAL_TIMEOUT;
break;
}
}
}
return retr;
}
/**
* @brief This function writes data on the SD
* @param SalSD SAL SD Object
* @param BlockIdx block index
* @param Data data pointer
* @param NumberOfBlock number of block
* @return @ref HAL_StatusTypeDef
**/
HAL_StatusTypeDef SAL_SD_WriteData(SAL_SD_ObjectTypeDef *SalSD, uint32_t BlockIdx, const uint8_t *const Data,
uint32_t NumberOfBlock)
{
uint32_t timeout = 100UL * NumberOfBlock;
HAL_StatusTypeDef retr;
retr = HAL_SD_WriteBlocks(SalSD->hSD, Data, BlockIdx, NumberOfBlock, timeout);
if (HAL_OK == retr)
{
timeout = HAL_GetTick();
/* Check the SD status */
while (HAL_SD_GetCardState(SalSD->hSD) != HAL_SD_CARD_TRANSFER)
{
if ((HAL_GetTick() - timeout) > READY_TIMEOUT)
{
retr = HAL_TIMEOUT;
break;
}
}
}
return retr;
}
/**
* @brief This function erases an amount of blocks on the SD
* @param SalSD SAL SD Object
* @param BlockIdx block index
* @param BlockCount number of block
* @return @ref HAL_StatusTypeDef
**/
HAL_StatusTypeDef SAL_SD_EraseBlock(SAL_SD_ObjectTypeDef *SalSD, uint32_t BlockIdx, uint32_t BlockCount)
{
uint32_t timeout;
HAL_StatusTypeDef retr;
retr = HAL_SD_Erase(SalSD->hSD, BlockIdx, BlockIdx + BlockCount);
if (HAL_OK == retr)
{
timeout = HAL_GetTick();
/* Check the SD status */
while (HAL_SD_GetCardState(SalSD->hSD) != HAL_SD_CARD_TRANSFER)
{
if ((HAL_GetTick() - timeout) > (READY_TIMEOUT * BlockCount))
{
retr = HAL_TIMEOUT;
break;
}
}
}
return retr;
}
/**
* @brief This function erases all the SD
* @param SalSD SAL SD Object
* @return @ref HAL_StatusTypeDef
**/
HAL_StatusTypeDef SAL_SD_MassErase(SAL_SD_ObjectTypeDef *SalSD)
{
return SAL_SD_EraseBlock(SalSD, 0, SalSD->hSD->SdCard.BlockNbr);
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#endif /* EXTMEM_SAL_SD == 1 */
@@ -0,0 +1,77 @@
/**
******************************************************************************
* @file stm32_sal_sd_api.h
* @author MCD Application Team
* @brief This file contains SAL SD function prototypes.
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32_SAL_SD_API_H
#define __STM32_SAL_SD_API_H
#ifdef __cplusplus
extern "C" {
#endif
/** @addtogroup SAL_SD
* @ingroup EXTMEM_SAL
* @{
*/
/** @defgroup SAL_SD
* @{
*/
/* Includes ------------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/** @defgroup SAL_SD_Exported_types SAL SD exported types
* @{
*/
/**
* @}
*/
/* Exported functions --------------------------------------------------------*/
/** @defgroup SAL_SD_Exported_Functions SAL SD Exported Functions
* @{
*/
HAL_StatusTypeDef SAL_SD_Init(SAL_SD_ObjectTypeDef *SalSD, void *HALHandle, EXTMEM_DRIVER_SDCARD_InfoTypeDef *Info);
HAL_StatusTypeDef SAL_SD_DeInit(SAL_SD_ObjectTypeDef *SalSD);
HAL_StatusTypeDef SAL_SD_ReadData(SAL_SD_ObjectTypeDef *SalSD, uint32_t BlockIdx, uint8_t *Data,
uint32_t NumberOfBlock);
HAL_StatusTypeDef SAL_SD_WriteData(SAL_SD_ObjectTypeDef *SalSD, uint32_t BlockIdx, const uint8_t *const Data,
uint32_t NumberOfBlock);
HAL_StatusTypeDef SAL_SD_EraseBlock(SAL_SD_ObjectTypeDef *SalSD, uint32_t BlockIdx, uint32_t BlockCount);
HAL_StatusTypeDef SAL_SD_MassErase(SAL_SD_ObjectTypeDef *SalSD);
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __STM32_SAL_SD_API_H */
@@ -0,0 +1,74 @@
/**
******************************************************************************
* @file stm32_sal_sd_type.h
* @author MCD Application Team
* @brief This file contains SAL SD type definitions.
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32_SAL_SD_TYPE_H
#define __STM32_SAL_SD_TYPE_H
#ifdef __cplusplus
extern "C" {
#endif
/** @addtogroup SAL_SD
* @ingroup EXTMEM_SAL
* @{
*/
/** @defgroup SAL_SD
* @{
*/
/* Includes ------------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/** @defgroup SAL_SD_Exported_types SAL SD exported types
* @{
*/
typedef struct
{
SD_HandleTypeDef *hSD; /*!< Pointer to the SD instance handle. */
} SAL_SD_ObjectTypeDef;
/**
* @}
*/
/* Exported functions --------------------------------------------------------*/
/** @defgroup SAL_SD_Exported_Functions SAL XSP Exported Functions
* @{
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __STM32_SAL_SD_TYPE_H */
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,100 @@
/**
******************************************************************************
* @file stm32_sal_xspi_api.h
* @author MCD Application Team
* @brief This file contains SAL XSPI function prototypes.
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32_SAL_XSPI_API_H
#define __STM32_SAL_XSPI_API_H
#ifdef __cplusplus
extern "C" {
#endif
/** @defgroup SAL_XSPI
* @ingroup EXTMEM_SAL
* @{
*/
/* Includes ------------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/** @defgroup SAL_XSPI_Exported_types SAL XSPI exported types
* @{
*/
/**
* @}
*/
/* Exported functions --------------------------------------------------------*/
/** @defgroup SAL_XSPI_Exported_Functions SAL XSPI Exported Functions
* @{
*/
HAL_StatusTypeDef SAL_XSPI_SetClock(SAL_XSPI_ObjectTypeDef *SalXspi, uint32_t ClockIn, uint32_t ClockRequested,
uint32_t *ClockReal);
HAL_StatusTypeDef SAL_XSPI_Init(SAL_XSPI_ObjectTypeDef *SalXspi, void *HALHandle);
HAL_StatusTypeDef SAL_XSPI_MemoryConfig(SAL_XSPI_ObjectTypeDef *SalXspi, SAL_XSPI_MemParamTypeTypeDef ParametersType,
void *ParamVal);
HAL_StatusTypeDef SAL_XSPI_GetSFDP(SAL_XSPI_ObjectTypeDef *SalXspi, uint32_t Address,
uint8_t *Data, uint32_t DataSize);
HAL_StatusTypeDef SAL_XSPI_GetId(SAL_XSPI_ObjectTypeDef *SalXspi, uint8_t *Data, uint32_t DataSize);
HAL_StatusTypeDef SAL_XSPI_Read(SAL_XSPI_ObjectTypeDef *SalXspi, uint8_t Command, uint32_t Address, uint8_t *Data,
uint32_t DataSize);
HAL_StatusTypeDef SAL_XSPI_Write(SAL_XSPI_ObjectTypeDef *SalXspi, uint8_t Command, uint32_t Address,
const uint8_t *Data, uint32_t DataSize);
HAL_StatusTypeDef SAL_XSPI_CommandSendAddress(SAL_XSPI_ObjectTypeDef *SalXspi, uint8_t Command, uint32_t Address);
HAL_StatusTypeDef SAL_XSPI_CommandSendData(SAL_XSPI_ObjectTypeDef *SalXspi, uint8_t Command,
uint8_t *Data, uint16_t DataSize);
HAL_StatusTypeDef SAL_XSPI_SendReadCommand(SAL_XSPI_ObjectTypeDef *SalXspi, uint8_t Command,
uint8_t *Data, uint16_t DataSize);
HAL_StatusTypeDef SAL_XSPI_CommandSendReadAddress(SAL_XSPI_ObjectTypeDef *SalXspi, uint8_t Command,
uint32_t Address, uint8_t *Data, uint16_t DataSize,
uint8_t ManuId);
HAL_StatusTypeDef SAL_XSPI_CheckStatusRegister(SAL_XSPI_ObjectTypeDef *SalXspi,
uint8_t Command, uint32_t Address, uint8_t MatchValue, uint8_t MatchMask,
uint8_t ManuId, uint32_t Timeout);
HAL_StatusTypeDef SAL_XSPI_ConfigureWrappMode(SAL_XSPI_ObjectTypeDef *SalXspi, uint8_t WrapCommand, uint8_t WrapDummy);
HAL_StatusTypeDef SAL_XSPI_EnableMapMode(SAL_XSPI_ObjectTypeDef *SalXspi, uint8_t CommandRead, uint8_t DummyRead,
uint8_t CommandWrite, uint8_t DummyWrite);
HAL_StatusTypeDef SAL_XSPI_DisableMapMode(SAL_XSPI_ObjectTypeDef *SalXspi);
HAL_StatusTypeDef SAL_XSPI_UpdateMemoryType(SAL_XSPI_ObjectTypeDef *SalXspi, SAL_XSPI_DataOrderTypeDef DataOrder);
/**
* @brief This function aborts the transaction
* @param SalXspi SAL XSPI handle
* @return @ref HAL_StatusTypeDef
**/
HAL_StatusTypeDef SAL_XSPI_Abort(SAL_XSPI_ObjectTypeDef *SalXspi);
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __STM32_SAL_XSPI_API_H */
@@ -0,0 +1,130 @@
/**
******************************************************************************
* @file stm32_sal_xspi_type.h
* @author MCD Application Team
* @brief This file contains SAL XSPI type definitions.
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32_SAL_XSPI_TYPE_H
#define __STM32_SAL_XSPI_TYPE_H
#ifdef __cplusplus
extern "C" {
#endif
/** @addtogroup SAL_XSPI
* @ingroup EXTMEM_SAL
* @{
*/
/* Includes ------------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/** @defgroup SAL_XSPI_Exported_types SAL XSPI exported types
* @{
*/
/**
* @brief Data order information.
*/
typedef enum
{
SAL_XSPI_ORDERINVERTED = 0,
} SAL_XSPI_DataOrderTypeDef;
/**
* @brief Enumeration of supported physical link configurations.
*/
typedef enum
{
PHY_LINK_1S1S1S, /*!< Physical link configure in 1S1S1S */
PHY_LINK_1S1S2S, /*!< Physical link configure in 1S1S2S */
PHY_LINK_1S2S2S, /*!< Physical link configure in 1S2S2S */
PHY_LINK_1S1D1D, /*!< Physical link configure in 1S1D1D */
PHY_LINK_4S4S4S, /*!< Physical link configure in 4S4S4S */
PHY_LINK_4S4D4D, /*!< Physical link configure in 4S4D4D */
PHY_LINK_4D4D4D, /*!< Physical link configure in 4D4D4D */
PHY_LINK_1S8S8S, /*!< Physical link configure in 1S8S8S */
PHY_LINK_8S8D8D, /*!< Physical link configure in 8S8D8D */
PHY_LINK_8D8D8D, /*!< Physical link configure in 8D8D8D */
PHY_LINK_RAM8, /*!< Physical link configure for RAM 8lines of data */
#if defined(HAL_XSPI_DATA_16_LINES)
PHY_LINK_RAM16, /*!< Physical link configure for RAM 16lines of data */
#endif /* defined(HAL_XSPI_DATA_16_LINES) */
} SAL_XSPI_PhysicalLinkTypeDef;
typedef struct
{
XSPI_HandleTypeDef *hxspi; /*!< Handle on the XSPI instance */
XSPI_RegularCmdTypeDef Commandbase; /*!< Command base configuration */
uint8_t CommandExtension; /*!< Flag on the 16-bit command extension 0 inverted 1 the same */
uint8_t SFDPDummyCycle; /*!< SDPF dummy cycle */
SAL_XSPI_PhysicalLinkTypeDef PhyLink; /*!< Only used for data Read in 4S4D4d 2S2D2D 1S1D1D */
uint8_t DTRDummyCycle; /*!< Specify that DTR read only valid for data read using DTRDummyCycle value */
} SAL_XSPI_ObjectTypeDef;
/**
* @brief define the list of the parameter
*/
typedef enum
{
PARAM_PHY_LINK, /*!< Physical link parameter */
PARAM_DUMMY_CYCLES, /*!< Dummy cycle parameter */
PARAM_ADDRESS_4BYTES, /*!< Address size parameter */
PARAM_DATA_STROBE, /*!< Data strobe parameter */
PARAM_FLASHSIZE, /*!< Flash size parameter */
} SAL_XSPI_MemParamTypeTypeDef;
/**
* @}
*/
/* Exported Macro ------------------------------------------------------------*/
#define SAL_XSPI_SET_DTRREADDUMMYCYLE(_OBJ_,_VAL_) (_OBJ_).DTRDummyCycle = (_VAL_)
#define SAL_XSPI_SET_SFDPDUMMYCYLE(_OBJ_,_VAL_) (_OBJ_).SFDPDummyCycle = (_VAL_)
#define SAL_XSPI_SET_COMMANDEXTENSION(_OBJ_,_VAL_) (_OBJ_).CommandExtension = (_VAL_)
#define SAL_XSPI_FORMAT_COMMANDSEND(_PTR_, _CMD_) \
_PTR_.CommandType = SAL_XSPI_COMMAND_SEND; \
_PTR_.Command = _CMD_;
/* Exported functions --------------------------------------------------------*/
/** @defgroup SAL_XSPI_Exported_Functions SAL XSP Exported Functions
* @{
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __STM32_SAL_XSPI_TYPE_H */