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/fat32test.c | 287 ++++++++++++++++++++++++++++++++++++ 1 file changed, 287 insertions(+) create mode 100644 testhal/ATSAMA5D2/SDMMC/fat32test.c (limited to 'testhal/ATSAMA5D2/SDMMC/fat32test.c') 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; +} -- cgit v1.2.3