aboutsummaryrefslogtreecommitdiffstats
path: root/demos/ARMCM3-STM32F103-FATFS-GCC
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-11-15 08:52:17 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-11-15 08:52:17 +0000
commit84cf9ce9ffa3d538b367f74c8206b8ef894d466f (patch)
treeb3931fee4361ec810cae4492fd4cca42bae6b037 /demos/ARMCM3-STM32F103-FATFS-GCC
parent55252f65b2a444692ff1b2673b32ec1cf2b205c0 (diff)
downloadChibiOS-84cf9ce9ffa3d538b367f74c8206b8ef894d466f.tar.gz
ChibiOS-84cf9ce9ffa3d538b367f74c8206b8ef894d466f.tar.bz2
ChibiOS-84cf9ce9ffa3d538b367f74c8206b8ef894d466f.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1299 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'demos/ARMCM3-STM32F103-FATFS-GCC')
-rw-r--r--demos/ARMCM3-STM32F103-FATFS-GCC/Makefile3
-rw-r--r--demos/ARMCM3-STM32F103-FATFS-GCC/main.c132
-rw-r--r--demos/ARMCM3-STM32F103-FATFS-GCC/readme.txt9
3 files changed, 96 insertions, 48 deletions
diff --git a/demos/ARMCM3-STM32F103-FATFS-GCC/Makefile b/demos/ARMCM3-STM32F103-FATFS-GCC/Makefile
index afb044c49..b84adf3a5 100644
--- a/demos/ARMCM3-STM32F103-FATFS-GCC/Makefile
+++ b/demos/ARMCM3-STM32F103-FATFS-GCC/Makefile
@@ -77,6 +77,7 @@ CSRC = ${PORTSRC} \
${CHIBIOS}/os/io/platforms/STM32/spi_lld.c \
${CHIBIOS}/os/io/platforms/STM32/stm32_dma.c \
${CHIBIOS}/os/various/evtimer.c \
+ ${CHIBIOS}/os/various/syscalls.c \
board.c main.c
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
@@ -158,7 +159,7 @@ CPPWARN = -Wall -Wextra
#
# List all default C defines here, like -D_DEBUG=1
-DDEFS =
+DDEFS = -DSTDOUT_SD=SD2 -DSTDIN_SD=SD2
# List all default ASM defines here, like -D_DEBUG=1
DADEFS =
diff --git a/demos/ARMCM3-STM32F103-FATFS-GCC/main.c b/demos/ARMCM3-STM32F103-FATFS-GCC/main.c
index 5fd6737a6..2ddf02b3f 100644
--- a/demos/ARMCM3-STM32F103-FATFS-GCC/main.c
+++ b/demos/ARMCM3-STM32F103-FATFS-GCC/main.c
@@ -27,52 +27,41 @@
#include <ff.h>
-#include "board.h"
+#include <stdio.h>
+#include <string.h>
-/*
- * Maximum speed SPI configuration (18MHz, CPHA=0, CPOL=0, MSb first).
- */
-static SPIConfig hs_spicfg = {
- IOPORT2, GPIOB_SPI2NSS, 0
-};
+#include "board.h"
-/*
- * Low speed SPI configuration (281.250KHz, CPHA=0, CPOL=0, MSb first).
+/**
+ * @brief FS object.
*/
-static SPIConfig ls_spicfg = {
- IOPORT2, GPIOB_SPI2NSS, SPI_CR1_BR_2 | SPI_CR1_BR_1
-};
+FATFS MMC_FS;
-/*
- * MMC driver instance.
+/**
+ * MMC driver instance.
*/
MMCDriver MMCD1;
-/*
- * MMC configuration (empty).
- */
-static const MMCConfig mmc_cfg = {};
+/* FS mounted and ready.*/
+static bool_t fs_ready = FALSE;
-/*
- * Card insertion verification.
- */
-static bool_t mmc_is_inserted(void) {
+/* Maximum speed SPI configuration (18MHz, CPHA=0, CPOL=0, MSb first).*/
+static SPIConfig hs_spicfg = {IOPORT2, GPIOB_SPI2NSS, 0};
- return palReadPad(IOPORT3, GPIOC_MMCCP);
-}
+/* Low speed SPI configuration (281.250KHz, CPHA=0, CPOL=0, MSb first).*/
+static SPIConfig ls_spicfg = {IOPORT2, GPIOB_SPI2NSS, SPI_CR1_BR_2 | SPI_CR1_BR_1};
-/*
- * Card protection verification.
- */
-static bool_t mmc_is_protected(void) {
+/* MMC configuration (empty).*/
+static const MMCConfig mmc_cfg = {};
- return !palReadPad(IOPORT3, GPIOC_MMCWP);
-}
+/* Card insertion verification.*/
+static bool_t mmc_is_inserted(void) {return palReadPad(IOPORT3, GPIOC_MMCCP);}
-/**
- * @brief FS object.
- */
-FATFS MMC_FS;
+/* Card protection verification.*/
+static bool_t mmc_is_protected(void) {return !palReadPad(IOPORT3, GPIOC_MMCWP);}
+
+/* Generic large buffer.*/
+uint8_t fbuff[1024];
/*
* Red LEDs blinker thread, times are in milliseconds.
@@ -90,14 +79,65 @@ static msg_t Thread1(void *arg) {
return 0;
}
+static FRESULT scan_files(char *path)
+{
+ FRESULT res;
+ FILINFO fno;
+ DIR dir;
+ int i;
+ char *fn;
+
+ res = f_opendir(&dir, path);
+ if (res == FR_OK) {
+ i = strlen(path);
+ for (;;) {
+ res = f_readdir(&dir, &fno);
+ if (res != FR_OK || fno.fname[0] == 0)
+ break;
+ if (fno.fname[0] == '.')
+ continue;
+ fn = fno.fname;
+ if (fno.fattrib & AM_DIR) {
+ siprintf(&path[i], "/%s", fn);
+ res = scan_files(path);
+ if (res != FR_OK)
+ break;
+ path[i] = 0;
+ }
+ else {
+ iprintf("%s/%s\r\n", path, fn);
+ }
+ }
+ }
+ return res;
+}
+
/*
* Executed as event handler at 500mS intervals.
*/
static void TimerHandler(eventid_t id) {
(void)id;
- if (palReadPad(IOPORT1, GPIOA_BUTTON))
- TestThread(&SD2);
+ if (palReadPad(IOPORT1, GPIOA_BUTTON)) {
+ if (fs_ready) {
+ FRESULT err;
+ uint32_t clusters;
+ FATFS *fsp;
+
+ err = f_getfree("/", &clusters, &fsp);
+ if (err != FR_OK) {
+ iprintf("FS: f_getfree() failed\r\n");
+ return;
+ }
+ iprintf("FS: %lu free clusters, %u sectors per cluster, %lu bytes free\r\n",
+ clusters, MMC_FS.csize,
+ clusters * (uint32_t)MMC_FS.csize * (uint32_t)MMC_SECTOR_SIZE);
+ fbuff[0] = 0;
+ scan_files((char *)fbuff);
+ }
+ else
+ TestThread(&SD2);
+ }
}
/*
@@ -105,25 +145,27 @@ static void TimerHandler(eventid_t id) {
*/
static void InsertHandler(eventid_t id) {
FRESULT err;
- uint32_t clusters;
- FATFS *fsp;
(void)id;
+ iprintf("MMC: inserted\r\n");
/*
* On insertion MMC initialization and FS mount.
*/
- if (mmcConnect(&MMCD1))
- return;
- err = f_mount(0, &MMC_FS);
- if (err != FR_OK) {
- mmcDisconnect(&MMCD1);
+ iprintf("MMC: initialization ");
+ if (mmcConnect(&MMCD1)) {
+ iprintf("failed\r\n");
return;
}
- err = f_getfree("/", &clusters, &fsp);
+ iprintf("ok\r\n");
+ iprintf("FS: mount ");
+ err = f_mount(0, &MMC_FS);
if (err != FR_OK) {
+ iprintf("failed\r\n");
mmcDisconnect(&MMCD1);
return;
}
+ fs_ready = TRUE;
+ iprintf("ok\r\n");
}
/*
@@ -132,6 +174,8 @@ static void InsertHandler(eventid_t id) {
static void RemoveHandler(eventid_t id) {
(void)id;
+ iprintf("MMC: removed\r\n");
+ fs_ready = FALSE;
}
/*
diff --git a/demos/ARMCM3-STM32F103-FATFS-GCC/readme.txt b/demos/ARMCM3-STM32F103-FATFS-GCC/readme.txt
index 09f544035..65f40a89a 100644
--- a/demos/ARMCM3-STM32F103-FATFS-GCC/readme.txt
+++ b/demos/ARMCM3-STM32F103-FATFS-GCC/readme.txt
@@ -8,9 +8,12 @@ The demo will on an Olimex STM32-P103 board.
** The Demo **
-The demo flashes the board LED using a thread, by pressing the button located
-on the board the test procedure is activated with output on the serial port
-COM2 (USART2).
+This demo shows how to integrate the FatFs file system and use the SPI and MMC
+drivers.
+The demo flashes the board LED using a thread and monitors the MMC slot for
+a card insertion. By pressing the button located on the board while a card is
+inserted a directory dump on the serial port is performed, if a card is not
+inserted then the test procedure is activated.
** Build Procedure **