diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-11-15 08:52:17 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-11-15 08:52:17 +0000 |
commit | 84cf9ce9ffa3d538b367f74c8206b8ef894d466f (patch) | |
tree | b3931fee4361ec810cae4492fd4cca42bae6b037 | |
parent | 55252f65b2a444692ff1b2673b32ec1cf2b205c0 (diff) | |
download | ChibiOS-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
-rw-r--r-- | demos/ARMCM3-STM32F103-FATFS-GCC/Makefile | 3 | ||||
-rw-r--r-- | demos/ARMCM3-STM32F103-FATFS-GCC/main.c | 132 | ||||
-rw-r--r-- | demos/ARMCM3-STM32F103-FATFS-GCC/readme.txt | 9 | ||||
-rw-r--r-- | ext/ff007e-patched.zip | bin | 634232 -> 634232 bytes | |||
-rw-r--r-- | os/various/syscalls.c | 27 | ||||
-rw-r--r-- | readme.txt | 3 |
6 files changed, 124 insertions, 50 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 **
diff --git a/ext/ff007e-patched.zip b/ext/ff007e-patched.zip Binary files differindex 7b7cd3160..0e10e0308 100644 --- a/ext/ff007e-patched.zip +++ b/ext/ff007e-patched.zip diff --git a/os/various/syscalls.c b/os/various/syscalls.c index 258d9c9d6..e635b1388 100644 --- a/os/various/syscalls.c +++ b/os/various/syscalls.c @@ -63,18 +63,31 @@ #include <sys/types.h> #include <ch.h> +#if defined(STDOUT_SD) || defined(STDIN_SD) +#include <serial.h> +#endif /***************************************************************************/ int _read_r(struct _reent *r, int file, char * ptr, int len) { (void)r; +#if defined(STDIN_SD) + if (!len || (file != 0)) { + errno = EINVAL; + return -1; + } + *ptr++ = chIOGet(&STDOUT_SD); + if (--len > 0) + len = chIORead(&STDOUT_SD, (uint8_t *)ptr, (size_t)len); + return len; +#else (void)file; (void)ptr; (void)len; - errno = EINVAL; return -1; +#endif } /***************************************************************************/ @@ -93,10 +106,20 @@ int _lseek_r(struct _reent *r, int file, int ptr, int dir) int _write_r(struct _reent *r, int file, char * ptr, int len) { + int n; + (void)r; (void)file; (void)ptr; - +#if defined(STDOUT_SD) + if (file != 1) { + errno = EINVAL; + return -1; + } + n = len; + while (n--) + chIOPut(&STDOUT_SD, *ptr++); +#endif return len; } diff --git a/readme.txt b/readme.txt index 3ab69d454..3f60fb448 100644 --- a/readme.txt +++ b/readme.txt @@ -15,6 +15,9 @@ - NEW: Generic MMC (over SPI) driver.
- NEW: Added a STM32 demo that integrates the MMC driver and the FatFs
file system.
+- NEW: Implemented I/O redirection on a serial driver into syscalls.c, now
+ it is possible (but not recommended) to use printf()/scanf() etc. An usage
+ example is in the new MMC/FatFs demo. Note the extra -D... into the Makefile.
- CHANGE: Moved the STM32 firmware library under ./ext, this way there is no
need to duplicate it in each demo program.
- CHANGE: Moved the file stm32f10x.h from the demos to the platforms support
|