Merge pull request #436 from rob-ng15/master

Reclock spi sdcard access after initialisation
This commit is contained in:
enjoy-digital 2020-03-21 09:26:25 +01:00 committed by GitHub
commit c547b2cc29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 0 deletions

View File

@ -444,6 +444,17 @@ uint8_t spi_sdcard_readMBR(void)
return FAILURE; return FAILURE;
} }
// Reclock the card
// Calculate 16MHz as an integer divider from the CONFIG_CLOCK_FREQUENCY
// Add 1 as will be rounded down
// Always ensure divider is at least 2 - half the processor speed
int divider;
divider = (int)(CONFIG_CLOCK_FREQUENCY/(16e6)) + 1;
if( divider<2 )
divider=2;
printf("Reclocking from %dKHz to %dKHz\n\n", CONFIG_CLOCK_FREQUENCY/(int)spisdcard_clk_divider_read()/1000, CONFIG_CLOCK_FREQUENCY/divider/1000);
spisdcard_clk_divider_write(divider);
// Read in FAT16 File Allocation Table, array of 16bit unsinged integers // Read in FAT16 File Allocation Table, array of 16bit unsinged integers
// Calculate Storage from TOP of MAIN RAM // Calculate Storage from TOP of MAIN RAM
sdCardFatTable = (uint16_t *)(MAIN_RAM_BASE+MAIN_RAM_SIZE-sdCardFatBootSector.sector_size*sdCardFatBootSector.fat_size_sectors); sdCardFatTable = (uint16_t *)(MAIN_RAM_BASE+MAIN_RAM_SIZE-sdCardFatBootSector.sector_size*sdCardFatBootSector.fat_size_sectors);