Rev 92 | Rev 119 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 92 | Rev 110 | ||
---|---|---|---|
Line 304... | Line 304... | ||
304 | 304 | ||
305 | end: |
305 | end: |
306 | if(result != SD_SUCCESS) |
306 | if(result != SD_SUCCESS) |
307 | { |
307 | { |
308 | sprintf(text,"Error %02X reading data from sd card (R1=%02X).\r\n", result, rsp); |
308 | sprintf(text,"Error %02X reading data from sd card (R1=%02X).\r\n", result, rsp); |
309 | SerialPutString(text); |
309 | UART1_PutString(text); |
310 | } |
310 | } |
311 | return(result); |
311 | return(result); |
Line 325... | Line 325... | ||
325 | { |
325 | { |
326 | u8 pn[6]; |
326 | u8 pn[6]; |
327 | u16 temp1, temp2; |
327 | u16 temp1, temp2; |
Line 328... | Line 328... | ||
328 | 328 | ||
329 | sprintf(text, "\r\n Manufacturer ID: %i\r\n", pCID[0]); |
329 | sprintf(text, "\r\n Manufacturer ID: %i\r\n", pCID[0]); |
330 | SerialPutString(text); |
330 | UART1_PutString(text); |
331 | memcpy(pn, &pCID[1], 2); |
331 | memcpy(pn, &pCID[1], 2); |
332 | pn[2] = '\0'; // terminate string |
332 | pn[2] = '\0'; // terminate string |
333 | sprintf(text, " Application ID: %s\r\n",pn); |
333 | sprintf(text, " Application ID: %s\r\n",pn); |
334 | SerialPutString(text); |
334 | UART1_PutString(text); |
335 | memcpy(pn, &pCID[3], 5); |
335 | memcpy(pn, &pCID[3], 5); |
336 | pn[5] = '\0'; // terminate string |
336 | pn[5] = '\0'; // terminate string |
337 | sprintf(text, " Product Name: %s\r\n",pn); |
337 | sprintf(text, " Product Name: %s\r\n",pn); |
338 | SerialPutString(text); |
338 | UART1_PutString(text); |
339 | sprintf(text, " Product Rev.: %i.%i\r\n",pCID[8]>>4, pCID[8]&0xF); |
339 | sprintf(text, " Product Rev.: %i.%i\r\n",pCID[8]>>4, pCID[8]&0xF); |
340 | SerialPutString(text); |
340 | UART1_PutString(text); |
341 | SerialPutString(" Serial No.: "); |
341 | UART1_PutString(" Serial No.: "); |
342 | for(temp1 = 0; temp1<4; temp1++) |
342 | for(temp1 = 0; temp1<4; temp1++) |
343 | { |
343 | { |
344 | sprintf(text,"%02X", pCID[9+temp1]); |
344 | sprintf(text,"%02X", pCID[9+temp1]); |
345 | SerialPutString(text); |
345 | UART1_PutString(text); |
346 | } |
346 | } |
347 | SerialPutString("\r\n"); |
347 | UART1_PutString("\r\n"); |
348 | temp1 = pCID[14] & 0x0F; // month |
348 | temp1 = pCID[14] & 0x0F; // month |
349 | temp2 = ((pCID[14]>>4)|(pCID[13]<<4)) + 2000; // year |
349 | temp2 = ((pCID[14]>>4)|(pCID[13]<<4)) + 2000; // year |
350 | sprintf(text, " Manufac. Date: %i/%i\r\n\r\n",temp1, temp2); |
350 | sprintf(text, " Manufac. Date: %i/%i\r\n\r\n",temp1, temp2); |
351 | SerialPutString(text); |
351 | UART1_PutString(text); |
Line 352... | Line 352... | ||
352 | } |
352 | } |
353 | 353 | ||
354 | //________________________________________________________________________________________________________________________________________ |
354 | //________________________________________________________________________________________________________________________________________ |
Line 395... | Line 395... | ||
395 | u8 rsp[6]; // SD-SPI response buffer |
395 | u8 rsp[6]; // SD-SPI response buffer |
396 | SD_Result_t result = SD_ERROR_UNKNOWN; |
396 | SD_Result_t result = SD_ERROR_UNKNOWN; |
Line 397... | Line 397... | ||
397 | 397 | ||
398 | if(SD_SWITCH) // init only if the SD-Switch is indicating a card in the slot |
398 | if(SD_SWITCH) // init only if the SD-Switch is indicating a card in the slot |
399 | { |
399 | { |
400 | SerialPutString("\r\n SSC init..."); |
400 | UART1_PutString("\r\n SSC init..."); |
401 | SSC_Init(); |
401 | SSC_Init(); |
Line 402... | Line 402... | ||
402 | SerialPutString("ok"); |
402 | UART1_PutString("ok"); |
403 | 403 | ||
404 | SerialPutString("\r\n SDC init..."); |
404 | UART1_PutString("\r\n SDC init..."); |
405 | SDCardInfo.Valid = 0; |
405 | SDCardInfo.Valid = 0; |
406 | /* The host shall supply power to the card so that the voltage is reached to Vdd_min within 250ms and |
406 | /* The host shall supply power to the card so that the voltage is reached to Vdd_min within 250ms and |
407 | start to supply at least 74 SD clocks to the SD card with keeping cmd line to high. In case of SPI |
407 | start to supply at least 74 SD clocks to the SD card with keeping cmd line to high. In case of SPI |
Line 417... | Line 417... | ||
417 | // switch to idle state |
417 | // switch to idle state |
418 | while(SDC_SendCMDR1(CMD_GO_IDLE_STATE, 0UL) != R1_IDLE_STATE) |
418 | while(SDC_SendCMDR1(CMD_GO_IDLE_STATE, 0UL) != R1_IDLE_STATE) |
419 | { |
419 | { |
420 | if (timeout++ > 20) |
420 | if (timeout++ > 20) |
421 | { |
421 | { |
422 | SerialPutString("reset timeout"); |
422 | UART1_PutString("reset timeout"); |
423 | result = SD_ERROR_RESET; |
423 | result = SD_ERROR_RESET; |
424 | goto end; |
424 | goto end; |
425 | } |
425 | } |
426 | } |
426 | } |
427 | // enable crc feature |
427 | // enable crc feature |
428 | /* if(SDC_SendCMDR1(CMD_CRC_ON_OFF, 1UL) != R1_IDLE_STATE) |
428 | /* if(SDC_SendCMDR1(CMD_CRC_ON_OFF, 1UL) != R1_IDLE_STATE) |
429 | { |
429 | { |
430 | sprintf(text,"Bad cmd59 R1=%02X.", rsp[0]); |
430 | sprintf(text,"Bad cmd59 R1=%02X.", rsp[0]); |
431 | SerialPutString(text); |
431 | UART1_PutString(text); |
432 | result = SD_ERROR_BAD_RESPONSE; |
432 | result = SD_ERROR_BAD_RESPONSE; |
433 | goto end; |
433 | goto end; |
434 | }*/ |
434 | }*/ |
435 | // check for card hw version |
435 | // check for card hw version |
436 | // 2.7-3.6V Range = 0x01, check pattern 0xAA |
436 | // 2.7-3.6V Range = 0x01, check pattern 0xAA |
437 | rsp[0] = SDC_SendCMDR1(CMD_SEND_IF_COND, 0x000001AA); |
437 | rsp[0] = SDC_SendCMDR1(CMD_SEND_IF_COND, 0x000001AA); |
438 | // answer to cmd58 is an R7 response (R1+ 4Byte IFCond) |
438 | // answer to cmd58 is an R7 response (R1+ 4Byte IFCond) |
439 | if(rsp[0] & R1_BAD_RESPONSE) |
439 | if(rsp[0] & R1_BAD_RESPONSE) |
440 | { |
440 | { |
441 | sprintf(text,"Bad cmd8 R1=%02X.", rsp[0]); |
441 | sprintf(text,"Bad cmd8 R1=%02X.", rsp[0]); |
442 | SerialPutString(text); |
442 | UART1_PutString(text); |
443 | result = SD_ERROR_BAD_RESPONSE; |
443 | result = SD_ERROR_BAD_RESPONSE; |
444 | goto end; |
444 | goto end; |
445 | } |
445 | } |
446 | if(rsp[0] & R1_ILLEGAL_CMD) |
446 | if(rsp[0] & R1_ILLEGAL_CMD) |
447 | { |
447 | { |
Line 458... | Line 458... | ||
458 | rsp[timeout] = SSC_GetChar(); |
458 | rsp[timeout] = SSC_GetChar(); |
459 | } |
459 | } |
460 | //check pattern |
460 | //check pattern |
461 | if(rsp[4]!= 0xAA) |
461 | if(rsp[4]!= 0xAA) |
462 | { |
462 | { |
463 | SerialPutString("Bad cmd8 R7 check pattern.\r\n"); |
463 | UART1_PutString("Bad cmd8 R7 check pattern.\r\n"); |
464 | result = SD_ERROR_BAD_RESPONSE; |
464 | result = SD_ERROR_BAD_RESPONSE; |
465 | goto end; |
465 | goto end; |
466 | } |
466 | } |
467 | if ( (rsp[3] & 0x0F)!= 0x01 ) // voltage range is not 2.7-3.6V |
467 | if ( (rsp[3] & 0x0F)!= 0x01 ) // voltage range is not 2.7-3.6V |
468 | { |
468 | { |
Line 469... | Line 469... | ||
469 | 469 | ||
470 | SerialPutString("Card is incompatible to 3.3V.\r\n"); |
470 | UART1_PutString("Card is incompatible to 3.3V.\r\n"); |
471 | result = SD_ERROR_BAD_VOLTAGE_RANGE; |
471 | result = SD_ERROR_BAD_VOLTAGE_RANGE; |
472 | goto end; |
472 | goto end; |
473 | } |
473 | } |
Line 474... | Line 474... | ||
474 | } |
474 | } |
475 | 475 | ||
476 | rsp[0] = SDC_SendCMDR1(CMD_READ_OCR, 0UL); |
476 | rsp[0] = SDC_SendCMDR1(CMD_READ_OCR, 0UL); |
477 | // answer to cmd58 is an R3 response (R1 + 4Byte OCR) |
477 | // answer to cmd58 is an R3 response (R1 + 4Byte OCR) |
478 | if(rsp[0] & R1_BAD_RESPONSE) |
478 | if(rsp[0] & R1_BAD_RESPONSE) |
479 | { |
479 | { |
480 | sprintf(text,"Bad cmd58 R1 %02x.", rsp[0]); |
480 | sprintf(text,"Bad cmd58 R1 %02x.", rsp[0]); |
481 | SerialPutString(text); |
481 | UART1_PutString(text); |
482 | result = SD_ERROR_BAD_RESPONSE; |
482 | result = SD_ERROR_BAD_RESPONSE; |
483 | goto end; |
483 | goto end; |
484 | } |
484 | } |
485 | if(rsp[0] & R1_ILLEGAL_CMD) |
485 | if(rsp[0] & R1_ILLEGAL_CMD) |
486 | { |
486 | { |
487 | SerialPutString("Not an SD-CARD."); |
487 | UART1_PutString("Not an SD-CARD."); |
488 | result = SD_ERROR_NO_SDCARD; |
488 | result = SD_ERROR_NO_SDCARD; |
489 | goto end; |
489 | goto end; |
490 | } |
490 | } |
Line 495... | Line 495... | ||
495 | } |
495 | } |
496 | // NavicCtrl uses 3.3 V, therefore check for bit 20 & 21 |
496 | // NavicCtrl uses 3.3 V, therefore check for bit 20 & 21 |
497 | if((rsp[2] & 0x30) != 0x30) |
497 | if((rsp[2] & 0x30) != 0x30) |
498 | { |
498 | { |
499 | // supply voltage is not supported by sd-card |
499 | // supply voltage is not supported by sd-card |
500 | SerialPutString("Card is incompatible to 3.3V."); |
500 | UART1_PutString("Card is incompatible to 3.3V."); |
501 | result = SD_ERROR_BAD_VOLTAGE_RANGE; |
501 | result = SD_ERROR_BAD_VOLTAGE_RANGE; |
502 | goto end; |
502 | goto end; |
503 | } |
503 | } |
Line 504... | Line 504... | ||
504 | 504 | ||
Line 508... | Line 508... | ||
508 | { |
508 | { |
509 | rsp[0] = SDC_SendACMDR1(ACMD_SEND_OP_COND, 0UL); |
509 | rsp[0] = SDC_SendACMDR1(ACMD_SEND_OP_COND, 0UL); |
510 | if(rsp[0] & R1_BAD_RESPONSE) |
510 | if(rsp[0] & R1_BAD_RESPONSE) |
511 | { |
511 | { |
512 | sprintf(text,"Bad Acmd41 R1=%02X.", rsp[0]); |
512 | sprintf(text,"Bad Acmd41 R1=%02X.", rsp[0]); |
513 | SerialPutString(text); |
513 | UART1_PutString(text); |
514 | result = SD_ERROR_BAD_RESPONSE; |
514 | result = SD_ERROR_BAD_RESPONSE; |
515 | goto end; |
515 | goto end; |
516 | } |
516 | } |
517 | if(CheckDelay(timeout)) |
517 | if(CheckDelay(timeout)) |
518 | { |
518 | { |
519 | SerialPutString("Init timeout."); |
519 | UART1_PutString("Init timeout."); |
520 | result = SD_ERROR_INITIALIZE; |
520 | result = SD_ERROR_INITIALIZE; |
521 | goto end; |
521 | goto end; |
522 | } |
522 | } |
523 | } while(rsp[0] & R1_IDLE_STATE); // loop until idle state |
523 | } while(rsp[0] & R1_IDLE_STATE); // loop until idle state |
Line 524... | Line 524... | ||
524 | 524 | ||
525 | if(rsp[0] != R1_NO_ERR) |
525 | if(rsp[0] != R1_NO_ERR) |
526 | { |
526 | { |
527 | SerialPutString("Init error."); |
527 | UART1_PutString("Init error."); |
528 | result = SD_ERROR_INITIALIZE; |
528 | result = SD_ERROR_INITIALIZE; |
529 | goto end; |
529 | goto end; |
530 | } |
530 | } |
531 | /* set block size to 512 bytes */ |
531 | /* set block size to 512 bytes */ |
532 | if(SDC_SendCMDR1(CMD_SET_BLOCKLEN, 512UL) != R1_NO_ERR) |
532 | if(SDC_SendCMDR1(CMD_SET_BLOCKLEN, 512UL) != R1_NO_ERR) |
533 | { |
533 | { |
534 | SerialPutString("Error setting block length to 512."); |
534 | UART1_PutString("Error setting block length to 512."); |
535 | result = SD_ERROR_SET_BLOCKLEN; |
535 | result = SD_ERROR_SET_BLOCKLEN; |
536 | goto end; |
536 | goto end; |
Line 537... | Line 537... | ||
537 | } |
537 | } |
Line 542... | Line 542... | ||
542 | 542 | ||
543 | // read CID register |
543 | // read CID register |
544 | result = SDC_GetCID((u8 *)&SDCardInfo.CID); |
544 | result = SDC_GetCID((u8 *)&SDCardInfo.CID); |
545 | if(result != SD_SUCCESS) |
545 | if(result != SD_SUCCESS) |
546 | { |
546 | { |
547 | SerialPutString("Error reading CID.\r\n"); |
547 | UART1_PutString("Error reading CID.\r\n"); |
548 | goto end; |
548 | goto end; |
Line 549... | Line 549... | ||
549 | } |
549 | } |
550 | 550 | ||
551 | // read CSD register |
551 | // read CSD register |
552 | result = SDC_GetCSD((u8 *)&SDCardInfo.CSD); |
552 | result = SDC_GetCSD((u8 *)&SDCardInfo.CSD); |
553 | if(result != SD_SUCCESS) |
553 | if(result != SD_SUCCESS) |
554 | { |
554 | { |
555 | SerialPutString("Error reading CSD."); |
555 | UART1_PutString("Error reading CSD."); |
Line 556... | Line 556... | ||
556 | goto end; |
556 | goto end; |
Line 557... | Line 557... | ||
557 | } |
557 | } |
558 | 558 | ||
Line 559... | Line 559... | ||
559 | SerialPutString("ok\r\n"); |
559 | UART1_PutString("ok\r\n"); |
Line 604... | Line 604... | ||
604 | } |
604 | } |
Line 605... | Line 605... | ||
605 | 605 | ||
606 | switch(SDCardInfo.Version) |
606 | switch(SDCardInfo.Version) |
607 | { |
607 | { |
608 | case VER_1X: |
608 | case VER_1X: |
609 | SerialPutString(" SD-CARD V1.x"); |
609 | UART1_PutString(" SD-CARD V1.x"); |
610 | break; |
610 | break; |
611 | case VER_20: |
611 | case VER_20: |
612 | SerialPutString(" SD-CARD V2.0 or later"); |
612 | UART1_PutString(" SD-CARD V2.0 or later"); |
613 | default: |
613 | default: |
614 | break; |
614 | break; |
615 | } |
615 | } |
616 | u16 mb_size = (u16)(SDCardInfo.Capacity/(1024L*1024L)); |
616 | u16 mb_size = (u16)(SDCardInfo.Capacity/(1024L*1024L)); |
617 | sprintf(text, "\r\n Capacity = %i MB", mb_size); |
617 | sprintf(text, "\r\n Capacity = %i MB", mb_size); |
Line 618... | Line 618... | ||
618 | SerialPutString(text); |
618 | UART1_PutString(text); |
619 | 619 | ||
620 | SDC_PrintCID((u8 *)&SDCardInfo.CID); |
620 | SDC_PrintCID((u8 *)&SDCardInfo.CID); |
621 | SDCardInfo.Valid = 1; |
621 | SDCardInfo.Valid = 1; |
Line 626... | Line 626... | ||
626 | else |
626 | else |
627 | { |
627 | { |
628 | SSC_Deinit(); |
628 | SSC_Deinit(); |
629 | SDCardInfo.Valid = 0; |
629 | SDCardInfo.Valid = 0; |
630 | result = SD_ERROR_NOCARD; |
630 | result = SD_ERROR_NOCARD; |
631 | SerialPutString("No Card in Slot."); |
631 | UART1_PutString("No Card in Slot."); |
632 | } |
632 | } |
633 | return(result); |
633 | return(result); |
634 | } |
634 | } |
Line 643... | Line 643... | ||
643 | // Returnvalue: the function returns 0 if the initialisation was successfull otherwise the function returns an errorcode. |
643 | // Returnvalue: the function returns 0 if the initialisation was successfull otherwise the function returns an errorcode. |
644 | //________________________________________________________________________________________________________________________________________ |
644 | //________________________________________________________________________________________________________________________________________ |
Line 645... | Line 645... | ||
645 | 645 | ||
646 | SD_Result_t SDC_Deinit(void) |
646 | SD_Result_t SDC_Deinit(void) |
647 | { |
647 | { |
648 | SerialPutString("\r\n SDC deinit..."); |
648 | UART1_PutString("\r\n SDC deinit..."); |
Line 649... | Line 649... | ||
649 | SSC_Deinit(); |
649 | SSC_Deinit(); |
650 | 650 | ||
651 | SDCardInfo.Valid = 0; |
651 | SDCardInfo.Valid = 0; |
Line 652... | Line 652... | ||
652 | SDCardInfo.Capacity = 0; |
652 | SDCardInfo.Capacity = 0; |
653 | SDCardInfo.Version = VER_UNKNOWN; |
653 | SDCardInfo.Version = VER_UNKNOWN; |
654 | 654 | ||
Line 655... | Line 655... | ||
655 | SerialPutString("ok"); |
655 | UART1_PutString("ok"); |
Line 752... | Line 752... | ||
752 | } |
752 | } |
753 | end: |
753 | end: |
754 | if(result != SD_SUCCESS) |
754 | if(result != SD_SUCCESS) |
755 | { |
755 | { |
756 | sprintf(text,"Error %02X writing data to sd card (R=%02X).\r\n", result, rsp); |
756 | sprintf(text,"Error %02X writing data to sd card (R=%02X).\r\n", result, rsp); |
757 | SerialPutString(text); |
757 | UART1_PutString(text); |
758 | } |
758 | } |
759 | return(result); |
759 | return(result); |
760 | } |
760 | } |