work on sd fat

master
Ondřej Hruška 10 years ago
parent 033273b9d1
commit f5bb468a6e
  1. 87
      devel/sdcard/Makefile
  2. 120
      devel/sdcard/main.c
  3. 9
      devel/sdcard/sdcard.pro
  4. 6
      devel/sdcard/sdcard.pro.user

@ -1,66 +1,99 @@
## === CPU settings === ###################################
# Makefile for MightyPork/avr-lib #
# Revision 3 #
###################################
## ===== CPU settings =====
# CPU type # CPU type
MCU = atmega328p MCU = atmega328p
# CPU frequency # CPU frequency
F_CPU = 16000000 F_CPU = 16000000
# Fuses # Fuses
LFUSE = 0xFF LFUSE = 0xFF
HFUSE = 0xDE HFUSE = 0xDE
EFUSE = 0x05 EFUSE = 0x05
OPTIMIZE = s
## ===== Source files =====
## === Source files ===
# Main C file # Main C file
MAIN = main.c MAIN = main.c
# Extra C files in this folder
LOCAL_SOURCE =
# Library directory (with C files)
EXTRA_SOURCE_DIR = lib/
# Library directory (with C and H files)
LIB_DIR = lib/
# C files in the library directory # C files in the library directory
EXTRA_SOURCE_FILES = uart.c iopins.c stream.c adc.c dht11.c sonar.c onewire.c spi.c sd.c fat16.c LIB_C_FILES = uart.c iopins.c stream.c adc.c dht11.c sonar.c onewire.c spi.c sd.c sd_blockdev.c fat16.c sd_fat.c
#Files that need config file:
# EXTRA_SOURCE_FILES += lcd.c # Extra Files that need config file:
# EXTRA_SOURCE_FILES += color.c wsrgb.c
# EXTRA_SOURCE_FILES += debouce.c
#LIB_C_FILES += lcd.c
#LIB_C_FILES += color.c wsrgb.c
#LIB_C_FILES += debouce.c
LIB_H_FILES = adc.h calc.h dht11.h fat16.h fat16_internal.h iopins.h nsdelay.h onewire.h
LIB_H_FILES += sd.h sd_blockdev.h sd_fat.h blockdev.h sonar.h spi.h stream.h uart.h
LIB_H_FILES += lcd.h color.h wsrgb.h debounce.h
## ===== Programmer =====
## === Programmer ===
PROGRAMMER_TYPE = arduino PROGRAMMER_TYPE = arduino
PROGRAMMER_ARGS = -b 57600 -P /dev/ttyUSB0 PROGRAMMER_ARGS = -b 57600 -P /dev/ttyUSB0
## === C flags === ## ===== C flags =====
CFLAGS = -std=gnu99 -mmcu=$(MCU) -DF_CPU=$(F_CPU)UL -I. -I$(LIB_DIR)
CFLAGS += -funsigned-char
CFLAGS += -funsigned-bitfields
CFLAGS += -fpack-struct
CFLAGS += -fshort-enums
CFLAGS += -finline-functions
CFLAGS += -ffunction-sections
CFLAGS += -fdata-sections
CFLAGS += -Wall
CFLAGS += -Wextra
CFLAGS += -Wno-main
CFLAGS += -Wno-comment
CFLAGS += -Wno-unused-but-set-variable
CFLAGS += -Wfatal-errors
CFLAGS += -Wl,--gc-sections
CFLAGS += -Wl,--relax
CFLAGS += -Wl,--relax
CFLAGS = -std=gnu99 -mmcu=$(MCU) -DF_CPU=$(F_CPU)UL -I. -I$(EXTRA_SOURCE_DIR) #CFLAGS += -lm ## Math
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums #CFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## Floating-point printf
CFLAGS += -Wall -Wno-main -Wno-strict-prototypes -Wno-comment #CFLAGS += -Wl,-u,vfprintf -lprintf_min ## Smaller printf
CFLAGS += -g2 -Wextra -Wfatal-errors -Wno-unused-but-set-variable
CFLAGS += -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,--relax CFLAGS_BUILD = $(CFLAGS) -O$(OPTIMIZE)
# CFLAGS += -lm ## Math
# CFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf
# CFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf
CFLAGS_BUILD = $(CFLAGS) -Os
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
## Defined programs / locations ## Defined programs / locations
CC = avr-gcc CC = avr-gcc
OBJCOPY = avr-objcopy OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump OBJDUMP = avr-objdump
AVRSIZE = avr-size AVRSIZE = avr-size
AVRDUDE = avrdude AVRDUDE = avrdude
UART_TERM = gtkterm -p /dev/ttyUSB0
## === File lists === ## === File lists ===
TARGET = $(strip $(basename $(MAIN))) TARGET = $(strip $(basename $(MAIN)))
SRC1 = $(TARGET).c SRC1 = $(TARGET).c
SRC = $(SRC1) SRC = $(SRC1)
EXTRA_SOURCE = $(addprefix $(EXTRA_SOURCE_DIR), $(EXTRA_SOURCE_FILES)) EXTRA_SOURCE = $(addprefix $(LIB_DIR), $(LIB_C_FILES))
LIB_H_FILES_FILES = $(addprefix $(LIB_DIR), $(LIB_H_FILES))
SRC += $(EXTRA_SOURCE) SRC += $(EXTRA_SOURCE)
SRC += $(LOCAL_SOURCE)
HEADERS = $(SRC:.c=.h) HEADERS = $(SRC:.c=.h)
OBJ = $(SRC:.c=.o) OBJ = $(SRC:.c=.o)
@ -73,7 +106,7 @@ pre: $(TARGET).pre
%.hex: %.elf %.hex: %.elf
$(OBJCOPY) -R .eeprom -O ihex $< $@ $(OBJCOPY) -R .eeprom -O ihex $< $@
%.elf: $(SRC) %.elf: $(SRC) $(LIB_H_FILES_FILES) Makefile
$(CC) $(CFLAGS_BUILD) $(SRC) --output $@ $(CC) $(CFLAGS_BUILD) $(SRC) --output $@
%.pre: $(SRC1) %.pre: $(SRC1)
@ -131,7 +164,7 @@ shell:
fser: all flash ser fser: all flash ser
ser: ser:
gtkterm -p /dev/ttyUSB0 $(UART_TERM)
# === fuses === # === fuses ===

@ -4,10 +4,11 @@
#include "lib/uart.h" #include "lib/uart.h"
#include "lib/stream.h" #include "lib/stream.h"
#include "lib/sd.h" #include "lib/sd.h"
#include "lib/sd_fat.h"
#include "lib/sd_blockdev.h"
void main() void test_lowlevel()
{ {
uart_init(9600);
uart_puts_P(PSTR("*** SD CARD SPI TEST ***\r\n")); uart_puts_P(PSTR("*** SD CARD SPI TEST ***\r\n"));
if (!sd_init()) if (!sd_init())
@ -16,11 +17,9 @@ void main()
while (1); while (1);
} }
uint8_t text[512]; uint8_t text[512];
put_str_P(uart, PSTR("\r\nReading...\r\n")); put_str_P(uart, PSTR("\r\nReading...\r\n"));
if (sd_read(0, 0, text, 0, 512)) if (sd_read(0, 0, text, 0, 512))
{ {
@ -56,9 +55,120 @@ void main()
} }
else else
{ {
put_str_P(uart, PSTR("Failed to read.")); put_str_P(uart, PSTR("Failed to read.\r\n"));
while (1); while (1);
} }
}
void try_reading_dirs(FAT16_FILE* f )
{
char buf[200];
do
{
if (!fat16_is_regular(f)) continue;
if (f->type == FT_SUBDIR)
{
vt_color_fg(VT_MAGENTA);
uart_puts_P(PSTR("\r\n--- DIRECTORY: "));
uart_puts(fat16_dispname(f, buf));
uart_puts_P(PSTR(" ---\r\n"));
vt_color_reset();
FSAVEPOS p = fat16_savepos(f);
if (fat16_opendir(f))
{
do
{
if (!fat16_is_regular(f)) continue;
vt_color_fg(VT_GREEN);
uart_puts_P(PSTR(">> --- File: "));
uart_puts(fat16_dispname(f, buf));
uart_puts_P(PSTR(" ---\r\n"));
vt_color_reset();
}
while (fat16_next(f));
}
fat16_reopen(f, &p);
}
else
{
vt_color_fg(VT_YELLOW);
uart_puts_P(PSTR("--- File: "));
uart_puts(fat16_dispname(f, buf));
uart_puts_P(PSTR(" ---\r\n"));
vt_color_reset();
uint16_t len = 0;
if ((len = fat16_read(f, buf, 199)))
{
buf[len] = 0;
uart_puts(buf);
put_nl(uart);
}
else
{
uart_puts_P(PSTR("COULD NOT READ.\n"));
}
}
}
while (fat16_next(f));
}
// Init a file pointer */
FAT16_FILE _f;
FAT16_FILE* f = &_f;
void main()
{
uart_init(9600);
vt_init();
vt_color_fg(VT_CYAN);
vt_attr(VT_BOLD, 1);
uart_puts_P(PSTR("\r\n*** FAT16 on SD card test ***\r\n"));
vt_color_reset();
vt_attr_reset();
if (!(sdfat_init()))
{
uart_puts_P(PSTR("Failed to init.\r\n"));
while (1);
}
uart_puts_P(PSTR("SD card with FAT16 inited.\r\n"));
// Read and print disk label
char lbl[16];
sdfat_disk_label(lbl);
put_str(uart, lbl);
put_nl(uart);
sdfat_root(f);
try_reading_dirs(f);
// if (fat16_find(f, "TESTFIL2.TXT"))
// {
// fat16_seek(f, f->size);
// fat16_write(f, "ONE MORE THING.\n", 16);
// sdfat_flush();
// uart_puts_P(PSTR("Write OK!\r\n"));
// }
// else
// {
// uart_puts_P(PSTR("Failed to open file.\r\n"));
// while (1);
// }
while (1); while (1);
} }

@ -22,7 +22,9 @@ SOURCES += main.c \
sd/spi.c \ sd/spi.c \
lib/fat16.c \ lib/fat16.c \
lib/sd.c \ lib/sd.c \
lib/spi.c lib/spi.c \
lib/sd_blockdev.c \
lib/sd_fat.c
include(deployment.pri) include(deployment.pri)
qtcAddDeployment() qtcAddDeployment()
@ -48,7 +50,10 @@ HEADERS += \
lib/fat16.h \ lib/fat16.h \
lib/fat16_internal.h \ lib/fat16_internal.h \
lib/spi.h \ lib/spi.h \
lib/sd.h lib/sd.h \
lib/blockdev.h \
lib/sd_blockdev.h \
lib/sd_fat.h
DISTFILES += \ DISTFILES += \
Makefile \ Makefile \

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.4.1, 2015-06-10T00:54:58. --> <!-- Written by QtCreator 3.4.1, 2015-06-10T11:27:22. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
@ -76,7 +76,7 @@
<value type="QString">-r</value> <value type="QString">-r</value>
</valuelist> </valuelist>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value> <value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">-B</value> <value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value> <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap> </valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value> <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
@ -178,7 +178,7 @@
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProcessStep.Arguments">flash -B</value> <value type="QString" key="ProjectExplorer.ProcessStep.Arguments">flash</value>
<value type="QString" key="ProjectExplorer.ProcessStep.Command">make</value> <value type="QString" key="ProjectExplorer.ProcessStep.Command">make</value>
<value type="QString" key="ProjectExplorer.ProcessStep.WorkingDirectory">%{buildDir}</value> <value type="QString" key="ProjectExplorer.ProcessStep.WorkingDirectory">%{buildDir}</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Custom Process Step</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Custom Process Step</value>

Loading…
Cancel
Save