annotate fatfs_sd.c @ 49:ace431a0d0f5

Add SDIO code poached from STM. Use FatFS to read from SD card. LFN doesn't work reliably so it's disabled for now.
author Daniel O'Connor <darius@dons.net.au>
date Wed, 03 Apr 2013 23:34:20 +1030
parents
children d7207a9d3c3b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
1 /*
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
2 * Glue between FatFS and the ST SDIO 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 "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
37 #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
38 #include "diskio.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
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 DSTATUS
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 disk_initialize(BYTE pdrv) {
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 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
43
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 /* Only have 1 disk */
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 if (pdrv != 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
46 return STA_NOINIT;
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 if ((err = SD_Init()) != SD_OK) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
49 printf("Failed init: %d\r\n", err);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
50 return STA_NOINIT;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
51 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
52
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 return 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
54 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
55
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
56 DSTATUS
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 disk_status(BYTE pdrv) {
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 if (pdrv != 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
59 return STA_NOINIT;
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
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 return 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
62 }
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 DRESULT
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
65 disk_read(BYTE pdrv, BYTE *buff, DWORD sector, BYTE count) {
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 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
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 if (pdrv != 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
69 return STA_NOINIT;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
70
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
71 if (count == 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
72 err = SD_ReadBlock(buff, sector * SD_BLOCK_SIZE, SD_BLOCK_SIZE);
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 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
74 err = SD_ReadMultiBlocks(buff, sector * SD_BLOCK_SIZE, SD_BLOCK_SIZE, count);
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
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 if (err != SD_OK) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
77 printf("Read failed: %d\r\n", err);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
78 return STA_NOINIT;
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 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
80
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
81 return RES_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
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 DRESULT
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 disk_write(BYTE pdrv, const BYTE *buff, DWORD sector, BYTE count) {
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 (pdrv != 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
87 return STA_NOINIT;
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
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 return RES_WRPRT;
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 }
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
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 DRESULT
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 disk_ioctl(BYTE pdrv, BYTE cmd, void *buff) {
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 WORD *wd;
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 DWORD *dwd;
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 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
97 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
98
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 wd = buff;
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 dwd = buff;
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 (pdrv != 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
103 return STA_NOINIT;
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 switch (cmd) {
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 case CTRL_SYNC:
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 printf("Sync\r\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
107 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
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 case GET_SECTOR_SIZE:
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("Get sector size\r\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 *wd = SD_BLOCK_SIZE;
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 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
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 case GET_SECTOR_COUNT:
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 printf("Get sector count\r\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
116
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
117 if ((err = SD_GetCardInfo(&cardinfo)) != SD_OK) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
118 printf("Get card info failed: %d\r\b", err);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
119 return RES_ERROR;
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 }
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 *dwd = cardinfo.CardCapacity / SD_BLOCK_SIZE;
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 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
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 case GET_BLOCK_SIZE:
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 printf("Get block size\r\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
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 if ((err = SD_GetCardInfo(&cardinfo)) != SD_OK) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
128 printf("Get card info failed: %d\r\b", err);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
129 return RES_ERROR;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
130 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
131
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
132 /* FatFS wants log2(blocksize) */
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
133 *dwd = 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
134 while (cardinfo.CardBlockSize > 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
135 *dwd++;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
136 cardinfo.CardBlockSize >>= 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
137 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
138 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
139
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
140 case CTRL_ERASE_SECTOR:
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
141 return RES_ERROR;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
142 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
143
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
144 return RES_OK;
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
145
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
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
148 /*
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
149 bit 31:25 Year from 1980 (0..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
150 bit 24:21 Month (1..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
151 bit 20:16 Day in month(1..31)
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
152 bit 15:11 Hour (0..23)
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
153 bit 10: 5 Minute (0..59)
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
154 bit 4: 0 Second / 2 (0..29)
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
155 */
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
156 DWORD
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
157 get_fattime(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
158 return 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
159 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
160
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
161 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
162 ff_memalloc(UINT msize) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
163 return malloc(msize);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
164 }
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
165
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
166 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
167 ff_memfree(void *mblock) {
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
168 free(mblock);
ace431a0d0f5 Add SDIO code poached from STM. Use FatFS to read from SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
169 }