annotate sd.c @ 50:d7207a9d3c3b

Add write support. LFN still broken though. Make sure we wait for the card to be done after a read or write (didn't seem to break reading but hosed writes).
author Daniel O'Connor <darius@dons.net.au>
date Fri, 05 Apr 2013 00:08:31 +1030
parents ace431a0d0f5
children 79c7892d07b3
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);
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 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
102
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 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
104 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
105 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
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 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
108
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 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
110 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
111 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
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
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 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
115 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
116 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
117 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
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
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 #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
121 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
122 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
123 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
124 }
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 #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
126 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
127 ;
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
50
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
129 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
130
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
131 read_exit:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
132 free(buf);
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
133 } 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
134 uint32_t addr;
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
135 uint8_t *buf;
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
136 uint32_t i;
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
137
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
138 if (argc < 3) {
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
139 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
140 return;
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
141 }
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
142 addr = atoi(argv[1]);
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
143
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
144 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
145 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
146 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
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
50
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
149 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
150 //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
151 if (i < argc - 2)
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
152 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
153 else
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
154 buf[i] = 0;
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
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
157 /* 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
158 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
159 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
160 goto write_exit;
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
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
163 #ifdef SD_DMA_MODE
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
164 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
165 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
166 goto write_exit;
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
167 }
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
168 #endif
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
169 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
170 ;
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
171
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
172 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
173 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
174 } 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
175 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
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 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
178 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
179 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
180 }
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 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
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 ((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
184 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
185 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
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
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 #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
189 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
190 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
191 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
192 }
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 #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
194 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
195 ;
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 printf("Erased OK\n");
50
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
197 } 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
198 FRESULT fserr;
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
199 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
200 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
201 }
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
202 } 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
203 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
204 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
205 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
206 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
207 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
208 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
209
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 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
211 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
212 } 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
213 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
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
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 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
217 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
218 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
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
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 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
222 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
223 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
224 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
225 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
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 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
228 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
229 #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
230 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
231 #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
232 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
233 #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
234 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
235 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
236 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
237 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
238 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
239 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
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 } 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
242 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
243 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
244 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
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 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
247 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
248 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
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
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 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
252 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
253 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
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
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 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
257 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
258 }
50
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
259
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
260 f_close(&f);
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
261
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
262 } 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
263 FRESULT fserr;
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
264 FIL f;
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
265
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
266 if (argc != 3) {
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
267 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
268 return;
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
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
271 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
272 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
273 return;
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
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
276 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
277 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
278 goto wr_out;
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
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
281 f_puts(argv[2], &f);
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
282 f_putc('\n', &f);
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
283 wr_out:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
284 f_close(&f);
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
285 } 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
286 FRESULT fserr;
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
287
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
288 if (argc != 2) {
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
289 printf("No file given\n");
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
290 return;
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
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
293 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
294 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
295 return;
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
296 }
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
297 } 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
298 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
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
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 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 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
304 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
305
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 /*!< 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
307 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
308
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 /*!< 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
310 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
311
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 /*!< 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
313 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
314
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 /*!< 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
316 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
317
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 /*!< 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
319 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
320 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
321 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
322
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 /*!< 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
324 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
325 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
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
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 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 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
330 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
331
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 /*!< 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
333 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
334
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 /*!< 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
336 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
337 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
338 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
339 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
340
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 /*!< 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
342 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
343 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
344
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 #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
346 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
347
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 /*!< 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
349 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
350 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
351 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
352 #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
353
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 /*!< 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
355 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
356
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
357 #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
358 /*!< 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
359 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
360 #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
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
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 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
364 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
365 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
366 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
367 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
368
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
369 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
370 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
371 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
372 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
373 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
374
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
375 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
376 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
377 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
378
50
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
379 char *
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
380 sderr2str(SD_Error err) {
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
381 switch (err) {
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
382 case SD_CMD_CRC_FAIL:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
383 return "CMD_CRC_FAIL";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
384 case SD_DATA_CRC_FAIL:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
385 return "DATA_CRC_FAIL";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
386 case SD_CMD_RSP_TIMEOUT:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
387 return "CMD_RSP_TIMEOUT";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
388 case SD_DATA_TIMEOUT:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
389 return "DATA_TIMEOUT";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
390 case SD_TX_UNDERRUN:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
391 return "TX_UNDERRUN";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
392 case SD_RX_OVERRUN:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
393 return "RX_OVERRUN";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
394 case SD_START_BIT_ERR:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
395 return "START_BIT_ERR";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
396 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
397 return "CMD_OUT_OF_RANGE";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
398 case SD_ADDR_MISALIGNED:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
399 return "ADDR_MISALIGNED";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
400 case SD_BLOCK_LEN_ERR:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
401 return "BLOCK_LEN_ERR";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
402 case SD_ERASE_SEQ_ERR:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
403 return "ERASE_SEQ_ERR";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
404 case SD_BAD_ERASE_PARAM:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
405 return "BAD_ERASE_PARAM";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
406 case SD_WRITE_PROT_VIOLATION:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
407 return "WRITE_PROT_VIOLATION";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
408 case SD_LOCK_UNLOCK_FAILED:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
409 return "LOCK_UNLOCK_FAILED";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
410 case SD_COM_CRC_FAILED:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
411 return "COM_CRC_FAILED";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
412 case SD_ILLEGAL_CMD:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
413 return "ILLEGAL_CMD";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
414 case SD_CARD_ECC_FAILED:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
415 return "CARD_ECC_FAILED";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
416 case SD_CC_ERROR:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
417 return "CC_ERROR";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
418 case SD_GENERAL_UNKNOWN_ERROR:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
419 return "GENERAL_UNKNOWN_ERROR";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
420 case SD_STREAM_READ_UNDERRUN:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
421 return "STREAM_READ_UNDERRUN";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
422 case SD_STREAM_WRITE_OVERRUN:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
423 return "STREAM_WRITE_OVERRUN";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
424 case SD_CID_CSD_OVERWRITE:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
425 return "OVERWRITE";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
426 case SD_WP_ERASE_SKIP:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
427 return "WP_ERASE_SKIP";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
428 case SD_CARD_ECC_DISABLED:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
429 return "CARD_ECC_DISABLED";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
430 case SD_ERASE_RESET:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
431 return "ERASE_RESET";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
432 case SD_AKE_SEQ_ERROR:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
433 return "AKE_SEQ_ERROR";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
434 case SD_INVALID_VOLTRANGE:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
435 return "INVALID_VOLTRANGE";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
436 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
437 return "ADDR_OUT_OF_RANGE";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
438 case SD_SWITCH_ERROR:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
439 return "SWITCH_ERROR";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
440 case SD_SDIO_DISABLED:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
441 return "SDIO_DISABLED";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
442 case SD_SDIO_FUNCTION_BUSY:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
443 return "SDIO_FUNCTION_BUSY";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
444 case SD_SDIO_FUNCTION_FAILED:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
445 return "SDIO_FUNCTION_FAILED";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
446 case SD_SDIO_UNKNOWN_FUNCTION:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
447 return "SDIO_UNKNOWN_FUNCTION";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
448 case SD_INTERNAL_ERROR:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
449 return "INTERNAL_ERROR";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
450 case SD_NOT_CONFIGURED:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
451 return "NOT_CONFIGURED";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
452 case SD_REQUEST_PENDING:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
453 return "REQUEST_PENDING";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
454 case SD_REQUEST_NOT_APPLICABLE:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
455 return "REQUEST_NOT_APPLICABLE";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
456 case SD_INVALID_PARAMETER:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
457 return "INVALID_PARAMETER";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
458 case SD_UNSUPPORTED_FEATURE:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
459 return "UNSUPPORTED_FEATURE";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
460 case SD_UNSUPPORTED_HW:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
461 return "UNSUPPORTED_HW";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
462 case SD_ERROR:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
463 return "ERROR";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
464 case SD_OK:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
465 return "OK";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
466 default:
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
467 return "Unknown";
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
468 }
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
469 }
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
470
50
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
471
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
472 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
473 uint32_t i;
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
474
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
475 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
476 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
477 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
478 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
479 }
d7207a9d3c3b Add write support. LFN still broken though.
Daniel O'Connor <darius@dons.net.au>
parents: 49
diff changeset
480 }