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: F746_AudioPlayerSD F746_SD_WavPlayer F746_SD_GraphicEqualizer_ren0620 F746_SD_TextFile_RW ... more
SDFileSystem.h
00001 //----------------------------------------------------------------------- 00002 // Fixed version not to issue warning message by N.Mikami 00003 // January 09, 2017 00004 //----------------------------------------------------------------------- 00005 00006 /* SD/MMC File System Library 00007 * Copyright (c) 2016 Neil Thiessen 00008 * Modified for the use with STM32F746 Discovery (C) 2016 Dieter Greaf 00009 * Licensed under the Apache License, Version 2.0 (the "License"); 00010 * you may not use this file except in compliance with the License. 00011 * You may obtain a copy of the License at 00012 * 00013 * http://www.apache.org/licenses/LICENSE-2.0 00014 * 00015 * Unless required by applicable law or agreed to in writing, software 00016 * distributed under the License is distributed on an "AS IS" BASIS, 00017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00018 * See the License for the specific language governing permissions and 00019 * limitations under the License. 00020 */ 00021 00022 #ifndef SD_FILE_SYSTEM_H 00023 #define SD_FILE_SYSTEM_H 00024 00025 #include "mbed.h" 00026 #include "stm32746g_discovery_sd.h" 00027 #include "FATFileSystem.h" 00028 00029 /** SDFileSystem class. 00030 * Used for creating a virtual file system for accessing SD/MMC cards via SPI. 00031 * 00032 * Example: 00033 * @code 00034 * #include "mbed.h" 00035 * #include "SDFileSystem.h" 00036 * 00037 * //Create an SDFileSystem object 00038 * SDFileSystem sd("sd"); 00039 * 00040 * int main() 00041 * { 00042 * //Mount the filesystem 00043 * sd.mount(); 00044 * 00045 * //Perform a write test 00046 * printf("\nWriting to SD card..."); 00047 * FILE *fp = fopen("/sd/sdtest.txt", "w"); 00048 * if (fp != NULL) { 00049 * fprintf(fp, "We're writing to an SD card!"); 00050 * fclose(fp); 00051 * printf("success!\n"); 00052 * } else { 00053 * printf("failed!\n"); 00054 * } 00055 * 00056 * //Perform a read test 00057 * printf("Reading from SD card..."); 00058 * fp = fopen("/sd/sdtest.txt", "r"); 00059 * if (fp != NULL) { 00060 * char c = fgetc(fp); 00061 * if (c == 'W') 00062 * printf("success!\n"); 00063 * else 00064 * printf("incorrect char (%c)!\n", c); 00065 * fclose(fp); 00066 * } else { 00067 * printf("failed!\n"); 00068 * } 00069 * 00070 * //Unmount the filesystem 00071 * sd.unmount(); 00072 * } 00073 * @endcode 00074 00075 */ 00076 #define CMD59 (0x40 | 59) 00077 using namespace mbed; 00078 00079 class SDFileSystem : public FATFileSystem 00080 { 00081 public: 00082 /** Represents the different card detect switch types 00083 */ 00084 enum SwitchType { 00085 SWITCH_NONE, /**< No card detect switch (assumes socket is always occupied) */ 00086 SWITCH_POS_NO, /**< Switch shorts to VDD when the socket is occupied (positive logic, normally open) */ 00087 SWITCH_POS_NC, /**< Switch shorts to VDD when the socket is empty (positive logic, normally closed) */ 00088 SWITCH_NEG_NO, /**< Switch shorts to GND when the socket is occupied (negative logic, normally open) */ 00089 SWITCH_NEG_NC /**< Switch shorts to GND when the socket is empty (negative logic, normally closed) */ 00090 }; 00091 00092 /** Represents the different SD/MMC card types 00093 */ 00094 enum CardType { 00095 CARD_NONE, /**< No card is present */ 00096 CARD_MMC, /**< MMC card */ 00097 CARD_SD, /**< Standard capacity SD card */ 00098 CARD_SDHC, /**< High capacity SD card */ 00099 CARD_UNKNOWN /**< Unknown or unsupported card */ 00100 }; 00101 00102 /** Create a virtual file system for accessing SD/MMC cards via SPI 00103 * 00104 * @param mosi The SPI data out pin. 00105 * @param miso The SPI data in pin. 00106 * @param sclk The SPI clock pin. 00107 * @param cs The SPI chip select pin. 00108 * @param name The name used to access the virtual filesystem. 00109 * @param cd The card detect pin. 00110 * @param cdtype The type of card detect switch. 00111 * @param hz The SPI bus frequency (defaults to 1MHz). 00112 */ 00113 SDFileSystem( const char* name); 00114 00115 /** Determine whether or not a card is present 00116 * 00117 * @returns 00118 * 'true' if a card is present, 00119 * 'false' if no card is present. 00120 */ 00121 bool card_present(); 00122 00123 /** Get the detected SD/MMC card type 00124 * 00125 * @returns The detected card type as a CardType enum. 00126 * 00127 * @note Valid after the filesystem has been mounted. 00128 */ 00129 SDFileSystem::CardType card_type(); 00130 00131 /** Get whether or not CRC is enabled for commands and data 00132 * 00133 * @returns 00134 * 'true' if CRC is enabled for commands and data, 00135 * 'false' if CRC is disabled for commands and data. 00136 */ 00137 bool crc(); 00138 00139 /** Set whether or not CRC is enabled for commands and data 00140 * 00141 * @param enabled Whether or not to enable CRC for commands and data. 00142 */ 00143 void crc(bool enabled); 00144 00145 /** Get whether or not 16-bit frames are enabled for data read/write operations 00146 * 00147 * @returns 00148 * 'true' if 16-bit frames will be used during data read/write operations, 00149 * 'false' if 8-bit frames will be used during data read/write operations. 00150 */ 00151 bool large_frames(); 00152 00153 /** Set whether or not 16-bit frames are enabled for data read/write operations 00154 * 00155 * @param enabled Whether or not 16-bit frames are enabled for data read/write operations. 00156 */ 00157 void large_frames(bool enabled); 00158 00159 /** Get whether or not write validation is enabled for data write operations 00160 * 00161 * @returns 00162 * 'true' if data writes will be verified using CMD13, 00163 * 'false' if data writes will not be verified. 00164 */ 00165 bool write_validation(); 00166 00167 /** Set whether or not write validation is enabled for data write operations 00168 * 00169 * @param enabled Whether or not write validation is enabled for data write operations. 00170 */ 00171 void write_validation(bool enabled); 00172 00173 virtual int unmount(); 00174 virtual int disk_initialize(); 00175 virtual int disk_status(); 00176 virtual int disk_read(uint8_t* buffer, uint32_t sector, uint32_t count); 00177 virtual int disk_write(const uint8_t* buffer, uint32_t sector, uint32_t count); 00178 virtual int disk_sync(); 00179 virtual uint32_t disk_sectors(); 00180 00181 private: 00182 Timer m_Timer; 00183 InterruptIn m_Cd; 00184 int m_CdAssert; 00185 SDFileSystem::CardType m_CardType; 00186 bool m_Crc; 00187 bool m_LargeFrames; 00188 bool m_WriteValidation; 00189 int m_Status; 00190 HAL_SD_CardInfoTypedef m_CardInfo; 00191 //Internal methods 00192 void onCardRemoval(); 00193 void checkSocket(); 00194 00195 // Followings are original 00196 // void DMA2_Stream3_IRQHandler(); 00197 // void DMA2_Stream6_IRQHandler(); 00198 // void SDMMC1_IRQHandler(); 00199 00200 // Modified 00201 static void DMA2_Stream3_IRQHandler(); 00202 static void DMA2_Stream6_IRQHandler(); 00203 static void SDMMC1_IRQHandler(); 00204 }; 00205 00206 #endif
Generated on Tue Jul 12 2022 23:17:10 by
1.7.2