SD card use for DISCO_F469NI basic example

Dependents:   DISCO-F469NI_SD_demo StoreBitmaps IntegrationPotentiometer IntegrationCAN ... more

Committer:
Jerome Coutant
Date:
Wed May 17 12:56:35 2017 +0200
Revision:
1:c532df66d66a
Parent:
0:173c7f7ccc35
DISCO-F769NI BSP update with F4 Cube V1.16.0

Who changed what in which revision?

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