Add [bootloader_zevero_sd_m1284p_make] bootloader prj

master
maxxir_w 7 years ago
parent e1ac761d22
commit 2a8a07c822

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="de.innot.avreclipse.toolchain.winavr.base.1143554398">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="de.innot.avreclipse.toolchain.winavr.base.1143554398" moduleId="org.eclipse.cdt.core.settings" name="Default">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.MakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildProperties="" description="" id="de.innot.avreclipse.toolchain.winavr.base.1143554398" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
<folderInfo id="de.innot.avreclipse.toolchain.winavr.base.1143554398.1169904047" name="/" resourcePath="">
<toolChain id="de.innot.avreclipse.toolchain.winavr.base.830163936" name="de.innot.avreclipse.toolchain.winavr.base" superClass="de.innot.avreclipse.toolchain.winavr.base">
<option id="de.innot.avreclipse.toolchain.options.toolchain.objcopy.flash.1597079461" name="Generate HEX file for Flash memory" superClass="de.innot.avreclipse.toolchain.options.toolchain.objcopy.flash"/>
<option id="de.innot.avreclipse.toolchain.options.toolchain.objcopy.eeprom.1605309061" name="Generate HEX file for EEPROM" superClass="de.innot.avreclipse.toolchain.options.toolchain.objcopy.eeprom"/>
<option id="de.innot.avreclipse.toolchain.options.toolchain.objdump.185980478" name="Generate Extended Listing (Source + generated Assembler)" superClass="de.innot.avreclipse.toolchain.options.toolchain.objdump"/>
<option id="de.innot.avreclipse.toolchain.options.toolchain.size.492808895" name="Print Size" superClass="de.innot.avreclipse.toolchain.options.toolchain.size"/>
<option id="de.innot.avreclipse.toolchain.options.toolchain.avrdude.1107948274" name="AVRDude" superClass="de.innot.avreclipse.toolchain.options.toolchain.avrdude"/>
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="de.innot.avreclipse.targetplatform.avr.1219728279" name="AVR Cross-Target" osList="all" superClass="de.innot.avreclipse.targetplatform.avr"/>
<builder id="de.innot.avreclipse.target.builder.winavr.base.1239458621" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="AVR GNU Make Builder" superClass="de.innot.avreclipse.target.builder.winavr.base"/>
<tool id="de.innot.avreclipse.tool.assembler.winavr.base.1052136627" name="AVR Assembler" superClass="de.innot.avreclipse.tool.assembler.winavr.base">
<inputType id="de.innot.avreclipse.tool.assembler.input.1283842618" superClass="de.innot.avreclipse.tool.assembler.input"/>
</tool>
<tool id="de.innot.avreclipse.tool.compiler.winavr.base.1733607236" name="AVR Compiler" superClass="de.innot.avreclipse.tool.compiler.winavr.base">
<inputType id="de.innot.avreclipse.compiler.winavr.input.2018460372" name="C Source Files" superClass="de.innot.avreclipse.compiler.winavr.input"/>
</tool>
<tool id="de.innot.avreclipse.tool.cppcompiler.base.994497101" name="AVR C++ Compiler" superClass="de.innot.avreclipse.tool.cppcompiler.base"/>
<tool id="de.innot.avreclipse.tool.linker.winavr.base.1606675340" name="AVR C Linker" superClass="de.innot.avreclipse.tool.linker.winavr.base"/>
<tool id="de.innot.avreclipse.tool.cpplinker.base.1727248957" name="AVR C++ Linker" superClass="de.innot.avreclipse.tool.cpplinker.base"/>
<tool id="de.innot.avreclipse.tool.archiver.winavr.base.530393396" name="AVR Archiver" superClass="de.innot.avreclipse.tool.archiver.winavr.base"/>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="00_m1284p_blink_make.null.242594707" name="00_m1284p_blink_make"/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="refreshScope"/>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets">
<buildTargets>
<target name="program" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>program</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
</buildTargets>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="de.innot.avreclipse.toolchain.winavr.base.1143554398;de.innot.avreclipse.toolchain.winavr.base.1143554398.1169904047;de.innot.avreclipse.tool.compiler.winavr.base.1733607236;de.innot.avreclipse.compiler.winavr.input.2018460372">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="de.innot.avreclipse.core.AVRGCCManagedMakePerProjectProfileC"/>
</scannerConfigBuildInfo>
</storageModule>
</cproject>

@ -0,0 +1,10 @@
*.o
*.eps
*.bak
*.a
*.bin
*.elf
*.hex
*.lst
*.map
/nbproject

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>bootloader_zevero_sd_m1284p_make</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
<nature>de.innot.avreclipse.core.avrnature</nature>
</natures>
</projectDescription>

@ -0,0 +1,24 @@
Copyright (c) 2015, zevero
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

@ -0,0 +1,70 @@
#------------------------------------------------------------------
# Makefile for stand-alone MMC boot strap loader
#------------------------------------------------------------------
# Change these defs for the target device
MCU_TARGET = atmega1284p # Target device to be used (32K or larger)
BOOT_ADR = 0x1F000 # Boot loader start address [byte] NOT [word] as in http://eleccelerator.com/fusecalc/fusecalc.php?chip=atmega1284p
F_CPU = 16000000 # CPU clock frequency [Hz] NOT critical: it just should be higher than the actual Hz
SD_CS_PORT = PORTB # Data Register of the SD CS pin
SD_CS_DDR = DDRB # Data Direction Register of the SD CS pin
SD_CS_BIT = 0 # Bit of the SD CS pin
USE_LED = 1 # Debug with two (defined in asmfunc.S)
USE_UART = 0 # Debug on Serial. 0 ... deactivate or divider of http://wormfood.net/avrbaudcalc.php for baud rate!
#------------------------------------------------------------------
ifeq ($(strip $(USE_UART)),0)
CSRC = main.c pff/src/pff.c diskio.c
else
CSRC = main.c pff/src/pff.c diskio.c uart/uart.c
endif
TARGET = avr_boot
ASRC = asmfunc.S
OPTIMIZE = -Os -mcall-prologues -ffunction-sections -fdata-sections
DEFS = -DBOOT_ADR=$(BOOT_ADR) -DF_CPU=$(F_CPU) -DUSE_LED=$(USE_LED) -DUSE_UART=$(USE_UART) -DSD_CS_PORT=$(SD_CS_PORT) -DSD_CS_DDR=$(SD_CS_DDR) -DSD_CS_BIT=$(SD_CS_BIT)
LIBS =
DEBUG = dwarf-2
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs $(DEFS)
ALL_ASFLAGS = -mmcu=$(MCU_TARGET) -I. -x assembler-with-cpp $(ASFLAGS)
CFLAGS = -g$(DEBUG) -Wall $(OPTIMIZE) $(ADDED_CFLAGS) -mmcu=$(MCU_TARGET) -std=c99 $(DEFS)
LDFLAGS = -Wl,-Map,$(TARGET).map -Wl,--gc-sections -Wl,--section-start,.text=$(BOOT_ADR)
OBJ = $(CSRC:.c=.o) $(ASRC:.S=.o)
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
all: clean $(TARGET).elf lst text bin size
$(TARGET).elf: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
clean:
rm -rf *.o $(TARGET).elf *.eps *.bak *.a *.bin
rm -rf pff/src/*.o uart/*.o
rm -rf *.lst *.map $(EXTRA_CLEAN_FILES)
rm -rf $(TARGET).hex
size: $(TARGET).elf
$(SIZE) -C --mcu=$(MCU_TARGET) $(TARGET).elf
lst: $(TARGET).lst
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
%.o : %.S
$(CC) -c $(ALL_ASFLAGS) $< -o $@
text: $(TARGET).hex
%.hex: %.elf
$(OBJCOPY) -j .text -j .data -j .fuse -O ihex $< $@
# --- make bin just to check size :)
bin: $(TARGET).bin
%.bin: %.hex
$(OBJCOPY) -I ihex -O binary $< $@
print-% : ; @echo $* = $($*) #test any var with make print-XXX

@ -0,0 +1,86 @@
avr_boot
========
SD card bootloader for atmega processors
As easy as it can get! I spent days with this. Hopefully you wont!
- for any ATMega with 4096kb Bootloader
- uses Petit FatFs R0.03 for FAT12, FAT16, FAT32
- looks for FIRMWARE.BIN and flashes it nearly instantly
- without any interference to your application
- no CRC Check and no version bytes in EEPROM (see KISS)
### Boards Manager installation
avr_boot is integrated in Arduino IDE version 1.6.4 or greater!!! [See here for instructions.](https://github.com/zevero/avr_boot/tree/gh-pages)
### Manual installation
This is with avr-gcc and avrdude under linux with an Atmega1284p and AVRISP mkII! Adaption to your case (WinAvr, another Atmega, another flash-tool) will not be complicated...
- adapt Makefile
- MCU_TARGET: Your atmegaXXX
- BOOT_ADR: in bytes not words!
- F_CPU: CPU Frequency (not critical. A higher value will work as well)
- SD_CS_PORT: Data Register of the SD CS pin(see the datasheet for your microcontroller)
- SD_CS_DDR: Data Direction Register of the SD CS pin
- SD_CS_BIT: Bit of the SD CS pin
- USE_LED: For debugging 0...deactivate or 1...active
- USE_UART: For debugging 0...deactivate or divider (UBRR) for baudate see http://wormfood.net/avrbaudcalc.php
- update spi_pins.h with the SPI pins of your microcontroller if not already defined
- if using USE_LED adapt LED-pins in asmfunc.S
- if you want to add FAT12 adapt pff/src/pffconfh.h (default ist FAT16 + FAT32)
- if you want to support lower case filenames adapt pff/src/pffconfh.h (default is uppercase)
- if you prefer another filename instead of FIRMWARE.BIN adapt main.c
- make (you may need to do "sudo apt-get install avr-libc gcc-avr")
- set fuses: avrdude -c avrispmkII -p m1284p -U hfuse:w:0xda:m
- find high fuse in http://eleccelerator.com/fusecalc/fusecalc.php?chip=atmega1284p
- flash: avrdude -c avrispmkII -p m1284p -Uflash:w:./avr_boot.hex:i -Ulock:w:0x3F:m
### Put your sketch on SD card
- in Arduino IDE go to File > Preferences and check "Show verbose output during compiliation"
- compile sketch and find the location of your /tmp/buildxxx/sketch.cpp.hex
- make bin file: avr-objcopy -I ihex -O binary sketch.cpp.hex FIRMWARE.BIN
- copy the file into the root of an SD (FAT16/FAT32)
- put it into the SD slot of your ATmega
- reset it
- it might already have happend!
### Bootloader sizes
Compiled under linux for atmega328p / atmega1284p
- 3674 / 3724 bytes
- 3984 / 4034 bytes debugging with USE_LED
- 3992 / 4052 bytes debugging with USE_UART
### Tested successfully on
- ATmega168
- ATmega328P
- ATmega32u4
- ATmega1284P
- ATmega2560 (see issue #2)
### Serial support - Help wanted
it should not be impossible to fit a normal serial bootloader (with automatic baudrate detection?) into the remaining bytes ... help is appreciated!
### KISS
If you wish you *can* add CRC Check or versioning with EEPROM *but* I prefere to keep things simple. avr_boot will reflash your FIRMWARE.BIN as long as it is present.
Is this a problem? No! It happens nearly instantly and only differing bytes are flashed really.
You may consider putting your logic into your application and perform a CRC Check after the fact to inform the user and delete or rename FIRMWARE.BIN
### Thanks to
- https://github.com/per1234 - Boards Manager Installation and help with differenct MCUs
- http://elm-chan.org/fsw/ff/00index_p.html
- Wilfried Klaas for the MCSDepthLogger https://github.com/willie68/OpenSeaMapLogger
- https://github.com/mharizanov/avr_boot
- https://github.com/osbock/avr_boot
- and others???
### Alternatives
- https://spaces.atmel.com/gf/project/sdbootloader/
- https://github.com/thseiler/embedded/tree/master/avr/2boots
- http://www.mikrocontroller.net/articles/MMC/SD_Bootloader_f%C3%BCr_AT_Mega
... call me stupid, but I passed several days debugging those - without success ...

@ -0,0 +1,271 @@
;---------------------------------------------------------------------------;
; MMC hardware controls and Flash controls (C)ChaN, 2010
;---------------------------------------------------------------------------;
; Hardware dependent macros to be modified //do this in Makefile
#include "spi_pins.h"
; ALL Pins given as Port (A,B,C,...) plus number
; LED Pins
;#define DDR_SS _SFR_IO_ADDR(DDRD), 5 // SS pin (PIN, PORT)
;#define PORT_SS _SFR_IO_ADDR(PORTD), 5
#define DDR_SS _SFR_IO_ADDR(DDRC), 3 // SS pin (PIN, PORT)
#define PORT_SS _SFR_IO_ADDR(PORTC), 3
;#define DDR_PW _SFR_IO_ADDR(DDRD), 6 // Power pin (PIN, PORT)
;#define PORT_PW _SFR_IO_ADDR(PORTD), 6
;SD CARD PINS
#define DDR_CS _SFR_IO_ADDR(SD_CS_DDR), SD_CS_BIT
#define PORT_CS _SFR_IO_ADDR(SD_CS_PORT), SD_CS_BIT
;---------------------------------------------------------------------------;
.nolist
#include <avr/io.h>
.list
.text
.global init_leds
.func init_leds
init_leds:
sbi DDR_SS
; sbi DDR_PW
ret
.endfunc
.global led_write_on
.func led_write_on
led_write_on:
sbi PORT_SS
ret
.endfunc
.global led_write_off
.func led_write_off
led_write_off:
cbi PORT_SS
ret
.endfunc
;.global led_power_on
;.func led_power_on
;led_power_on:
; sbi PORT_PW
; ret
;.endfunc
;.;global led_power_off
;.;func led_power_off
;led_power_off:
; cbi PORT_PW
; ret
;.endfunc
;.;global led_power_toggle
;.func led_power_toggle
;led_power_toggle:
; sbis PORT_PW
; jmp led_power_on
; jmp led_power_off
;.endfunc
.global led_write_toggle
.func led_write_toggle
led_write_toggle:
sbis PORT_SS
jmp led_write_on
jmp led_write_off
.endfunc
;---------------------------------------------------------------------------;
; Initialize MMC port
;
; void init_spi (void);
.global init_spi
.func init_spi
init_spi:
sbi DDR_CS ; CS: output
sbi DDR_DI ; DI: output
sbi DDR_CK ; SCLK: output
sbi PORT_DO ; DO: pull-up
ret
.endfunc
;---------------------------------------------------------------------------;
; Delay 100 microseconds
;
; void dly_us (UINT n);
.global dly_100us
.func dly_100us
dly_100us:
ldi r24, lo8(F_CPU / 100000) /* Loop counter */
1: sbiw r30, 1 /* 10 clocks per loop */
sbiw r30, 1
sbiw r30, 1
nop
dec r24
brne 1b
ret
.endfunc
;---------------------------------------------------------------------------;
; Select MMC
;
; void select (void);
.global select
.func select
select:
rcall deselect
cbi PORT_CS
rjmp rcv_spi
.endfunc
;---------------------------------------------------------------------------;
; Deselect MMC
;
; void deselect (void);
.global deselect
.func deselect
deselect:
sbi PORT_CS
; Goto next function
.endfunc
;---------------------------------------------------------------------------;
; Receive a byte
;
; BYTE rcv_spi (void);
.global rcv_spi
.func rcv_spi
rcv_spi:
ldi r24, 0xFF ; Send 0xFF to receive data
; Goto next function
.endfunc
;---------------------------------------------------------------------------;
; Transmit a byte
;
; void xmit_spi (BYTE);
.global xmit_spi
.func xmit_spi
xmit_spi:
ldi r25, 8
1: sbrc r24, 7 ; DI = Bit to sent
sbi PORT_DI ;
sbrs r24, 7 ;
cbi PORT_DI ; /
lsl r24 ; Get DO from MMC
sbic PIN_DO ;
inc r24 ; /
sbi PORT_CK ; A positive pulse to SCLK
cbi PORT_CK ; /
dec r25 ; Repeat 8 times
brne 1b ; /
ret
.endfunc
;---------------------------------------------------------------------------
; Erase a flash page
;
; void flash_erase (DWORD flash_addr);
#ifndef SPMCSR
#define SPMCSR SPMCR
#endif
.global flash_erase
.func flash_erase
flash_erase:
movw ZL, r22
#if FLASHEND >= 0x10000
out _SFR_IO_ADDR(RAMPZ), r24
#endif
; Initiate erase operation
ldi r24, 0b00000011
sts _SFR_MEM_ADDR(SPMCSR), r24
spm
; Wait for end of erase operation
1: lds r24, _SFR_MEM_ADDR(SPMCSR)
sbrc r24, 0
rjmp 1b
; Re-enable read access to the flash
ldi r24, 0b00010001
sts _SFR_MEM_ADDR(SPMCSR), r24
spm
9: ret
.endfunc
;---------------------------------------------------------------------------
; Write a flash page
;
; void flash_write (DWORD flash_addr, const BYTE* data);
.global flash_write
.func flash_write
flash_write:
push r0
push r1
#if FLASHEND >= 0x10000
out _SFR_IO_ADDR(RAMPZ), r24
#endif
; Fill page buffer
movw ZL, r22
movw XL, r20
ldi r25, lo8(SPM_PAGESIZE/2)
1: ld r0, X+
ld r1, X+
ldi r24, 0b00000001
sts _SFR_MEM_ADDR(SPMCSR), r24
spm
adiw ZL, 2
dec r25
brne 1b
; Initiate write operation
movw ZL, r22
ldi r24, 0b00000101
sts _SFR_MEM_ADDR(SPMCSR), r24
spm
; Wait for end of write operation
2: lds r24, _SFR_MEM_ADDR(SPMCSR)
sbrc r24, 0
rjmp 2b
; Re-enable read access to the flash
ldi r24, 0b00010001
sts _SFR_MEM_ADDR(SPMCSR), r24
spm
9: pop r1
pop r0
ret
.endfunc

@ -0,0 +1,226 @@
/*-----------------------------------------------------------------------*/
/* Low level disk I/O module skeleton for Petit FatFs (C)ChaN, 2014 */
/*-----------------------------------------------------------------------*/
#include "pff/src/pff.h"
#include "pff/src/diskio.h"
void init_spi (void); /* Initialize SPI port (asmfunc.S) */
void deselect (void); /* Select MMC (asmfunc.S) */
void select (void); /* Deselect MMC (asmfunc.S) */
void xmit_spi (BYTE d); /* Send a byte to the MMC (asmfunc.S) */
BYTE rcv_spi (void); /* Send a 0xFF to the MMC and get the received byte (asmfunc.S) */
void dly_100us (void); /* Delay 100 microseconds (asmfunc.S) */
/*--------------------------------------------------------------------------
Module Private Functions
---------------------------------------------------------------------------*/
/* Definitions for MMC/SDC command */
#define CMD0 (0x40+0) /* GO_IDLE_STATE */
#define CMD1 (0x40+1) /* SEND_OP_COND (MMC) */
#define ACMD41 (0xC0+41) /* SEND_OP_COND (SDC) */
#define CMD8 (0x40+8) /* SEND_IF_COND */
#define CMD16 (0x40+16) /* SET_BLOCKLEN */
#define CMD17 (0x40+17) /* READ_SINGLE_BLOCK */
#define CMD24 (0x40+24) /* WRITE_BLOCK */
#define CMD55 (0x40+55) /* APP_CMD */
#define CMD58 (0x40+58) /* READ_OCR */
/* Card type flags (CardType) */
#define CT_MMC 0x01 /* MMC ver 3 */
#define CT_SD1 0x02 /* SD ver 1 */
#define CT_SD2 0x04 /* SD ver 2 */
#define CT_BLOCK 0x08 /* Block addressing */
static
BYTE CardType;
/*-----------------------------------------------------------------------*/
/* Send a command packet to MMC */
/*-----------------------------------------------------------------------*/
static
BYTE send_cmd (
BYTE cmd, /* 1st byte (Start + Index) */
DWORD arg /* Argument (32 bits) */
)
{
BYTE n, res;
if (cmd & 0x80) { /* ACMD<n> is the command sequense of CMD55-CMD<n> */
cmd &= 0x7F;
res = send_cmd(CMD55, 0);
if (res > 1) return res;
}
/* Select the card */
select();
/* Send a command packet */
xmit_spi(cmd); /* Start + Command index */
xmit_spi((BYTE)(arg >> 24)); /* Argument[31..24] */
xmit_spi((BYTE)(arg >> 16)); /* Argument[23..16] */
xmit_spi((BYTE)(arg >> 8)); /* Argument[15..8] */
xmit_spi((BYTE)arg); /* Argument[7..0] */
n = 0x01; /* Dummy CRC + Stop */
if (cmd == CMD0) n = 0x95; /* Valid CRC for CMD0(0) */
if (cmd == CMD8) n = 0x87; /* Valid CRC for CMD8(0x1AA) */
xmit_spi(n);
/* Receive a command response */
n = 10; /* Wait for a valid response in timeout of 10 attempts */
do {
res = rcv_spi();
} while ((res & 0x80) && --n);
return res; /* Return with the response value */
}
/*--------------------------------------------------------------------------
Public Functions
---------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/
/* Initialize Disk Drive */
/*-----------------------------------------------------------------------*/
DSTATUS disk_initialize (void)
{
DSTATUS stat;
BYTE n, cmd, ty, ocr[4];
UINT tmr;
init_spi(); /* Initialize ports to control MMC */
for (n = 100; n; n--) dly_100us(); /* 10ms delay */
for (n = 10; n; n--) deselect(); /* 80 Dummy clocks with CS=H */
ty = 0;
if (send_cmd(CMD0, 0) == 1) { /* Enter Idle state */
if (send_cmd(CMD8, 0x1AA) == 1) { /* SDv2 */
for (n = 0; n < 4; n++) ocr[n] = rcv_spi(); /* Get trailing return value of R7 resp */
if (ocr[2] == 0x01 && ocr[3] == 0xAA) { /* The card can work at vdd range of 2.7-3.6V */
for (tmr = 10000; tmr && send_cmd(ACMD41, 1UL << 30); tmr--) dly_100us(); /* Wait for leaving idle state (ACMD41 with HCS bit) */
if (tmr && send_cmd(CMD58, 0) == 0) { /* Check CCS bit in the OCR */
for (n = 0; n < 4; n++) ocr[n] = rcv_spi();
ty = (ocr[0] & 0x40) ? CT_SD2 | CT_BLOCK : CT_SD2; /* SDv2 (HC or SC) */
}
}
} else { /* SDv1 or MMCv3 */
if (send_cmd(ACMD41, 0) <= 1) {
ty = CT_SD1; cmd = ACMD41; /* SDv1 */
} else {
ty = CT_MMC; cmd = CMD1; /* MMCv3 */
}
for (tmr = 10000; tmr && send_cmd(cmd, 0); tmr--) dly_100us(); /* Wait for leaving idle state */
if (!tmr || send_cmd(CMD16, 512) != 0) /* Set R/W block length to 512 */
ty = 0;
}
}
CardType = ty;
deselect();
stat = ty ? 0 : STA_NOINIT;
return stat;
}
/*-----------------------------------------------------------------------*/
/* Read Partial Sector */
/*-----------------------------------------------------------------------*/
DRESULT disk_readp (
BYTE* buff, /* Pointer to the destination object */
DWORD sector, /* Sector number (LBA) */
UINT offset, /* Offset in the sector */
UINT count /* Byte count (bit15:destination) */
)
{
DRESULT res;
BYTE rc;
WORD bc;
if (!(CardType & CT_BLOCK)) sector *= 512; /* Convert to byte address if needed */
res = RES_ERROR;
if (send_cmd(CMD17, sector) == 0) { /* READ_SINGLE_BLOCK */
bc = 40000;
do { /* Wait for data packet */
rc = rcv_spi();
} while (rc == 0xFF && --bc);
if (rc == 0xFE) { /* A data packet arrived */
bc = 514 - offset - count;
/* Skip leading bytes */
if (offset) {
do rcv_spi(); while (--offset);
}
/* Receive a part of the sector */
do {
*buff++ = rcv_spi();
} while (--count);
/* Skip trailing bytes and CRC */
do rcv_spi(); while (--bc);
res = RES_OK;
}
}
deselect();
return res;
}
/*-----------------------------------------------------------------------*/
/* Write Partial Sector */
/*-----------------------------------------------------------------------*/
/*
DRESULT disk_writep (
const BYTE* buff, // Pointer to the data to be written, NULL:Initiate/Finalize write operation
DWORD sc // Sector number (LBA) or Number of bytes to send
)
{
DRESULT res;
if (!buff) {
if (sc) {
// Initiate write process
} else {
// Finalize write process
}
} else {
// Send data to the disk
}
return res;
}
*/

@ -0,0 +1,29 @@
3) Working FUSE for M1284 (with bootloader Zevero-SD)
I.e - Arduino Bootloader to Flash from SD Card: https://github.com/zevero/avr_boot
PS. SET FUSES:
==============
LOW = 0xFF
HIGH = 0xDA
EXTD = 0xFD
========================================
It means:
Ext. XTAL High FREQ START-UP 16K CK + 65ms
JTAG DISABLED
BROWN-OUT 2.7V ON
BOOT-LOADER ENABLED
BOOT Flash Section Size = 2048 words; Boot Start address = 0xF800
=========================================
AVRDUDE arguments:
-U lfuse:w:0xff:m -U hfuse:w:0xda:m -U efuse:w:0xfd:m
Full commands to write from console:
avrdude -Pusb -cavrispmkii -patmega1284p -B5 -U lfuse:w:0xff:m -U hfuse:w:0xda:m -U efuse:w:0xfd:m
Detection avrdude CPU: B5 (5us bit clock period for programmer SPI) - VERY IMPORTANT (1Mhz CPU M1284p FREQ DEFAULT)
avrdude -Pusb -cavrispmkii -patmega1284p -B5
Check m1284p fuse here:
http://eleccelerator.com/fusecalc/fusecalc.php?chip=atmega1284p

@ -0,0 +1,259 @@
/*-------------------------------------------------------------------------/
/ Stand-alone MMC boot loader R0.01
/--------------------------------------------------------------------------/
/
/ Copyright (C) 2010, ChaN, all right reserved.
/
/ * This software is a free software and there is NO WARRANTY.
/ * No restriction on use. You can use, modify and redistribute it for
/ personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY.
/ * Redistributions of source code must retain the above copyright notice.
/
/--------------------------------------------------------------------------/
/ Dec 6, 2010 R0.01 First release
/--------------------------------------------------------------------------/
/ This is a stand-alone MMC/SD boot loader for megaAVRs. It requires a 4KB
/ boot section for code, four GPIO pins for MMC/SD as shown in sch.jpg and
/ nothing else. To port the boot loader into your project, follow the
/ instruction described below.
/
/ 1. Setup the hardware. Attach a memory card socket to the any GPIO port
/ where you like. Select boot size at least 4KB for the boot loader with
/ BOOTSZ fuses and enable boot loader with BOOTRST fuse.
/
/ 2. Setup the software. Change the four port definitions in the asmfunc.S.
/ Change MCU_TARGET, BOOT_ADR and MCU_FREQ in the Makefile. The BOOT_ADR
/ is a BYTE address of boot section in the flash. Build the boot loader
/ and write it to the device with a programmer.
/
/ 3. Build the application program and output it in binary form instead of
/ hex format. Rename the file "app.bin" and put it into the memory card.
/
/ 4. Insert the card and turn the target power on. When the boot loader found
/ the application file, the file is written into the flash memory prior to
/ start the application program. On-board LED lights (if exist) during
/ the flash programming operation.
/
/-------------------------------------------------------------------------*/
const char filename[13] ="FIRMWARE.BIN\0"; // EDIT FILENAME HERE
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/eeprom.h>
#include <util/delay.h>
#include <string.h>
#include "pff/src/pff.h"
#include <avr/wdt.h> //Watchdog
// The following code is recommended in http://avr-libc.nongnu.org/user-manual/group__avr__watchdog.html but is disabled for now because avr_boot doesn't currently do anything with mcusr_mirror so for now we will only reset MCUSR and disable WDT.
//uint8_t mcusr_mirror __attribute__ ((section (".noinit")));void get_mcusr(void) __attribute__((naked)) __attribute__((section(".init3")));void get_mcusr(void){mcusr_mirror = MCUSR;MCUSR = 0;wdt_disable();}
void disable_watchdog(void) __attribute__((naked)) __attribute__((section(".init3")));
void disable_watchdog(void)
{
#if defined(MCUCSR)
MCUCSR = ~(_BV(WDRF)); //Some MCUs require the watchdog reset flag to be cleared before WDT can be disabled. & operation is skipped to spare few bytes as bits in MCUSR can only be cleared.
#else
MCUSR = ~(_BV(WDRF)); //Some MCUs require the watchdog reset flag to be cleared before WDT can be disabled. & operation is skipped to spare few bytes as bits in MCUSR can only be cleared.
#endif
wdt_disable(); //immediately disable watchdog in case it was running in the application to avoid perpetual reset loop
}
#if BOOT_ADR > 0xFFFF
#define PGM_READ_BYTE(x) pgm_read_byte_far(x)
#else
#define PGM_READ_BYTE(x) pgm_read_byte(x)
#endif
#if USE_UART
#include "uart/uart.h"
#endif
#if USE_LED
void init_leds();
void led_power_on();
void led_power_off();
void led_power_toggle();
void led_write_on();
void led_write_off();
void led_write_toggle();
#endif
void flash_erase (DWORD); /* Erase a flash page (asmfunc.S) */
void flash_write (DWORD, const BYTE*); /* Program a flash page (asmfunc.S) */
FATFS Fatfs; // Petit-FatFs work area
BYTE Buff[SPM_PAGESIZE]; // Page data buffer
static uint8_t pagecmp(const DWORD fa, uint8_t buff[SPM_PAGESIZE])
{
UINT i;
uint8_t b_flash,b_buff;
for (i = 0; i < SPM_PAGESIZE; i++) {
b_flash = PGM_READ_BYTE(fa+i);
b_buff = buff[i];
if ( b_flash != b_buff) {
#if USE_UART //output first difference
UART_puthex32(fa);UART_puts(PSTR(":"));
UART_puthex(b_flash);UART_puts(PSTR(" "));
UART_puthex(b_buff); UART_newline();
#endif
return 1;
}
}
#if USE_UART //output first difference
UART_puthex32(fa);UART_puts(PSTR(":"));
UART_puts(PSTR("="));UART_newline();
#endif
return 0;
}
void doFlash() {
DWORD fa; /* Flash address */
UINT br; /* Bytes read */
#if USE_LED
uint8_t i;
for(i=0;i<50;i++) { led_write_toggle();_delay_ms(100);} //Start Programming: Flash WRITE Wildly for 5 secs
#endif
for (fa = 0; fa < BOOT_ADR; fa += SPM_PAGESIZE) { /* Update all application pages */
memset(Buff, 0xFF, SPM_PAGESIZE); /* Clear buffer */
pf_read(Buff, SPM_PAGESIZE, &br); /* Load a page data */
if (pagecmp(fa, Buff)) { /* Only flash if page is changed */
#if USE_LED
led_write_off();
//led_power_on();
#endif
flash_erase(fa); /* Erase a page */
flash_write(fa, Buff); /* Write it if the data is available */
} else {
#if USE_LED
//led_power_off();
led_write_on();
#endif
}
}
}
void checkFile() {
uint8_t fresult;
fresult = pf_mount(&Fatfs); /* Initialize file system */
if (fresult != FR_OK) { /* File System could not be mounted */
#if USE_UART
UART_puts(PSTR("File not mounted"));
UART_newline();
#endif
#if USE_LED
//uint8_t i;
//led_write_on();
//for(i=0;i<2*fresult;i++) { led_power_toggle();_delay_ms(500);}//Give error number while Write led is on
//led_write_off();
#endif
return;
}
/*
WORD flashver = eeprom_read_word((const uint16_t *)E2END - 1);
if (flashver > 999) {
flashver = 0;
}
BYTE y, tmp;
WORD x;
BYTE found = 0;
for (x = flashver+10; x > flashver; x--) {
y = x / 100;
filename[5] = y + 0x30;
tmp = x % 100;
y = tmp / 10;
filename[6] = y + 0x30;
tmp = x % 10;
filename[7] = tmp + 0x30;
if (pf_open(filename) == FR_OK) { // File opens normally
found = 1;
doProgram();
}
led_power_toggle();
}
if (found == 0) {*/
fresult = pf_open(filename);
if (fresult != FR_OK) { /* File could not be opened */
#if USE_UART
UART_puts(PSTR("File not open"));
UART_newline();
#endif
#if USE_LED
//uint8_t i;
//led_power_on();
//for(i=0;i<2*fresult;i++) { led_write_toggle();_delay_ms(500);}//Give error number while Power led is on
//led_power_off();
#endif
return;
}
doFlash();
#if USE_LED
led_write_off();
//led_power_off();
_delay_ms(2000);
uint8_t i;
//for(i=0;i<40;i++) { led_power_toggle();_delay_ms(50);}//SUCCESS FLASH WILDLY for 2 secs
for(i=0;i<40;i++) { led_write_toggle();_delay_ms(50);}//SUCCESS FLASH WILDLY for 2 secs
#endif
}
int main (void)
{
#if USE_LED
init_leds();
uint8_t i=0;
#endif
#if USE_UART
UART_init();
UART_puts(PSTR("AVR_BOOT"));
UART_newline();
#endif
while (1) {
#if USE_LED
//led_power_on();_delay_ms(200);led_power_off(); //Test Power Led
led_write_on();_delay_ms(200);led_write_off(); //Test Write Led
#endif
checkFile();
if (pgm_read_word(0) != 0xFFFF) ((void(*)(void))0)(); //EXIT BOOTLOADER
#if USE_UART
UART_puts(PSTR("retry"));
UART_newline();
#endif
#if USE_LED
//for(i=0;i<10;i++) { led_power_toggle();_delay_ms(200);} //SOMETHING WENT WRONG: Flash Power LED
for(i=0;i<10;i++) { led_write_toggle();_delay_ms(200);} //SOMETHING WENT WRONG: Flash Write LED
#endif
_delay_ms(5000); // Retry
}
}

@ -0,0 +1,77 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="cache-control" content="no-cache">
<meta name="description" content="A tiny FAT file system for embedded projects">
<link rel="start" title="Site Top" href="../../">
<link rel="up" title="Freewares" href="../../fsw_e.html">
<link rel="stylesheet" href="css_e.css" type="text/css" media="screen" title="ELM Default">
<link rel="stylesheet" href="css_p.css" type="text/css" media="screen" title="ELM Default">
<title>Petit FAT File System Module</title>
</head>
<body>
<h1>Petit FAT File System Module</h1>
<hr>
<div class="abst">
<img src="img/layers3.png" class="rset" width="245" height="255" alt="layer">
<p>Petit FatFs is a sub-set of FatFs module for tiny 8-bit microcontrollers. It is written in compliance with ANSI C and completely separated from the disk I/O layer. It can be incorporated into the tiny microcontrollers with limited memory even if the RAM size is less than sector size. Also full featured FAT file system module is available <a href="http://elm-chan.org/fsw/ff/00index_e.html">here</a>↗.</p>
<h4>Features</h4>
<ul>
<li>Very small RAM consumption (44 bytes work area + certain stack).</li>
<li>Very small code size (2K-4K bytes).</li>
<li>FAT12, FAT16 and FAT32.</li>
<li>Single volume and Single file.</li>
<li>File write function with some restrictions.</li>
</ul>
</div>
<div class="para">
<h3>Application Interface</h3>
<p>Petit FatFs module provides following functions.</p>
<ul>
<li><a href="pf/mount.html">pf_mount</a> - Mount a Volume</li>
<li><a href="pf/open.html">pf_open</a> - Open a File</li>
<li><a href="pf/read.html">pf_read</a> - Read File</li>
<li><a href="pf/write.html">pf_write</a> - Write File</li>
<li><a href="pf/lseek.html">pf_lseek</a> - Move read/write Pointer</li>
<li><a href="pf/opendir.html">pf_opendir</a> - Open a Directory</li>
<li><a href="pf/readdir.html">pf_readdir</a> - Read a Directory Item</li>
</ul>
</div>
<div class="para">
<h3>Disk I/O Interface</h3>
<p>Since the Petit FatFs module is completely separated from disk I/O layer, it requires following functions to lower layer to read data from storage device. The low level disk I/O module is not a part of Petit FatFs module and it must be provided by user. The sample drivers are also available in the resources.</p>
<ul>
<li><a href="pf/dinit.html">disk_initialize</a> - Initialize storage device</li>
<li><a href="pf/dreadp.html">disk_readp</a> - Read a partial sector</li>
<li><a href="pf/dwritep.html">disk_writep</a> - Divided write to a sector</li>
</ul>
</div>
<div class="para">
<h3>Resources</h3>
<p>The Petit FatFs module is a free software and is opened for education, research and development. You can use, modify and/or redistribute it for personal, non-profit or commercial use without any restriction under your responsibility. For further information, refer to the application note.</p>
<ul>
<li><a href="http://elm-chan.org/fsw/ff/bd/"><em>FatFs User Forum</em></a></li>
<li>Read first: <a href="pf/appnote.html">Petit FatFs module application note</a> <span class="mfd">June 10, 2014</span></li>
<li>Latest Information: <a href="http://elm-chan.org/fsw/ff/00index_p.html">http://elm-chan.org/fsw/ff/00index_p.html</a></li>
<li><a href="http://www.microsoft.com/whdc/system/platform/firmware/fatgen.mspx">FAT32 Specification by Microsoft</a>↗ (The reference document on FAT file system)</li>
<li><a href="http://elm-chan.org/docs/mmc/mmc_e.html">How to Use MMC/SDC</a></li>
<li><a href="img/rwtest3.png">Benchmark 3</a> (ATtiny85/8MHz with MMC via USI)</li>
</ul>
</div>
<hr>
<p class="foot"><a href="../../fsw_e.html">Return</a></p>
</body>
</html>

@ -0,0 +1,65 @@
* {margin: 0; padding: 0; border-width: 0;}
body {margin: 8px; background-color: #e0ffff; font-color: black; font-family: serif; line-height: 133%; max-width: 1024px;}
a:link {color: blue;}
a:visited {color: darkmagenta;}
a:hover {background-color: #a0ffff;}
a:active {color: darkmagenta; overflow: hidden; outline:none; position: relative; top: 1px; left: 1px;}
abbr {border-width: 1px;}
p {margin: 0 0 0.3em 1em;}
i {margin: 0 0.3em 0 0;}
b {margin: 0 0.1em;}
em {font-style: normal; font-weight: bold; margin: 0 0.1em;}
strong {}
pre {border: 1px dashed gray; margin: 0.5em 1em; padding: 0.5em; line-height: 1.2em; font-size: 85%; font-family: "Consolas", "Courier New", monospace; background-color: white;}
pre span.c {color: green;}
pre span.k {color: blue;}
pre span.arg {font-style: italic;}
tt {margin: 0 0.2em; font-size: 0.85em; font-family: "Consolas", "Courier New", monospace; }
tt.arg {font-style: italic;}
ol {margin: 0.5em 2.5em;}
ul {margin: 0.5em 2em;}
dl {margin: 0.5em 1em;}
dd {margin: 0 2em;}
dt {font-size: 0.85em; font-family: "Consolas", "Courier New", monospace;}
dl.par dt {margin: 0.5em 0 0 0 ; font-style: italic; }
dl.ret dt {margin: 0.5em 0 0 0 ; font-size: 0.85em; font-family: "Consolas", "Courier New", monospace;}
hr {border-width: 1px; margin: 1em;}
div.abst {font-family: sans-serif;}
div.para {clear: both; font-family: serif;}
div.ret a {font-size: 0.85em; font-family: "Consolas", "Courier New", monospace; }
.equ {text-indent: 0; margin: 1em 2em 1em;}
.indent {margin-left: 2em;}
.rset {float: right; margin: 0.3em 0 0.5em 0.5em;}
.lset {float: left; margin: 0.3em 0.5em 0.5em 0.5em;}
ul.flat li {list-style-type: none; margin: 0;}
a.imglnk img {border: 1px solid;}
.iequ {white-space: nowrap; font-weight: bold;}
.clr {clear: both;}
.it {font-style: italic;}
.mfd {font-size: 0.7em; padding: 0 1px; border: 1px solid; white-space : nowrap}
.ral {text-align: right; }
.lal {text-align: left; }
.cal {text-align: center; }
h1 {line-height: 1em; font-size: 2em; font-family: sans-serif; padding: 0.3em 0 0.3em;}
p.hdd {float: right; text-align: right; margin-top: 0.5em;}
hr.hds {clear: both; margin-bottom: 1em;}
h2 {font-size: 2em; font-family: sans-serif; background-color: #d8d8FF; padding: 0.5em 0.5em; margin: 0 0 0.5em;}
h3 {font-size: 1.5em; font-family: sans-serif; margin: 1.5em 0 0.5em;}
h4 {font-size: 1.2em; font-family: sans-serif; margin: 1em 0 0.2em;}
h5 {font-size: 1em; font-family: sans-serif; margin: 0.5em 0 0em;}
small {font-size: 80%;}
.indent {margin-left: 2em;}
/* Tables */
table {margin: 0.5em 1em; border-collapse: collapse; border: 2px solid black; }
th {background-color: white; border-style: solid; border-width: 1px 1px 2px; border-color: black; padding: 0 3px; vertical-align: top; white-space: nowrap;}
td {background-color: white; border: 1px solid black; padding: 0 3px; vertical-align: top; line-height: 1.3em;}
table.lst td:first-child {font-size: 0.85em; font-family: "Consolas", "Courier New", monospace;}
table.lst2 td {font-size: 0.85em; font-family: "Consolas", "Courier New", monospace;}
table caption {font-family: sans-serif; font-weight: bold;}
tr.lst3 td { border-width: 2px 1px 1px; }
p.foot {clear: both; text-indent: 0; margin: 1em 0.5em 1em;}

@ -0,0 +1 @@
body {margin: 8px; background-color: #ffecf0; font-color: black; font-family: serif; line-height: 133%; max-width: 1024px;}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

@ -0,0 +1,91 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="Petit FatFs" href="../00index_p.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<link rel="stylesheet" href="../css_p.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs Module Application Note</title>
</head>
<body>
<h1>Petit FatFs Module Application Note</h1>
<hr>
<h3>Basic Considerations</h3>
<p>The FatFs module is assuming following conditions on portability.</p>
<ul>
<li>ANSI C<br>
The FatFs module is a middleware written in ANSI C (C89). There is no platform dependence, so long as the compiler is in compliance with ANSI C.</li>
<li>Size of integer types<br>
The FatFs module assumes that size of char/short/long are 8/16/32 bit and int is 16 or 32 bit. These correspondence are defined in <tt>integer.h</tt>. This will not be a problem on most compilers. When any conflict with existing definitions is occured, you must resolve it with care.</li>
</ul>
</div>
<div class="para">
<h3>Memory Usage (R0.03)</h3>
<table class="lst2">
<tr><th></th><th>AVR</th><th>x86</th></tr>
<tr><td>Compiler</td><td>gcc(WinAVR)</td><td>VC6</td></tr>
<tr><td>_WORD_ACCESS</td><td>1</td><td>1</td></tr>
<tr class="lst3"><td>Code (default)</td><td>2100</td><td>1720</td></tr>
<tr><td>Code (!_USE_READ)</td><td>-444</td><td>-246</td></tr>
<tr><td>Code (_USE_DIR)</td><td>+1002</td><td>+420</td></tr>
<tr><td>Code (_USE_LSEEK)</td><td>+490</td><td>+228</td></tr>
<tr><td>Code (_USE_WRITE)</td><td>+518</td><td>+351</td></tr>
<tr><td>RAM (bss)</td><td>2</td><td>4</td></tr>
<tr><td>RAM (work)</td><td>42</td><td>44</td></tr>
</table>
<p>This is the size of the Petit FatFs module itself. In addition to this, a low level disk I/O module will be required for a complete function. The size of MMC/SDC module on AVR becomes approximate 620 bytes without write function and 840 bytes with write function.</p>
</div>
<div class="para">
<h3>Module Size Reduction</h3>
<p>Follwing table shows which function is removed by configuration options for the module size reduction.</p>
<table class="lst2">
<tr><td rowspan="2">Function</td><td>_USE_READ</td><td>_USE_DIR</td><td>_USE_LSEEK</td><td>_USE_WRITE</td></tr>
<tr><td>0</td><td>0</td><td>0</td><td>0</td></tr>
<tr class="lst3"><td>pf_mount</td><td></td><td></td><td></td><td></td></tr>
<tr><td>pf_open</td><td></td><td></td><td></td><td></td></tr>
<tr><td>pf_read</td><td>x</td><td></td><td></td><td></td></tr>
<tr><td>pf_lseek</td><td></td><td></td><td>x</td><td></td></tr>
<tr><td>pf_opendir</td><td></td><td>x</td><td></td><td></td></tr>
<tr><td>pf_readdir</td><td></td><td>x</td><td></td><td></td></tr>
<tr><td>pf_write</td><td></td><td></td><td></td><td>x</td></tr>
</table>
</div>
<div class="para">
<h3>Performance effective file access</h3>
<p>For good performance on reading a file on the small embedded system, application programmer should consider what process is done in the file system module.</p>
<p>The Petit FatFs reads the disk sectors without a sector buffer. This means the file system reads a part of the sector contains the required data every reference point even if they are in the same sector. However the generic storage device are not byte addressable so that the disk I/O layer will read the entire sector and pick up the data bytes from the read data steram.</p>
<p>When read 512 byte data from a file at a time, the data sector will be read only a time. When read that data in byte-by-byte, the data sector will be read 512 times. Therefore the byte-by-byte read request will <a href="../img/rwtest3.png">drastically decrease</a> the read performance. To avoid this stupid read controls, the file data should be read in long block as possible. Sector alignment access is not impotant on the Petit FatFs.</p>
<p>The tiny microcontrollers targeted by Petit FatFs has a limited size of RAM. It may not able to allocate a certain size of read buffer and most type of text processing will require byte-by-byte read operation. The Petit FatFs supports data forwarding feature for such purpose.</p>
</div>
<div class="para">
<h3>About FatFs License</h3>
<p>Petit FatFs has being developped as a personal project of author, ChaN. It is free from the code anyone else wrote. Following code block shows a copy of the license document that included in the source files.</p>
<pre>/*----------------------------------------------------------------------------/
/ Petit FatFs - FAT file system module R0.03 (C)ChaN, 2014
/-----------------------------------------------------------------------------/
/ Petit FatFs module is a generic FAT file system module for small embedded
/ systems. This is a free software that opened for education, research and
/ commercial developments under license policy of following trems.
/
/ Copyright (C) 2014, ChaN, all right reserved.
/
/ * The Petit FatFs module is a free software and there is NO WARRANTY.
/ * No restriction on use. You can use, modify and redistribute it for
/ personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY.
/ * Redistributions of source code must retain the above copyright notice.
/
/-----------------------------------------------------------------------------/</pre>
<p>Therefore FatFs license is one of the BSD-style licenses but there is a significant feature. Because FatFs is for embedded projects, the conditions of redistributions in binary form, such as embedded code, hex file, binary library and any form without source code, are not specified in order to extend usability to commercial use. The documentation of the distributions need not include about Petit FatFs and its license document, and it may also. This is equivalent to the BSD 1-Clause License. Of course Petit FatFs is compatible with the projects under GNU GPL. When redistribute the Petit FatFs with any modification, the license can also be changed to GNU GPL or BSD-style license.</p>
</div>
<p class="foot"><a href="../00index_p.html">Return</a></p>
</body>
</html>

@ -0,0 +1,40 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="Petit FatFs" href="../00index_p.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<link rel="stylesheet" href="../css_p.css" type="text/css" media="screen" title="ELM Default">
<title>Petit FatFs - disk_initialize</title>
</head>
<body>
<div class="para">
<h2>disk_initialize</h2>
<p>The disk_initialize function initializes the disk drive.</p>
<pre>
DSTATUS disk_initialize (void)
</pre>
</div>
<div class="para">
<h4>Return Values</h4>
<p>The disk status is returned in combination of following flags.</p>
<dl class="ret">
<dt>STA_NOINIT</dt>
<dd>Indicates that the disk drive has not been initialized. This flag is set on: system reset, disk removal and disk_initialize function failed, and cleared on: disk_initialize function succeeded.</dd>
<dt>STA_NODISK</dt>
<dd>Indicates that no medium in the drive. This is always cleared on fixed disk drive. This flag is not referred by Petit FatFs.</dd>
</dl>
</div>
<div class="para">
<h4>Description</h4>
<p>The disk_initialize function initializes the storage device. If the function succeeded, <tt>STA_NOINIT</tt> flag in the return value is cleared.</p>
</div>
<p class="foot"><a href="../00index_p.html">Return</a></p>
</body>
</html>

@ -0,0 +1,59 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="Petit FatFs" href="../00index_p.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<link rel="stylesheet" href="../css_p.css" type="text/css" media="screen" title="ELM Default">
<title>Petit FatFs - disk_readp</title>
</head>
<body>
<div class="para">
<h2>disk_readp</h2>
<p>The disk_readp function reads a partial sector of the device.</p>
<pre>
DRESULT disk_readp (
BYTE* <span class="arg">buff</span>, <span class="c">/* [OUT] Pointer to the read buffer */</span>
DWORD <span class="arg">sector</span>, <span class="c">/* [IN] Sector number */</span>
UINT <span class="arg">offset</span>, <span class="c">/* [IN] Byte offset in the sector to start to read */</span>
UINT <span class="arg">count</span> <span class="c">/* [IN] Number of bytes to read */</span>
);
</pre>
</div>
<div class="para">
<h4>Parameters</h4>
<dl class="par">
<dt>buff</dt>
<dd>Pointer to the read buffer to store the read data. If a NULL is given, read bytes will be forwarded to the outgoing stream instead of the memory.</dd>
<dt>sector</dt>
<dd>Specifies the sector number to be read in logical block address (LBA).</dd>
<dt>offset</dt>
<dd>Specifies the byte offset in the sector to start to read. The value can be 0 to 511.</dd>
<dt>count</dt>
<dd>Specifies number of bytes to read. The value can be 0 to 512 and <tt class="arg">offset</tt> + <tt class="arg">count</tt> must not exceed 512.</dd>
</dl>
</div>
<div class="para">
<h4>Return Value</h4>
<dl class="ret">
<dt>RES_OK (0)</dt>
<dd>The function succeeded.</dd>
<dt>RES_ERROR</dt>
<dd>Any hard error occured during the disk read operation and could not recover it.</dd>
<dt>RES_PARERR</dt>
<dd>Invalid parameter.</dd>
<dt>RES_NOTRDY</dt>
<dd>The device has not been initialized.</dd>
</dl>
</div>
<p class="foot"><a href="../00index_p.html">Return</a></p>
</body>
</html>

@ -0,0 +1,73 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="Petit FatFs" href="../00index_p.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<link rel="stylesheet" href="../css_p.css" type="text/css" media="screen" title="ELM Default">
<title>Petit FatFs - disk_writep</title>
</head>
<body>
<div class="para">
<h2>disk_writep</h2>
<p>The disk_writep function writes data to the sector.</p>
<pre>
DRESULT disk_writep (
BYTE* <span class="arg">buff</span>, <span class="c">/* [IN] Pointer to the data to be written */</span>
DWORD <span class="arg">sc</span>, <span class="c">/* [IN] Sector number or Number of bytes to wtite */</span>
);
</pre>
</div>
<div class="para">
<h4>Parameters</h4>
<dl class="par">
<dt>buff</dt>
<dd>Pointer to the data to be written to the sector. If a NULL is given, the function initiate/finalize a write transaction to the sector.</dd>
<dt>sc</dt>
<dd>Specifies nubmer of bytes to write if <tt class="arg">buff</tt> is not a NULL. If <tt class="arg">buff</tt> is a NULL and <tt class="arg">sc</tt> is not a zero, the function initiates a write transactin to the sector. If <tt class="arg">buff</tt> and <tt class="arg">sc</tt> are zero, the function finalize the current sector write transactin.</dd>
</dl>
</div>
<div class="para">
<h4>Return Value</h4>
<dl class="ret">
<dt>RES_OK (0)</dt>
<dd>The function succeeded.</dd>
<dt>RES_ERROR</dt>
<dd>Any hard error occured during the write operation and could not recover it or the medium is write protected.</dd>
<dt>RES_PARERR</dt>
<dd>Invalid parameter.</dd>
<dt>RES_NOTRDY</dt>
<dd>The device has not been initialized.</dd>
</dl>
</div>
<div class="para">
<h4>Description</h4>
<p>A sector write operation is done in following sequence.</p>
<ol>
<li><tt>disk_writep(0, sector_number);</tt> Initiate a sector write transaction.</li>
<li><tt>disk_writep(data, byte_to_write);</tt> Start to write data to the sector.</li>
<li><tt>disk_writep(data, byte_to_write);</tt> And data can be written upto 512 bytes with one or more calls.</li>
<li><tt>disk_writep(data, byte_to_write);</tt> ...</li>
<li><tt>disk_writep(0, 0);</tt> Finalize the write transaction. If number of bytes sent is less than 512, left bytes in the sector is filled by zero.</li>
</ol>
<p>If a write transaction is in progress, <tt>disk_readp()</tt> function will fail and <tt>disk_initialize()</tt> function finalize the current write transaction.</p>
</div>
<div class="para">
<h4>Remarks</h4>
<p>This funciton is needed when <tt>_USE_WRITE == 1</tt>.</p>
</div>
<p class="foot"><a href="../00index_p.html">Return</a></p>
</body>
</html>

@ -0,0 +1,22 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="Petit FatFs" href="../00index_p.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<link rel="stylesheet" href="../css_p.css" type="text/css" media="screen" title="ELM Default">
<title>Petit FatFs - Path Names</title>
</head>
<body>
<div class="para">
<h2>Format of the path names</h2>
<p>The path name format on the Petit FatFs module is similer to MS-DOS as follows.</p>
<pre>"[/]<em>directory</em>/<em>file</em>"</pre>
<p>The Petit FatFs module supports only 8.3 format file name. The sub-directories are separated with a /. The path name is terminated with a nul character, control character or white space. Heading spaces are ignored and skipped. When <tt>_USE_LCC == 1</tt>, lower case characters are allowed for the path name.</p>
<p>The Petit FatFs module does not have a concept of current directory like OS oriented file system. All objects on the volume are always specified in full path name following from the root directory. Heading separator is ignored and it can be exist or omitted.</p>
</div>
</body>
</html>

@ -0,0 +1,79 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="Petit FatFs" href="../00index_p.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<link rel="stylesheet" href="../css_p.css" type="text/css" media="screen" title="ELM Default">
<title>Petit FatFs - pf_lseek</title>
</head>
<body>
<div class="para">
<h2>pf_lseek</h2>
<p>The pf_lseek function moves the file read/write pointer of the open file.</p>
<pre>
FRESULT pf_lseek (
DWORD <span class="arg">ofs</span> <span class="c">/* [IN] File offset in unit of byte */</span>
);
</pre>
</div>
<div class="para">
<h4>Parameters</h4>
<dl class="par">
<dt>ofs</dt>
<dd>Number of bytes where from start of the file</dd>
</dl>
</div>
<div class="para">
<h4>Return Values</h4>
<dl class="ret">
<dt>FR_OK (0)</dt>
<dd>The function succeeded.</dd>
<dt>FR_DISK_ERR</dt>
<dd>The function failed due to an error in the disk function, a wrong FAT structure or an internal error.</dd>
<dt>FR_NOT_OPENED</dt>
<dd>The file has not been opened.</dd>
</dl>
</div>
<div class="para">
<h4>Description</h4>
<p>The <tt>pf_lseek()</tt> function moves the file read/write pointer of the open file. The <tt class="arg">offset</tt> can be specified in only origin from top of the file.</p>
</div>
<div class="para">
<h4>Example</h4>
<pre>
<span class="c">/* Move to offset of 5000 from top of the file */</span>
res = pf_lseek(5000);
<span class="c">/* Forward 3000 bytes */</span>
res = pf_lseek(fs.fptr + 3000);
<span class="c">/* Rewind 2000 bytes (take care on wraparound) */</span>
res = pf_lseek(fs.fptr - 2000);
</pre>
</div>
<div class="para">
<h4>QuickInfo</h4>
<p>Available when <tt>_USE_LSEEK == 1</tt>.</p>
</div>
<div class="para">
<h4>References</h4>
<p><tt><a href="open.html">pf_open</a>, <a href="sfatfs.html">FATFS</a></tt></p>
</div>
<p class="foot"><a href="../00index_p.html">Return</a></p>
</body>
</html>

@ -0,0 +1,65 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="Petit FatFs" href="../00index_p.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<link rel="stylesheet" href="../css_p.css" type="text/css" media="screen" title="ELM Default">
<title>Petit FatFs - pf_mount</title>
</head>
<body>
<div class="para">
<h2>pf_mount</h2>
<p>The pf_mount fucntion mounts a volume.</p>
<pre>
FRESULT pf_mount (
FATFS* <span class="arg">fs</span> <span class="c">/* [IN] Pointer to the work area */</span>
);
</pre>
</div>
<div class="para">
<h4>Parameters</h4>
<dl class="par">
<dt>fs</dt>
<dd>Pointer to the work area (file system object) to be registered.</dd>
</dl>
</div>
<div class="para">
<h4>Return Values</h4>
<dl class="ret">
<dt>FR_OK (0)</dt>
<dd>The function succeeded.</dd>
<dt>FR_NOT_READY</dt>
<dd>The drive could not be initialized due to a disk error or no medium.</dd>
<dt>FR_DISK_ERR</dt>
<dd>An error occured in the disk function.</dd>
<dt>FR_NO_FILESYSTEM</dt>
<dd>There is no valid FAT partition on the disk.</dd>
</dl>
</div>
<div class="para">
<h4>Description</h4>
<p>The <tt>pf_mount()</tt> function registers a work area to the Petit FatFs module. The volume is mounted on registration. The volume must be mounted with this function prior to any other file function and after every media changes.</p>
</div>
<div class="para">
<h4>QuickInfo</h4>
<p>Always available.</p>
</div>
<div class="para">
<h4>References</h4>
<p><tt><a href="sfatfs.html">FATFS</a></tt></p>
</div>
<p class="foot"><a href="../00index_p.html">Return</a></p>
</body>
</html>

@ -0,0 +1,103 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="Petit FatFs" href="../00index_p.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<link rel="stylesheet" href="../css_p.css" type="text/css" media="screen" title="ELM Default">
<title>Petit FatFs - pf_open</title>
</head>
<body>
<div class="para">
<h2>pf_open</h2>
<p>The pf_open function opens an existing file.</p>
<pre>
FRESULT pf_open (
const char* <span class="arg">path</span> <span class="c">/* [IN] Pointer to the file neme */</span>
);
</pre>
</div>
<div class="para">
<h4>Parameters</h4>
<dl class="par">
<dt>path</dt>
<dd>Pointer to a null-terminated string that specifies the <a href="filename.html">file name</a> to open.</dd>
</dl>
</div>
<div class="para">
<h4>Return Values</h4>
<dl class="ret">
<dt>FR_OK (0)</dt>
<dd>The function succeeded.</dd>
<dt>FR_NO_FILE</dt>
<dd>Could not find the file or path.</dd>
<dt>FR_DISK_ERR</dt>
<dd>The function failed due to a hard error in the disk function, a wrong FAT structure or an internal error.</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>The volume has not been mounted.</dd>
</dl>
</div>
<div class="para">
<h4>Description</h4>
<p>The file must be opend prior to use <tt>pf_read()</tt> and <tt>pf_lseek()</tt> function. The open file is valid until next open.</p>
</div>
<div class="para">
<h4>Example</h4>
<pre>
int main (void)
{
FATFS fs; <span class="c">/* Work area (file system object) for the volume */</span>
BYTE buff[16]; <span class="c">/* File read buffer */</span>
UINT br; <span class="c">/* File read count */</span>
FRESULT res; <span class="c">/* Petit FatFs function common result code */</span>
<span class="c">/* Mount the volume */</span>
pf_mount(&amp;fs);
if (res) die(res);
<span class="c">/* Open a file */</span>
res = pf_open("srcfile.dat");
if (res) die(res);
<span class="c">/* Read data to the memory */</span>
res = pf_read(buff, 16, &amp;br); <span class="c">/* Read data to the buff[] */</span>
if (res) die(res); <span class="c">/* Check error */</span>
if (br != 16) die(255); <span class="c">/* Check EOF */</span>
....
<span class="c">/* Forward data to the outgoing stream */</span>
do
res = pf_read(0, 512, &amp;br); <span class="c">/* Send data to the stream */</span>
while (res || br != 512); <span class="c">/* Break on error or eof */</span>
....
}
</pre>
</div>
<div class="para">
<h4>QuickInfo</h4>
<p>Always available.</p>
</div>
<div class="para">
<h4>References</h4>
<p><tt><a href="read.html">pf_read</a>, <a href="sfatfs.html">FATFS</a></tt></p>
</div>
<p class="foot"><a href="../00index_p.html">Return</a></p>
</body>
</html>

@ -0,0 +1,72 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="Petit FatFs" href="../00index_p.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<link rel="stylesheet" href="../css_p.css" type="text/css" media="screen" title="ELM Default">
<title>Petit FatFs - pf_opendir</title>
</head>
<body>
<div class="para">
<h2>pf_opendir</h2>
<p>The pf_opendir function opens a directory.</p>
<pre>
FRESULT pf_opendir (
DIR* <span class="arg">dp</span>, <span class="c">/* [OUT] Pointer to the blank directory object structure */</span>
const char* <span class="arg">path</span> <span class="c">/* [IN] Pointer to the directory name */</span>
);
</pre>
</div>
<div class="para">
<h4>Parameters</h4>
<dl class="par">
<dt>dp</dt>
<dd>Pointer to the blank directory object to be created.</dd>
<dt>path</dt>
<dd>Pinter to the null-terminated string that specifies the <a href="filename.html">directory name</a> to be opened.</dd>
</dl>
</div>
<div class="para">
<h4>Return Values</h4>
<dl class="ret">
<dt>FR_OK (0)</dt>
<dd>The function succeeded and the directory object is created. It is used for subsequent calls to read the directory entries.</dd>
<dt>FR_NO_FILE</dt>
<dd>Could not find the path.</dd>
<dt>FR_NOT_READY</dt>
<dd>The disk drive cannot work due to no medium in the drive or any other reason.</dd>
<dt>FR_DISK_ERR</dt>
<dd>The function failed due to a hard error in the disk function, a wrong FAT structure or an internal error.</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>The volume has no work area.</dd>
</dl>
</div>
<div class="para">
<h4>Description</h4>
<p>The <tt>pf_opendir()</tt> function opens an exsisting directory and creates the directory object for subsequent calls. The directory object structure can be discarded at any time without any procedure.</p>
</div>
<div class="para">
<h4>QuickInfo</h4>
<p>Available when <tt>_USE_DIR == 1</tt>.</p>
</div>
<div class="para">
<h4>References</h4>
<p><tt><a href="readdir.html">f_readdir</a>, <a href="sdir.html">DIR</a></tt></p>
</div>
<p class="foot"><a href="../00index_p.html">Return</a></p>
</body>
</html>

@ -0,0 +1,73 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="Petit FatFs" href="../00index_p.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<link rel="stylesheet" href="../css_p.css" type="text/css" media="screen" title="ELM Default">
<title>Petit FatFs - pf_read</title>
</head>
<body>
<div class="para">
<h2>pf_read</h2>
<p>The pf_read function reads data from the file.</p>
<pre>
FRESULT pf_read (
void* <span class="arg">buff</span>, <span class="c">/* [OUT] Pointer to the read buffer */</span>
UINT <span class="arg">btr</span>, <span class="c">/* [IN] Number of bytes to read */</span>
UINT* <span class="arg">br</span> <span class="c">/* [OUT] Number of bytes read */</span>
);
</pre>
</div>
<div class="para">
<h4>Parameters</h4>
<dl class="par">
<dt>buff</dt>
<dd>Pointer to the buffer to store the read data. A NULL specifies the destination is an outgoing stream.</dd>
<dt>btr</dt>
<dd>Number of bytes to read.</dd>
<dt>br</dt>
<dd>Pointer to the variable to return number of bytes read.</dd>
</dl>
</div>
<div class="para">
<h4>Return Values</h4>
<dl class="ret">
<dt>FR_OK (0)</dt>
<dd>The function succeeded.</dd>
<dt>FR_DISK_ERR</dt>
<dd>The function failed due to a hard error in the disk function, a wrong FAT structure or an internal error.</dd>
<dt>FR_NOT_OPENED</dt>
<dd>The file has not been opened.</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>The volume has not been mounted.</dd>
</dl>
</div>
<div class="para">
<h4>Description</h4>
<p>The file read/write pointer in the file system object advances in number of bytes read. After the function succeeded, <tt>*br</tt> should be checked to detect end of file. In case of <tt>*br &lt; btr</tt>, it means the read pointer reached end of file during read operation.</p>
<p>If a NULL is given to the <tt class="arg">buff</tt>, the read bytes will be forwarded to the outgoing stream instead of the memory. The streaming function will be typically built-in the <tt>disk_readp()</tt> function.</p>
</div>
<div class="para">
<h4>QuickInfo</h4>
<p>Available when <tt>_USE_READ == 1</tt>.</p>
</div>
<div class="para">
<h4>References</h4>
<p><tt><a href="open.html">pf_open</a>, <a href="write.html">pf_write</a>, <a href="sfatfs.html">FATFS</a></tt></p>
</div>
<p class="foot"><a href="../00index_p.html">Return</a></p>
</body>
</html>

@ -0,0 +1,100 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="Petit FatFs" href="../00index_p.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<link rel="stylesheet" href="../css_p.css" type="text/css" media="screen" title="ELM Default">
<title>Petit FatFs - pf_readdir</title>
</head>
<body>
<div class="para">
<h2>pf_readdir</h2>
<p>The pf_readdir function reads directory entries.</p>
<pre>
FRESULT pf_readdir (
DIR* <span class="arg">dp</span>, <span class="c">/* [IN] Pointer to the open directory object */</span>
FILINFO* <span class="arg">fno</span> <span class="c">/* [OUT] Pointer to the file information structure */</span>
);
</pre>
</div>
<div class="para">
<h4>Parameters</h4>
<dl class="par">
<dt>dp</dt>
<dd>Pointer to the open directory object.</dd>
<dt>fno</dt>
<dd>Pointer to the file information structure to store the read item.</dd>
</dl>
</div>
<div class="para">
<h4>Return Values</h4>
<dl class="ret">
<dt>FR_OK (0)</dt>
<dd>The function succeeded.</dd>
<dt>FR_DISK_ERR</dt>
<dd>The function failed due to an error in the disk function, a wrong FAT structure or an internal error.</dd>
<dt>FR_NOT_OPENED</dt>
<dd>The directory object has not been opened.</dd>
</dl>
</div>
<div class="para">
<h4>Description</h4>
<p>The <tt>pf_readdir()</tt> function reads directory entries in sequence. All items in the directory can be read by calling this function repeatedly. When all directory entries have been read and no item to read, the function returns a null string into member <tt>f_name[]</tt> in the file information structure without error. When a null pointer is given to the <tt class="arg">fno</tt>, the read index of the directory object will be rewinded.</p>
</div>
<div class="para">
<h4>Sample Code</h4>
<pre>
FRESULT scan_files (char* path)
{
FRESULT res;
FILINFO fno;
DIR dir;
int i;
res = pf_opendir(&amp;dir, path);
if (res == FR_OK) {
i = strlen(path);
for (;;) {
res = pf_readdir(&amp;dir, &amp;fno);
if (res != FR_OK || fno.fname[0] == 0) break;
if (fno.fattrib &amp; AM_DIR) {
sprintf(&amp;path[i], "/%s", fno.fname);
res = scan_files(path);
if (res != FR_OK) break;
path[i] = 0;
} else {
printf("%s/%s\n", path, fno.fname);
}
}
}
return res;
}
</pre>
</div>
<div class="para">
<h4>QuickInfo</h4>
<p>Available when <tt>_USE_DIR == 1</tt>.</p>
</div>
<div class="para">
<h4>References</h4>
<p><tt><a href="opendir.html">pf_opendir</a>, <a href="sfileinfo.html">FILINFO</a>, <a href="sdir.html">DIR</a></tt></p>
</div>
<p class="foot"><a href="../00index_p.html">Return</a></p>
</body>
</html>

@ -0,0 +1,30 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="Petit FatFs" href="../00index_p.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<link rel="stylesheet" href="../css_p.css" type="text/css" media="screen" title="ELM Default">
<title>Petit FatFs - DIR</title>
</head>
<body>
<div class="para">
<h2>DIR</h2>
<p>The <tt>DIR</tt> structure is used for the work area to read a directory by pf_oepndir, pf_readdir function.</p>
<pre>
typedef struct {
WORD index; <span class="c">/* Current read/write index number */</span>
BYTE* fn; <span class="c">/* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */</span>
CLUST sclust; <span class="c">/* Table start cluster (0:Static table) */</span>
CLUST clust; <span class="c">/* Current cluster */</span>
DWORD sect; <span class="c">/* Current sector */</span>
} DIR;
</pre>
</div>
<p class="foot"><a href="../00index_p.html">Return</a></p>
</body>
</html>

@ -0,0 +1,39 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="Petit FatFs" href="../00index_p.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<link rel="stylesheet" href="../css_p.css" type="text/css" media="screen" title="ELM Default">
<title>Petit FatFs - FATFS</title>
</head>
<body>
<div class="para">
<h2>FATFS</h2>
<p>The <tt>FATFS</tt> structure holds dynamic work area of the logical drive and a file. It is given by application program and registerd/unregisterd to the Petit FatFs module with pf_mount function. There is no member that can be changed by application programs.</p>
<pre>
typedef struct {
BYTE fs_type; <span class="c">/* FAT sub type */</span>
BYTE csize; <span class="c">/* Number of sectors per cluster */</span>
BYTE flag; <span class="c">/* File status flags */</span>
BYTE pad1;
WORD n_rootdir; <span class="c">/* Number of root directory entries (0 on FAT32) */</span>
CLUST n_fatent; <span class="c">/* Number of FAT entries (= number of clusters + 2) */</span>
DWORD fatbase; <span class="c">/* FAT start sector */</span>
DWORD dirbase; <span class="c">/* Root directory start sector (Cluster# on FAT32) */</span>
DWORD database; <span class="c">/* Data start sector */</span>
DWORD fptr; <span class="c">/* File read/write pointer */</span>
DWORD fsize; <span class="c">/* File size */</span>
CLUST org_clust; <span class="c">/* File start cluster */</span>
CLUST curr_clust; <span class="c">/* File current cluster */</span>
DWORD dsect; <span class="c">/* File current data sector */</span>
} FATFS;
</pre>
</div>
<p class="foot"><a href="../00index_p.html">Return</a></p>
</body>
</html>

@ -0,0 +1,62 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="Petit FatFs" href="../00index_p.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<link rel="stylesheet" href="../css_p.css" type="text/css" media="screen" title="ELM Default">
<title>Petit FatFs - FILINFO</title>
</head>
<body>
<div class="para">
<h2>FILINFO</h2>
<p>The <tt>FILINFO</tt> structure holds a file information returned by pf_readdir function.</p>
<pre>
typedef struct {
DWORD fsize; <span class="c">/* File size */</span>
WORD fdate; <span class="c">/* Last modified date */</span>
WORD ftime; <span class="c">/* Last modified time */</span>
BYTE fattrib; <span class="c">/* Attribute */</span>
char fname[13]; <span class="c">/* File name */</span>
} FILINFO;
</pre>
</div>
<h4>Members</h4>
<dl>
<dt>fsize</dt>
<dd>Indicates size of the file in unit of byte. This is always zero when it is a directory.</dd>
<dt>fdate</dt>
<dd>Indicates the date that the file was modified or the directory was created.<br>
<dl>
<dt>bit15:9</dt>
<dd>Year origin from 1980 (0..127)</dd>
<dt>bit8:5</dt>
<dd>Month (1..12)</dd>
<dt>bit4:0</dt>
<dd>Day (1..31)</dd>
</dl>
</dd>
<dt>ftime</dt>
<dd>Indicates the time that the file was modified or the directory was created.<br>
<dl>
<dt>bit15:11</dt>
<dd>Hour (0..23)</dd>
<dt>bit10:5</dt>
<dd>Minute (0..59)</dd>
<dt>bit4:0</dt>
<dd>Second / 2 (0..29)</dd>
</dl>
</dd>
<dt>fattrib</dt>
<dd>Indicates the file/directory attribute in combination of <tt>AM_DIR</tt>, <tt>AM_RDO</tt>, <tt>AM_HID</tt>, <tt>AM_SYS</tt> and <tt>AM_ARC</tt>.</dd>
<dt>fname[]</dt>
<dd>Indicates the file/directory name in 8.3 format null-terminated string.</dd>
</dl>
<p class="foot"><a href="../00index_p.html">Return</a></p>
</body>
</html>

@ -0,0 +1,86 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="Petit FatFs" href="../00index_p.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<link rel="stylesheet" href="../css_p.css" type="text/css" media="screen" title="ELM Default">
<title>Petit FatFs - pf_write</title>
</head>
<body>
<div class="para">
<h2>pf_write</h2>
<p>The pf_write function writes data to the file.</p>
<pre>
FRESULT pf_write (
const void* <span class="arg">buff</span>, <span class="c">/* [IN] Pointer to the data to be written */</span>
UINT <span class="arg">btw</span>, <span class="c">/* [IN] Number of bytes to write */</span>
UINT* <span class="arg">bw</span> <span class="c">/* [OUT] Pointer to the variable to return number of bytes written */</span>
);
</pre>
</div>
<div class="para">
<h4>Parameters</h4>
<dl class="par">
<dt>buff</dt>
<dd>Pointer to the data to be wtitten. A NULL specifies to finalize the current write operation.</dd>
<dt>btw</dt>
<dd>Number of bytes to write.</dd>
<dt>bw</dt>
<dd>Pointer to the variable to return number of bytes read.</dd>
</dl>
</div>
<div class="para">
<h4>Return Values</h4>
<dl class="ret">
<dt>FR_OK (0)</dt>
<dd>The function succeeded.</dd>
<dt>FR_DISK_ERR</dt>
<dd>The function failed due to a hard error in the disk function, write protected, a wrong FAT structure or an internal error.</dd>
<dt>FR_NOT_OPENED</dt>
<dd>The file has not been opened.</dd>
<dt>FR_NOT_ENABLED</dt>
<dd>The volume has not been mounted.</dd>
</dl>
</div>
<div class="para">
<h4>Description</h4>
<p>The write function has some restrictions listed below:</p>
<ul>
<li>Cannot create file. Only existing file can be written.</li>
<li>Cannot expand file size.</li>
<li>Cannot update time stamp of the file.</li>
<li>Write operation can start/stop on the sector boundary.</li>
<li>Read-only attribute of the file cannot block write operation.</li>
</ul>
<p>File write operation must be done in following sequence.</p>
<ol>
<li><tt>pf_lseek(ofs);</tt> read/write pointer must be moved to sector bundary prior to initiate write operation or it will be rounded-down to the sector boundary.</li>
<li><tt>pf_write(buff, btw, &amp;bw);</tt> Initiate write operation. Write first data to the file.</li>
<li><tt>pf_write(buff, btw, &amp;bw);</tt> Write next data. Any other file function cannot be used while a write operation is in progress.</li>
<li><tt>pf_write(0, 0, &amp;bw);</tt> Finalize the write operation. If read/write pointer is not on the sector boundary, left bytes in the sector will be filled with zero.</li>
</ol>
<p>The read/write pointer in the file system object advances in number of bytes written. After the function succeeded, <tt>*bw</tt> should be checked to detect end of file. In case of <tt>*bw &lt; btw</tt>, it means the read/write pointer reached end of file during the write operation. Once a write operation is initiated, it must be finalized or the written data can be lost.</p>
</div>
<div class="para">
<h4>QuickInfo</h4>
<p>Available when <tt>_USE_WRITE == 1</tt>.</p>
</div>
<div class="para">
<h4>References</h4>
<p><tt><a href="open.html">pf_open</a>, <a href="sfatfs.html">FATFS</a></tt></p>
</div>
<p class="foot"><a href="../00index_p.html">Return</a></p>
</body>
</html>

@ -0,0 +1,46 @@
Petit FatFs Module Source Files R0.03 (C)ChaN, 2014
FILES
pff.h Common include file for Petit FatFs and application module.
pff.c Petit FatFs module.
diskio.h Common include file for Petit FatFs and disk I/O module.
diskio.c Skeleton of low level disk I/O module.
integer.h Alternative type definitions for integer variables.
Low level disk I/O module is not included in this archive because the Petit
FatFs module is only a generic file system layer and not depend on any
specific storage device. You have to provide a low level disk I/O module that
written to control your storage device.
AGREEMENTS
Petit FatFs module is an open source software to implement FAT file system to
small embedded systems. This is a free software and is opened for education,
research and commercial developments under license policy of following trems.
Copyright (C) 2014, ChaN, all right reserved.
* The Petit FatFs module is a free software and there is NO WARRANTY.
* No restriction on use. You can use, modify and redistribute it for
personal, non-profit or commercial use UNDER YOUR RESPONSIBILITY.
* Redistributions of source code must retain the above copyright notice.
REVISION HISTORY
Jun 15, 2009 R0.01a First release (Branched from FatFs R0.07b)
Dec 14, 2009 R0.02 Added multiple code page support.
Added write funciton.
Changed stream read mode interface.
Dec 07,'2010 R0.02a Added some configuration options.
Fixed fails to open objects with DBCS character.
Jun 10, 2014 R0.03 Separated out configuration options to pffconf.h.
Added _USE_LCC option.
Added _FS_FAT16 option.

@ -0,0 +1,73 @@
/*-----------------------------------------------------------------------*/
/* Low level disk I/O module skeleton for Petit FatFs (C)ChaN, 2014 */
/*-----------------------------------------------------------------------*/
#include "diskio.h"
/*-----------------------------------------------------------------------*/
/* Initialize Disk Drive */
/*-----------------------------------------------------------------------*/
DSTATUS disk_initialize (void)
{
DSTATUS stat;
// Put your code here
return stat;
}
/*-----------------------------------------------------------------------*/
/* Read Partial Sector */
/*-----------------------------------------------------------------------*/
DRESULT disk_readp (
BYTE* buff, /* Pointer to the destination object */
DWORD sector, /* Sector number (LBA) */
UINT offset, /* Offset in the sector */
UINT count /* Byte count (bit15:destination) */
)
{
DRESULT res;
// Put your code here
return res;
}
/*-----------------------------------------------------------------------*/
/* Write Partial Sector */
/*-----------------------------------------------------------------------*/
DRESULT disk_writep (
BYTE* buff, /* Pointer to the data to be written, NULL:Initiate/Finalize write operation */
DWORD sc /* Sector number (LBA) or Number of bytes to send */
)
{
DRESULT res;
if (!buff) {
if (sc) {
// Initiate write process
} else {
// Finalize write process
}
} else {
// Send data to the disk
}
return res;
}

@ -0,0 +1,42 @@
/*-----------------------------------------------------------------------
/ PFF - Low level disk interface modlue include file (C)ChaN, 2014
/-----------------------------------------------------------------------*/
#ifndef _DISKIO_DEFINED
#define _DISKIO_DEFINED
#ifdef __cplusplus
extern "C" {
#endif
#include "integer.h"
/* Status of Disk Functions */
typedef BYTE DSTATUS;
/* Results of Disk Functions */
typedef enum {
RES_OK = 0, /* 0: Function succeeded */
RES_ERROR, /* 1: Disk error */
RES_NOTRDY, /* 2: Not ready */
RES_PARERR /* 3: Invalid parameter */
} DRESULT;
/*---------------------------------------*/
/* Prototypes for disk control functions */
DSTATUS disk_initialize (void);
DRESULT disk_readp (BYTE* buff, DWORD sector, UINT offser, UINT count);
DRESULT disk_writep (const BYTE* buff, DWORD sc);
#define STA_NOINIT 0x01 /* Drive not initialized */
#define STA_NODISK 0x02 /* No medium in the drive */
#ifdef __cplusplus
}
#endif
#endif /* _DISKIO_DEFINED */

@ -0,0 +1,33 @@
/*-------------------------------------------*/
/* Integer type definitions for FatFs module */
/*-------------------------------------------*/
#ifndef _FF_INTEGER
#define _FF_INTEGER
#ifdef _WIN32 /* FatFs development platform */
#include <windows.h>
#include <tchar.h>
#else /* Embedded platform */
/* This type MUST be 8 bit */
typedef unsigned char BYTE;
/* These types MUST be 16 bit */
typedef short SHORT;
typedef unsigned short WORD;
typedef unsigned short WCHAR;
/* These types MUST be 16 bit or 32 bit */
typedef int INT;
typedef unsigned int UINT;
/* These types MUST be 32 bit */
typedef long LONG;
typedef unsigned long DWORD;
#endif
#endif

File diff suppressed because it is too large Load Diff

@ -0,0 +1,159 @@
/*---------------------------------------------------------------------------/
/ Petit FatFs - FAT file system module include file R0.03 (C)ChaN, 2014
/----------------------------------------------------------------------------/
/ Petit FatFs module is an open source software to implement FAT file system to
/ small embedded systems. This is a free software and is opened for education,
/ research and commercial developments under license policy of following trems.
/
/ Copyright (C) 2014, ChaN, all right reserved.
/
/ * The Petit FatFs module is a free software and there is NO WARRANTY.
/ * No restriction on use. You can use, modify and redistribute it for
/ personal, non-profit or commercial use UNDER YOUR RESPONSIBILITY.
/ * Redistributions of source code must retain the above copyright notice.
/
/----------------------------------------------------------------------------*/
#ifndef _PFATFS
#define _PFATFS 4004 /* Revision ID */
#ifdef __cplusplus
extern "C" {
#endif
#include "integer.h"
#include "pffconf.h"
#if _PFATFS != _PFFCONF
#error Wrong configuration file (pffconf.h).
#endif
#if _FS_FAT32
#define CLUST DWORD
#else
#define CLUST WORD
#endif
/* File system object structure */
typedef struct {
BYTE fs_type; /* FAT sub type */
BYTE flag; /* File status flags */
BYTE csize; /* Number of sectors per cluster */
BYTE pad1;
WORD n_rootdir; /* Number of root directory entries (0 on FAT32) */
CLUST n_fatent; /* Number of FAT entries (= number of clusters + 2) */
DWORD fatbase; /* FAT start sector */
DWORD dirbase; /* Root directory start sector (Cluster# on FAT32) */
DWORD database; /* Data start sector */
DWORD fptr; /* File R/W pointer */
DWORD fsize; /* File size */
CLUST org_clust; /* File start cluster */
CLUST curr_clust; /* File current cluster */
DWORD dsect; /* File current data sector */
} FATFS;
/* Directory object structure */
typedef struct {
WORD index; /* Current read/write index number */
BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
CLUST sclust; /* Table start cluster (0:Static table) */
CLUST clust; /* Current cluster */
DWORD sect; /* Current sector */
} DIR;
/* File status structure */
typedef struct {
DWORD fsize; /* File size */
WORD fdate; /* Last modified date */
WORD ftime; /* Last modified time */
BYTE fattrib; /* Attribute */
char fname[13]; /* File name */
} FILINFO;
/* File function return code (FRESULT) */
typedef enum {
FR_OK = 0, /* 0 */
FR_DISK_ERR, /* 1 */
FR_NOT_READY, /* 2 */
FR_NO_FILE, /* 3 */
FR_NOT_OPENED, /* 4 */
FR_NOT_ENABLED, /* 5 */
FR_NO_FILESYSTEM /* 6 */
} FRESULT;
/*--------------------------------------------------------------*/
/* Petit FatFs module application interface */
FRESULT pf_mount (FATFS* fs); /* Mount/Unmount a logical drive */
FRESULT pf_open (const char* path); /* Open a file */
FRESULT pf_read (void* buff, UINT btr, UINT* br); /* Read data from the open file */
FRESULT pf_write (const void* buff, UINT btw, UINT* bw); /* Write data to the open file */
FRESULT pf_lseek (DWORD ofs); /* Move file pointer of the open file */
FRESULT pf_opendir (DIR* dj, const char* path); /* Open a directory */
FRESULT pf_readdir (DIR* dj, FILINFO* fno); /* Read a directory item from the open directory */
/*--------------------------------------------------------------*/
/* Flags and offset address */
/* File status flag (FATFS.flag) */
#define FA_OPENED 0x01
#define FA_WPRT 0x02
#define FA__WIP 0x40
/* FAT sub type (FATFS.fs_type) */
#define FS_FAT12 1
#define FS_FAT16 2
#define FS_FAT32 3
/* File attribute bits for directory entry */
#define AM_RDO 0x01 /* Read only */
#define AM_HID 0x02 /* Hidden */
#define AM_SYS 0x04 /* System */
#define AM_VOL 0x08 /* Volume label */
#define AM_LFN 0x0F /* LFN entry */
#define AM_DIR 0x10 /* Directory */
#define AM_ARC 0x20 /* Archive */
#define AM_MASK 0x3F /* Mask of defined bits */
/*--------------------------------*/
/* Multi-byte word access macros */
#if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */
#define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
#define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
#define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
#define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
#else /* Use byte-by-byte access to the FAT structure */
#define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
#define LD_DWORD(ptr) (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr))
#define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8)
#define ST_DWORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8); *((BYTE*)(ptr)+2)=(BYTE)((DWORD)(val)>>16); *((BYTE*)(ptr)+3)=(BYTE)((DWORD)(val)>>24)
#endif
#ifdef __cplusplus
}
#endif
#endif /* _PFATFS */

@ -0,0 +1,89 @@
/*---------------------------------------------------------------------------/
/ Petit FatFs - Configuration file R0.03 (C)ChaN, 2014
/---------------------------------------------------------------------------*/
#ifndef _PFFCONF
#define _PFFCONF 4004 /* Revision ID */
/*---------------------------------------------------------------------------/
/ Function Configurations
/---------------------------------------------------------------------------*/
#define _USE_READ 1 /* Enable pf_read() function */
#define _USE_DIR 0 /* Enable pf_opendir() and pf_readdir() function */
#define _USE_LSEEK 0 /* Enable pf_lseek() function */
#define _USE_WRITE 0 /* Enable pf_write() function */
#define _FS_FAT12 0 /* Enable FAT12 */
#define _FS_FAT16 1 /* Enable FAT16 */
#define _FS_FAT32 1 /* Enable FAT32 */
/*---------------------------------------------------------------------------/
/ Locale and Namespace Configurations
/---------------------------------------------------------------------------*/
#define _USE_LCC 0 /* Allow lower case characters for path name */
#define _CODE_PAGE 437
/* The _CODE_PAGE specifies the code page to be used on the target system.
/ SBCS code pages with _USE_LCC == 1 requiers a 128 byte of case conversion
/ table. This might occupy RAM on some platforms, e.g. avr-gcc.
/ When _USE_LCC == 0, _CODE_PAGE has no effect.
/
/ 932 - Japanese Shift_JIS (DBCS, OEM, Windows)
/ 936 - Simplified Chinese GBK (DBCS, OEM, Windows)
/ 949 - Korean (DBCS, OEM, Windows)
/ 950 - Traditional Chinese Big5 (DBCS, OEM, Windows)
/ 1250 - Central Europe (Windows)
/ 1251 - Cyrillic (Windows)
/ 1252 - Latin 1 (Windows)
/ 1253 - Greek (Windows)
/ 1254 - Turkish (Windows)
/ 1255 - Hebrew (Windows)
/ 1256 - Arabic (Windows)
/ 1257 - Baltic (Windows)
/ 1258 - Vietnam (OEM, Windows)
/ 437 - U.S. (OEM)
/ 720 - Arabic (OEM)
/ 737 - Greek (OEM)
/ 775 - Baltic (OEM)
/ 850 - Multilingual Latin 1 (OEM)
/ 858 - Multilingual Latin 1 + Euro (OEM)
/ 852 - Latin 2 (OEM)
/ 855 - Cyrillic (OEM)
/ 866 - Russian (OEM)
/ 857 - Turkish (OEM)
/ 862 - Hebrew (OEM)
/ 874 - Thai (OEM, Windows)
*/
/*---------------------------------------------------------------------------/
/ System Configurations
/---------------------------------------------------------------------------*/
#define _WORD_ACCESS 1
/* The _WORD_ACCESS option is an only platform dependent option. It defines
/ which access method is used to the word data on the FAT volume.
/
/ 0: Byte-by-byte access. Always compatible with all platforms.
/ 1: Word access. Do not choose this unless under both the following conditions.
/
/ * Address misaligned memory access is always allowed for ALL instructions.
/ * Byte order on the memory is little-endian.
/
/ If it is the case, _WORD_ACCESS can also be set to 1 to improve performance and
/ reduce code size. Following table shows an example of some processor types.
/
/ ARM7TDMI 0 ColdFire 0 V850E 0
/ Cortex-M3 0 Z80 0/1 V850ES 0/1
/ Cortex-M0 0 RX600(LE) 0/1 TLCS-870 0/1
/ AVR 0/1 RX600(BE) 0 TLCS-900 0/1
/ AVR32 0 RL78 0 R32C 0
/ PIC18 0/1 SH-2 0 M16C 0/1
/ PIC24 0 H8S 0 MSP430 0
/ PIC32 0 H8/300H 0 x86 0/1
*/
#endif /* _PFFCONF */

@ -0,0 +1,76 @@
// MOSI, MISO, and SCK pin definitions for all standard ATmega microcontrollers
#ifndef SPI_PINS_H
#define SPI_PINS_H
#if defined(__AVR_ATmega64__) || defined(__AVR_ATmega64A__) || defined(__AVR_ATmega128__) || defined(__AVR_ATmega128A__) || \
defined(__AVR_ATmega640__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || \
defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__) || \
defined(__AVR_ATmega165__) || defined(__AVR_ATmega165A__) || defined(__AVR_ATmega165P__) || defined(__AVR_ATmega165PA__) || defined(__AVR_ATmega325__) ||defined(__AVR_ATmega325A__) || defined(__AVR_ATmega325P__) || defined(__AVR_ATmega325PA__) || defined(__AVR_ATmega645__) || defined(__AVR_ATmega645A__) || defined(__AVR_ATmega645P__) || \
defined(__AVR_ATmega3250__) || defined(__AVR_ATmega3250A__) || defined(__AVR_ATmega3250P__) || defined(__AVR_ATmega3250PA__) || defined(__AVR_ATmega6450__) || defined(__AVR_ATmega6450A__) || defined(__AVR_ATmega6450P__) || \
defined(__AVR_ATmega169__) || defined(__AVR_ATmega169A__) || defined(__AVR_ATmega169P__) || defined(__AVR_ATmega169PA__) || defined(__AVR_ATmega329__) || defined(__AVR_ATmega329A__) || defined(__AVR_ATmega329P__) || defined(__AVR_ATmega329PA__) || defined(__AVR_ATmega3290__) || defined(__AVR_ATmega3290A__) || defined(__AVR_ATmega3290P__) || defined(__AVR_ATmega3290PA__) || defined(__AVR_ATmega649__) || defined(__AVR_ATmega649A__) || defined(__AVR_ATmega649P__) || defined(__AVR_ATmega6490__) || defined(__AVR_ATmega6490A__) || defined(__AVR_ATmega6490P__) || \
defined(__AVR_ATmega8U2__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega32U6__) || \
defined(__AVR_AT90CAN32__ ) || defined(__AVR_AT90CAN64__ ) || defined(__AVR_AT90CAN128__ ) || \
defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
#define DDR_DI _SFR_IO_ADDR(DDRB), 2 //MMC DI MOSI pin (DDR, PORT)
#define PORT_DI _SFR_IO_ADDR(PORTB), 2
#define PIN_DO _SFR_IO_ADDR(PINB), 3 //MMC DO MISO pin (PIN, PORT)
#define PORT_DO _SFR_IO_ADDR(PORTB), 3
#define DDR_CK _SFR_IO_ADDR(DDRB), 1 //MMC SCK pin (DDR, PORT)
#define PORT_CK _SFR_IO_ADDR(PORTB), 1
#elif defined(__AVR_ATmega8__) || defined(__AVR_ATmega8A__) || defined(__AVR_ATmega48__) || defined(__AVR_ATmega48A__) || defined(__AVR_ATmega48P__) || defined(__AVR_ATmega48PA__) || defined(__AVR_ATmega48PB__) || defined(__AVR_ATmega88__) || defined(__AVR_ATmega88A__) || defined(__AVR_ATmega88P__) || defined(__AVR_ATmega88PA__) || defined(__AVR_ATmega88PB__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega168A__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega168PA__) || defined(__AVR_ATmega168PB__) ||defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328PB__)
#define DDR_DI _SFR_IO_ADDR(DDRB), 3
#define PORT_DI _SFR_IO_ADDR(PORTB), 3
#define PIN_DO _SFR_IO_ADDR(PINB), 4
#define PORT_DO _SFR_IO_ADDR(PORTB), 4
#define DDR_CK _SFR_IO_ADDR(DDRB), 5
#define PORT_CK _SFR_IO_ADDR(PORTB), 5
#elif defined(__AVR_ATmega16__) || defined(__AVR_ATmega16A__) || defined(__AVR_ATmega32__) || defined(__AVR_ATmega32A__) || \
defined(__AVR_ATmega161__) || defined(__AVR_ATmega162__) || defined(__AVR_ATmega163__) || \
defined(__AVR_ATmega164A__) || defined(__AVR_ATmega164P__) || defined(__AVR_ATmega164PA__) || defined(__AVR_ATmega323__) || defined(__AVR_ATmega324A__) || defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega324PB__) || defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || \
defined(__AVR_ATmega8515__) || defined(__AVR_ATmega8535__)
#define DDR_DI _SFR_IO_ADDR(DDRB), 5
#define PORT_DI _SFR_IO_ADDR(PORTB), 5
#define PIN_DO _SFR_IO_ADDR(PINB), 6
#define PORT_DO _SFR_IO_ADDR(PORTB), 6
#define DDR_CK _SFR_IO_ADDR(DDRB), 7
#define PORT_CK _SFR_IO_ADDR(PORTB), 7
#elif defined(__AVR_ATmega16M1__) || defined(__AVR_ATmega32M1__) || defined(__AVR_ATmega64M1__) || defined(__AVR_ATmega32C1__) || defined(__AVR_ATmega64C1__) || \
defined(__AVR_AT90PWM1__) || defined(__AVR_AT90PWM2__) || defined(__AVR_AT90PWM2B__) || defined(__AVR_AT90PWM3__) || defined(__AVR_AT90PWM3B__) || defined(__AVR_AT90PWM216__) || defined(__AVR_AT90PWM316__)
#define DDR_DI _SFR_IO_ADDR(DDRB), 1
#define PORT_DI _SFR_IO_ADDR(PORTB), 1
#define PIN_DO _SFR_IO_ADDR(PINB), 0
#define PORT_DO _SFR_IO_ADDR(PORTB), 0
#define DDR_CK _SFR_IO_ADDR(DDRB), 7
#define PORT_CK _SFR_IO_ADDR(PORTB), 7
#elif defined(__AVR_AT90PWM81__) || defined(__AVR_AT90PWM161__)
#define DDR_DI _SFR_IO_ADDR(DDRB), 4
#define PORT_DI _SFR_IO_ADDR(PORTB), 4
#define PIN_DO _SFR_IO_ADDR(PINB), 6
#define PORT_DO _SFR_IO_ADDR(PORTB), 6
#define DDR_CK _SFR_IO_ADDR(DDRB), 5
#define PORT_CK _SFR_IO_ADDR(PORTB), 5
#else
#error SPI pins not defined for your processor. You must modify spi_pins.h
#endif
#endif //SPI_PINS_H

@ -0,0 +1,107 @@
/*
** This is a simple set of UART routines for debug purposes
** It's Tx only and the baud rate is fixed (see UART_init)
*/
#include "uart.h"
#define UCSRA UCSR0A
#define UCSRB UCSR0B
#define UCSRC UCSR0C
#define UBRRH UBRR0H
#define UBRRL UBRR0L
#define UDRE UDRE0
#define UDR UDR0
#define RXC RXC0
#if BOOT_ADR > 0xFFFF
#define PGM_READ_BYTE(x) pgm_read_byte_far(x)
#else
#define PGM_READ_BYTE(x) pgm_read_byte(x)
#endif
// Just enable the UART Tx and set baud rate for 38400 on 3.6864MHz (STK500)
void UART_init(void) {
UCSRB = (1 << TXEN0);
UBRRL = USE_UART; // SEE HERE: http://wormfood.net/avrbaudcalc.php
}
// The classic Tx one character routine
void UART_put(uint8_t c) {
while (!(UCSRA & (1 << UDRE)));
UDR = c;
}
// classic Tx a C-string routine
// As there is no .data (in the bootloader) it only makes sense for theis to use PSTR()
void UART_puts(const char * str) {
char c;
do {
c = PGM_READ_BYTE(str++);
if (c) {
UART_put(c);
}
} while (c != 0);
}
// Just outputs "\r\n"
void UART_newline(void){
UART_put('\r');
UART_put('\n');
}
// used in printing a 2 digit hex number, outputs one of the two nibbles
// the parameter is expected to be 0..F
void UART_putnibble(uint8_t c) {
if (c < 10) {
UART_put('0' + c);
}
else {
UART_put('A' + c - 10);
}
}
// print both nibbles of an 8 bit hex number
void UART_puthex(uint8_t c) {
UART_putnibble(c >> 4);
UART_putnibble(c & 0x0F);
}
// print both bytes of a 16 bit hex number
void UART_puthex16(uint16_t n) {
UART_puthex(n >> 8);
UART_puthex(n & 0xFF);
}
// print both bytes of a 32 bit hex number
void UART_puthex32(uint32_t n) {
UART_puthex(n >> 24);
UART_puthex(n >> 16 & 0xFF);
UART_puthex(n >> 8 & 0xFF);
UART_puthex(n & 0xFF);
}
// this expect the first parameter to be a string in dlash (that is PSTR())
// and then the second to be a value to print out in hex. typically used in
// the form UART_putsP(PSTR("SecPerClus = "), SecPerClus)
void UART_putsP(const char * str, uint16_t n) {
UART_puts(str);
UART_puthex16(n);
UART_newline();
}
// dump the 512 bytes at the given address in the form:
// CD BF 10 E0 A0 E6 B0 E0 E4 E5 F0 E0 02 C0 05 90 Ϳ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20>
void UART_dumpsector(uint8_t * Buff) {
for (uint16_t i=0; i<512; i++) {
if ((i % 16) == 0) {
UART_put(' ');
for(uint16_t j=(i -16); j<=i; j++) {
UART_put(((Buff[j]>=(uint8_t)32) && (Buff[j]<(uint8_t)127)) ? Buff[j] : '.');
}
UART_newline();
}
UART_puthex(Buff[i]);
UART_put(' ');
}
UART_newline();
}

@ -0,0 +1,32 @@
#include <avr/io.h>
#include <avr/pgmspace.h>
/*
** This is a simple set of UART routines for debug purposes
** It's Tx only and the baud rate is fixed (see UART_init)
*/
// Just enable the UART Tx and set baud rate for 38400 on 3.6864MHz (STK500)
void UART_init(void);
// The classic Tx one character routine
void UART_put(uint8_t c);
// classic Tx a C-string routine (string in PROGMEM)
void UART_puts(const char * str);
// this expect the first parameter to be a string in dlash (that is PSTR())
// and then the second to be a value to print out in hex. typically used in
// the form UART_putsP(PSTR("SecPerClus = "), SecPerClus)
void UART_putsP(const char * str, uint16_t n);
// Just outputs "\r\n"
void UART_newline(void);
// used in printing a 2 digit hex number, outputs one of the two nibbles
// the parameter is expected to be 0..F
void UART_putnibble(uint8_t c);
// print both nibbles of an 8 bit hex number
void UART_puthex(uint8_t c);
// print both bytes of a 16 bit hex number
void UART_puthex16(uint16_t n);
// print both bytes of a 32 bit hex number
void UART_puthex32(uint32_t n);
// dump the 512 bytes at the given address in the form:
// CD BF 10 E0 A0 E6 B0 E0 E4 E5 F0 E0 02 C0 05 90 Ϳ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20>
void UART_dumpsector(uint8_t * Buff);

@ -0,0 +1,247 @@
:020000021000EC
:10F000000C9446F80C9472F80C9472F80C9472F804
:10F010000C9472F80C9472F80C9472F80C9472F8C8
:10F020000C9472F80C9472F80C9472F80C9472F8B8
:10F030000C9472F80C9472F80C9472F80C9472F8A8
:10F040000C9472F80C9472F80C9472F80C9472F898
:10F050000C9472F80C9472F80C9472F80C9472F888
:10F060000C9472F80C9472F80C9472F80C9472F878
:10F070000C9472F80C9472F80C9472F80C9472F868
:10F080000C9472F80C9472F80C9472F811241FBE50
:10F09000CFEFD0E4DEBFCDBF87EF84BF0FB6F894CB
:10F0A000A895809160008861809360001092600054
:10F0B0000FBE11E0A0E0B1E0E0E3FFEF01E00BBF25
:10F0C00002C007900D92AE30B107D9F722E0AEE052
:10F0D000B1E001C01D92AB33B207E1F70E9458F9CD
:10F0E0000C9496FF0C9400F83B9A0895439A089567
:10F0F00043980895439B0C9476F80C9478F8209AE2
:10F10000259A279A2E9A089580EA31973197319758
:10F1100000008A95D1F7089502D0289801C0289A56
:10F120008FEF98E087FD2D9A87FF2D98880F1E9905
:10F1300083952F9A2F989A95A9F70895FB018BBF75
:10F1400083E080935700E8958091570080FDFCCFC5
:10F1500081E180935700E89508950F921F928BBF2D
:10F16000FB01DA0190E80D901D9081E0809357003B
:10F17000E89532969A95B9F7FB0185E080935700A0
:10F18000E8958091570080FDFCCF81E18093570086
:10F19000E8951F900F900895CF92DF92EF92FF9223
:10F1A0001F93CF93DF9300D0CDB7DEB712E30E9459
:10F1B0007AF82FEF81EE94E0215080409040E1F703
:10F1C00000C00000115099F7C12CD12C760140E00D
:10F1D00051E06FEF70E08BE391E00E948FFFAE0192
:10F1E0004F5F5F4F60E071E08BE391E00E9437FD7D
:10F1F000ABE3B1E0B701A6016BBFFA0197918D9126
:10F2000098131FC04F5F5F4F6F4F7F4F22E0AB33AC
:10F21000B20791F70E9476F88FEFD81AE80AF80A39
:10F22000C11490EFD90691E0E906F10481F60F9040
:10F230000F90DF91CF911F91FF90EF90DF90CF90D3
:10F2400008950E9478F8C701B6010E949EF84BE32A
:10F2500051E0C701B6010E94ADF8DECFCF9381E146
:10F2600091E00E94B2FA811121C080E091E00E94F9
:10F270009FFB81111BC00E94CCF80E9478F82FEFF1
:10F2800087EA91E6215080409040E1F700C00000FD
:10F29000C8E20E947AF82FEF80E792E02150804088
:10F2A0009040E1F700C00000C15099F7CF91089558
:10F2B0000E9474F800E010E00E9476F82FEF83ECD3
:10F2C00099E0215080409040E1F700C000000E948A
:10F2D00078F80E942EF9F80185919491019611F029
:10F2E000F8010995CAE00E947AF8FFEF23EC89E063
:10F2F000F15020408040E1F700C00000C15099F774
:10F300009FEFE3E2F4EF9150E040F040E1F700C0FE
:10F310000000D2CF0F931F93E0910E01F0910F01E7
:10F320009B01AC0122503109410951098681978125
:10F33000A085B1850297A109B109281739074A07A5
:10F340005B0768F4A281B0E00E943EFF0289138946
:10F3500024893589600F711F821F931F03C060E0ED
:10F3600070E0CB011F910F9108950F931F93CF93DE
:10F37000DF93DC01E0910E01F0910F0111961C92D8
:10F380001E9214966D917D918D919C91179761308D
:10F3900071058105910569F1068117812085318507
:10F3A000601771078207930720F5611571058105C4
:10F3B000910539F42081233021F466857785808991
:10F3C0009189ED01688779878A879B876115710527
:10F3D0008105910519F00E948AF904C06685778538
:10F3E000808991896C877D878E879F8780E090E0F8
:10F3F00002C081E090E0DF91CF911F910F910895BD
:10F40000A4E0B0E0E6E0FAEF0C9453FFE0910E01C7
:10F41000F0910F01623071058105910508F459C022
:10F42000C680D780E084F1846C157D058E059F052C
:10F4300008F04FC02081223019F0233001F149C07B
:10F440009B013327220F331FBB27A92F982F872F0C
:10F45000C284D384E484F584AC01BD014C0D5D1DF0
:10F460006E1D7F1D02E010E0CE0101960E94CDFED0
:10F47000892B79F569817A8180E090E02EC09B012B
:10F480002F773327220F331F220F331FDC01CB01CD
:10F4900057E0B695A795979587955A95D1F7C28469
:10F4A000D384E484F584AC01BD014C0D5D1D6E1D5B
:10F4B0007F1D04E010E0CE0101960E94CDFE892B55
:10F4C00041F489819A81AB81BC81BC01CD019F70DF
:10F4D00004C061E070E080E090E02496E8E00C94E5
:10F4E0006FFFA0E0B0E0E7E7FAEF0C9453FFEC0108
:10F4F0006A017B0102E010E02EEF31E00E94CDFEB8
:10F50000892B31F58881998185359A4A19F526E349
:10F5100030E0B701A601CE010E94CDFE892B39F45F
:10F52000888199818634914411F480E016C002E00C
:10F5300010E022E530E0B701A601CE010E94CDFE29
:10F54000892B51F4888199818634914429F4EDCF37
:10F5500083E003C082E001C081E0CDB7DEB7E8E020
:10F560000C946FFFA4E2B0E0E8EBFAEF0C9449FFD3
:10F570001C0110920F0110920E010E9432FE80FDBC
:10F58000A0C040E050E0BA01CE0101960E9471FA9D
:10F59000813009F500E110E02EEB31E040E050E071
:10F5A000BA01CE0101960E94CDFE892B19F081E0AF
:10F5B00090E0C1C08D81811103C086E090E0BBC0A6
:10F5C00049845A846B847C84B301A201CE010196E4
:10F5D0000E9471FA03C0412C512C3201833039F35F
:10F5E0008111EBCF04E210E02DE030E0B301A20185
:10F5F000CE0101960E94CDFE892BC9F62A853B8556
:10F6000040E050E0211531054105510521F4288DD8
:10F61000398D4A8D5B8DAC81B0E00E943EFF4B017D
:10F620005C010A811B8120E030E0400E511E621E09
:10F63000731EF10142865386648675864981428332
:10F64000CD80DE80D582C4828F819885A0E0B0E035
:10F650000097A105B10521F48C899D89AE89BF89E8
:10F6600054E0D694C7945A95E1F7E12CF12C801B15
:10F67000910BA20BB30B88199909AA09BB09BC010C
:10F68000CD016C197D098E099F09242F30E040E0DF
:10F6900050E00E941CFFDA01C9010296A11DB11DB4
:10F6A000F10186839783A087B187BA01A901465FDC
:10F6B0005F40610971094F3F5F4E61057105A0F11F
:10F6C00003C082E090E037C0873F9F4FA105B1059E
:10F6D00008F473CF83E0F1018083833029F488A19B
:10F6E00099A1AAA1BBA107C0D501C401840D951D94
:10F6F000A61DB71DF10186879787A08BB18BC40C1F
:10F70000D51CE61CF71CC80CD91CEA1CFB1CF1011B
:10F71000C28AD38AE48AF58A118230920F0120923C
:10F720000E0180E090E007C0873F9F4FA105B10523
:10F7300088F682E0D0CFA496E2E10C9465FF4F9268
:10F740005F926F927F929F92AF92BF92CF92DF9221
:10F75000EF92FF920F931F93CF93DF93CDB7DEB756
:10F76000EC970FB6F894DEBF0FBECDBFC0900E0170
:10F77000D0900F01C114D10409F452C1D6011196E1
:10F780001C929E012F5C3F4F3CA32BA3FC012E2F0C
:10F790009F2F81918032D9F3E22EF92E8F3219F406
:10F7A000BFEFEB1AFB0A1DA21EA21FA218A6F701AB
:10F7B0008081803238F0A0E29A2E5E01FCE0AF0E2C
:10F7C000B11C6AC0CE0181960E94B5F919820097DA
:10F7D00009F4F1C036C180E090E028E031E0390F53
:10F7E000D701A90FB11D9C91913208F060C0E30EC2
:10F7F000F11C81E0913208F080E08387CE01819690
:10F800000E94B5F9009709F01CC129A13AA12F70F7
:10F810003327F5E0220F331FFA95E1F74DA55EA5DA
:10F820006FA578A900E210E0CE0101960E94CDFEFE
:10F83000892B09F0FAC08981882309F4F9C04C8525
:10F8400043FD53C06BA17CA1FE0131969B01EA15DB
:10F85000FB05E9F5DB011B968C918111ACC044FFDF
:10F86000E7C0E0910E01F0910F018081833009F033
:10F870009EC08D899E89A0E0B0E0DC019927882791
:10F880004B8D5C8D60E070E0842B952BA62BB72B05
:10F890008DA39EA3AFA3B8A7EBA1FCA1DF01CF016D
:10F8A0000B96A817B90709F496CF9D92FACF9F320D
:10F8B00009F49DCF9E3209F4BEC0821708F097CF9D
:10F8C000DF01A80FB11D9C938F5F932F87CF81918C
:10F8D000D9015D919D01082E000C990B851B9109A2
:10F8E00057FD9395892B09F4B2CF60900E0170906B
:10F8F0000F0109A11AA10F5F1F4F09F499C08DA52F
:10F900009EA5AFA5B8A90097A105B10509F490C0BF
:10F9100098012F703327232B09F046C00196A11DB3
:10F92000B11D8DA79EA7AFA7B8AB69A57AA58BA57A
:10F930009CA5611571058105910541F4F301848150
:10F9400095810817190708F073C02EC0D3011296CD
:10F950002C9130E0A901415051099801E4E036951D
:10F960002795EA95E1F724233523232BE9F40E9418
:10F9700000FA623071058105910508F456C0F30163
:10F9800046805780608471846415750586059705E7
:10F9900008F04EC069A77AA78BA79CA70E948AF996
:10F9A0006DA77EA78FA798AB1AA309A32ECF80E0DF
:10F9B00090E0DC0165CF89818823A1F18C8584FDED
:10F9C00031C0E0910E01F0910F018081833041F44C
:10F9D0008D899E89A0E0B0E0DC019927882703C0CB
:10F9E00080E090E0DC014B8D5C8D60E070E0842B6A
:10F9F000952BA62BB72BF601868F978FA0A3B1A3CB
:10FA00008D8D9E8DAF8DB8A1828F938FA48FB58F72
:10FA1000168A178A108E118E81E0818380E003C0E0
:10FA200085E001C083E090E00CC081E090E009C077
:10FA300083E090E006C0283009F0D9CE88E02BE0C2
:10FA400044CFEC960FB6F894DEBF0FBECDBFDF916A
:10FA5000CF911F910F91FF90EF90DF90CF90BF90CB
:10FA6000AF909F907F906F905F904F900895A0E02F
:10FA7000B0E0EDE3FDEF0C944BFF4C016B015A013C
:10FA8000C0910E01D0910F01FA01118210822097CE
:10FA900009F4A1C0898180FFA1C08A8D9B8DAC8DA6
:10FAA000BD8D4E895F89688D798D841B950BA60B62
:10FAB000B70BA60160E070E084179507A607B707AB
:10FAC00008F46C013401412C32E0532EC114D104EE
:10FAD00009F47EC08E899F89A88DB98DAC01BD01C6
:10FAE000517066277727452B462B472BD1F5FA8097
:10FAF000FA94AC01BD0129E0769567955795479535
:10FB00002A95D1F7F422C1F4892B8A2B8B2B29F467
:10FB10006E8D7F8D88A199A106C06AA17BA18CA161
:10FB20009DA10E9400FA6230710581059105A0F146
:10FB30006AA37BA38CA39DA36AA17BA18CA19DA199
:10FB40000E948AF9611571058105910529F1DC0191
:10FB5000CB018F0D911DA11DB11D8EA39FA3A8A741
:10FB6000B9A72E893F893170C201821B930B7601A0
:10FB70008C159D0508F47C014EA15FA168A579A5AF
:10FB80008114910411F0C30102C080E090E087016C
:10FB90000E94CDFE892B21F0198281E090E020C0E7
:10FBA0008E899F89A88DB98D8E0D9F1DA11DB11DB8
:10FBB0008E8B9F8BA88FB98F6E0C7F1CCE18DF08A1
:10FBC000F50180819181E80EF91EF182E0827ECFFD
:10FBD00080E090E005C085E090E002C084E090E025
:10FBE000CDB7DEB7E0E10C9467FFFF920F931F9350
:10FBF000CF93DF93C82FD42F152F062FF72E87FF13
:10FC000009C040E050E0BA0187E70E94F5FD82306C
:10FC100020F5CF770E948CF88C2F0E9491F88F2DC1
:10FC20000E9491F8802F0E9491F8812F0E9491F8F4
:10FC30008D2F0E9491F8C03421F0C83421F487E858
:10FC400003C085E901C081E00E9491F8CAE00E94EA
:10FC500090F887FF02C0C150D1F7CDB7DEB7E5E01D
:10FC60000C9472FFA4E0B0E0E8E3FEEF0C9454FFC4
:10FC70000E947FF814E60E9484F81150E1F71AE020
:10FC80000E948FF81150E1F740E050E0BA0180E4A3
:10FC90000E94F5FD813009F07AC04AEA51E060E047
:10FCA00070E088E40E94F5FD813051F58E010F5F10
:10FCB0001F4F780124E0D22ED00E0E9490F8F70159
:10FCC00081937F01DE12F9CF8B81813009F05FC013
:10FCD0008C818A3A09F05BC090E1E92E97E2F92E17
:10FCE00040E050E060E070E489EE0E94F5FD88237A
:10FCF00039F10E9484F8F1E0EF1AF10889F747C062
:10FD000040E050E0BA0189EE0E94F5FD823018F023
:10FD100011E001E402C012E009EE80E1E82E87E282
:10FD2000F82E40E050E0BA01802F0E94F5FD8823B4
:10FD300029F10E9484F8F1E0EF1AF10891F727C049
:10FD400040E050E0BA018AE70E94F5FD81111FC032
:10FD50000E9490F8F80181938F01DE12F9CF89811A
:10FD600086FD02C014E001C01CE0109310010E9447
:10FD70008FF881E0112369F080E00BC040E052E091
:10FD800060E070E080E50E94F5FD882371F310E0EB
:10FD9000ECCF2496E7E00C9470FFA0E0B0E0E3ED38
:10FDA000FEEF0C9453FFD82EC92E790180911001DB
:10FDB00083FD07C089E0440F551F661F771F8A9592
:10FDC000D1F781E50E94F5FD882319F0C1E0D0E06C
:10FDD0002BC0C0E4DCE90E9490F88F3F19F4219712
:10FDE000D1F7F4CF8E3F91F7C2E0D2E0C01BD10B28
:10FDF000CE19DF09E114F10419F4ED2CFC2C06C036
:10FE00000E9490F881E0E81AF108F4CF0E9490F87F
:10FE1000F70181937F0101501109C1F70E9490F809
:10FE20002197E1F7C0E0D0E00E948FF8CE01CDB776
:10FE3000DEB7E8E00C946FFFA1E21A2EAA1BBB1BF1
:10FE4000FD010DC0AA1FBB1FEE1FFF1FA217B307A6
:10FE5000E407F50720F0A21BB30BE40BF50B661FBC
:10FE6000771F881F991F1A9469F760957095809580
:10FE700090959B01AC01BD01CF0108950E9480FFC8
:10FE8000A59F900DB49F900DA49F800D911D1124EE
:10FE900008952F923F924F925F926F927F928F922E
:10FEA0009F92AF92BF92CF92DF92EF92FF920F9309
:10FEB0001F93CF93DF93CDB7DEB7CA1BDB0B0FB613
:10FEC000F894DEBF0FBECDBF09942A8839884888D0
:10FED0005F846E847D848C849B84AA84B984C88466
:10FEE000DF80EE80FD800C811B81AA81B981CE0F5D
:10FEF000D11D0FB6F894DEBF0FBECDBFED01089542
:10FF0000A29FB001B39FC001A39F700D811D11245A
:10FF1000911DB29F700D811D1124911D0895DC016A
:10FF200001C06D9341505040E0F70895F894FFCF21
:0EFF30004649524D574152452E42494E00005F
:040000031000F000F9
:00000001FF