Mercurial > ~darius > hgwebdir.cgi > stm32temp
annotate sd.c @ 57:adc9b1555f9d
Add the ability to log temperatures to SD card.
Fix a few warnings while I am here.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Mon, 08 Apr 2013 22:20:40 +0930 |
parents | f0563086040d |
children | 488085e0c7e1 |
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); |
50
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
51 char *sderr2str(SD_Error err); |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
52 void dump_buf(uint8_t *buf, uint32_t size); |
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
|
53 |
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 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
|
55 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
|
56 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
|
57 } |
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 |
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 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
|
60 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
|
61 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
|
62 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
|
63 |
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 if ((err = SD_Init()) != SD_OK) { |
50
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
65 printf("Failed init: %s\n", sderr2str(err)); |
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
|
66 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
|
67 } |
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 |
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 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
|
70 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
|
71 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
|
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 } |
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 |
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 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
|
76 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
|
77 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
|
78 |
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 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
|
80 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
|
81 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
|
82 } |
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 |
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 (!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
|
85 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
|
86 if ((err = SD_GetCardInfo(&cardinfo)) != SD_OK) { |
50
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
87 printf("Get card info failed: %s\r\b", sderr2str(err)); |
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
|
88 } 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
|
89 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 } |
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], "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
|
97 sd_domount(); |
50
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
98 } else if (!strcmp(argv[0], "rdb")) { |
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
|
99 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
|
100 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
|
101 |
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 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
|
103 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
|
104 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
|
105 } |
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 addr = atoi(argv[1]); |
56
f0563086040d
Fix more warnings. Note the 'buf might be used uninitialised' warning appears to be a GCC bug.
Daniel O'Connor <darius@dons.net.au>
parents:
55
diff
changeset
|
107 |
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
|
108 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
|
109 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
|
110 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
|
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 |
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 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
|
114 if ((err = SD_ReadBlock(buf, addr * SD_BLOCK_SIZE, SD_BLOCK_SIZE)) != SD_OK) { |
50
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
115 printf("Read block returned %s\n", sderr2str(err)); |
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
|
116 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
|
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 |
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 #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
|
120 if ((err = SD_WaitReadOperation()) != SD_OK) { |
50
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
121 printf("Wait returned %s\n", sderr2str(err)); |
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
|
122 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
|
123 } |
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 #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
|
125 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
|
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 |
50
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
128 dump_buf(buf, SD_BLOCK_SIZE); |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
129 |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
130 read_exit: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
131 free(buf); |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
132 } else if (!strcmp(argv[0], "wrb")) { |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
133 uint32_t addr; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
134 uint8_t *buf; |
56
f0563086040d
Fix more warnings. Note the 'buf might be used uninitialised' warning appears to be a GCC bug.
Daniel O'Connor <darius@dons.net.au>
parents:
55
diff
changeset
|
135 int32_t i; |
50
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
136 |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
137 if (argc < 3) { |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
138 printf("Block to read and/or fill value(s) not specified\n"); |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
139 return; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
140 } |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
141 addr = atoi(argv[1]); |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
142 |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
143 if ((buf = malloc(SD_BLOCK_SIZE)) == NULL) { |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
144 printf("Unable to allocate buffer\n"); |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
145 return; |
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
|
146 } |
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 |
50
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
148 for (i = 0; i < SD_BLOCK_SIZE; i++) { |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
149 //buf[i] = atoi(argv[(i % (argc - 2)) + 2]); |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
150 if (i < argc - 2) |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
151 buf[i] = atoi(argv[i + 2]); |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
152 else |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
153 buf[i] = 0; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
154 } |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
155 |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
156 /* If passed values not modulo 512 it hangs */ |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
157 if ((err = SD_WriteBlock(buf, addr * SD_BLOCK_SIZE, SD_BLOCK_SIZE)) != SD_OK) { |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
158 printf("Write block returned %s\n", sderr2str(err)); |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
159 goto write_exit; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
160 } |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
161 |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
162 #ifdef SD_DMA_MODE |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
163 if ((err = SD_WaitWriteOperation()) != SD_OK) { |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
164 printf("Wait returned %s\n", sderr2str(err)); |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
165 goto write_exit; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
166 } |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
167 #endif |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
168 while(SD_GetStatus() != SD_TRANSFER_OK) |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
169 ; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
170 |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
171 write_exit: |
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
|
172 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
|
173 } 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
|
174 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
|
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 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
|
177 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
|
178 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
|
179 } |
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 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
|
181 |
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 if ((err = SD_Erase(addr * SD_BLOCK_SIZE, (addr + 1) * SD_BLOCK_SIZE)) != SD_OK) { |
50
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
183 printf("Erase block returned %s\n", sderr2str(err)); |
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
|
184 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
|
185 } |
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 |
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 #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
|
188 if ((err = SD_WaitReadOperation()) != SD_OK) { |
50
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
189 printf("Wait returned %s\n", sderr2str(err)); |
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
|
190 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
|
191 } |
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 #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
|
193 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
|
194 ; |
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 printf("Erased OK\n"); |
50
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
196 } else if (!strcmp(argv[0], "mkfs")) { |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
197 FRESULT fserr; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
198 if ((fserr = f_mkfs(0, 0, 0)) != FR_OK) { |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
199 printf("Unable to mkfs: %d\n", fserr); |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
200 } |
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
|
201 } 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
|
202 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
|
203 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
|
204 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
|
205 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
|
206 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
|
207 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
|
208 |
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 if ((fserr = f_getlabel("", label, &sn)) != FR_OK) { |
50
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
210 printf("Unable to read label: %d\n", fserr); |
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
|
211 } else { |
56
f0563086040d
Fix more warnings. Note the 'buf might be used uninitialised' warning appears to be a GCC bug.
Daniel O'Connor <darius@dons.net.au>
parents:
55
diff
changeset
|
212 printf("Label: %s Serial: %ld\n", label, sn); |
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
|
213 } |
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 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
|
216 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
|
217 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
|
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 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
|
221 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
|
222 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
|
223 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
|
224 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
|
225 } |
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 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
|
227 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
|
228 #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
|
229 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
|
230 #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
|
231 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
|
232 #endif |
56
f0563086040d
Fix more warnings. Note the 'buf might be used uninitialised' warning appears to be a GCC bug.
Daniel O'Connor <darius@dons.net.au>
parents:
55
diff
changeset
|
233 printf("%-12s %5lu %d/%d/%d %02d:%02d:%02d %s%s%s%s%s\n", fn, fno.fsize, |
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
|
234 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
|
235 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
|
236 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
|
237 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
|
238 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
|
239 } |
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 } 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
|
241 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
|
242 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
|
243 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
|
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 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
|
246 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
|
247 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
|
248 } |
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 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
|
251 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
|
252 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
|
253 } |
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 |
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 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
|
256 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
|
257 } |
50
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
258 |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
259 f_close(&f); |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
260 |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
261 } else if (!strcmp(argv[0], "wr")) { |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
262 FRESULT fserr; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
263 FIL f; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
264 |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
265 if (argc != 3) { |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
266 printf("No file and/or text given\n"); |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
267 return; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
268 } |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
269 |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
270 if ((fserr = f_open(&f, argv[1], FA_WRITE | FA_OPEN_ALWAYS)) != FR_OK) { |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
271 printf("Failed to open file: %d\n", fserr); |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
272 return; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
273 } |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
274 |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
275 if ((fserr = f_lseek(&f, f_size(&f))) != FR_OK) { |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
276 printf("Failed to seek to end of file: %d\n", fserr); |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
277 goto wr_out; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
278 } |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
279 |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
280 f_puts(argv[2], &f); |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
281 f_putc('\n', &f); |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
282 wr_out: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
283 f_close(&f); |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
284 } else if (!strcmp(argv[0], "rm")) { |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
285 FRESULT fserr; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
286 |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
287 if (argc != 2) { |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
288 printf("No file given\n"); |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
289 return; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
290 } |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
291 |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
292 if ((fserr = f_unlink(argv[1])) != FR_OK) { |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
293 printf("Failed to remove file: %d\n", fserr); |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
294 return; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
295 } |
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
|
296 } 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
|
297 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
|
298 } |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
299 } |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
300 |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
301 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
|
302 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
|
303 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
|
304 |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
305 /*!< 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
|
306 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
|
307 |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
308 /*!< 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
|
309 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
|
310 |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
311 /*!< 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
|
312 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
|
313 |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
314 /*!< 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
|
315 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
|
316 |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
317 /*!< 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
|
318 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
|
319 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
|
320 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
|
321 |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
322 /*!< 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
|
323 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
|
324 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
|
325 } |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
326 |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
327 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
|
328 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
|
329 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
|
330 |
54 | 331 /* GPIOC and GPIOD Periph clock enable */ |
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
|
332 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
|
333 |
54 | 334 /* Configure PC.08, PC.09, PC.10, PC.11, PC.12 pin: D0, D1, D2, D3, CLK pin */ |
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
|
335 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
|
336 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
|
337 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
|
338 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
|
339 |
54 | 340 /* Configure PD.02 CMD line */ |
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
|
341 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
|
342 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
|
343 |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
344 #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
|
345 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
|
346 |
54 | 347 /* Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */ |
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
|
348 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
|
349 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
|
350 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
|
351 #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
|
352 |
54 | 353 /* Enable the SDIO AHB Clock */ |
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
|
354 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
|
355 |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
356 #ifdef SD_DMA_MODE |
54 | 357 /* Enable the DMA2 Clock */ |
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
|
358 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
|
359 #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
|
360 } |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
361 |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
362 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
|
363 SD_LowLevel_DMA_RxConfig(uint32_t *BufferDST, uint32_t BufferSize) { |
55
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
364 DMA_InitTypeDef DMA_InitStructure; |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
365 |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
366 DMA_ClearFlag(DMA2_FLAG_TC4 | DMA2_FLAG_TE4 | DMA2_FLAG_HT4 | DMA2_FLAG_GL4); |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
367 |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
368 /* DMA2 Channel4 disable */ |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
369 DMA_Cmd(DMA2_Channel4, DISABLE); |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
370 |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
371 /* DMA2 Channel4 Config */ |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
372 DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)0x40018080; |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
373 DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)BufferDST; |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
374 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
375 DMA_InitStructure.DMA_BufferSize = BufferSize / 4; |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
376 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
377 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
378 DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
379 DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
380 DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
381 DMA_InitStructure.DMA_Priority = DMA_Priority_High; |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
382 DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
383 DMA_Init(DMA2_Channel4, &DMA_InitStructure); |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
384 |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
385 /* DMA2 Channel4 enable */ |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
386 DMA_Cmd(DMA2_Channel4, ENABLE); |
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
|
387 } |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
388 |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
389 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
|
390 SD_LowLevel_DMA_TxConfig(uint32_t *BufferSRC, uint32_t BufferSize) { |
55
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
391 DMA_InitTypeDef DMA_InitStructure; |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
392 |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
393 DMA_ClearFlag(DMA2_FLAG_TC4 | DMA2_FLAG_TE4 | DMA2_FLAG_HT4 | DMA2_FLAG_GL4); |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
394 |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
395 /* DMA2 Channel4 disable */ |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
396 DMA_Cmd(DMA2_Channel4, DISABLE); |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
397 |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
398 /* DMA2 Channel4 Config */ |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
399 DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)0x40018080; |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
400 DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)BufferSRC; |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
401 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
402 DMA_InitStructure.DMA_BufferSize = BufferSize / 4; |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
403 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
404 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
405 DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
406 DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
407 DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
408 DMA_InitStructure.DMA_Priority = DMA_Priority_High; |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
409 DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
410 DMA_Init(DMA2_Channel4, &DMA_InitStructure); |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
411 |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
412 /* DMA2 Channel4 enable */ |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
413 DMA_Cmd(DMA2_Channel4, ENABLE); |
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
|
414 } |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
415 |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
416 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
|
417 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
|
418 } |
ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
419 |
50
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
420 char * |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
421 sderr2str(SD_Error err) { |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
422 switch (err) { |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
423 case SD_CMD_CRC_FAIL: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
424 return "CMD_CRC_FAIL"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
425 case SD_DATA_CRC_FAIL: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
426 return "DATA_CRC_FAIL"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
427 case SD_CMD_RSP_TIMEOUT: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
428 return "CMD_RSP_TIMEOUT"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
429 case SD_DATA_TIMEOUT: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
430 return "DATA_TIMEOUT"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
431 case SD_TX_UNDERRUN: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
432 return "TX_UNDERRUN"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
433 case SD_RX_OVERRUN: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
434 return "RX_OVERRUN"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
435 case SD_START_BIT_ERR: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
436 return "START_BIT_ERR"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
437 case SD_CMD_OUT_OF_RANGE: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
438 return "CMD_OUT_OF_RANGE"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
439 case SD_ADDR_MISALIGNED: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
440 return "ADDR_MISALIGNED"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
441 case SD_BLOCK_LEN_ERR: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
442 return "BLOCK_LEN_ERR"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
443 case SD_ERASE_SEQ_ERR: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
444 return "ERASE_SEQ_ERR"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
445 case SD_BAD_ERASE_PARAM: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
446 return "BAD_ERASE_PARAM"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
447 case SD_WRITE_PROT_VIOLATION: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
448 return "WRITE_PROT_VIOLATION"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
449 case SD_LOCK_UNLOCK_FAILED: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
450 return "LOCK_UNLOCK_FAILED"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
451 case SD_COM_CRC_FAILED: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
452 return "COM_CRC_FAILED"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
453 case SD_ILLEGAL_CMD: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
454 return "ILLEGAL_CMD"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
455 case SD_CARD_ECC_FAILED: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
456 return "CARD_ECC_FAILED"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
457 case SD_CC_ERROR: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
458 return "CC_ERROR"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
459 case SD_GENERAL_UNKNOWN_ERROR: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
460 return "GENERAL_UNKNOWN_ERROR"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
461 case SD_STREAM_READ_UNDERRUN: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
462 return "STREAM_READ_UNDERRUN"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
463 case SD_STREAM_WRITE_OVERRUN: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
464 return "STREAM_WRITE_OVERRUN"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
465 case SD_CID_CSD_OVERWRITE: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
466 return "OVERWRITE"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
467 case SD_WP_ERASE_SKIP: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
468 return "WP_ERASE_SKIP"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
469 case SD_CARD_ECC_DISABLED: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
470 return "CARD_ECC_DISABLED"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
471 case SD_ERASE_RESET: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
472 return "ERASE_RESET"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
473 case SD_AKE_SEQ_ERROR: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
474 return "AKE_SEQ_ERROR"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
475 case SD_INVALID_VOLTRANGE: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
476 return "INVALID_VOLTRANGE"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
477 case SD_ADDR_OUT_OF_RANGE: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
478 return "ADDR_OUT_OF_RANGE"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
479 case SD_SWITCH_ERROR: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
480 return "SWITCH_ERROR"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
481 case SD_SDIO_DISABLED: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
482 return "SDIO_DISABLED"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
483 case SD_SDIO_FUNCTION_BUSY: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
484 return "SDIO_FUNCTION_BUSY"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
485 case SD_SDIO_FUNCTION_FAILED: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
486 return "SDIO_FUNCTION_FAILED"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
487 case SD_SDIO_UNKNOWN_FUNCTION: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
488 return "SDIO_UNKNOWN_FUNCTION"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
489 case SD_INTERNAL_ERROR: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
490 return "INTERNAL_ERROR"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
491 case SD_NOT_CONFIGURED: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
492 return "NOT_CONFIGURED"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
493 case SD_REQUEST_PENDING: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
494 return "REQUEST_PENDING"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
495 case SD_REQUEST_NOT_APPLICABLE: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
496 return "REQUEST_NOT_APPLICABLE"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
497 case SD_INVALID_PARAMETER: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
498 return "INVALID_PARAMETER"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
499 case SD_UNSUPPORTED_FEATURE: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
500 return "UNSUPPORTED_FEATURE"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
501 case SD_UNSUPPORTED_HW: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
502 return "UNSUPPORTED_HW"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
503 case SD_ERROR: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
504 return "ERROR"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
505 case SD_OK: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
506 return "OK"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
507 default: |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
508 return "Unknown"; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
509 } |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
510 } |
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
|
511 |
50
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
512 |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
513 void dump_buf(uint8_t *buf, uint32_t size) { |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
514 uint32_t i; |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
515 |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
516 for (i = 0; i < size; i += 16) { |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
517 printf("0x%04lx: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", i, |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
518 buf[i + 0], buf[i + 1], buf[i + 2], buf[i + 3], buf[i + 4], buf[i + 5], buf[i + 6], buf[i + 7], |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
519 buf[i + 8], buf[i + 9], buf[i + 10], buf[i + 11], buf[i + 12], buf[i + 13], buf[i + 14], buf[i + 15]); |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
520 } |
d7207a9d3c3b
Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents:
49
diff
changeset
|
521 } |
55
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
522 |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
523 void SDIO_IRQHandler(void) { |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
524 /* Process All SDIO Interrupt Sources */ |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
525 SD_ProcessIRQSrc(); |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
526 } |
b21db2b47a27
Enable DMA mode by initing DMA channel and enabling IRQ handler.
Daniel O'Connor <darius@dons.net.au>
parents:
54
diff
changeset
|
527 |