annotate sd.c @ 49:ace431a0d0f5

Add SDIO code poached from STM. Use FatFS to read from SD card. LFN doesn't work reliably so it's disabled for now.
author Daniel O'Connor <darius@dons.net.au>
date Wed, 03 Apr 2013 23:34:20 +1030
parents
children d7207a9d3c3b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
1 /*
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
2 * SD card code
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
3 *
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
4 * Copyright (c) 2013
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
5 * Daniel O'Connor <darius@dons.net.au>. All rights reserved.
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
6 *
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
7 * Redistribution and use in source and binary forms, with or without
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
8 * modification, are permitted provided that the following conditions
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
9 * are met:
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
10 * 1. Redistributions of source code must retain the above copyright
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer.
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
15 *
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
26 * SUCH DAMAGE.
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
27 */
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
28
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
29 #include <assert.h>
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
30 #include <inttypes.h>
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
31 #include <stdio.h>
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
32 #include <stdint.h>
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
33 #include <stdlib.h>
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
34 #include <string.h>
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
35
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
36 #include "ff.h"
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
37 #include "stm32f10x.h"
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
38 #include "sd.h"
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
39 #include "stm32_eval_sdio_sd.h"
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
40
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
41 #define FAT_YEAR(d) ((((d) & 0xfe00) >> 9) + 1980)
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
42 #define FAT_MONTH(d) (((d) & 0x01e0) >> 5)
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
43 #define FAT_DAY(d) (((d) & 0x001f) >> 0)
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
44 #define FAT_HOUR(t) (((t) & 0xf800) >> 11)
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
45 #define FAT_MIN(t) (((t) & 0x07e0) >> 5)
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
46 #define FAT_SEC(t) (((t) & 0x001f) << 1)
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
47
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
48 static FATFS fsh;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
49
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
50 static void sd_domount(void);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
51
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
52 void
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
53 sd_init(void) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
54 sd_domount();
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
55 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
56
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
57 void
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
58 sd_domount(void) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
59 SD_Error err;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
60 FRESULT fserr;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
61
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
62 if ((err = SD_Init()) != SD_OK) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
63 printf("Failed init: %d\n", err);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
64 return;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
65 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
66
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
67 if ((fserr = f_mount(0, &fsh)) != FR_OK) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
68 printf("Unable to mount FS\n");
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
69 return;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
70 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
71 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
72
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
73 void
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
74 sd_cmd(int argc, char **argv) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
75 SD_Error err;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
76
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
77 if (argc < 1) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
78 printf("No command specified\n");
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
79 return;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
80 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
81
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
82 if (!strcmp(argv[0], "info")) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
83 SD_CardInfo cardinfo;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
84 if ((err = SD_GetCardInfo(&cardinfo)) != SD_OK) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
85 printf("Get card info failed: %d\r\b", err);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
86 } else {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
87 printf("Mfg ID %" PRIu8 ", OEM %" PRIu16 ", Prod1 %" PRIu32 ", Prod2 %" PRIu8 ", Rev %" PRIu8 ", SN %" PRIu32 ", Mfg %" PRIu16 "\n",
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
88 cardinfo.SD_cid.ManufacturerID, cardinfo.SD_cid.OEM_AppliID,
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
89 cardinfo.SD_cid.ProdName1, cardinfo.SD_cid.ProdName2,
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
90 cardinfo.SD_cid.ProdRev, cardinfo.SD_cid.ProdSN,
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
91 cardinfo.SD_cid.ManufactDate);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
92 printf("Capacity %" PRIu32 ", blocksize %" PRIu32 "\n", cardinfo.CardCapacity, cardinfo.CardBlockSize);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
93 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
94 } else if (!strcmp(argv[0], "mount")) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
95 sd_domount();
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
96 } else if (!strcmp(argv[0], "read")) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
97 uint32_t addr;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
98 uint8_t *buf;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
99 uint32_t i;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
100
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
101 if (argc != 2) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
102 printf("Block to read not specified\n");
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
103 return;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
104 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
105 addr = atoi(argv[1]);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
106
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
107 if ((buf = malloc(SD_BLOCK_SIZE)) == NULL) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
108 printf("Unable to allocate buffer\n");
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
109 return;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
110 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
111
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
112 /* If passed values not modulo 512 it hangs */
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
113 if ((err = SD_ReadBlock(buf, addr * SD_BLOCK_SIZE, SD_BLOCK_SIZE)) != SD_OK) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
114 printf("Read block returned %d\n", err);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
115 goto read_exit;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
116 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
117
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
118 #ifdef SD_DMA_MODE
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
119 if ((err = SD_WaitReadOperation()) != SD_OK) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
120 printf("Wait returned %d\n", err);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
121 goto read_exit;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
122 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
123 #endif
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
124 while(SD_GetStatus() != SD_TRANSFER_OK)
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
125 ;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
126
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
127 for (i = 0; i < SD_BLOCK_SIZE; i += 16) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
128 printf("0x%04lx: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", i,
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
129 buf[i + 0], buf[i + 1], buf[i + 2], buf[i + 3], buf[i + 4], buf[i + 5], buf[i + 6], buf[i + 7],
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
130 buf[i + 8], buf[i + 9], buf[i + 10], buf[i + 11], buf[i + 12], buf[i + 13], buf[i + 14], buf[i + 15]);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
131 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
132
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
133 read_exit:
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
134 free(buf);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
135 } else if (!strcmp(argv[0], "erase")) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
136 uint32_t addr;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
137
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
138 if (argc != 2) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
139 printf("Block to erase not specified\n");
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
140 return;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
141 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
142 addr = atoi(argv[1]);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
143
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
144 if ((err = SD_Erase(addr * SD_BLOCK_SIZE, (addr + 1) * SD_BLOCK_SIZE)) != SD_OK) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
145 printf("Erase block returned %d\n", err);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
146 goto read_exit;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
147 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
148
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
149 #ifdef SD_DMA_MODE
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
150 if ((err = SD_WaitReadOperation()) != SD_OK) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
151 printf("Wait returned %d\n", err);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
152 goto read_exit;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
153 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
154 #endif
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
155 while(SD_GetStatus() != SD_TRANSFER_OK)
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
156 ;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
157 printf("Erased OK\n");
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
158 } else if (!strcmp(argv[0], "ls")) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
159 FRESULT fserr;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
160 DIR d;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
161 FILINFO fno;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
162 char *fn;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
163 char label[12];
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
164 DWORD sn;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
165
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
166 if ((fserr = f_getlabel("", label, &sn)) != FR_OK) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
167 printf("Unable to read label\n");
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
168 } else {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
169 printf("Label: %s Serial: %d\n", label, sn);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
170 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
171
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
172 if ((fserr = f_opendir(&d, argc == 1 ? "\\" : argv[1])) != FR_OK) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
173 printf("Unable to opendir: %d\n", fserr);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
174 return;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
175 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
176
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
177 for (;;) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
178 fserr = f_readdir(&d, &fno);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
179 if (fserr != FR_OK) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
180 printf("Readdir failed: %d\n", fserr);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
181 break;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
182 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
183 if (fno.fname[0] == '\0')
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
184 break;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
185 #if _USE_LFN
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
186 fn = *fno.lfname ? fno.lfname : fno.fname;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
187 #else
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
188 fn = fno.fname;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
189 #endif
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
190 printf("%-12s %5u %d/%d/%d %02d:%02d:%02d %s%s%s%s%s\n", fn, fno.fsize,
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
191 FAT_YEAR(fno.fdate), FAT_MONTH(fno.fdate), FAT_DAY(fno.fdate),
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
192 FAT_HOUR(fno.ftime), FAT_MIN(fno.ftime), FAT_SEC(fno.ftime),
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
193 fno.fattrib & AM_DIR ? "D" : "", fno.fattrib & AM_RDO ? "R" : "",
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
194 fno.fattrib & AM_HID ? "H" : "", fno.fattrib & AM_SYS ? "S" : "",
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
195 fno.fattrib & AM_ARC ? "A" : "");
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
196 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
197 } else if (!strcmp(argv[0], "cat")) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
198 FRESULT fserr;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
199 FIL f;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
200 char buf[128], *tmp;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
201
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
202 if (argc != 2) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
203 printf("No file given\n");
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
204 return;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
205 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
206
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
207 if ((fserr = f_open(&f, argv[1], FA_READ)) != FR_OK) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
208 printf("Failed to open file: %d\n", fserr);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
209 return;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
210 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
211
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
212 while ((tmp = f_gets(buf, sizeof(buf), &f)) != NULL) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
213 puts(tmp);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
214 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
215 } else {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
216 printf("Unknown command\n");
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
217 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
218 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
219
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
220 void
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
221 SD_LowLevel_DeInit(void) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
222 GPIO_InitTypeDef GPIO_InitStructure;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
223
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
224 /*!< Disable SDIO Clock */
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
225 SDIO_ClockCmd(DISABLE);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
226
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
227 /*!< Set Power State to OFF */
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
228 SDIO_SetPowerState(SDIO_PowerState_OFF);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
229
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
230 /*!< DeInitializes the SDIO peripheral */
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
231 SDIO_DeInit();
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
232
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
233 /*!< Disable the SDIO AHB Clock */
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
234 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_SDIO, DISABLE);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
235
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
236 /*!< Configure PC.08, PC.09, PC.10, PC.11, PC.12 pin: D0, D1, D2, D3, CLK pin */
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
237 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
238 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
239 GPIO_Init(GPIOC, &GPIO_InitStructure);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
240
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
241 /*!< Configure PD.02 CMD line */
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
242 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
243 GPIO_Init(GPIOD, &GPIO_InitStructure);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
244 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
245
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
246 void
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
247 SD_LowLevel_Init(void) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
248 GPIO_InitTypeDef GPIO_InitStructure;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
249
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
250 /*!< GPIOC and GPIOD Periph clock enable */
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
251 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
252
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
253 /*!< Configure PC.08, PC.09, PC.10, PC.11, PC.12 pin: D0, D1, D2, D3, CLK pin */
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
254 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
255 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
256 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
257 GPIO_Init(GPIOC, &GPIO_InitStructure);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
258
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
259 /*!< Configure PD.02 CMD line */
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
260 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
261 GPIO_Init(GPIOD, &GPIO_InitStructure);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
262
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
263 #ifdef SD_HAVE_DETECT
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
264 RCC_APB2PeriphClockCmd(SD_DETECT_GPIO_CLK, ENABLE);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
265
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
266 /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
267 GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
268 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
269 GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
270 #endif
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
271
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
272 /*!< Enable the SDIO AHB Clock */
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
273 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_SDIO, ENABLE);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
274
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
275 #ifdef SD_DMA_MODE
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
276 /*!< Enable the DMA2 Clock */
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
277 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
278 #endif
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
279 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
280
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
281 void
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
282 SD_LowLevel_DMA_RxConfig(uint32_t *BufferDST, uint32_t BufferSize) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
283 printf("SD_LowLevel_DMA_RxConfig unimplemented\n");
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
284 abort();
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
285 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
286
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
287 void
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
288 SD_LowLevel_DMA_TxConfig(uint32_t *BufferSRC, uint32_t BufferSize) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
289 printf("SD_LowLevel_DMA_TxConfig unimplemented\n");
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
290 abort();
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
291 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
292
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
293 uint32_t SD_DMAEndOfTransferStatus(void) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
294 return (uint32_t)DMA_GetFlagStatus(DMA2_FLAG_TC4);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
295 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
296
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
297
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
298