Browse Source

Fix FAT16 detection

main
PaulStoffregen 9 years ago
parent
commit
c4530cbc40
3 changed files with 12 additions and 8 deletions
  1. +1
    -1
      SD_t3.h
  2. +8
    -4
      cache_t3.cpp
  3. +3
    -3
      init_t3.cpp

+ 1
- 1
SD_t3.h View File

@@ -27,7 +27,7 @@
// This Teensy 3.x optimized version is a work-in-progress.
// Uncomment this line to use the Teensy version. Otherwise,
// the normal SD library is used.
#define USE_TEENSY3_OPTIMIZED_CODE
//#define USE_TEENSY3_OPTIMIZED_CODE

/* Why reinvent the SD library wheel...
* 1: Allow reading files from within interrupts

+ 8
- 4
cache_t3.cpp View File

@@ -37,7 +37,9 @@ cache_t SDCache::cache[SD_CACHE_SIZE];
#define CACHE_FLAG_IS_DIRTY 2
#define CACHE_FLAG_IS_FAT 4

/*
//#define PRINT_SECTORS

#ifdef PRINT_SECTORS
static void print_sector(const void *data)
{
const uint8_t *p = (const uint8_t *)data;
@@ -46,7 +48,7 @@ static void print_sector(const void *data)
if ((i & 31) == 31) Serial.println();
}
}
*/
#endif

// Read a sector into the cache. If the sector is already cached,
// of course no actual read occurs. This is the primary function
@@ -76,8 +78,10 @@ sector_t * SDCache::read(uint32_t lba, bool is_fat)
c->flags = CACHE_FLAG_HAS_DATA;
if (is_fat) c->flags |= CACHE_FLAG_IS_FAT;
ret = &c->data;
//Serial.printf("cache read %u\n", lba);
//print_sector(&c->data);
#ifdef PRINT_SECTORS
Serial.printf("cache read %u\n", lba);
print_sector(&c->data);
#endif
}
}
}

+ 3
- 3
init_t3.cpp View File

@@ -164,7 +164,7 @@ bool SDClass::begin(uint8_t csPin)
//Serial.printf(" sectors_per_fat = %d\n", sectors_per_fat);
uint32_t root_dir_entries = unaligned_read16_align8(vol->u8 + BPB_RootEntCnt);
//Serial.printf(" root_dir_entries = %d\n", root_dir_entries);
uint32_t root_dir_sectors = (root_dir_entries + 31) >> 5;
uint32_t root_dir_sectors = (root_dir_entries + 15) >> 4;
//Serial.printf(" root_dir_sectors = %d\n", root_dir_sectors);

uint32_t total_sectors = unaligned_read16_align8(vol->u8 + BPB_TotSec16);
@@ -173,7 +173,7 @@ bool SDClass::begin(uint8_t csPin)

fat1_begin_lba = partition_lba + reserved_sectors;
fat2_begin_lba = fat1_begin_lba + sectors_per_fat;
data_begin_lba = fat2_begin_lba + sectors_per_fat;
data_begin_lba = fat2_begin_lba + sectors_per_fat + root_dir_sectors;

uint32_t cluster_count = (total_sectors - reserved_sectors
- root_dir_sectors - (sectors_per_fat << 1)) >> s2c;
@@ -184,7 +184,7 @@ bool SDClass::begin(uint8_t csPin)
} else if (cluster_count < 65525) {
fat_type = 16;
rootDir.length = root_dir_entries << 5;
rootDir.start_cluster = partition_lba + reserved_sectors;
rootDir.start_cluster = partition_lba + reserved_sectors + sectors_per_fat * 2;
rootDir.type = FILE_DIR_ROOT16;
} else {
fat_type = 32;

Loading…
Cancel
Save