Sample application using SerialShell, SDFileSystem and Ethernet support
Dependencies: EthernetInterface SDFileSystem2 SerialShell mbed-rtos mbed
Fork of FRDM_K64F-Ethernet by
Revision 1:10cb71a29f88, committed 2015-04-28
- Comitter:
- vpcola
- Date:
- Tue Apr 28 17:01:47 2015 +0000
- Parent:
- 0:bbc9cfdee3bc
- Commit message:
- A sample K64F solution with SerialShell, SDFileSystem and Ethernet support
Changed in this revision
diff -r bbc9cfdee3bc -r 10cb71a29f88 EthernetInterface.lib --- a/EthernetInterface.lib Mon Sep 22 02:34:12 2014 +0000 +++ b/EthernetInterface.lib Tue Apr 28 17:01:47 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/EthernetInterface/#5887ae6c0c2c +http://mbed.org/users/mbed_official/code/EthernetInterface/#2fc406e2553f
diff -r bbc9cfdee3bc -r 10cb71a29f88 SDFileSystem.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Tue Apr 28 17:01:47 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/vpcola/code/SDFileSystem2/#572d27f56fcd
diff -r bbc9cfdee3bc -r 10cb71a29f88 SerialShell.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SerialShell.lib Tue Apr 28 17:01:47 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/vpcola/code/SerialShell/#25fa46a375dd
diff -r bbc9cfdee3bc -r 10cb71a29f88 main.cpp --- a/main.cpp Mon Sep 22 02:34:12 2014 +0000 +++ b/main.cpp Tue Apr 28 17:01:47 2015 +0000 @@ -1,11 +1,110 @@ #include "mbed.h" #include "EthernetInterface.h" +#include "SDFileSystem.h" +#include "Shell.h" #define MBED_DEV_IP "192.168.0.52" #define MBED_DEV_MASK "255.255.255.0" #define MBED_DEV_GW "0.0.0.0" #define ECHO_SERVER_PORT 5000 +#define SD_MOSI PTE3 +#define SD_MISO PTE1 +#define SD_SCLK PTE2 +#define SD_CS PTE4 +#define SD_DETECT PTE6 + +Serial pc(PTC17,PTC16); +SDFileSystem sd(SD_MOSI, SD_MISO, SD_SCLK, SD_CS, "sd"); + +#define SHELL_STACK_SIZ 1024 +// Pre-allocate the shell's stack (on global mem) +unsigned char shellStack[SHELL_STACK_SIZ]; +Shell shell(&pc); + +/** + * \brief Gets the amount of free memory + * \param none + * \return none + **/ +static void cmd_mem(Stream * chp, int argc, char * argv[]) +{ + // In order to get free mem within RTOS + // we need to get the main thread's stack pointer + // and subtract it with the top of the heap + // ------+-------------------+ Last Address of RAM (INITIAL_SP) + // | Scheduler Stack | + // +-------------------+ + // | Main Thread Stack | + // | | | + // | v | + // +-------------------+ <- bottom_of_stack/__get_MSP() + // RAM | | + // | Available RAM | + // | | + // +-------------------+ <- top_of_heap + // | ^ | + // | | | + // | Heap | + // +-------------------+ <- __end__ / HEAP_START (linker defined var) + // | ZI | + // +-------------------+ + // | ZI: Shell Stack | + // +-------------------+ + // | ZI: Idle Stack | + // +-------------------+ + // | ZI: Timer Stack | + // +-------------------+ + // | RW | + // ------+===================+ First Address of RAM + // | | + // Flash | | + // + + uint32_t bottom_of_stack = __get_MSP(); + char * top_of_heap = (char *) malloc(sizeof(char)); + uint32_t diff = bottom_of_stack - (uint32_t) top_of_heap; + + free((void *) top_of_heap); + + chp->printf("Available Memory : %d bytes\r\n", + diff); +} + +/** + * \brief List Directories and files + * \param none + * \return int + **/ +static void cmd_ls(Stream * chp, int argc, char * argv[]) +{ + DIR * dp; + struct dirent * dirp; + FILINFO fileInfo; + char dirroot[256]; + + if (argc >= 1) + sprintf(dirroot, "/sd/%s", argv[0]); + else + sprintf(dirroot, "/sd"); + + chp->printf("Listing directory [%s]\r\n", dirroot); + + dp = opendir(dirroot); + while((dirp = readdir(dp)) != NULL) + { + if (sd.stat(dirp->d_name, &fileInfo) == 0) + { + if (fileInfo.fattrib & AM_DIR ) + chp->printf("<DIR>\t\t"); + else + chp->printf("%ld\t\t", fileInfo.fsize); + } + chp->printf("%s\r\n", dirp->d_name); + } + closedir(dp); +} + int main (void) { EthernetInterface eth; @@ -16,7 +115,15 @@ TCPSocketServer server; server.bind(ECHO_SERVER_PORT); server.listen(); + + // Start the shell + pc.printf("Starting debug shell ...\r\n"); + shell.addCommand("ls", cmd_ls); + shell.addCommand("mem", cmd_mem); + // Start the thread statically (separate stack) + shell.start(osPriorityNormal, SHELL_STACK_SIZ, shellStack); + while (true) { printf("\nWait for new connection...\n"); TCPSocketConnection client;
diff -r bbc9cfdee3bc -r 10cb71a29f88 mbed-rtos.lib --- a/mbed-rtos.lib Mon Sep 22 02:34:12 2014 +0000 +++ b/mbed-rtos.lib Tue Apr 28 17:01:47 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed-rtos/#631c0f1008c3 +http://mbed.org/users/mbed_official/code/mbed-rtos/#557d5b275f31
diff -r bbc9cfdee3bc -r 10cb71a29f88 mbed.bld --- a/mbed.bld Mon Sep 22 02:34:12 2014 +0000 +++ b/mbed.bld Tue Apr 28 17:01:47 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/433970e64889 \ No newline at end of file