Skip to content

Support for SCI-SPI SD card #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# KallistiOS ##version##
#
# libfatfs Makefile
# (C) 2025 Ruslan Rostovtsev
#

.PHONY: all

# Default target
all:
$(MAKE) -C fatfs

# Pass all targets to fatfs/Makefile
%:
$(MAKE) -C fatfs $@
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,30 @@ cp -R include fatfs /opt/toolchains/dc/kos/addons
make
```

### Build Options
You can customize the build with the following options:
- `DEBUG=1` - Enable debug output (disabled by default)
- `DMA_BUF=0` - Disable DMA buffer (enabled by default)
- `SD_CHECK_CRC=1` - Enable CRC checking for SD cards (disabled by default)

Examples:
```console
# Build with defaults
make

# Build with CRC checking for SD cards
make SD_CHECK_CRC=1

# Build without DMA buffer
make DMA_BUF=0
```

## Usage
- Add `#include <fatfs.h>` in your C source file.
- Add `-lfatfs` in your `Makefile` on the line which builds your program, e.g.:
- `kos-cc -o $(TARGET) $(OBJS) -lfatfs`
- Simply call `fs_fat_mount_sd()` to mount a FAT partition to `/sd` and/or call `fs_fat_mount_ide()` to mount a FAT partition to `/ide`.
- Additionally, you can use other block devices by calling `fs_fat_mount()` with the appropriate parameters for the target device -- see `fatfs.h` for more information.
- To reduce memory usage you can disable DMA buffer, look in `Makefile`.

## Links
- DreamShell: https://github.com/DC-SWAT/DreamShell
Expand Down
56 changes: 34 additions & 22 deletions fatfs/Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
# KallistiOS ##version##
#
# libfatfs Makefile
# (C) 2025 Ruslan Rostovtsev
#

TARGET = libfatfs.a
OBJS = src/option/ccsbcs.o \
src/option/syscall.o \
src/ff.o \
src/dc.o \
src/dc_bdev.o

KOS_CFLAGS += -W -Wextra -pedantic -Isrc -I../include

# Uncomment to enable debug output.
# KOS_CFLAGS += -DFATFS_DEBUG=1

# Comment out to reduce memory usage.
KOS_CFLAGS += -DFATFS_USE_DMA_BUF=1

include $(KOS_BASE)/addons/Makefile.prefab
# KallistiOS ##version##
#
# libfatfs Makefile
# (C) 2025 Ruslan Rostovtsev
#

TARGET = libfatfs.a
OBJS = src/option/ccsbcs.o \
src/option/syscall.o \
src/ff.o \
src/dc.o \
src/dc_bdev.o

KOS_CFLAGS += -W -Wextra -pedantic -Isrc -I../include

# Enable debug output if DEBUG=1
ifdef DEBUG
KOS_CFLAGS += -DFATFS_DEBUG=1
endif

# Enable DMA buffer unless DMA_BUF=0
ifndef DMA_BUF
DMA_BUF = 1
endif
ifeq ($(DMA_BUF), 1)
KOS_CFLAGS += -DFATFS_USE_DMA_BUF=1
endif

# Enable CRC checking for SD cards if SD_CHECK_CRC=1
ifdef SD_CHECK_CRC
KOS_CFLAGS += -DFATFS_SD_CHECK_CRC=1
endif

include $(KOS_BASE)/addons/Makefile.prefab
5 changes: 5 additions & 0 deletions fatfs/src/dc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,11 @@ int fs_fat_shutdown(void) {
if (!initted) {
return 0;
}

/* Clean up SD and IDE resources */
fs_fat_unmount_sd();
fs_fat_unmount_ide();

for (i = 0; i < MAX_FAT_MOUNTS; ++i) {

if (fat_mnt[i].dev != NULL) {
Expand Down
Loading