diff options
author | areviu <areviu.info@gmail.com> | 2018-02-01 18:49:41 +0000 |
---|---|---|
committer | areviu <areviu.info@gmail.com> | 2018-02-01 18:49:41 +0000 |
commit | ba9b7671a05e8476e66ec5fd779e29d55040ce97 (patch) | |
tree | bcdc7b2843f4e8387ceb3665f883fc1d966118ea /testhal/ATSAMA5D2/SDMMC | |
parent | cc6694372669d387b54a1bdfb76720d58d8824d1 (diff) | |
download | ChibiOS-ba9b7671a05e8476e66ec5fd779e29d55040ce97.tar.gz ChibiOS-ba9b7671a05e8476e66ec5fd779e29d55040ce97.tar.bz2 ChibiOS-ba9b7671a05e8476e66ec5fd779e29d55040ce97.zip |
update sdmmc test hal project with read and write to file
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11419 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'testhal/ATSAMA5D2/SDMMC')
-rw-r--r-- | testhal/ATSAMA5D2/SDMMC/main.c | 78 | ||||
-rw-r--r-- | testhal/ATSAMA5D2/SDMMC/mcuconf.h | 2 |
2 files changed, 77 insertions, 3 deletions
diff --git a/testhal/ATSAMA5D2/SDMMC/main.c b/testhal/ATSAMA5D2/SDMMC/main.c index 48cb01548..551b4dd65 100644 --- a/testhal/ATSAMA5D2/SDMMC/main.c +++ b/testhal/ATSAMA5D2/SDMMC/main.c @@ -25,14 +25,17 @@ #define BLOCK_CNT 3u
+
+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(EXT_SIZE + SSR_SIZE + SCR_SIZE + SB1_SIZE + SB2_SIZE, L1_CACHE_BYTES)];
+CACHE_ALIGNED uint8_t sdmmcbuffer[ROUND_UP_MULT(SDMMC_BUFFER_SIZE, L1_CACHE_BYTES)];
static FATFS fs_header;
-//static FIL f_header;
+static FIL f_header;
BaseSequentialStream * ts;
@@ -65,6 +68,8 @@ static const SamaSDMMCConfig sdmmc_slot1_cfg = { };
void getdir(SdmmcDriver *sdmmcp);
+void writefile(SdmmcDriver *sdmmcp);
+void readfile(SdmmcDriver *sdmmcp);
/*
* Application entry point.
*/
@@ -103,8 +108,11 @@ int main(void) { //sdmmcShowDeviceInfo(&SDMMCD1);
if ( sdmmcMountVolume(&SDMMCD1,&fs_header) ) {
- chprintf(ts,"reading files:\n\r");
+ writefile(&SDMMCD1);
+ chprintf(ts,"reading dir:\n\r");
getdir(&SDMMCD1);
+ readfile(&SDMMCD1);
+
}
sdmmcCloseDevice(&SDMMCD1);
}
@@ -139,6 +147,70 @@ bool sdmmcGetInstance(uint8_t index, SdmmcDriver **sdmmcp) return false;
}
+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);
+
+}
+
+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;i<len;i++) {
+ chprintf(ts,"%c", buffer[i]);
+ }
+ }
+ }
+ else
+ {
+ chprintf(ts,"Failed error %d\n\r", res);
+ }
+ f_close(&f_header);
+
+}
+
void getdir(SdmmcDriver *sdmmcp)
{
const TCHAR drive_path[] = { '0' + sdmmcp->config->slot_id, ':', '\0' };
diff --git a/testhal/ATSAMA5D2/SDMMC/mcuconf.h b/testhal/ATSAMA5D2/SDMMC/mcuconf.h index b9173531f..d1e0fe8d6 100644 --- a/testhal/ATSAMA5D2/SDMMC/mcuconf.h +++ b/testhal/ATSAMA5D2/SDMMC/mcuconf.h @@ -82,10 +82,12 @@ /*
* SECUMOD
*/
+#define HAL_USE_SECUMOD FALSE
#define SAMA_ST_USE_PIT TRUE
#define SAMA_ST_USE_TC0 FALSE
#define SAMA_ST_USE_TC1 FALSE
+
/*
* TC driver system settings.
*/
|