Skip to content

Commit 41e9022

Browse files
committed
Added SD Card support to bootloader. New binaries.
1 parent 0cca97c commit 41e9022

File tree

153 files changed

+5709
-982
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+5709
-982
lines changed

bootloaders/zero/Makefile

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818

1919
# Begin Config ###############################
2020

21+
# -----------------------------------------------------------------------------
22+
# SD Card support. This can also be set in the relevant board_definitions file.
23+
# SDCARD_DISABLED, SDCARD_ENABLED
24+
SDCARD?=SDCARD_DISABLED
25+
2126
# -----------------------------------------------------------------------------
2227
# Boards definitions:
2328
# MT_D21E_rev_A, MT_D21E_rev_B, MT_D11
@@ -44,7 +49,11 @@ MCU?=SAMD21E18A
4449

4550
# End Config ###############################
4651

52+
ifeq ($(findstring ENABLED,$(SDCARD)),ENABLED)
53+
NAME=sam_ba_sdcard_$(BOARD_ID)_$(MCU)
54+
else
4755
NAME=sam_ba_$(BOARD_ID)_$(MCU)
56+
endif
4857

4958
ifeq ($(findstring 18,$(MCU)),18)
5059
FLASHSIZE=256KB
@@ -113,7 +122,8 @@ SIZE=$(ARM_GCC_PATH)size
113122

114123
# -----------------------------------------------------------------------------
115124
# Compiler options
116-
CFLAGS_EXTRA=-D__$(MCU)__ -DBOARD_ID_$(BOARD_ID)
125+
# eliminate PARANOIA define to save a tiny amount of code (~40B)
126+
CFLAGS_EXTRA=-D$(SDCARD) -D__$(MCU)__ -DBOARD_ID_$(BOARD_ID) -DPARANOIA
117127
CFLAGS=-mthumb -mcpu=cortex-m0plus -Wall -c -std=gnu99 -ffunction-sections -fdata-sections -nostdlib -nostartfiles --param max-inline-insns-single=500 -Wa,-adhlns=$(<:%.c=$(BUILD_PATH)/%.lst)
118128
ifdef DEBUG
119129
CFLAGS+=-g3 -O1 -DDEBUG=1
@@ -141,6 +151,10 @@ SOURCES= \
141151
board_driver_serial.c \
142152
board_init.c \
143153
board_startup.c \
154+
util.c \
155+
SDCard/sdBootloader.c \
156+
SDCard/mmcbbp.c \
157+
SDCard/pff.c \
144158
main.c \
145159
sam_ba_monitor.c \
146160
sam_ba_serial.c
@@ -152,6 +166,10 @@ SOURCES= \
152166
board_driver_usb.c \
153167
board_init.c \
154168
board_startup.c \
169+
util.c \
170+
SDCard/sdBootloader.c \
171+
SDCard/mmcbbp.c \
172+
SDCard/pff.c \
155173
main.c \
156174
sam_ba_usb.c \
157175
sam_ba_cdc.c \
@@ -200,6 +218,7 @@ $(BUILD_PATH):
200218
@echo ----------------------------------------------------------
201219
@echo Creating build folder
202220
-mkdir $(BUILD_PATH)
221+
-mkdir $(BUILD_PATH)/SDCard
203222

204223
print_info:
205224
@echo ----------------------------------------------------------
@@ -227,14 +246,18 @@ clean: $(AS_CLEAN)
227246
@echo Cleaning project
228247
-$(RM) $(BIN)
229248
-$(RM) $(HEX)
249+
-$(RM) $(BUILD_PATH)/SDCard/*.*
230250
-$(RM) $(BUILD_PATH)/*.*
251+
-rmdir $(BUILD_PATH)/SDCard
231252
-rmdir $(BUILD_PATH)
232253

233254
mostly_clean: $(AS_CLEAN)
234255
@echo ----------------------------------------------------------
235256
@echo Cleaning project except bin
236257
-$(RM) $(HEX)
258+
-$(RM) $(BUILD_PATH)/SDCard/*.*
237259
-$(RM) $(BUILD_PATH)/*.*
260+
-rmdir $(BUILD_PATH)/SDCard
238261
-rmdir $(BUILD_PATH)
239262

240263
.phony: print_info $(BUILD_PATH)

bootloaders/zero/README.md

Lines changed: 590 additions & 86 deletions
Large diffs are not rendered by default.

bootloaders/zero/SDCard/00readme.txt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Petit FatFs Module Source Files R0.03 (C)ChaN, 2014
2+
3+
4+
FILES
5+
6+
pff.h Common include file for Petit FatFs and application module.
7+
pff.c Petit FatFs module.
8+
diskio.h Common include file for Petit FatFs and disk I/O module.
9+
diskio.c Skeleton of low level disk I/O module.
10+
integer.h Alternative type definitions for integer variables.
11+
12+
Low level disk I/O module is not included in this archive because the Petit
13+
FatFs module is only a generic file system layer and not depend on any
14+
specific storage device. You have to provide a low level disk I/O module that
15+
written to control your storage device.
16+
17+
18+
19+
AGREEMENTS
20+
21+
Petit FatFs module is an open source software to implement FAT file system to
22+
small embedded systems. This is a free software and is opened for education,
23+
research and commercial developments under license policy of following trems.
24+
25+
Copyright (C) 2014, ChaN, all right reserved.
26+
27+
* The Petit FatFs module is a free software and there is NO WARRANTY.
28+
* No restriction on use. You can use, modify and redistribute it for
29+
personal, non-profit or commercial use UNDER YOUR RESPONSIBILITY.
30+
* Redistributions of source code must retain the above copyright notice.
31+
32+
33+
34+
REVISION HISTORY
35+
36+
Jun 15, 2009 R0.01a First release (Branched from FatFs R0.07b)
37+
38+
Dec 14, 2009 R0.02 Added multiple code page support.
39+
Added write funciton.
40+
Changed stream read mode interface.
41+
Dec 07,'2010 R0.02a Added some configuration options.
42+
Fixed fails to open objects with DBCS character.
43+
44+
Jun 10, 2014 R0.03 Separated out configuration options to pffconf.h.
45+
Added _USE_LCC option.
46+
Added _FS_FAT16 option.

bootloaders/zero/SDCard/diskio.h

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*-----------------------------------------------------------------------
2+
/ PFF - Low level disk interface modlue include file (C)ChaN, 2014
3+
/-----------------------------------------------------------------------*/
4+
5+
#ifndef _DISKIO_DEFINED
6+
#define _DISKIO_DEFINED
7+
8+
#ifdef __cplusplus
9+
extern "C" {
10+
#endif
11+
12+
#include <sam.h>
13+
#include "integer.h"
14+
15+
16+
/* Status of Disk Functions */
17+
typedef BYTE DSTATUS;
18+
19+
20+
/* Results of Disk Functions */
21+
typedef enum {
22+
RES_OK = 0, /* 0: Function succeeded */
23+
RES_ERROR, /* 1: Disk error */
24+
RES_NOTRDY, /* 2: Not ready */
25+
RES_PARERR /* 3: Invalid parameter */
26+
} DRESULT;
27+
28+
29+
/* SERCOM SPI available pad settings */
30+
enum spi_pad_settings {
31+
SPI_RX_PAD0_TX_PAD2_SCK_PAD3 = SERCOM_SPI_CTRLA_DIPO(0) | SERCOM_SPI_CTRLA_DOPO(1),
32+
SPI_RX_PAD0_TX_PAD3_SCK_PAD1 = SERCOM_SPI_CTRLA_DIPO(0) | SERCOM_SPI_CTRLA_DOPO(2),
33+
SPI_RX_PAD1_TX_PAD2_SCK_PAD3 = SERCOM_SPI_CTRLA_DIPO(1) | SERCOM_SPI_CTRLA_DOPO(1),
34+
SPI_RX_PAD1_TX_PAD0_SCK_PAD3 = SERCOM_SPI_CTRLA_DIPO(1) | SERCOM_SPI_CTRLA_DOPO(3),
35+
SPI_RX_PAD2_TX_PAD0_SCK_PAD1 = SERCOM_SPI_CTRLA_DIPO(2) | SERCOM_SPI_CTRLA_DOPO(0),
36+
SPI_RX_PAD2_TX_PAD3_SCK_PAD1 = SERCOM_SPI_CTRLA_DIPO(2) | SERCOM_SPI_CTRLA_DOPO(2),
37+
SPI_RX_PAD2_TX_PAD0_SCK_PAD3 = SERCOM_SPI_CTRLA_DIPO(2) | SERCOM_SPI_CTRLA_DOPO(3),
38+
SPI_RX_PAD3_TX_PAD0_SCK_PAD1 = SERCOM_SPI_CTRLA_DIPO(3) | SERCOM_SPI_CTRLA_DOPO(0),
39+
};
40+
41+
42+
/*---------------------------------------*/
43+
/* Prototypes for disk control functions */
44+
45+
DSTATUS disk_initialize (void);
46+
DRESULT disk_readp (BYTE* buff, DWORD sector, UINT offser, UINT count);
47+
DRESULT disk_writep (const BYTE* buff, DWORD sc);
48+
49+
#define DUMMY_BYTE 0xFF
50+
51+
#define STA_NOINIT 0x01 /* Drive not initialized */
52+
#define STA_NODISK 0x02 /* No medium in the drive */
53+
54+
/* Card type flags (CardType) */
55+
#define CT_MMC 0x01 /* MMC ver 3 */
56+
#define CT_SD1 0x02 /* SD ver 1 */
57+
#define CT_SD2 0x04 /* SD ver 2 */
58+
#define CT_SDC (CT_SD1|CT_SD2) /* SD */
59+
#define CT_BLOCK 0x08 /* Block addressing */
60+
61+
/* Definitions for MMC/SDC command */
62+
#define CMD0 (0x40+0) /* GO_IDLE_STATE */
63+
#define CMD1 (0x40+1) /* SEND_OP_COND (MMC) */
64+
#define ACMD41 (0xC0+41) /* SEND_OP_COND (SDC) */
65+
#define CMD8 (0x40+8) /* SEND_IF_COND */
66+
#define CMD16 (0x40+16) /* SET_BLOCKLEN */
67+
#define CMD17 (0x40+17) /* READ_SINGLE_BLOCK */
68+
#define CMD24 (0x40+24) /* WRITE_BLOCK */
69+
#define CMD55 (0x40+55) /* APP_CMD */
70+
#define CMD58 (0x40+58) /* READ_OCR */
71+
72+
#define SERCOM_MODE_USART_EXT_CLK_Val 0x0ul
73+
#define SERCOM_MODE_USART_INT_CLK_Val 0x1ul
74+
#define SERCOM_MODE_SPI_SLAVE_Val 0x2ul
75+
#define SERCOM_MODE_SPI_MASTER_Val 0x3ul
76+
#define SERCOM_MODE_I2C_SLAVE_Val 0x4ul
77+
#define SERCOM_MODE_I2C_MASTER_Val 0x5ul
78+
79+
#define SERCOM_DORD_MSB_FIRST_Val 0x0ul
80+
#define SERCOM_DORD_LSB_FIRST_Val 0x1ul
81+
82+
#define SERCOM_CHAR_SIZE_8_BITS_Val 0x0ul
83+
#define SERCOM_CHAR_SIZE_9_BITS_Val 0x1ul
84+
85+
#define SDCARD_SPI_BUAD_SLOW 250000ul
86+
#define SDCARD_SPI_BUAD_FAST 6000000ul
87+
88+
#ifdef __cplusplus
89+
}
90+
#endif
91+
92+
#endif /* _DISKIO_DEFINED */

bootloaders/zero/SDCard/integer.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*-------------------------------------------*/
2+
/* Integer type definitions for FatFs module */
3+
/*-------------------------------------------*/
4+
5+
#ifndef _FF_INTEGER
6+
#define _FF_INTEGER
7+
8+
#ifdef _WIN32 /* FatFs development platform */
9+
10+
#include <windows.h>
11+
#include <tchar.h>
12+
13+
#else /* Embedded platform */
14+
15+
/* This type MUST be 8 bit */
16+
typedef unsigned char BYTE;
17+
18+
/* These types MUST be 16 bit */
19+
typedef short SHORT;
20+
typedef unsigned short WORD;
21+
typedef unsigned short WCHAR;
22+
23+
/* These types MUST be 16 bit or 32 bit */
24+
typedef int INT;
25+
typedef unsigned int UINT;
26+
27+
/* These types MUST be 32 bit */
28+
typedef long LONG;
29+
typedef unsigned long DWORD;
30+
31+
#endif
32+
33+
#endif

0 commit comments

Comments
 (0)