chaithanya rss
/
CDMS_SDCARD
SD card Standalone code.
Revision 1:231e99f73b19, committed 2016-09-19
- Comitter:
- chaithanyarss
- Date:
- Mon Sep 19 06:46:27 2016 +0000
- Parent:
- 0:83e597a2a37c
- Commit message:
- lol
Changed in this revision
SD.h | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 83e597a2a37c -r 231e99f73b19 SD.h --- a/SD.h Tue Jul 05 10:11:24 2016 +0000 +++ b/SD.h Mon Sep 19 06:46:27 2016 +0000 @@ -5,6 +5,7 @@ #define SPI_CS_SDC PTE22 DigitalOut cs_sd(SPI_CS_SDC); +DigitalOut SD_SW_EN_DS (PTD4,1); SPI spi( SPI_MOSI, SPI_MISO, SPI_CLK ); uint32_t FSC_CURRENT[6]; @@ -12,7 +13,7 @@ uint8_t SD_RD_ERROR; -#define SD_COMMAND_TIMEOUT 5000 +#define SD_COMMAND_TIMEOUT 10 #define SD_DBG 0 @@ -76,6 +77,10 @@ int FCTN_CDMS_SD_INIT() { + SD_SW_EN_DS = 0; + wait_ms(10); + SD_SW_EN_DS = 1; + wait_ms(10); int i = initialise_card(); //debug_if(SD_DBG, "init card = %d\n", i); sectors = sd_sectors(); @@ -88,7 +93,7 @@ //printf("\rDisk initialization successfull\r\n"); } - spi.frequency(1000000); // Set to 1MHz for data transfer + spi.frequency(500000); // Set to 1MHz for data transfer return 0; } @@ -97,6 +102,7 @@ uint32_t fsc; uint32_t start_fsc; uint8_t buffer[512]; + gPC.printf("Reached SD_MNG func"); int b=disk_read(buffer, SD_MNG_SECT); fsc=(uint32_t)(buffer[0]<<24)+(uint32_t)(buffer[1]<<16)+(uint32_t)(buffer[2]<<8)+(uint32_t)buffer[3]; @@ -401,7 +407,7 @@ gPC.printf("0x%02X",R1_response); // send CMD0, should return with all zeros except IDLE STATE set (bit 0) if (R1_response != R1_IDLE_STATE) { - //debug("No disk, or could not put SD card in to spi idle state\r\n"); + gPC.printf("No disk, or could not put SD card in to spi idle state\r"); CDMS_LED3 = 1; return SDCARD_FAIL; } @@ -411,12 +417,12 @@ // send CMD8 to determine whther it is ver 2.x int r = cmd8(); if (r == R1_IDLE_STATE) { - gPC.puts("Entering V2\r"); + //gPC.puts("Entering V2\n"); int q = initialise_card_v2(); return q; } else if (r == (R1_IDLE_STATE | R1_ILLEGAL_COMMAND)) { - gPC.puts("Entering V1"); + gPC.puts("Entering V1\n"); return initialise_card_v1(); } else { @@ -430,7 +436,7 @@ for (int i = 0; i < SD_COMMAND_TIMEOUT; i++) { cmd(55, 0); if (cmd(41, 0) == 0) { - gPC.puts("\rv1 initialization successfull\r\n"); + gPC.puts("\rv1 initialization successfull\n"); cdv = 512; //debug_if(SD_DBG, "\n\rInit: SEDCARD_V1\n\r"); @@ -450,8 +456,9 @@ cmd58(); cmd(55, 0); if (cmd(41, 0x40000000) == 0) { + // if (DEBUG) - gPC.puts("\rv2 initialization successfull\r\n"); + gPC.puts("v2 initialization successfull\n"); CDMS_LED3 =1; cmd58(); //debug_if(SD_DBG, "\n\rInit: SDCARD_V2\n\r");
diff -r 83e597a2a37c -r 231e99f73b19 main.cpp --- a/main.cpp Tue Jul 05 10:11:24 2016 +0000 +++ b/main.cpp Mon Sep 19 06:46:27 2016 +0000 @@ -8,39 +8,50 @@ #include "SD.h" - int main() { + int count=0; + gPC.baud(1200); spi.format(8,0); spi.frequency(1000000); cs_sd = 1; - + gPC.printf("\nWelcome\n"); CDMS_LED1 = 1; CDMS_LED4 = 0; + uint8_t buffer[512]; + uint8_t test[512]; + int j,k,i,lol=0; FCTN_CDMS_SD_INIT(); - uint8_t test[512] = {0}; - disk_write(test,7000); //to be used only just before launch + for(i=0;i<512;i++) + test[i] = 0; + i = disk_write(test,7000); //to be used only just before launch - uint8_t buffer[512]; - for(int i = 0;i<512;i++) + while(1){ + count++; + gPC.printf("\r[%d] ",count); + + FCTN_CDMS_SD_INIT(); + + for(i = 0;i<512;i++) { - buffer[i] = i%100; + buffer[i] = lol%11; + lol++; } FCTN_SD_MNGR(); - SD_WRITE(buffer,FSC_CURRENT[2]+1,2); - - SD_READ(test,FSC_CURRENT[2],2); + wait(1); + j = SD_WRITE(buffer,FSC_CURRENT[4]+1,4); + if(j!= 0) + gPC.printf("\n\rWrite failure\n"); + + k = SD_READ(test,FSC_CURRENT[4],4); + if(k!=160) + gPC.printf("%d\n",k); + for(i=0;i<15;i++) + { + if(buffer[i]!=test[i]) + gPC.printf("0x%02X 0x%02X\r\n",buffer[i],test[i]); + } - for(int i=0;i<15;i++) - { - if(buffer[i] == test[i]) - { - CDMS_LED4 = !CDMS_LED4; - wait_ms(1000); - } - } - - - + } } \ No newline at end of file