diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES index 95ffb1c..9ee85c9 100644 --- a/apps/plugins/SOURCES +++ b/apps/plugins/SOURCES @@ -168,3 +168,4 @@ lua.c #if defined(HAVE_USBSTACK) && defined(USB_ENABLE_HID) remote_control.c #endif +test_disk.c diff --git a/apps/plugins/test_disk.c b/apps/plugins/test_disk.c index 34cb94d..33e04a0 100644 --- a/apps/plugins/test_disk.c +++ b/apps/plugins/test_disk.c @@ -24,7 +24,7 @@ PLUGIN_HEADER -#define TESTBASEDIR "/__TEST__" +#define TESTBASEDIR "//__TEST__" #define TEST_FILE TESTBASEDIR "/test_disk.tmp" #define FRND_SEED 0x78C3 /* arbirary */ diff --git a/firmware/target/arm/as3525/ata_sd_as3525.c b/firmware/target/arm/as3525/ata_sd_as3525.c index 995bf93..756e0a6 100644 --- a/firmware/target/arm/as3525/ata_sd_as3525.c +++ b/firmware/target/arm/as3525/ata_sd_as3525.c @@ -104,8 +104,9 @@ static void init_pl180_controller(const int drive); static tCardInfo card_info[NUM_DRIVES]; /* maximum timeouts recommanded in the SD Specification v2.00 */ -#define SD_MAX_READ_TIMEOUT ((AS3525_PCLK_FREQ) / 1000 * 100) /* 100 ms */ -#define SD_MAX_WRITE_TIMEOUT ((AS3525_PCLK_FREQ) / 1000 * 250) /* 250 ms */ +#define SD_MCICLK_FREQ (MCI_CLOCK(drive) & MCI_CLOCK_BYPASS)? AS3525_PCLK_FREQ: ((AS3525_PCLK_FREQ) / (2*((MCI_CLOCK(drive) & 0xff) + 1))) +#define SD_MAX_READ_TIMEOUT ((SD_MCICLK_FREQ) / 1000 * 100) /* 100 ms */ +#define SD_MAX_WRITE_TIMEOUT ((SD_MCICLK_FREQ) / 1000 * 250) /* 250 ms */ /* for compatibility */ static long last_disk_activity = -1; @@ -245,6 +246,7 @@ static int sd_init_card(const int drive) unsigned long response; long init_timeout; bool sdhc; + bool hscard = false; unsigned long temp_reg[4]; int i; @@ -295,6 +297,9 @@ static int sd_init_card(const int drive) &card_info[drive].rca)) return -6; + /* Change to pushpull bus mode for higher frequencies */ + MCI_POWER(drive) &= ~MCI_POWER_OPEN_DRAIN; + /* send CSD */ if(!send_cmd(drive, SD_SEND_CSD, card_info[drive].rca, MCI_RESP|MCI_LONG_RESP|MCI_ARG, temp_reg)) @@ -305,22 +310,31 @@ static int sd_init_card(const int drive) sd_parse_csd(&card_info[drive]); - if(!send_cmd(drive, SD_SELECT_CARD, card_info[drive].rca, MCI_ARG, NULL)) - return -9; - - if(!send_cmd(drive, SD_APP_CMD, card_info[drive].rca, MCI_ARG, NULL)) - return -10; + card_info[drive].initialized = 1; - if(!send_cmd(drive, SD_SET_BUS_WIDTH, card_info[drive].rca | 2, MCI_ARG, NULL)) - return -11; + if(!send_cmd(drive, SD_SELECT_CARD, card_info[drive].rca, MCI_ARG, NULL)) + return -8; - if(!send_cmd(drive, SD_SET_BLOCKLEN, card_info[drive].blocksize, MCI_ARG, - NULL)) - return -12; + /* Check card for HS capable and if so switch to HS */ + if(card_info[drive].speed > 125000) + { + hscard = true; + if(!send_cmd(drive, SD_SWITCH_FUNC, 0x80fffff1, MCI_ARG, NULL)) + return -9; + } - card_info[drive].initialized = 1; + if(drive == 0) + { + /* full speed for controller clock */ + MCI_CLOCK(drive) |= MCI_CLOCK_BYPASS; + } + else + { + /* Drop freq for uSD Card to spec ( < 50MHz) */ + /* MCICLK == PCLK/2 for HS, PCLK/4 for std */ + MCI_CLOCK(drive) = MCI_CLOCK_ENABLE | (hscard ? 0: 1); + } - MCI_CLOCK(drive) |= MCI_CLOCK_BYPASS; /* full speed for controller clock */ mci_delay(); /* @@ -603,7 +617,7 @@ static int sd_select_bank(signed char bank) DMA_PERI_SD, DMAC_FLOWCTRL_PERI_MEM_TO_PERI, true, false, 0, DMA_S8, NULL); - MCI_DATA_TIMER(INTERNAL_AS3525) = SD_MAX_WRITE_TIMEOUT; + MCI_DATA_TIMER(INTERNAL_AS3525) = ((AS3525_PCLK_FREQ) / 1000 * 250); /*Max Write Timeout 250 ms */ MCI_DATA_LENGTH(INTERNAL_AS3525) = 512; MCI_DATA_CTRL(INTERNAL_AS3525) = (1<<0) /* enable */ | (0<<1) /* transfer direction */ |