Nam

Dependents:   uSD

Committer:
phungductung
Date:
Fri Jun 07 15:39:16 2019 +0000
Revision:
0:b5f04a643750
spkt;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
phungductung 0:b5f04a643750 1 /* Copyright (c) 2010-2016 mbed.org, MIT License
phungductung 0:b5f04a643750 2 *
phungductung 0:b5f04a643750 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
phungductung 0:b5f04a643750 4 * and associated documentation files (the "Software"), to deal in the Software without
phungductung 0:b5f04a643750 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
phungductung 0:b5f04a643750 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
phungductung 0:b5f04a643750 7 * Software is furnished to do so, subject to the following conditions:
phungductung 0:b5f04a643750 8 *
phungductung 0:b5f04a643750 9 * The above copyright notice and this permission notice shall be included in all copies or
phungductung 0:b5f04a643750 10 * substantial portions of the Software.
phungductung 0:b5f04a643750 11 *
phungductung 0:b5f04a643750 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
phungductung 0:b5f04a643750 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
phungductung 0:b5f04a643750 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
phungductung 0:b5f04a643750 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
phungductung 0:b5f04a643750 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
phungductung 0:b5f04a643750 17 */
phungductung 0:b5f04a643750 18
phungductung 0:b5f04a643750 19 #ifndef __SDRAM_DISCO_F746NG_H
phungductung 0:b5f04a643750 20 #define __SDRAM_DISCO_F746NG_H
phungductung 0:b5f04a643750 21
phungductung 0:b5f04a643750 22 #ifdef TARGET_DISCO_F746NG
phungductung 0:b5f04a643750 23
phungductung 0:b5f04a643750 24 #include "mbed.h"
phungductung 0:b5f04a643750 25 #include "stm32746g_discovery_sd.h"
phungductung 0:b5f04a643750 26
phungductung 0:b5f04a643750 27 /*
phungductung 0:b5f04a643750 28 This class drives the uSD card driver mounted on DISCO_F746NG board.
phungductung 0:b5f04a643750 29
phungductung 0:b5f04a643750 30 Usage:
phungductung 0:b5f04a643750 31
phungductung 0:b5f04a643750 32 #include "mbed.h"
phungductung 0:b5f04a643750 33 #include "SD_DISCO_F746NG.h"
phungductung 0:b5f04a643750 34
phungductung 0:b5f04a643750 35 SD_DISCO_F746NG sd;
phungductung 0:b5f04a643750 36
phungductung 0:b5f04a643750 37 int main()
phungductung 0:b5f04a643750 38 {
phungductung 0:b5f04a643750 39 sd.Erase(BLOCK_START_ADDR, (BLOCKSIZE * NUM_OF_BLOCKS);
phungductung 0:b5f04a643750 40 sd.WriteBlocks(aTxBuffer, BLOCK_START_ADDR, BLOCKSIZE, NUM_OF_BLOCKS);
phungductung 0:b5f04a643750 41 sd.ReadBlocks(aRxBuffer, BLOCK_START_ADDR, BLOCKSIZE, NUM_OF_BLOCKS);
phungductung 0:b5f04a643750 42 while 1 {}
phungductung 0:b5f04a643750 43
phungductung 0:b5f04a643750 44 }
phungductung 0:b5f04a643750 45 */
phungductung 0:b5f04a643750 46 class SD_DISCO_F746NG
phungductung 0:b5f04a643750 47 {
phungductung 0:b5f04a643750 48
phungductung 0:b5f04a643750 49 public:
phungductung 0:b5f04a643750 50 //! Constructor
phungductung 0:b5f04a643750 51 SD_DISCO_F746NG();
phungductung 0:b5f04a643750 52
phungductung 0:b5f04a643750 53 //! Destructor
phungductung 0:b5f04a643750 54 ~SD_DISCO_F746NG();
phungductung 0:b5f04a643750 55
phungductung 0:b5f04a643750 56 /**
phungductung 0:b5f04a643750 57 * @brief Initializes the SD card device.
phungductung 0:b5f04a643750 58 * @retval SD status
phungductung 0:b5f04a643750 59 */
phungductung 0:b5f04a643750 60 uint8_t Init(void);
phungductung 0:b5f04a643750 61
phungductung 0:b5f04a643750 62 /**
phungductung 0:b5f04a643750 63 * @brief DeInitializes the SD card device.
phungductung 0:b5f04a643750 64 * @retval SD status
phungductung 0:b5f04a643750 65 */
phungductung 0:b5f04a643750 66 uint8_t DeInit(void);
phungductung 0:b5f04a643750 67
phungductung 0:b5f04a643750 68 /**
phungductung 0:b5f04a643750 69 * @brief Configures Interrupt mode for SD detection pin.
phungductung 0:b5f04a643750 70 * @retval Returns MSD_OK
phungductung 0:b5f04a643750 71 */
phungductung 0:b5f04a643750 72 uint8_t ITConfig(void);
phungductung 0:b5f04a643750 73
phungductung 0:b5f04a643750 74 /**
phungductung 0:b5f04a643750 75 * @brief Detects if SD card is correctly plugged in the memory slot or not.
phungductung 0:b5f04a643750 76 * @retval Returns if SD is detected or not
phungductung 0:b5f04a643750 77 */
phungductung 0:b5f04a643750 78 uint8_t IsDetected(void);
phungductung 0:b5f04a643750 79
phungductung 0:b5f04a643750 80 /**
phungductung 0:b5f04a643750 81 * @brief Reads block(s); from a specified address in an SD card, in polling mode.
phungductung 0:b5f04a643750 82 * @param pData: Pointer to the buffer that will contain the data to transmit
phungductung 0:b5f04a643750 83 * @param ReadAddr: Address from where data is to be read
phungductung 0:b5f04a643750 84 * @param BlockSize: SD card data block size, that should be 512
phungductung 0:b5f04a643750 85 * @param NumOfBlocks: Number of SD blocks to read
phungductung 0:b5f04a643750 86 * @retval SD status
phungductung 0:b5f04a643750 87 */
phungductung 0:b5f04a643750 88 uint8_t ReadBlocks(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks, uint32_t Timeout);
phungductung 0:b5f04a643750 89
phungductung 0:b5f04a643750 90 /**
phungductung 0:b5f04a643750 91 * @brief Writes block(s); to a specified address in an SD card, in polling mode.
phungductung 0:b5f04a643750 92 * @param pData: Pointer to the buffer that will contain the data to transmit
phungductung 0:b5f04a643750 93 * @param WriteAddr: Address from where data is to be written
phungductung 0:b5f04a643750 94 * @param BlockSize: SD card data block size, that should be 512
phungductung 0:b5f04a643750 95 * @param NumOfBlocks: Number of SD blocks to write
phungductung 0:b5f04a643750 96 * @retval SD status
phungductung 0:b5f04a643750 97 */
phungductung 0:b5f04a643750 98 uint8_t WriteBlocks(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks, uint32_t Timeout);
phungductung 0:b5f04a643750 99
phungductung 0:b5f04a643750 100 /**
phungductung 0:b5f04a643750 101 * @brief Reads block(s); from a specified address in an SD card, in DMA mode.
phungductung 0:b5f04a643750 102 * @param pData: Pointer to the buffer that will contain the data to transmit
phungductung 0:b5f04a643750 103 * @param ReadAddr: Address from where data is to be read
phungductung 0:b5f04a643750 104 * @param BlockSize: SD card data block size, that should be 512
phungductung 0:b5f04a643750 105 * @param NumOfBlocks: Number of SD blocks to read
phungductung 0:b5f04a643750 106 * @retval SD status
phungductung 0:b5f04a643750 107 */
phungductung 0:b5f04a643750 108 uint8_t ReadBlocks_DMA(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks);
phungductung 0:b5f04a643750 109
phungductung 0:b5f04a643750 110 /**
phungductung 0:b5f04a643750 111 * @brief Writes block(s); to a specified address in an SD card, in DMA mode.
phungductung 0:b5f04a643750 112 * @param pData: Pointer to the buffer that will contain the data to transmit
phungductung 0:b5f04a643750 113 * @param WriteAddr: Address from where data is to be written
phungductung 0:b5f04a643750 114 * @param BlockSize: SD card data block size, that should be 512
phungductung 0:b5f04a643750 115 * @param NumOfBlocks: Number of SD blocks to write
phungductung 0:b5f04a643750 116 * @retval SD status
phungductung 0:b5f04a643750 117 */
phungductung 0:b5f04a643750 118 uint8_t WriteBlocks_DMA(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks);
phungductung 0:b5f04a643750 119
phungductung 0:b5f04a643750 120 /**
phungductung 0:b5f04a643750 121 * @brief Erases the specified memory area of the given SD card.
phungductung 0:b5f04a643750 122 * @param StartAddr: Start byte address
phungductung 0:b5f04a643750 123 * @param EndAddr: End byte address
phungductung 0:b5f04a643750 124 * @retval SD status
phungductung 0:b5f04a643750 125 */
phungductung 0:b5f04a643750 126 uint8_t Erase(uint64_t StartAddr, uint64_t EndAddr);
phungductung 0:b5f04a643750 127
phungductung 0:b5f04a643750 128 /**
phungductung 0:b5f04a643750 129 * @brief Gets the current SD card data status.
phungductung 0:b5f04a643750 130 * @retval Data transfer state.
phungductung 0:b5f04a643750 131 * This value can be one of the following values:
phungductung 0:b5f04a643750 132 * @arg SD_TRANSFER_OK: No data transfer is acting
phungductung 0:b5f04a643750 133 * @arg SD_TRANSFER_BUSY: Data transfer is acting
phungductung 0:b5f04a643750 134 * @arg SD_TRANSFER_ERROR: Data transfer error
phungductung 0:b5f04a643750 135 */
phungductung 0:b5f04a643750 136 uint8_t GetCardState(void);
phungductung 0:b5f04a643750 137
phungductung 0:b5f04a643750 138 /**
phungductung 0:b5f04a643750 139 * @brief Get SD information about specific SD card.
phungductung 0:b5f04a643750 140 * @param CardInfo: Pointer to HAL_SD_CardInfoTypedef structure
phungductung 0:b5f04a643750 141 * @retval None
phungductung 0:b5f04a643750 142 */
phungductung 0:b5f04a643750 143 void GetCardInfo(HAL_SD_CardInfoTypeDef *CardInfo);
phungductung 0:b5f04a643750 144
phungductung 0:b5f04a643750 145 private:
phungductung 0:b5f04a643750 146
phungductung 0:b5f04a643750 147 };
phungductung 0:b5f04a643750 148
phungductung 0:b5f04a643750 149 #else
phungductung 0:b5f04a643750 150 #error "This class must be used with DISCO_F746NG board only."
phungductung 0:b5f04a643750 151 #endif // TARGET_DISCO_F746NG
phungductung 0:b5f04a643750 152
phungductung 0:b5f04a643750 153 #endif