SDFileSystem for STM32F746NG DISCOVERY with 4bit SDMMC interface on fixed pins

Dependencies:   FATFileSystem

Dependents:   DISCO-F746NG_SDFileSystem uzairkhan DISCO-F746NG_Scope_copy

Fork of SDFileSystem by Neil Thiessen

Committer:
DieterGraef
Date:
Sat Apr 16 13:01:50 2016 +0000
Revision:
27:8d192c180436
Parent:
26:8f15aa3b052b
Changed hard locking mechanism to watchdog , solved issue with the sleep mode of SD cards

Who changed what in which revision?

UserRevisionLine numberNew contents of line
neilt6 0:2a6d8a096edc 1 /* SD/MMC File System Library
neilt6 22:3fa5eaf48e81 2 * Copyright (c) 2016 Neil Thiessen
DieterGraef 23:c03ef1abef0e 3 * Modified for the use with STM32F746 Discovery (C) 2016 Dieter Greaf
neilt6 0:2a6d8a096edc 4 * Licensed under the Apache License, Version 2.0 (the "License");
neilt6 0:2a6d8a096edc 5 * you may not use this file except in compliance with the License.
neilt6 0:2a6d8a096edc 6 * You may obtain a copy of the License at
neilt6 0:2a6d8a096edc 7 *
neilt6 0:2a6d8a096edc 8 * http://www.apache.org/licenses/LICENSE-2.0
neilt6 0:2a6d8a096edc 9 *
neilt6 0:2a6d8a096edc 10 * Unless required by applicable law or agreed to in writing, software
neilt6 0:2a6d8a096edc 11 * distributed under the License is distributed on an "AS IS" BASIS,
neilt6 0:2a6d8a096edc 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
neilt6 0:2a6d8a096edc 13 * See the License for the specific language governing permissions and
neilt6 0:2a6d8a096edc 14 * limitations under the License.
neilt6 0:2a6d8a096edc 15 */
neilt6 0:2a6d8a096edc 16
neilt6 0:2a6d8a096edc 17 #include "SDFileSystem.h"
neilt6 18:2286a4e7fa31 18 #include "diskio.h"
neilt6 18:2286a4e7fa31 19 #include "SDCRC.h"
DieterGraef 23:c03ef1abef0e 20 //for cache flush function
DieterGraef 23:c03ef1abef0e 21 #include "SD_Helper.h"
neilt6 0:2a6d8a096edc 22
DieterGraef 23:c03ef1abef0e 23 SDFileSystem::SDFileSystem( const char* name)
DieterGraef 23:c03ef1abef0e 24 : FATFileSystem(name), m_Cd(PC_13)
neilt6 0:2a6d8a096edc 25 {
neilt6 0:2a6d8a096edc 26 //Initialize the member variables
DieterGraef 27:8d192c180436 27 void* h;
DieterGraef 23:c03ef1abef0e 28 uint8_t initstat;
neilt6 6:55a26a56046a 29 m_CardType = CARD_NONE;
neilt6 7:61db99e52c0d 30 m_Crc = true;
neilt6 6:55a26a56046a 31 m_LargeFrames = false;
neilt6 13:635147efa748 32 m_WriteValidation = true;
neilt6 0:2a6d8a096edc 33 m_Status = STA_NOINIT;
DieterGraef 23:c03ef1abef0e 34 m_Cd.mode(PullUp);
DieterGraef 23:c03ef1abef0e 35 m_CdAssert = 0;
DieterGraef 23:c03ef1abef0e 36 m_Cd.rise(this, &SDFileSystem::onCardRemoval);
DieterGraef 23:c03ef1abef0e 37 h=(void*)&SDFileSystem::DMA2_Stream3_IRQHandler;
DieterGraef 23:c03ef1abef0e 38 NVIC_SetVector(DMA2_Stream3_IRQn,(uint32_t)h);
DieterGraef 23:c03ef1abef0e 39 h=(void*)&SDFileSystem::DMA2_Stream6_IRQHandler;
DieterGraef 23:c03ef1abef0e 40 NVIC_SetVector(DMA2_Stream6_IRQn,(uint32_t)h);
DieterGraef 23:c03ef1abef0e 41 h=(void*)&SDFileSystem::SDMMC1_IRQHandler;
DieterGraef 23:c03ef1abef0e 42 NVIC_SetVector(SDMMC1_IRQn,(uint32_t)h);
DieterGraef 24:698affe9560c 43 BSP_SD_Clear_Busy();
DieterGraef 23:c03ef1abef0e 44 initstat=BSP_SD_Init();
DieterGraef 23:c03ef1abef0e 45 if (initstat!=MSD_OK)
DieterGraef 23:c03ef1abef0e 46 {
DieterGraef 23:c03ef1abef0e 47 m_Status |= STA_NOINIT;
DieterGraef 23:c03ef1abef0e 48 }
DieterGraef 23:c03ef1abef0e 49 else
DieterGraef 23:c03ef1abef0e 50 {
DieterGraef 23:c03ef1abef0e 51 m_Status &= ~STA_NOINIT;
DieterGraef 23:c03ef1abef0e 52 }
neilt6 0:2a6d8a096edc 53 }
neilt6 0:2a6d8a096edc 54
neilt6 20:2c1e8d442f68 55 bool SDFileSystem::card_present()
neilt6 0:2a6d8a096edc 56 {
neilt6 20:2c1e8d442f68 57 //Check the card socket
neilt6 0:2a6d8a096edc 58 checkSocket();
neilt6 0:2a6d8a096edc 59
neilt6 20:2c1e8d442f68 60 //Return whether or not a card is present
neilt6 20:2c1e8d442f68 61 return !(m_Status & STA_NODISK);
neilt6 20:2c1e8d442f68 62 }
neilt6 0:2a6d8a096edc 63
neilt6 20:2c1e8d442f68 64 SDFileSystem::CardType SDFileSystem::card_type()
neilt6 20:2c1e8d442f68 65 {
neilt6 20:2c1e8d442f68 66 //Check the card socket
neilt6 20:2c1e8d442f68 67 checkSocket();
neilt6 18:2286a4e7fa31 68
neilt6 0:2a6d8a096edc 69 //Return the card type
neilt6 0:2a6d8a096edc 70 return m_CardType;
neilt6 0:2a6d8a096edc 71 }
neilt6 0:2a6d8a096edc 72
neilt6 7:61db99e52c0d 73 bool SDFileSystem::crc()
neilt6 6:55a26a56046a 74 {
neilt6 6:55a26a56046a 75 //Return whether or not CRC is enabled
neilt6 7:61db99e52c0d 76 return m_Crc;
neilt6 6:55a26a56046a 77 }
neilt6 6:55a26a56046a 78
neilt6 7:61db99e52c0d 79 void SDFileSystem::crc(bool enabled)
neilt6 6:55a26a56046a 80 {
neilt6 20:2c1e8d442f68 81 //Check the card socket
neilt6 6:55a26a56046a 82 checkSocket();
neilt6 6:55a26a56046a 83
neilt6 6:55a26a56046a 84 //Just update the member variable if the card isn't initialized
neilt6 6:55a26a56046a 85 if (m_Status & STA_NOINIT) {
neilt6 7:61db99e52c0d 86 m_Crc = enabled;
neilt6 6:55a26a56046a 87 return;
neilt6 6:55a26a56046a 88 }
neilt6 6:55a26a56046a 89
neilt6 6:55a26a56046a 90 //Enable or disable CRC
neilt6 7:61db99e52c0d 91 if (enabled && !m_Crc) {
neilt6 6:55a26a56046a 92 //Send CMD59(0x00000001) to enable CRC
neilt6 7:61db99e52c0d 93 m_Crc = true;
DieterGraef 23:c03ef1abef0e 94 BSP_SD_CommandTransaction(CMD59, 0x00000001);
neilt6 7:61db99e52c0d 95 } else if (!enabled && m_Crc) {
DieterGraef 23:c03ef1abef0e 96 //Send CMD59(0x00000000) to disableAPP/MBED/targets/hal/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F746NG CRC
DieterGraef 23:c03ef1abef0e 97 BSP_SD_CommandTransaction(CMD59, 0x00000000);
neilt6 7:61db99e52c0d 98 m_Crc = false;
neilt6 6:55a26a56046a 99 }
neilt6 6:55a26a56046a 100 }
neilt6 6:55a26a56046a 101
neilt6 6:55a26a56046a 102 bool SDFileSystem::large_frames()
neilt6 6:55a26a56046a 103 {
neilt6 6:55a26a56046a 104 //Return whether or not 16-bit frames are enabled
neilt6 6:55a26a56046a 105 return m_LargeFrames;
neilt6 6:55a26a56046a 106 }
neilt6 6:55a26a56046a 107
neilt6 6:55a26a56046a 108 void SDFileSystem::large_frames(bool enabled)
neilt6 6:55a26a56046a 109 {
neilt6 6:55a26a56046a 110 //Set whether or not 16-bit frames are enabled
neilt6 6:55a26a56046a 111 m_LargeFrames = enabled;
neilt6 6:55a26a56046a 112 }
neilt6 6:55a26a56046a 113
neilt6 13:635147efa748 114 bool SDFileSystem::write_validation()
neilt6 13:635147efa748 115 {
neilt6 13:635147efa748 116 //Return whether or not write validation is enabled
neilt6 13:635147efa748 117 return m_WriteValidation;
neilt6 13:635147efa748 118 }
neilt6 13:635147efa748 119
neilt6 13:635147efa748 120 void SDFileSystem::write_validation(bool enabled)
neilt6 13:635147efa748 121 {
neilt6 13:635147efa748 122 //Set whether or not write validation is enabled
neilt6 13:635147efa748 123 m_WriteValidation = enabled;
neilt6 13:635147efa748 124 }
neilt6 13:635147efa748 125
neilt6 11:67ddc53e3983 126 int SDFileSystem::unmount()
neilt6 11:67ddc53e3983 127 {
neilt6 11:67ddc53e3983 128 //Unmount the filesystem
neilt6 11:67ddc53e3983 129 FATFileSystem::unmount();
neilt6 11:67ddc53e3983 130
neilt6 20:2c1e8d442f68 131 //Change the status to not initialized, and the card type to unknown
neilt6 11:67ddc53e3983 132 m_Status |= STA_NOINIT;
neilt6 20:2c1e8d442f68 133 m_CardType = CARD_UNKNOWN;
neilt6 11:67ddc53e3983 134
neilt6 11:67ddc53e3983 135 //Always succeeds
neilt6 11:67ddc53e3983 136 return 0;
neilt6 11:67ddc53e3983 137 }
neilt6 11:67ddc53e3983 138
neilt6 0:2a6d8a096edc 139 int SDFileSystem::disk_initialize()
neilt6 0:2a6d8a096edc 140 {
neilt6 0:2a6d8a096edc 141
neilt6 0:2a6d8a096edc 142 //Make sure there's a card in the socket before proceeding
neilt6 0:2a6d8a096edc 143 checkSocket();
neilt6 0:2a6d8a096edc 144 if (m_Status & STA_NODISK)
neilt6 0:2a6d8a096edc 145 return m_Status;
DieterGraef 23:c03ef1abef0e 146 BSP_SD_GetCardInfo(&m_CardInfo);
neilt6 12:eebddab6eff2 147
DieterGraef 23:c03ef1abef0e 148 switch(m_CardInfo.CardType)
DieterGraef 23:c03ef1abef0e 149 {
DieterGraef 23:c03ef1abef0e 150 case STD_CAPACITY_SD_CARD_V1_1:
DieterGraef 23:c03ef1abef0e 151 { m_CardType = CARD_SD;
DieterGraef 23:c03ef1abef0e 152 break; }
DieterGraef 23:c03ef1abef0e 153 case STD_CAPACITY_SD_CARD_V2_0:
DieterGraef 23:c03ef1abef0e 154 { m_CardType = CARD_SD;
DieterGraef 23:c03ef1abef0e 155 break; }
DieterGraef 23:c03ef1abef0e 156 case HIGH_CAPACITY_SD_CARD:
DieterGraef 23:c03ef1abef0e 157 { m_CardType = CARD_SDHC;
DieterGraef 23:c03ef1abef0e 158 break; }
DieterGraef 23:c03ef1abef0e 159 case MULTIMEDIA_CARD:
DieterGraef 23:c03ef1abef0e 160 { m_CardType = CARD_MMC;
DieterGraef 23:c03ef1abef0e 161 break; }
DieterGraef 23:c03ef1abef0e 162 case SECURE_DIGITAL_IO_CARD:
DieterGraef 23:c03ef1abef0e 163 { m_CardType = CARD_SD;
DieterGraef 23:c03ef1abef0e 164 break; }
DieterGraef 23:c03ef1abef0e 165 case HIGH_SPEED_MULTIMEDIA_CARD:
DieterGraef 23:c03ef1abef0e 166 { m_CardType = CARD_MMC;
DieterGraef 23:c03ef1abef0e 167 break; }
DieterGraef 23:c03ef1abef0e 168 case SECURE_DIGITAL_IO_COMBO_CARD:
DieterGraef 23:c03ef1abef0e 169 { m_CardType = CARD_SD;
DieterGraef 23:c03ef1abef0e 170 break; }
DieterGraef 23:c03ef1abef0e 171 case HIGH_CAPACITY_MMC_CARD:
DieterGraef 23:c03ef1abef0e 172 { m_CardType = CARD_MMC;
DieterGraef 23:c03ef1abef0e 173 break; }
DieterGraef 23:c03ef1abef0e 174 default:
DieterGraef 23:c03ef1abef0e 175 {m_CardType = CARD_UNKNOWN;
DieterGraef 23:c03ef1abef0e 176 return m_Status;}
DieterGraef 23:c03ef1abef0e 177 }
neilt6 0:2a6d8a096edc 178 //The card is now initialized
neilt6 0:2a6d8a096edc 179 m_Status &= ~STA_NOINIT;
neilt6 0:2a6d8a096edc 180
neilt6 9:1906befe7f30 181 //Return the disk status
neilt6 0:2a6d8a096edc 182 return m_Status;
neilt6 0:2a6d8a096edc 183 }
neilt6 0:2a6d8a096edc 184
neilt6 0:2a6d8a096edc 185 int SDFileSystem::disk_status()
neilt6 0:2a6d8a096edc 186 {
neilt6 20:2c1e8d442f68 187 //Check the card socket
neilt6 0:2a6d8a096edc 188 checkSocket();
neilt6 0:2a6d8a096edc 189
neilt6 9:1906befe7f30 190 //Return the disk status
DieterGraef 27:8d192c180436 191 return m_Status; //Check the card socket
DieterGraef 27:8d192c180436 192 checkSocket();
DieterGraef 27:8d192c180436 193 if (m_Status){return m_Status;}
DieterGraef 27:8d192c180436 194 m_CardStatus=BSP_SD_GetStatus();
DieterGraef 27:8d192c180436 195 //Return the disk status
DieterGraef 27:8d192c180436 196 return m_CardStatus;
neilt6 0:2a6d8a096edc 197 }
neilt6 0:2a6d8a096edc 198
neilt6 21:d10a519c0910 199 int SDFileSystem::disk_read(uint8_t* buffer, uint32_t sector, uint32_t count)
neilt6 0:2a6d8a096edc 200 {
DieterGraef 23:c03ef1abef0e 201 int retval;
DieterGraef 27:8d192c180436 202 uint32_t wdog;
neilt6 9:1906befe7f30 203 //Make sure the card is initialized before proceeding
neilt6 0:2a6d8a096edc 204 if (m_Status & STA_NOINIT)
neilt6 0:2a6d8a096edc 205 return RES_NOTRDY;
DieterGraef 27:8d192c180436 206 wdog=HAL_GetTick();
DieterGraef 25:391eade4ef85 207 __DSB();
DieterGraef 25:391eade4ef85 208 __ISB();
DieterGraef 27:8d192c180436 209 while(BSP_SD_Get_Busy()==1)
DieterGraef 27:8d192c180436 210 {
DieterGraef 27:8d192c180436 211 if((HAL_GetTick()-wdog)>64)
DieterGraef 27:8d192c180436 212 {
DieterGraef 27:8d192c180436 213 BSP_SD_Clear_Busy();
DieterGraef 27:8d192c180436 214 return RES_ERROR;
DieterGraef 27:8d192c180436 215 }
DieterGraef 27:8d192c180436 216 }
DieterGraef 24:698affe9560c 217 BSP_SD_Set_Busy();
neilt6 11:67ddc53e3983 218 //Read a single block, or multiple blocks
neilt6 11:67ddc53e3983 219 if (count > 1) {
DieterGraef 23:c03ef1abef0e 220 BSP_SD_Set_RX_Busy();
DieterGraef 26:8f15aa3b052b 221 SCB_InvalidateDCache_by_Addr((uint32_t *)buffer,(512*count));
DieterGraef 23:c03ef1abef0e 222 retval=BSP_SD_ReadBlocks_DMA((uint32_t *)buffer, (uint64_t) (sector * 512),512, count);
DieterGraef 24:698affe9560c 223 while((BSP_SD_Get_RX_Busy()==1)&&(retval==MSD_OK)){;}
DieterGraef 23:c03ef1abef0e 224 CPU_CACHE_Flush((uint32_t *)buffer,(512*count));
DieterGraef 24:698affe9560c 225 BSP_SD_Clear_Busy();
DieterGraef 23:c03ef1abef0e 226 return (retval ? RES_ERROR : RES_OK);
neilt6 11:67ddc53e3983 227 } else {
DieterGraef 23:c03ef1abef0e 228 BSP_SD_Set_RX_Busy();
DieterGraef 26:8f15aa3b052b 229 SCB_InvalidateDCache_by_Addr((uint32_t *)buffer,(512));
DieterGraef 23:c03ef1abef0e 230 retval= BSP_SD_ReadBlocks_DMA((uint32_t *)buffer, (uint64_t) (sector * 512), 512, 1);
DieterGraef 24:698affe9560c 231 while((BSP_SD_Get_RX_Busy()==1)&&(retval==MSD_OK)){;}
DieterGraef 23:c03ef1abef0e 232 CPU_CACHE_Flush((uint32_t *)buffer,(512));
DieterGraef 24:698affe9560c 233 BSP_SD_Clear_Busy();
DieterGraef 23:c03ef1abef0e 234 return (retval ? RES_ERROR : RES_OK);
neilt6 0:2a6d8a096edc 235 }
neilt6 0:2a6d8a096edc 236 }
neilt6 0:2a6d8a096edc 237
neilt6 21:d10a519c0910 238 int SDFileSystem::disk_write(const uint8_t* buffer, uint32_t sector, uint32_t count)
neilt6 0:2a6d8a096edc 239 {
DieterGraef 23:c03ef1abef0e 240 int retval;
DieterGraef 27:8d192c180436 241 uint32_t wdog;
neilt6 9:1906befe7f30 242 //Make sure the card is initialized before proceeding
neilt6 0:2a6d8a096edc 243 if (m_Status & STA_NOINIT)
neilt6 0:2a6d8a096edc 244 return RES_NOTRDY;
DieterGraef 27:8d192c180436 245 wdog=HAL_GetTick();
DieterGraef 25:391eade4ef85 246 __DSB();
DieterGraef 25:391eade4ef85 247 __ISB();
DieterGraef 27:8d192c180436 248 while(BSP_SD_Get_Busy()==1)
DieterGraef 27:8d192c180436 249 {
DieterGraef 27:8d192c180436 250 if((HAL_GetTick()-wdog)>64)
DieterGraef 27:8d192c180436 251 {
DieterGraef 27:8d192c180436 252 BSP_SD_Clear_Busy();
DieterGraef 27:8d192c180436 253 return RES_ERROR;
DieterGraef 27:8d192c180436 254 }
DieterGraef 27:8d192c180436 255 }
DieterGraef 24:698affe9560c 256 BSP_SD_Set_Busy();
neilt6 9:1906befe7f30 257 //Make sure the card isn't write protected before proceeding
neilt6 0:2a6d8a096edc 258 if (m_Status & STA_PROTECT)
DieterGraef 24:698affe9560c 259 {
DieterGraef 24:698affe9560c 260 BSP_SD_Clear_Busy();
DieterGraef 24:698affe9560c 261 return RES_WRPRT;
DieterGraef 24:698affe9560c 262 }
neilt6 11:67ddc53e3983 263 //Write a single block, or multiple blocks
neilt6 11:67ddc53e3983 264 if (count > 1) {
DieterGraef 23:c03ef1abef0e 265 CPU_CACHE_Flush((uint32_t *)buffer,(512*count));
DieterGraef 23:c03ef1abef0e 266 BSP_SD_Set_TX_Busy();
DieterGraef 23:c03ef1abef0e 267 retval= BSP_SD_WriteBlocks_DMA((uint32_t *)buffer, (uint64_t) (sector * 512), 512, count);
DieterGraef 24:698affe9560c 268 while((BSP_SD_Get_TX_Busy()==1)&&(retval==MSD_OK)){;}
DieterGraef 24:698affe9560c 269 BSP_SD_Clear_Busy();
DieterGraef 23:c03ef1abef0e 270 return (retval? RES_ERROR : RES_OK);
neilt6 11:67ddc53e3983 271 } else {
DieterGraef 23:c03ef1abef0e 272 CPU_CACHE_Flush((uint32_t *)buffer,(512));
DieterGraef 23:c03ef1abef0e 273 BSP_SD_Set_TX_Busy();
DieterGraef 23:c03ef1abef0e 274 retval= BSP_SD_WriteBlocks_DMA((uint32_t *)buffer, (uint64_t) (sector * 512), 512, 1);
DieterGraef 24:698affe9560c 275 while((BSP_SD_Get_TX_Busy()==1)&&(retval==MSD_OK)){;}
DieterGraef 24:698affe9560c 276 BSP_SD_Clear_Busy();
DieterGraef 23:c03ef1abef0e 277 return (retval? RES_ERROR : RES_OK);
DieterGraef 23:c03ef1abef0e 278
neilt6 0:2a6d8a096edc 279 }
neilt6 0:2a6d8a096edc 280 }
neilt6 0:2a6d8a096edc 281
neilt6 0:2a6d8a096edc 282 int SDFileSystem::disk_sync()
neilt6 0:2a6d8a096edc 283 {
neilt6 0:2a6d8a096edc 284 //Select the card so we're forced to wait for the end of any internal write processes
DieterGraef 25:391eade4ef85 285 __DSB();
DieterGraef 25:391eade4ef85 286 __ISB();
DieterGraef 24:698affe9560c 287 while(BSP_SD_Get_Busy()==1){;}
DieterGraef 24:698affe9560c 288 BSP_SD_Set_Busy();
DieterGraef 23:c03ef1abef0e 289 while(BSP_SD_GetStatus()==SD_TRANSFER_BUSY){;}
DieterGraef 23:c03ef1abef0e 290 if(BSP_SD_GetStatus()==SD_TRANSFER_OK)
DieterGraef 23:c03ef1abef0e 291 {
DieterGraef 24:698affe9560c 292 BSP_SD_Clear_Busy();
neilt6 10:395539a1481a 293 return RES_OK;
neilt6 10:395539a1481a 294 } else {
DieterGraef 24:698affe9560c 295 BSP_SD_Clear_Busy();
neilt6 10:395539a1481a 296 return RES_ERROR;
neilt6 10:395539a1481a 297 }
neilt6 0:2a6d8a096edc 298 }
neilt6 0:2a6d8a096edc 299
neilt6 21:d10a519c0910 300 uint32_t SDFileSystem::disk_sectors()
neilt6 0:2a6d8a096edc 301 {
DieterGraef 23:c03ef1abef0e 302 uint32_t sectors=0;
neilt6 9:1906befe7f30 303 //Make sure the card is initialized before proceeding
neilt6 0:2a6d8a096edc 304 if (m_Status & STA_NOINIT)
neilt6 0:2a6d8a096edc 305 return 0;
DieterGraef 25:391eade4ef85 306 __DSB();
DieterGraef 25:391eade4ef85 307 __ISB();
DieterGraef 24:698affe9560c 308 while(BSP_SD_Get_Busy()==1){;}
DieterGraef 24:698affe9560c 309 BSP_SD_Set_Busy();
DieterGraef 24:698affe9560c 310 BSP_SD_GetCardInfo(&m_CardInfo);
DieterGraef 24:698affe9560c 311 sectors=m_CardInfo.CardCapacity>>9;
DieterGraef 24:698affe9560c 312 BSP_SD_Clear_Busy();
DieterGraef 23:c03ef1abef0e 313 return sectors;
neilt6 0:2a6d8a096edc 314 }
neilt6 0:2a6d8a096edc 315
neilt6 13:635147efa748 316 void SDFileSystem::onCardRemoval()
neilt6 13:635147efa748 317 {
neilt6 20:2c1e8d442f68 318 //Check the card socket
neilt6 13:635147efa748 319 checkSocket();
neilt6 13:635147efa748 320 }
neilt6 13:635147efa748 321
neilt6 13:635147efa748 322 inline void SDFileSystem::checkSocket()
neilt6 0:2a6d8a096edc 323 {
neilt6 16:c2c1f0b16380 324 //Use the card detect switch (if available) to determine if the socket is occupied
neilt6 20:2c1e8d442f68 325 if (m_CdAssert != -1) {
neilt6 20:2c1e8d442f68 326 if (m_Status & STA_NODISK) {
neilt6 20:2c1e8d442f68 327 if (m_Cd == m_CdAssert) {
neilt6 20:2c1e8d442f68 328 //The socket is now occupied
neilt6 20:2c1e8d442f68 329 m_Status &= ~STA_NODISK;
neilt6 20:2c1e8d442f68 330 m_CardType = CARD_UNKNOWN;
neilt6 20:2c1e8d442f68 331 }
neilt6 20:2c1e8d442f68 332 } else {
neilt6 20:2c1e8d442f68 333 if (m_Cd != m_CdAssert) {
neilt6 20:2c1e8d442f68 334 //The socket is now empty
neilt6 20:2c1e8d442f68 335 m_Status |= (STA_NODISK | STA_NOINIT);
neilt6 20:2c1e8d442f68 336 m_CardType = CARD_NONE;
neilt6 20:2c1e8d442f68 337 }
neilt6 20:2c1e8d442f68 338 }
neilt6 0:2a6d8a096edc 339 }
neilt6 0:2a6d8a096edc 340 }
neilt6 0:2a6d8a096edc 341
neilt6 0:2a6d8a096edc 342
DieterGraef 23:c03ef1abef0e 343 /*interrupthandlers */
DieterGraef 23:c03ef1abef0e 344 /**
DieterGraef 23:c03ef1abef0e 345 * @brief This function handles DMA2 Stream 3 interrupt request.
DieterGraef 23:c03ef1abef0e 346 * @param None
DieterGraef 23:c03ef1abef0e 347 * @retval None
DieterGraef 23:c03ef1abef0e 348 */
DieterGraef 23:c03ef1abef0e 349 void SDFileSystem::DMA2_Stream3_IRQHandler(void)
neilt6 11:67ddc53e3983 350 {
DieterGraef 23:c03ef1abef0e 351 BSP_SD_DMA_Rx_IRQHandler();
DieterGraef 23:c03ef1abef0e 352 BSP_SD_Clear_RX_Busy();
neilt6 11:67ddc53e3983 353 }
neilt6 11:67ddc53e3983 354
DieterGraef 23:c03ef1abef0e 355 /**
DieterGraef 23:c03ef1abef0e 356 * @brief This function handles DMA2 Stream 6 interrupt request.
DieterGraef 23:c03ef1abef0e 357 * @param None
DieterGraef 23:c03ef1abef0e 358 * @retval None
DieterGraef 23:c03ef1abef0e 359 */
DieterGraef 23:c03ef1abef0e 360 void SDFileSystem::DMA2_Stream6_IRQHandler(void)
neilt6 11:67ddc53e3983 361 {
DieterGraef 23:c03ef1abef0e 362 BSP_SD_DMA_Tx_IRQHandler();
DieterGraef 23:c03ef1abef0e 363 BSP_SD_Clear_TX_Busy();
neilt6 11:67ddc53e3983 364 }
neilt6 9:1906befe7f30 365
DieterGraef 23:c03ef1abef0e 366 /**
DieterGraef 23:c03ef1abef0e 367 * @brief This function handles SDIO interrupt request.
DieterGraef 23:c03ef1abef0e 368 * @param None
DieterGraef 23:c03ef1abef0e 369 * @retval None
DieterGraef 23:c03ef1abef0e 370 */
DieterGraef 23:c03ef1abef0e 371 void SDFileSystem::SDMMC1_IRQHandler(void)
neilt6 11:67ddc53e3983 372 {
DieterGraef 23:c03ef1abef0e 373 BSP_SD_IRQHandler();
neilt6 9:1906befe7f30 374 }