From 0c51b431f291b88062f9303a85e4a69f29ff6ac4 Mon Sep 17 00:00:00 2001 From: areviu Date: Mon, 26 Feb 2018 19:06:49 +0000 Subject: sdmmc driver update, added support for reliance edge fs git-svn-id: https://svn.code.sf.net/p/chibios/svn2/trunk@11551 110e8d01-0319-4d1e-a829-52ad28d1bb01 --- testhal/ATSAMA5D2/SDMMC/.cproject | 9 +- testhal/ATSAMA5D2/SDMMC/.project | 5 + testhal/ATSAMA5D2/SDMMC/Makefile | 18 +- .../SDMMC/debug/SAMA5D2-SDMMC (DDRAM).launch | 58 +++++ .../debug/SAMA5D2-SDMMC (Load and Run).launch | 2 +- .../SDMMC/debug/SAMA5D2-SDMMC (bootstrap).launch | 2 +- testhal/ATSAMA5D2/SDMMC/fat32test.c | 287 +++++++++++++++++++++ testhal/ATSAMA5D2/SDMMC/fat32test.h | 10 + testhal/ATSAMA5D2/SDMMC/ffconf.h | 269 +++++++++++++++++++ testhal/ATSAMA5D2/SDMMC/main.c | 151 +++-------- testhal/ATSAMA5D2/SDMMC/mcuconf.h | 2 +- testhal/ATSAMA5D2/SDMMC/readme.txt | 1 + testhal/ATSAMA5D2/SDMMC/redconf.c | 36 +++ testhal/ATSAMA5D2/SDMMC/redconf.h | 114 ++++++++ testhal/ATSAMA5D2/SDMMC/reledgetest.c | 268 +++++++++++++++++++ testhal/ATSAMA5D2/SDMMC/reledgetest.h | 8 + 16 files changed, 1110 insertions(+), 130 deletions(-) create mode 100644 testhal/ATSAMA5D2/SDMMC/debug/SAMA5D2-SDMMC (DDRAM).launch create mode 100644 testhal/ATSAMA5D2/SDMMC/fat32test.c create mode 100644 testhal/ATSAMA5D2/SDMMC/fat32test.h create mode 100644 testhal/ATSAMA5D2/SDMMC/ffconf.h create mode 100644 testhal/ATSAMA5D2/SDMMC/redconf.c create mode 100644 testhal/ATSAMA5D2/SDMMC/redconf.h create mode 100644 testhal/ATSAMA5D2/SDMMC/reledgetest.c create mode 100644 testhal/ATSAMA5D2/SDMMC/reledgetest.h (limited to 'testhal') diff --git a/testhal/ATSAMA5D2/SDMMC/.cproject b/testhal/ATSAMA5D2/SDMMC/.cproject index 1c30c8b9b..e9cbdc182 100644 --- a/testhal/ATSAMA5D2/SDMMC/.cproject +++ b/testhal/ATSAMA5D2/SDMMC/.cproject @@ -32,7 +32,8 @@ - + + @@ -55,4 +56,10 @@ + + + + + + diff --git a/testhal/ATSAMA5D2/SDMMC/.project b/testhal/ATSAMA5D2/SDMMC/.project index fc56de69d..0a941555e 100644 --- a/testhal/ATSAMA5D2/SDMMC/.project +++ b/testhal/ATSAMA5D2/SDMMC/.project @@ -87,5 +87,10 @@ 2 CHIBIOS/os + + reliance-edge + 2 + $%7BPARENT-3-PROJECT_LOC%7D/ext/reliance-edge + diff --git a/testhal/ATSAMA5D2/SDMMC/Makefile b/testhal/ATSAMA5D2/SDMMC/Makefile index 42697581f..c9dc8bec4 100644 --- a/testhal/ATSAMA5D2/SDMMC/Makefile +++ b/testhal/ATSAMA5D2/SDMMC/Makefile @@ -121,15 +121,12 @@ include $(CHIBIOS)/os/hal/osal/rt/osal.mk # RTOS files (optional). include $(CHIBIOS)/os/rt/rt.mk include $(CHIBIOS)/os/common/ports/ARMCAx-TZ/compilers/GCC/mk/port_generic.mk -# Other files (optional). -#include $(CHIBIOS)/test/lib/test.mk -#include $(CHIBIOS)/test/rt/rt_test.mk -#include $(CHIBIOS)/test/oslib/oslib_test.mk +include $(CHIBIOS)/os/various/reledge_bindings/reledge.mk include $(CHIBIOS)/os/various/fatfs_bindings/fatfs.mk include $(CHIBIOS)/os/hal/lib/streams/streams.mk # Define linker script file here -LDSCRIPT= $(STARTUPLD)/SAMA5D2.ld - +#LDSCRIPT= $(STARTUPLD)/SAMA5D2.ld +LDSCRIPT= $(STARTUPLD)/SAMA5D2ddr.ld # C sources that can be compiled in ARM or THUMB mode depending on the global # setting. CSRC = $(STARTUPSRC) \ @@ -140,7 +137,7 @@ CSRC = $(STARTUPSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ $(TESTSRC) $(STREAMSSRC) \ - main.c + main.c fat32test.c reledgetest.c redconf.c $(RELEDGESRC) CSRC += $(CHIBIOS)/os/various/syscalls.c CSRC += $(CHIBIOS)/os/various/fatfs_bindings/fatfs_syscall.c @@ -177,9 +174,8 @@ ASMXSRC = $(STARTUPASM) $(PORTASM) $(OSALASM) INCDIR = $(CHIBIOS)/os/license \ $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \ $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \ - $(CHIBIOS)/os/various $(STREAMSINC) + $(CHIBIOS)/os/various $(STREAMSINC) $(FATFSINC) $(RELEDGEINC) -INCDIR += $(FATFSINC) # # Project, sources and paths ############################################################################## @@ -228,10 +224,10 @@ CPPWARN = -Wall -Wextra -Wundef # # List all user C define here, like -D_DEBUG=1 -UDEFS = -DCH_CFG_USE_MMU -DPLATFORM_SDMMC_USE_SDMMC1=1 +UDEFS = -DPLATFORM_SDMMC_USE_SDMMC1=1 # Define ASM defines here -UADEFS = -DCH_CFG_USE_MMU +UADEFS = # List all user directories here UINCDIR = diff --git a/testhal/ATSAMA5D2/SDMMC/debug/SAMA5D2-SDMMC (DDRAM).launch b/testhal/ATSAMA5D2/SDMMC/debug/SAMA5D2-SDMMC (DDRAM).launch new file mode 100644 index 000000000..48a548c60 --- /dev/null +++ b/testhal/ATSAMA5D2/SDMMC/debug/SAMA5D2-SDMMC (DDRAM).launch @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/testhal/ATSAMA5D2/SDMMC/debug/SAMA5D2-SDMMC (Load and Run).launch b/testhal/ATSAMA5D2/SDMMC/debug/SAMA5D2-SDMMC (Load and Run).launch index e68b5ed9a..4d7c946f4 100644 --- a/testhal/ATSAMA5D2/SDMMC/debug/SAMA5D2-SDMMC (Load and Run).launch +++ b/testhal/ATSAMA5D2/SDMMC/debug/SAMA5D2-SDMMC (Load and Run).launch @@ -17,7 +17,7 @@ - + diff --git a/testhal/ATSAMA5D2/SDMMC/debug/SAMA5D2-SDMMC (bootstrap).launch b/testhal/ATSAMA5D2/SDMMC/debug/SAMA5D2-SDMMC (bootstrap).launch index 7a1b87b82..33bb28a80 100644 --- a/testhal/ATSAMA5D2/SDMMC/debug/SAMA5D2-SDMMC (bootstrap).launch +++ b/testhal/ATSAMA5D2/SDMMC/debug/SAMA5D2-SDMMC (bootstrap).launch @@ -6,7 +6,7 @@ - + diff --git a/testhal/ATSAMA5D2/SDMMC/fat32test.c b/testhal/ATSAMA5D2/SDMMC/fat32test.c new file mode 100644 index 000000000..83a199add --- /dev/null +++ b/testhal/ATSAMA5D2/SDMMC/fat32test.c @@ -0,0 +1,287 @@ +/* + ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ +#include +#include "ch.h" +#include "hal.h" + +#include "ff.h" +#include "sama_sdmmc_lld.h" +#include "chprintf.h" + + +extern BaseSequentialStream * ts; + + + +#if FF_MULTI_PARTITION == 1 +#define DEMO_VOLUMES 2 + +PARTITION VolToPart[] = { + {1, 1}, /* "0:" ==> Physical drive 1, 1st partition */ + {1, 2}, /* "1:" ==> Physical drive 1, 2nd partition */ +}; + +const TCHAR volume_paths[DEMO_VOLUMES][3] = +{ + { '0', ':', '\0' }, + { '1', ':', '\0' } +}; + +const TCHAR volume_labels[DEMO_VOLUMES][13] = +{ + { '0', ':','C','H','I','B','I','V','O','L','_','1','\0' }, + { '1', ':','C','H','I','B','I','V','O','L','_','2','\0' } +}; + +//two partition: 20% of total size the first, 80% the second +//using a number > 100 means sector count +const DWORD plist[] = { 50, 50, 0, 0 }; + + +#else +#define DEMO_VOLUMES 1 +const TCHAR volume_paths[DEMO_VOLUMES][3] = +{ + { '0', ':', '\0' } +}; + +const TCHAR volume_labels[DEMO_VOLUMES][13] = +{ + { '0', ':','C','H','I','B','I','V','O','L','_','1','\0' } +}; + +#endif + + + + +static FATFS fs_header; +static FIL f_header; +const char test_file_path[] = "test.txt"; + +//Welcome to Chibios! +const uint8_t buffer[19]={ 0x57,0x65,0x6C,0x63,0x6F, + 0x6D,0x65,0x20,0x74,0x6F, + 0x20,0x43,0x68,0x69,0x62, + 0x69,0x4F,0x53,0x21 +}; + +static void getdir(uint8_t vi); +static void writefile(uint8_t vi); +static void readfile(uint8_t vi); +static bool format(void); +static bool mountVolume(uint8_t vi, FATFS *fs); +static bool unmountVolume(uint8_t vi); + +extern CACHE_ALIGNED uint8_t data_buf[]; + +void fat32test_demo(void) +{ + uint8_t i; + chprintf(ts,"Init FAT32 FS\r\n" ); + if ( format() ) { + + for (i=0;in_fatent - 2) * fs->csize; + fre_sect = fre_clust * fs->csize; + + chprintf(ts,"%10lu KiB total drive space.\r\n%10lu KiB available.\r\n",tot_sect / 2, fre_sect / 2); + } + + } + + return true; +} + + +static bool unmountVolume(uint8_t vi) +{ + FRESULT res; + bool rc = true; + + res = f_mount(NULL, volume_paths[vi], 0); + if (res != FR_OK) + rc = false; + + return rc; + +} + + +static bool format(void) +{ + uint8_t i; + + FRESULT res = FR_OK; + + + +#if FF_MULTI_PARTITION == 1 + chprintf(ts, "fdisk ... \n\r"); + res = f_fdisk(0, plist, data_buf); +#endif + + if (res == FR_OK) { + + for (i = 0; i < DEMO_VOLUMES; i++) { + chprintf(ts, "Creating fat32 volume %s\n\r", volume_paths[i]); + + res = f_mkfs(volume_paths[i], FM_FAT32, 0, data_buf,FF_MAX_SS); + + if (res == FR_OK) { + chprintf(ts, "format OK\r\n"); + + } else { + chprintf(ts, "failed creating volume %s error %d\n\r", volume_paths[i],res); + return false; + } + + } + } + return true; +} diff --git a/testhal/ATSAMA5D2/SDMMC/fat32test.h b/testhal/ATSAMA5D2/SDMMC/fat32test.h new file mode 100644 index 000000000..a9d0a2c66 --- /dev/null +++ b/testhal/ATSAMA5D2/SDMMC/fat32test.h @@ -0,0 +1,10 @@ +#ifndef FAT32TEST_H_ +#define FAT32TEST_H_ + + + + +extern void fat32test_demo(void); + + +#endif /* FAT32TEST_H_ */ diff --git a/testhal/ATSAMA5D2/SDMMC/ffconf.h b/testhal/ATSAMA5D2/SDMMC/ffconf.h new file mode 100644 index 000000000..18a902237 --- /dev/null +++ b/testhal/ATSAMA5D2/SDMMC/ffconf.h @@ -0,0 +1,269 @@ +/* CHIBIOS FIX */ +#include "ch.h" +#include "sama_sdmmc_conf.h" +/*---------------------------------------------------------------------------/ +/ FatFs - FAT file system module configuration file R0.12 (C)ChaN, 2016 +/---------------------------------------------------------------------------*/ + +//#define _FFCONF 88100 /* Revision ID */ +#define FFCONF_DEF 87030 /* Revision ID */ +/*---------------------------------------------------------------------------/ +/ Function Configurations +/---------------------------------------------------------------------------*/ + +#define FF_FS_READONLY 0 +/* This option switches read-only configuration. (0:Read/Write or 1:Read-only) +/ Read-only configuration removes writing API functions, f_write(), f_sync(), +/ f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree() +/ and optional writing functions as well. */ + + +#define FF_FS_MINIMIZE 0 +/* This option defines minimization level to remove some basic API functions. +/ +/ 0: All basic functions are enabled. +/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename() +/ are removed. +/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1. +/ 3: f_lseek() function is removed in addition to 2. */ + + +#define FF_USE_STRFUNC 0 +/* This option switches string functions, f_gets(), f_putc(), f_puts() and +/ f_printf(). +/ +/ 0: Disable string functions. +/ 1: Enable without LF-CRLF conversion. +/ 2: Enable with LF-CRLF conversion. */ + + +#define FF_USE_FIND 0 +/* This option switches filtered directory read functions, f_findfirst() and +/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */ + + +#define FF_USE_MKFS 1 +/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */ + + +#define FF_USE_FASTSEEK 0 +/* This option switches fast seek function. (0:Disable or 1:Enable) */ + + +#define FF_USE_EXPAND 0 +/* This option switches f_expand function. (0:Disable or 1:Enable) */ + + +#define FF_USE_CHMOD 0 +/* This option switches attribute manipulation functions, f_chmod() and f_utime(). +/ (0:Disable or 1:Enable) Also _FS_READONLY needs to be 0 to enable this option. */ + + +#define FF_USE_LABEL 1 +/* This option switches volume label functions, f_getlabel() and f_setlabel(). +/ (0:Disable or 1:Enable) */ + + +#define FF_USE_FORWARD 0 +/* This option switches f_forward() function. (0:Disable or 1:Enable) +/ To enable it, also _FS_TINY need to be 1. */ + + +/*---------------------------------------------------------------------------/ +/ Locale and Namespace Configurations +/---------------------------------------------------------------------------*/ + +#define FF_CODE_PAGE 850 +/* This option specifies the OEM code page to be used on the target system. +/ Incorrect setting of the code page can cause a file open failure. +/ +/ 1 - ASCII (No extended character. Non-LFN cfg. only) +/ 437 - U.S. +/ 720 - Arabic +/ 737 - Greek +/ 771 - KBL +/ 775 - Baltic +/ 850 - Latin 1 +/ 852 - Latin 2 +/ 855 - Cyrillic +/ 857 - Turkish +/ 860 - Portuguese +/ 861 - Icelandic +/ 862 - Hebrew +/ 863 - Canadian French +/ 864 - Arabic +/ 865 - Nordic +/ 866 - Russian +/ 869 - Greek 2 +/ 932 - Japanese (DBCS) +/ 936 - Simplified Chinese (DBCS) +/ 949 - Korean (DBCS) +/ 950 - Traditional Chinese (DBCS) +*/ + + +#define FF_USE_LFN 2 +#define FF_MAX_LFN 255 +/* The _USE_LFN switches the support of long file name (LFN). +/ +/ 0: Disable support of LFN. _MAX_LFN has no effect. +/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe. +/ 2: Enable LFN with dynamic working buffer on the STACK. +/ 3: Enable LFN with dynamic working buffer on the HEAP. +/ +/ To enable the LFN, Unicode handling functions (option/unicode.c) must be added +/ to the project. The working buffer occupies (_MAX_LFN + 1) * 2 bytes and +/ additional 608 bytes at exFAT enabled. _MAX_LFN can be in range from 12 to 255. +/ It should be set 255 to support full featured LFN operations. +/ When use stack for the working buffer, take care on stack overflow. When use heap +/ memory for the working buffer, memory management functions, ff_memalloc() and +/ ff_memfree(), must be added to the project. */ + + +#define FF_LFN_UNICODE 0 +/* This option switches character encoding on the API. (0:ANSI/OEM or 1:Unicode) +/ To use Unicode string for the path name, enable LFN and set _LFN_UNICODE = 1. +/ This option also affects behavior of string I/O functions. */ + + +#define FF_STRF_ENCODE 3 +/* When _LFN_UNICODE == 1, this option selects the character encoding on the file to +/ be read/written via string I/O functions, f_gets(), f_putc(), f_puts and f_printf(). +/ +/ 0: ANSI/OEM +/ 1: UTF-16LE +/ 2: UTF-16BE +/ 3: UTF-8 +/ +/ This option has no effect when _LFN_UNICODE == 0. */ + + +#define FF_FS_RPATH 0 +/* This option configures support of relative path. +/ +/ 0: Disable relative path and remove related functions. +/ 1: Enable relative path. f_chdir() and f_chdrive() are available. +/ 2: f_getcwd() function is available in addition to 1. +*/ + + +/*---------------------------------------------------------------------------/ +/ Drive/Volume Configurations +/---------------------------------------------------------------------------*/ + +#define FF_VOLUMES 2 +/* Number of volumes (logical drives) to be used. */ + + +#define FF_STR_VOLUME_ID 0 +#define FF_VOLUME_STRS "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3" +/* _STR_VOLUME_ID switches string support of volume ID. +/ When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive +/ number in the path name. _VOLUME_STRS defines the drive ID strings for each +/ logical drives. Number of items must be equal to _VOLUMES. Valid characters for +/ the drive ID strings are: A-Z and 0-9. */ + + +#define FF_MULTI_PARTITION 1 +/* This option switches support of multi-partition on a physical drive. +/ By default (0), each logical drive number is bound to the same physical drive +/ number and only an FAT volume found on the physical drive will be mounted. +/ When multi-partition is enabled (1), each logical drive number can be bound to +/ arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk() +/ funciton will be available. */ + + +#define FF_MIN_SS SDMMC_BLOCK_SIZE +#define FF_MAX_SS SDMMC_BLOCK_SIZE +/* These options configure the range of sector size to be supported. (512, 1024, +/ 2048 or 4096) Always set both 512 for most systems, all type of memory cards and +/ harddisk. But a larger value may be required for on-board flash memory and some +/ type of optical media. When _MAX_SS is larger than _MIN_SS, FatFs is configured +/ to variable sector size and GET_SECTOR_SIZE command must be implemented to the +/ disk_ioctl() function. */ + + +#define FF_USE_TRIM 0 +/* This option switches support of ATA-TRIM. (0:Disable or 1:Enable) +/ To enable Trim function, also CTRL_TRIM command should be implemented to the +/ disk_ioctl() function. */ + + +#define FF_FS_NOFSINFO 0 +/* If you need to know correct free space on the FAT32 volume, set bit 0 of this +/ option, and f_getfree() function at first time after volume mount will force +/ a full FAT scan. Bit 1 controls the use of last allocated cluster number. +/ +/ bit0=0: Use free cluster count in the FSINFO if available. +/ bit0=1: Do not trust free cluster count in the FSINFO. +/ bit1=0: Use last allocated cluster number in the FSINFO if available. +/ bit1=1: Do not trust last allocated cluster number in the FSINFO. +*/ + + + +/*---------------------------------------------------------------------------/ +/ System Configurations +/---------------------------------------------------------------------------*/ + +#define FF_FS_TINY 0 +/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny) +/ At the tiny configuration, size of the file object (FIL) is reduced _MAX_SS bytes. +/ Instead of private sector buffer eliminated from the file object, common sector +/ buffer in the file system object (FATFS) is used for the file data transfer. */ + + +#define FF_FS_EXFAT 1 +/* This option switches support of exFAT file system in addition to the traditional +/ FAT file system. (0:Disable or 1:Enable) To enable exFAT, also LFN must be enabled. +/ Note that enabling exFAT discards C89 compatibility. */ + + +#define FF_FS_NORTC 1 +#define FF_NORTC_MON 1 +#define FF_NORTC_MDAY 1 +#define FF_NORTC_YEAR 2018 +/* The option _FS_NORTC switches timestamp functiton. If the system does not have +/ any RTC function or valid timestamp is not needed, set _FS_NORTC = 1 to disable +/ the timestamp function. All objects modified by FatFs will have a fixed timestamp +/ defined by _NORTC_MON, _NORTC_MDAY and _NORTC_YEAR in local time. +/ To enable timestamp function (_FS_NORTC = 0), get_fattime() function need to be +/ added to the project to get current time form real-time clock. _NORTC_MON, +/ _NORTC_MDAY and _NORTC_YEAR have no effect. +/ These options have no effect at read-only configuration (_FS_READONLY = 1). */ + + +#define FF_FS_LOCK 0 +/* The option _FS_LOCK switches file lock function to control duplicated file open +/ and illegal operation to open objects. This option must be 0 when _FS_READONLY +/ is 1. +/ +/ 0: Disable file lock function. To avoid volume corruption, application program +/ should avoid illegal open, remove and rename to the open objects. +/ >0: Enable file lock function. The value defines how many files/sub-directories +/ can be opened simultaneously under file lock control. Note that the file +/ lock control is independent of re-entrancy. */ + + +#define FF_FS_REENTRANT 0 +#define FF_FS_TIMEOUT MS2ST(1000) +#define FF_SYNC_t semaphore_t* +/* The option _FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs +/ module itself. Note that regardless of this option, file access to different +/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs() +/ and f_fdisk() function, are always not re-entrant. Only file/directory access +/ to the same volume is under control of this function. +/ +/ 0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect. +/ 1: Enable re-entrancy. Also user provided synchronization handlers, +/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj() +/ function, must be added to the project. Samples are available in +/ option/syscall.c. +/ +/ The _FS_TIMEOUT defines timeout period in unit of time tick. +/ The _SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*, +/ SemaphoreHandle_t and etc.. A header file for O/S definitions needs to be +/ included somewhere in the scope of ff.c. */ + + +/*--- End of configuration options ---*/ diff --git a/testhal/ATSAMA5D2/SDMMC/main.c b/testhal/ATSAMA5D2/SDMMC/main.c index 551b4dd65..b424ce152 100644 --- a/testhal/ATSAMA5D2/SDMMC/main.c +++ b/testhal/ATSAMA5D2/SDMMC/main.c @@ -18,7 +18,15 @@ #include "hal.h" #include "sama_sdmmc_lld.h" #include "chprintf.h" +#include "fat32test.h" +#include "reledgetest.h" +//----------- DEMO CONFIGURATION ------------------------ +//0 (SLOT0) or 1 (SLOT1) +#define DEMO_SLOT 0 +//1 for FFLib, 0 for Reliance +#define DEMO_FAT 1 +//---------------------------------------------------------- #define BLOCK_CNT_MAX 32u #define DMADL_CNT_MAX 64u @@ -26,16 +34,13 @@ -const char test_file_path[] = "test.txt"; - CACHE_ALIGNED uint8_t data_buf[BLOCK_CNT_MAX * 512ul]; CACHE_ALIGNED static uint32_t dma_table[DMADL_CNT_MAX * SDMMC_DMADL_SIZE]; CACHE_ALIGNED uint8_t sdmmcbuffer[ROUND_UP_MULT(SDMMC_BUFFER_SIZE, L1_CACHE_BYTES)]; -static FATFS fs_header; -static FIL f_header; + BaseSequentialStream * ts; @@ -56,9 +61,17 @@ static THD_FUNCTION(Thread1, arg) { } } - - -static const SamaSDMMCConfig sdmmc_slot1_cfg = { +#if DEMO_SLOT == 0 +static const SamaSDMMCConfig sdmmc_cfg = { + SDMMC_SLOT0, + sdmmcbuffer, + data_buf, + sizeof(data_buf), + dma_table, + DMADL_CNT_MAX +}; +#else +static const SamaSDMMCConfig sdmmc_cfg = { SDMMC_SLOT1, sdmmcbuffer, data_buf, @@ -66,10 +79,8 @@ static const SamaSDMMCConfig sdmmc_slot1_cfg = { dma_table, DMADL_CNT_MAX }; +#endif -void getdir(SdmmcDriver *sdmmcp); -void writefile(SdmmcDriver *sdmmcp); -void readfile(SdmmcDriver *sdmmcp); /* * Application entry point. */ @@ -98,23 +109,26 @@ int main(void) { sdmmcInit(); - sdmmcStart(&SDMMCD1, &sdmmc_slot1_cfg); + sdmmcStart(&SDMMCD1, &sdmmc_cfg); if (SDMMCD1.state != MCID_INIT_ERROR) { - chprintf(ts,"starting MMC Demo\n\r"); + chprintf(ts,"starting MMC Demo with slot %d\n\r",SDMMCD1.config->slot_id); if (sdmmcOpenDevice(&SDMMCD1)) { - //sdmmcShowDeviceInfo(&SDMMCD1); - if ( sdmmcMountVolume(&SDMMCD1,&fs_header) ) { - writefile(&SDMMCD1); - chprintf(ts,"reading dir:\n\r"); - getdir(&SDMMCD1); - readfile(&SDMMCD1); +#if DEMO_FAT == 1 + fat32test_demo(); +#else + relianceedge_demo(); +#endif + if (SDMMCD1.config->slot_id == SDMMC_SLOT1) + { + chprintf(ts,"remove card to finish demo\n\r"); + sdmmcCloseDevice(&SDMMCD1); } - sdmmcCloseDevice(&SDMMCD1); + } @@ -140,106 +154,13 @@ int main(void) { bool sdmmcGetInstance(uint8_t index, SdmmcDriver **sdmmcp) { - if (index == SDMMCD1.config->slot_id) { - *sdmmcp = &SDMMCD1; - return true; - } - return false; -} + (void)index; -void writefile(SdmmcDriver *sdmmcp) -{ - const TCHAR drive_path[] = { '0' + sdmmcp->config->slot_id, ':', '\0' }; - TCHAR file_path[sizeof(drive_path) + sizeof(test_file_path)]; - FRESULT res; - UINT len; - uint8_t buffer[]={ 0x57,0x65,0x6C,0x63,0x6F, - 0x6D,0x65,0x20,0x74,0x6F, - 0x20,0x43,0x68,0x69,0x62, - 0x69,0x4F,0x53,0x21}; - - - strcpy(file_path, drive_path); - strcat(file_path, test_file_path); - - chprintf(ts,"Creating new file ... "); - res = f_open(&f_header, file_path, FA_WRITE | FA_CREATE_ALWAYS); - if (res == FR_OK) { - chprintf(ts,"OK\r\n"); - res = f_write(&f_header, buffer, 19, &len); - if (res == FR_OK) { - chprintf(ts,"written %d bytes\n\r", len); - } - } - else - { - chprintf(ts,"Failed error %d\n\r", res); - } - f_close(&f_header); + *sdmmcp = &SDMMCD1; + return true; } -void readfile(SdmmcDriver *sdmmcp) -{ - const TCHAR drive_path[] = { '0' + sdmmcp->config->slot_id, ':', '\0' }; - TCHAR file_path[sizeof(drive_path) + sizeof(test_file_path)]; - FRESULT res; - UINT len; - uint8_t buffer[19]; - UINT i; - - strcpy(file_path, drive_path); - strcat(file_path, test_file_path); - - chprintf(ts,"Reading back the new file ... "); - res = f_open(&f_header, file_path, FA_OPEN_EXISTING | FA_READ); - if (res == FR_OK) { - chprintf(ts,"OK\r\n"); - res = f_read(&f_header, buffer, 19, &len); - if (res == FR_OK) { - chprintf(ts,"read %d bytes\n\r", len); - for (i=0;iconfig->slot_id, ':', '\0' }; - DIR dir = { .sect = 0 }; - FILINFO fno = { 0 }; - FRESULT res; - bool is_dir; - - res = f_opendir(&dir, drive_path); - if (res != FR_OK) { - chprintf(ts,"Failed to open dir, error %d\n\r", res); - return; - } - chprintf(ts,"files in the root directory:\n\r"); - for (;;) { - res = f_readdir(&dir, &fno); - if (res != FR_OK) { - chprintf(ts,"cannot read dir, error (%d)\n\r", res); - break; - } - if (fno.fname[0] == '\0') - break; - is_dir = fno.fattrib & AM_DIR ? true : false; - chprintf(ts," %s%s%c\n\r", is_dir ? "[" : "", fno.fname, - is_dir ? ']' : ' '); - } - - res = f_closedir(&dir); -} diff --git a/testhal/ATSAMA5D2/SDMMC/mcuconf.h b/testhal/ATSAMA5D2/SDMMC/mcuconf.h index d1e0fe8d6..5e2eeefe3 100644 --- a/testhal/ATSAMA5D2/SDMMC/mcuconf.h +++ b/testhal/ATSAMA5D2/SDMMC/mcuconf.h @@ -23,7 +23,7 @@ * HAL driver system settings. */ #define SAMA_HAL_IS_SECURE TRUE -#define SAMA_NO_INIT FALSE +#define SAMA_NO_INIT TRUE #define SAMA_MOSCRC_ENABLED FALSE #define SAMA_MOSCXT_ENABLED TRUE #define SAMA_MOSC_SEL SAMA_MOSC_MOSCXT diff --git a/testhal/ATSAMA5D2/SDMMC/readme.txt b/testhal/ATSAMA5D2/SDMMC/readme.txt index cc6e568f6..49423b98c 100644 --- a/testhal/ATSAMA5D2/SDMMC/readme.txt +++ b/testhal/ATSAMA5D2/SDMMC/readme.txt @@ -7,6 +7,7 @@ The demo targets a generic ARM Cortex-A5 device without HAL support. ** The Demo ** +Testing FF and Reliance Edge Libraries ** Build Procedure ** diff --git a/testhal/ATSAMA5D2/SDMMC/redconf.c b/testhal/ATSAMA5D2/SDMMC/redconf.c new file mode 100644 index 000000000..7c0647332 --- /dev/null +++ b/testhal/ATSAMA5D2/SDMMC/redconf.c @@ -0,0 +1,36 @@ +/* THIS FILE WAS GENERATED BY THE DATALIGHT RELIANCE EDGE CONFIGURATION + UTILITY. DO NOT MODIFY. + + Generated by configuration utility version 2.02 +*/ +/** @file +*/ + +#include "hal.h" + +#if (HAL_USE_SDMMC == TRUE) +#include "sama_sdmmc_lld.h" +#if SDMMC_USE_RELEDGE_LIB == 1 +#include +#include +#include +#include +#include + + +const VOLCONF gaRedVolConf[REDCONF_VOLUME_COUNT] = +{ + { + SDMMC_BLOCK_SIZE, //ulSectorSize + 1048576U, //ullSectorCount + 0U, //ullSectorOffset + false, //fAtomicSectorWrite + 1024U, //ulInodeCount + 2U, //bBlockIoRetries + "CHIBIVOL" + } +}; + +#endif +#endif + diff --git a/testhal/ATSAMA5D2/SDMMC/redconf.h b/testhal/ATSAMA5D2/SDMMC/redconf.h new file mode 100644 index 000000000..ab51742f4 --- /dev/null +++ b/testhal/ATSAMA5D2/SDMMC/redconf.h @@ -0,0 +1,114 @@ +/* THIS FILE WAS GENERATED BY THE DATALIGHT RELIANCE EDGE CONFIGURATION + UTILITY. DO NOT MODIFY. + + Generated by configuration utility version 2.02 +*/ +/** @file +*/ +#ifndef REDCONF_H +#define REDCONF_H + + +#include + +#define REDCONF_READ_ONLY 0 + +#define REDCONF_API_POSIX 1 + +#define REDCONF_API_FSE 0 + +#define REDCONF_API_POSIX_FORMAT 1 + +#define REDCONF_API_POSIX_LINK 1 + +#define REDCONF_API_POSIX_UNLINK 1 + +#define REDCONF_API_POSIX_MKDIR 1 + +#define REDCONF_API_POSIX_RMDIR 1 + +#define REDCONF_API_POSIX_RENAME 1 + +#define REDCONF_RENAME_ATOMIC 1 + +#define REDCONF_API_POSIX_FTRUNCATE 1 + +#define REDCONF_API_POSIX_READDIR 1 + +#define REDCONF_API_POSIX_CWD 0 + +#define REDCONF_NAME_MAX 12U + +#define REDCONF_PATH_SEPARATOR '/' + +#define REDCONF_TASK_COUNT 10U + +#define REDCONF_HANDLE_COUNT 10U + +#define REDCONF_API_FSE_FORMAT 0 + +#define REDCONF_API_FSE_TRUNCATE 0 + +#define REDCONF_API_FSE_TRANSMASKGET 0 + +#define REDCONF_API_FSE_TRANSMASKSET 0 + +#define REDCONF_OUTPUT 1 + +#define REDCONF_ASSERTS 1 + +#define REDCONF_BLOCK_SIZE 512U + +#define REDCONF_VOLUME_COUNT 1U + +#define REDCONF_ENDIAN_BIG 0 + +#define REDCONF_ALIGNMENT_SIZE 4U + +#define REDCONF_CRC_ALGORITHM CRC_SLICEBY8 + +#define REDCONF_INODE_BLOCKS 1 + +#define REDCONF_INODE_TIMESTAMPS 1 + +#define REDCONF_ATIME 0 + +#define REDCONF_DIRECT_POINTERS 4U + +#define REDCONF_INDIRECT_POINTERS 32U + +#define REDCONF_BUFFER_COUNT 12U + +#define RedMemCpyUnchecked memcpy + +#define RedMemMoveUnchecked memmove + +#define RedMemSetUnchecked memset + +#define RedMemCmpUnchecked memcmp + +#define RedStrLenUnchecked strlen + +#define RedStrCmpUnchecked strcmp + +#define RedStrNCmpUnchecked strncmp + +#define RedStrNCpyUnchecked strncpy + +#define REDCONF_TRANSACT_DEFAULT (( RED_TRANSACT_CREAT | RED_TRANSACT_MKDIR | RED_TRANSACT_RENAME | RED_TRANSACT_LINK | RED_TRANSACT_UNLINK | RED_TRANSACT_FSYNC | RED_TRANSACT_CLOSE | RED_TRANSACT_VOLFULL | RED_TRANSACT_UMOUNT ) & RED_TRANSACT_MASK) + +#define REDCONF_IMAP_INLINE 0 + +#define REDCONF_IMAP_EXTERNAL 1 + +#define REDCONF_DISCARDS 0 + +#define REDCONF_IMAGE_BUILDER 0 + +#define REDCONF_CHECKER 0 + +#define RED_CONFIG_UTILITY_VERSION 0x2000200U + +#define RED_CONFIG_MINCOMPAT_VER 0x1000200U + +#endif diff --git a/testhal/ATSAMA5D2/SDMMC/reledgetest.c b/testhal/ATSAMA5D2/SDMMC/reledgetest.c new file mode 100644 index 000000000..a741ff83c --- /dev/null +++ b/testhal/ATSAMA5D2/SDMMC/reledgetest.c @@ -0,0 +1,268 @@ +/* + ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ +#include +#include +#include "ch.h" +#include "hal.h" +#include "sama_sdmmc_lld.h" + +#if SDMMC_USE_RELEDGE_LIB == 1 +#include "chprintf.h" +#include +#include +#include +#include +#include +#include +#include + +static int32_t format(uint8_t volnum); +static void readfiles(void); +static void writefiles(uint8_t volnum); + +#define fsRAM_BUFFER_SIZE 30 +static char cRAMBuffer[ fsRAM_BUFFER_SIZE ]; + +static const char *pcDirectory1 = "/DIR1", *pcDirectory2 = "/DIR1/DIR2"; +extern BaseSequentialStream * ts; +extern const VOLCONF gaRedVolConf[REDCONF_VOLUME_COUNT]; + +void relianceedge_demo(void) +{ + int32_t ret; + int volnum = 0; + const char *pszVolume = gaRedVolConf[volnum].pszPathPrefix; + + chprintf(ts,"Init Reliance Edge FS\r\n" ); + ret = red_init(); + + chprintf(ts,"Start formatting fs ... " ); + ret = format(volnum); + + if ( ret == 0 ) + { + chprintf(ts,"OK , mounting volume .." ); + + ret = red_mount(pszVolume); + if ( ret == 0 ) + { + chprintf(ts,"OK\r\n writing files ..\r\n" ); + writefiles(volnum); + chprintf(ts,"OK\r\n reading files ..\r\n" ); + readfiles(); + } + } + else + { + chprintf(ts,"FAILED! \r\n" ); + } +} + + + +static void writefiles(uint8_t volnum) +{ + uint32_t i, j; + char path[ 64 ]; + const uint32_t filen = 5; + + uint32_t ulEventMask; + int32_t written, filedescr, status; + int iByte; + + const char *pszVolume = gaRedVolConf[volnum].pszPathPrefix; + /* Save the current transaction point settings. */ + status = red_gettransmask( pszVolume, &ulEventMask ); + osalDbgCheck( status == 0 ); + + /* Disable automatic transaction points so that all of the files can be + created in one atomic operation. */ + status = red_settransmask( pszVolume, RED_TRANSACT_MANUAL ); + osalDbgCheck( status == 0 ); + + /* Create filen files. Each created file will be + ( i * fsRAM_BUFFER_SIZE ) bytes in length, and filled + with a different repeating character. */ + for( i = 1; i <= filen; i++ ) + { + /* Generate a file name. */ + sprintf( path, "/root%03d.txt", (int)i ); + + /* Print out the file name and the directory into which the file is + being written. */ + chprintf(ts,"Creating file %s\r\n", path ); + + /* Open the file, creating the file if it does not already exist. */ + filedescr = red_open( path, RED_O_CREAT|RED_O_TRUNC|RED_O_WRONLY ); + osalDbgCheck( filedescr != -1 ); + + /* Fill the RAM buffer with data that will be written to the file. This + is just a repeating ascii character that indicates the file number. */ + memset( cRAMBuffer, ( int ) ( '0' + i ), fsRAM_BUFFER_SIZE ); + + /* Write the RAM buffer to the opened file a number of times. The + number of times the RAM buffer is written to the file depends on the + file number, so the length of each created file will be different. */ + for( j = 0; j < i; j++ ) + { + written = red_write( filedescr, cRAMBuffer, fsRAM_BUFFER_SIZE ); + osalDbgCheck( written == fsRAM_BUFFER_SIZE ); + } + + /* Close the file so another file can be created. */ + status = red_close( filedescr ); + osalDbgCheck( status == 0 ); + } + + /* Commit a transaction point, atomically adding the set of files to the + transacted state. */ + status = red_transact( pszVolume ); + osalDbgCheck( status == 0 ); + + /* Create a sub directory. */ + chprintf(ts,"Creating directory %s\r\n", pcDirectory1 ); + + status = red_mkdir( pcDirectory1 ); + osalDbgCheck( status == 0 ); + + /* Create a subdirectory in the new directory. */ + chprintf(ts, "Creating directory %s\r\n", pcDirectory2 ); + + status = red_mkdir( pcDirectory2 ); + osalDbgCheck( status == 0 ); + + /* Generate the file name. */ + sprintf( path, "%s/file.txt", pcDirectory2 ); + + /* Print out the file name and the directory into which the file is being + written. */ + chprintf(ts, "Writing file %s\r\n", path ); + + filedescr = red_open( path, RED_O_CREAT|RED_O_TRUNC|RED_O_WRONLY ); + + /* Write the file. It is filled with incrementing ascii characters starting + from '0'. */ + for( iByte = 0; iByte < fsRAM_BUFFER_SIZE; iByte++ ) + { + cRAMBuffer[ iByte ] = ( char ) ( ( int ) '0' + iByte ); + } + + written = red_write( filedescr, cRAMBuffer, fsRAM_BUFFER_SIZE ); + osalDbgCheck( written == fsRAM_BUFFER_SIZE ); + + /* Finished so close the file. */ + status = red_close( filedescr ); + osalDbgCheck( status == 0 ); + + /* Commit a transaction point, atomically adding the set of files and + directories to the transacted state. */ + status = red_transact( pszVolume ); + osalDbgCheck( status == 0 ); + + /* Restore previous transaction point settings. */ + status = red_settransmask( pszVolume, ulEventMask ); + osalDbgCheck( status == 0 ); +} + +static void readfiles(void) +{ + uint32_t i, j; + char path[ 64 ]; + const uint32_t filen = 5; + long lChar; + int32_t lBytesRead, filedescr, status; + int iByte; + + + /* Read back the files that were created by prvCreateDemoFiles(). */ + for( i = 1; i <= filen; i++ ) + { + /* Generate the file name. */ + sprintf( path, "/root%03d.txt",(int) i ); + + /* Print out the file name and the directory from which the file is + being read. */ + chprintf(ts,"Reading file %s\r\n", path ); + + /* Open the file for reading. */ + filedescr = red_open( path, RED_O_RDONLY ); + osalDbgCheck( filedescr != -1 ); + + /* Read the file into the RAM buffer, checking the file contents are as + expected. The size of the file depends on the file number. */ + for( j = 0; j < i; j++ ) + { + /* Start with the RAM buffer clear. */ + memset( cRAMBuffer, 0x00, fsRAM_BUFFER_SIZE ); + + lBytesRead = red_read( filedescr, cRAMBuffer, fsRAM_BUFFER_SIZE ); + osalDbgCheck( lBytesRead == fsRAM_BUFFER_SIZE ); + + /* Check the RAM buffer is filled with the expected data. Each + file contains a different repeating ascii character that indicates + the number of the file. */ + for( lChar = 0; lChar < fsRAM_BUFFER_SIZE; lChar++ ) + { + osalDbgCheck( cRAMBuffer[ lChar ] == ( '0' + ( char ) i ) ); + } + } + + /* Close the file. */ + status = red_close( filedescr ); + osalDbgCheck( status == 0 ); + } + + /* Generate the file name. */ + sprintf( path, "%s/file.txt", pcDirectory2 ); + + /* Print out the file name and the directory from which the file is being + read. */ + chprintf(ts, "Reading file %s\r\n", path ); + + /* This time the file is opened for reading. */ + filedescr = red_open( path, RED_O_RDONLY ); + osalDbgCheck( filedescr != -1 ); + + /* Read the file. */ + lBytesRead = red_read( filedescr, cRAMBuffer, fsRAM_BUFFER_SIZE ); + osalDbgCheck( lBytesRead == fsRAM_BUFFER_SIZE ); + + /* Verify the file 1 byte at a time. */ + for( iByte = 0; iByte < fsRAM_BUFFER_SIZE; iByte++ ) + { + osalDbgCheck( cRAMBuffer[ iByte ] == ( char ) ( ( int ) '0' + iByte ) ); + } + + /* Finished so close the file. */ + status = red_close( filedescr ); + osalDbgCheck( status == 0 ); + +} + + +static int32_t format(uint8_t volnum) +{ + int32_t ret=-1; +#if REDCONF_API_POSIX_FORMAT == 1 + const char *pszVolume = gaRedVolConf[volnum].pszPathPrefix; + ret = red_format(pszVolume); + +#endif + return ret; +} + +#endif + diff --git a/testhal/ATSAMA5D2/SDMMC/reledgetest.h b/testhal/ATSAMA5D2/SDMMC/reledgetest.h new file mode 100644 index 000000000..1e5ee7cc8 --- /dev/null +++ b/testhal/ATSAMA5D2/SDMMC/reledgetest.h @@ -0,0 +1,8 @@ +#ifndef RELEDGETEST_H_ +#define RELEDGETEST_H_ + + + +extern void relianceedge_demo(void); + +#endif /* RELEDGETEST_H_ */ -- cgit v1.2.3