Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: DISCO-F469NI_SD_demo StoreBitmaps IntegrationPotentiometer IntegrationCAN ... more
SD_DISCO_F469NI.h@0:173c7f7ccc35, 2016-03-18 (annotated)
- Committer:
- adustm
- Date:
- Fri Mar 18 15:19:45 2016 +0000
- Revision:
- 0:173c7f7ccc35
- Child:
- 1:c532df66d66a
Class for SD_DISCO_F469NI
Who changed what in which revision?
User | Revision | Line number | New 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 |
adustm | 0:173c7f7ccc35 | 83 | * @param BlockSize: SD card data block size, that should be 512 |
adustm | 0:173c7f7ccc35 | 84 | * @param NumOfBlocks: Number of SD blocks to read |
adustm | 0:173c7f7ccc35 | 85 | * @retval SD status |
adustm | 0:173c7f7ccc35 | 86 | */ |
adustm | 0:173c7f7ccc35 | 87 | uint8_t ReadBlocks(uint32_t *pData, uint64_t ReadAddr, uint32_t BlockSize, uint32_t NumOfBlocks); |
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 BlockSize: SD card data block size, that should be 512 |
adustm | 0:173c7f7ccc35 | 94 | * @param NumOfBlocks: Number of SD blocks to write |
adustm | 0:173c7f7ccc35 | 95 | * @retval SD status |
adustm | 0:173c7f7ccc35 | 96 | */ |
adustm | 0:173c7f7ccc35 | 97 | uint8_t WriteBlocks(uint32_t *pData, uint64_t WriteAddr, uint32_t BlockSize, uint32_t NumOfBlocks); |
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 |
adustm | 0:173c7f7ccc35 | 103 | * @param BlockSize: SD card data block size, that should be 512 |
adustm | 0:173c7f7ccc35 | 104 | * @param NumOfBlocks: Number of SD blocks to read |
adustm | 0:173c7f7ccc35 | 105 | * @retval SD status |
adustm | 0:173c7f7ccc35 | 106 | */ |
adustm | 0:173c7f7ccc35 | 107 | uint8_t ReadBlocks_DMA(uint32_t *pData, uint64_t ReadAddr, uint32_t BlockSize, uint32_t NumOfBlocks); |
adustm | 0:173c7f7ccc35 | 108 | |
adustm | 0:173c7f7ccc35 | 109 | /** |
adustm | 0:173c7f7ccc35 | 110 | * @brief Writes block(s); to a specified address in an SD card, in DMA mode. |
adustm | 0:173c7f7ccc35 | 111 | * @param pData: Pointer to the buffer that will contain the data to transmit |
adustm | 0:173c7f7ccc35 | 112 | * @param WriteAddr: Address from where data is to be written |
adustm | 0:173c7f7ccc35 | 113 | * @param BlockSize: SD card data block size, that should be 512 |
adustm | 0:173c7f7ccc35 | 114 | * @param NumOfBlocks: Number of SD blocks to write |
adustm | 0:173c7f7ccc35 | 115 | * @retval SD status |
adustm | 0:173c7f7ccc35 | 116 | */ |
adustm | 0:173c7f7ccc35 | 117 | uint8_t WriteBlocks_DMA(uint32_t *pData, uint64_t WriteAddr, uint32_t BlockSize, uint32_t NumOfBlocks); |
adustm | 0:173c7f7ccc35 | 118 | |
adustm | 0:173c7f7ccc35 | 119 | /** |
adustm | 0:173c7f7ccc35 | 120 | * @brief Erases the specified memory area of the given SD card. |
adustm | 0:173c7f7ccc35 | 121 | * @param StartAddr: Start byte address |
adustm | 0:173c7f7ccc35 | 122 | * @param EndAddr: End byte address |
adustm | 0:173c7f7ccc35 | 123 | * @retval SD status |
adustm | 0:173c7f7ccc35 | 124 | */ |
adustm | 0:173c7f7ccc35 | 125 | uint8_t Erase(uint64_t StartAddr, uint64_t EndAddr); |
adustm | 0:173c7f7ccc35 | 126 | /** |
adustm | 0:173c7f7ccc35 | 127 | * @brief Gets the current SD card data status. |
adustm | 0:173c7f7ccc35 | 128 | * @retval Data transfer state. |
adustm | 0:173c7f7ccc35 | 129 | * This value can be one of the following values: |
adustm | 0:173c7f7ccc35 | 130 | * @arg SD_TRANSFER_OK: No data transfer is acting |
adustm | 0:173c7f7ccc35 | 131 | * @arg SD_TRANSFER_BUSY: Data transfer is acting |
adustm | 0:173c7f7ccc35 | 132 | * @arg SD_TRANSFER_ERROR: Data transfer error |
adustm | 0:173c7f7ccc35 | 133 | */ |
adustm | 0:173c7f7ccc35 | 134 | HAL_SD_TransferStateTypedef GetStatus(void); |
adustm | 0:173c7f7ccc35 | 135 | |
adustm | 0:173c7f7ccc35 | 136 | /** |
adustm | 0:173c7f7ccc35 | 137 | * @brief Get SD information about specific SD card. |
adustm | 0:173c7f7ccc35 | 138 | * @param CardInfo: Pointer to HAL_SD_CardInfoTypedef structure |
adustm | 0:173c7f7ccc35 | 139 | */ |
adustm | 0:173c7f7ccc35 | 140 | void GetCardInfo(HAL_SD_CardInfoTypedef *CardInfo); |
adustm | 0:173c7f7ccc35 | 141 | |
adustm | 0:173c7f7ccc35 | 142 | private: |
adustm | 0:173c7f7ccc35 | 143 | |
adustm | 0:173c7f7ccc35 | 144 | }; |
adustm | 0:173c7f7ccc35 | 145 | |
adustm | 0:173c7f7ccc35 | 146 | #else |
adustm | 0:173c7f7ccc35 | 147 | #error "This class must be used with DISCO_F469NI board only." |
adustm | 0:173c7f7ccc35 | 148 | #endif // TARGET_DISCO_F469NI |
adustm | 0:173c7f7ccc35 | 149 | |
adustm | 0:173c7f7ccc35 | 150 | #endif |
adustm | 0:173c7f7ccc35 | 151 |