[ECOS] STM32 Standard Peripheral Library in eCos
Jerzy Dyrda
jerzdy@gmail.com
Wed Jun 18 10:08:00 GMT 2014
Hello Oleg,
On Wednesday 18 of June 2014 12:39:04 Oleg Uzenkov wrote:
[snip]
> > IMHO STM32 Standard Peripheral Library doesn't fit to any driver
> > oriented OS but
> > due to fact that it exists some system just incorporate it as it i.e.
> > agreed for its drawbacks.
> Please, could you name some OS that incorporate it?
E.g. FreeRTOS.
> Does anyone know of any examples using MMC SPI driver in ecos to interface
> SD card (any platform)? I would appreciate any links or sample code.
#include <pkgconf/system.h>
#ifdef CYGPKG_DEVS_DISK_MMC
#include <pkgconf/io_fileio.h>
#include <pkgconf/fs_fat.h>
#endif
#include <cyg/infra/cyg_type.h>
#include <cyg/infra/testcase.h> // Test macros
#include <cyg/infra/cyg_ass.h> // Assertion macros
#include <cyg/infra/diag.h> // Diagnostic output
#include <fcntl.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <dirent.h>
#include <stdio.h>
#include <cyg/hal/hal_arch.h> // CYGNUM_HAL_STACK_SIZE_TYPICAL
#include <cyg/hal/hal_if.h>
#include <cyg/kernel/kapi.h>
#include <string.h>
#include CYGHWR_MEMORY_LAYOUT_H
#ifdef CYGPKG_NET_LWIP
#include <lwip.h>
#endif // CYGPKG_NET_LWIP
#ifdef CYGPKG_DEVS_DISK_MMC
#include <cyg/fileio/fileio.h>
#include <cyg/fs/fatfs.h>
#endif
externC int hello_world(void);
void do_version (void);
#ifdef CYGPKG_DEVS_DISK_MMC
#ifdef CYGPKG_DEVS_SPI_CORTEXM_STM32
#include <cyg/io/spi_stm32.h>
CYG_DEVS_SPI_CORTEXM_STM32_DEVICE (
cyg_spi_mmc_dev0, 3, 0, false, 0, 0, 5000000, 1, 1, 1
);
#else
#error "Needed SPI connection to MMC card"
#endif
void checkcwd( const char *cwd )
{
static char cwdbuf[PATH_MAX];
char *ret;
ret = getcwd( cwdbuf, sizeof(cwdbuf));
if( ret == NULL ) diag_printf("Error getcwd\n");
if( strcmp( cwdbuf, cwd ) != 0 )
{
diag_printf( "cwdbuf %s cwd %s\n",cwdbuf, cwd );
diag_printf( "Current directory mismatch");
}
}
static void listdir( char *name, int statp, int numexpected, int *numgot )
{
int err;
DIR *dirp;
int num=0;
diag_printf("<INFO>: reading directory %s\n",name);
dirp = opendir( name );
if( dirp == NULL ) diag_printf("Can't opendir\n");
for(;;)
{
struct dirent *entry = readdir( dirp );
if( entry == NULL )
break;
num++;
diag_printf("<INFO>: entry %14s",entry->d_name);
#ifdef CYGPKG_FS_FAT_RET_DIRENT_DTYPE
diag_printf(" d_type %2x", entry->d_type);
#endif
if( statp )
{
char fullname[PATH_MAX];
struct stat sbuf;
if( name[0] )
{
strcpy(fullname, name );
if( !(name[0] == '/' && name[1] == 0 ) )
strcat(fullname, "/" );
}
else fullname[0] = 0;
strcat(fullname, entry->d_name );
err = stat( fullname, &sbuf );
if( err < 0 )
{
if( errno == ENOSYS )
diag_printf(" <no status available>");
else diag_printf( "stat=%d err=%x\n", stat, err );
}
else
{
diag_printf(" [mode %08x ino %08x nlink %d size %ld]",
sbuf.st_mode,sbuf.st_ino,sbuf.st_nlink,(long)sbuf.st_size);
}
#ifdef CYGPKG_FS_FAT_RET_DIRENT_DTYPE
if ((entry->d_type & S_IFMT) != (sbuf.st_mode & S_IFMT))
diag_printf("File mode's don't match between dirent and stat");
#endif
}
diag_printf("\n");
}
err = closedir( dirp );
if( err < 0 ) diag_printf( "stat=%d err=%x\n", stat, err );
if (numexpected >= 0 && num != numexpected)
diag_printf("Wrong number of dir entries\n");
if ( numgot != NULL )
*numgot = num;
}
#endif
int main(void)
{
#ifdef CYGPKG_DEVS_DISK_MMC
int existingdirents=-1;
diag_printf("Mounting MMC disk\n");
if (ENOERR != mount( "/dev/mmcdisk0/", "/disk", "fatfs" ))
diag_printf("MMC disk not mounted\n");
if (ENOERR != chdir( "/disk" ))
diag_printf("Changing directory to /disk failed\n");
checkcwd( "/disk" );
listdir( "/disk", true, -1, &existingdirents );
#endif
Best regards,
jerzy
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
More information about the Ecos-discuss
mailing list