git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1299 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
55252f65b2
commit
84cf9ce9ff
|
@ -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 =
|
||||
|
|
|
@ -27,53 +27,42 @@
|
|||
|
||||
#include <ff.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "board.h"
|
||||
|
||||
/*
|
||||
* Maximum speed SPI configuration (18MHz, CPHA=0, CPOL=0, MSb first).
|
||||
*/
|
||||
static SPIConfig hs_spicfg = {
|
||||
IOPORT2, GPIOB_SPI2NSS, 0
|
||||
};
|
||||
|
||||
/*
|
||||
* 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
|
||||
};
|
||||
|
||||
/*
|
||||
* MMC driver instance.
|
||||
*/
|
||||
MMCDriver MMCD1;
|
||||
|
||||
/*
|
||||
* MMC configuration (empty).
|
||||
*/
|
||||
static const MMCConfig mmc_cfg = {};
|
||||
|
||||
/*
|
||||
* Card insertion verification.
|
||||
*/
|
||||
static bool_t mmc_is_inserted(void) {
|
||||
|
||||
return palReadPad(IOPORT3, GPIOC_MMCCP);
|
||||
}
|
||||
|
||||
/*
|
||||
* Card protection verification.
|
||||
*/
|
||||
static bool_t mmc_is_protected(void) {
|
||||
|
||||
return !palReadPad(IOPORT3, GPIOC_MMCWP);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief FS object.
|
||||
*/
|
||||
FATFS MMC_FS;
|
||||
|
||||
/**
|
||||
* MMC driver instance.
|
||||
*/
|
||||
MMCDriver MMCD1;
|
||||
|
||||
/* FS mounted and ready.*/
|
||||
static bool_t fs_ready = FALSE;
|
||||
|
||||
/* Maximum speed SPI configuration (18MHz, CPHA=0, CPOL=0, MSb first).*/
|
||||
static SPIConfig hs_spicfg = {IOPORT2, GPIOB_SPI2NSS, 0};
|
||||
|
||||
/* 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};
|
||||
|
||||
/* MMC configuration (empty).*/
|
||||
static const MMCConfig mmc_cfg = {};
|
||||
|
||||
/* Card insertion verification.*/
|
||||
static bool_t mmc_is_inserted(void) {return palReadPad(IOPORT3, GPIOC_MMCCP);}
|
||||
|
||||
/* 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))
|
||||
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))
|
||||
iprintf("MMC: initialization ");
|
||||
if (mmcConnect(&MMCD1)) {
|
||||
iprintf("failed\r\n");
|
||||
return;
|
||||
}
|
||||
iprintf("ok\r\n");
|
||||
iprintf("FS: mount ");
|
||||
err = f_mount(0, &MMC_FS);
|
||||
if (err != FR_OK) {
|
||||
iprintf("failed\r\n");
|
||||
mmcDisconnect(&MMCD1);
|
||||
return;
|
||||
}
|
||||
err = f_getfree("/", &clusters, &fsp);
|
||||
if (err != FR_OK) {
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -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 **
|
||||
|
||||
|
|
Binary file not shown.
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue