EFFS SDHC Flash Card File System
Overview
This NetBurner application demonstrates comprehensive flash card file system operations using the Embedded Flash File System (EFFS) with FAT support. The application provides FTP server functionality, file management operations, and performance testing capabilities for SD/MMC/SDHC flash cards.
Supported Platforms
- MOD5441X - Multi-drive support (on-board + external)
- NANO54415 - SDHC interface support
- SB800EX - SDHC interface support
Flash Card Interface Types
Interface Comparison
SPI Interface:**
Note: SPI and SDHC are mutually exclusive - flash card connector must be wired for one type only.
Hardware Requirements
- NetBurner module with flash card interface
- SD/MMC/SDHC flash card (formatted FAT16/FAT32)
- Network connection for FTP access
- Serial console for interactive commands
- Optional: TEST.BIN file for speed testing
Application Functionality
Core Features
- File System Operations: Directory listing, file display, space management
- FTP Server: Network-based file transfer capabilities
- Performance Testing: File read/write speed benchmarking
- Time Management: NTP synchronization with manual fallback
- Interactive Menu System: Serial console command interface
Program Flow
- System Initialization
- Initialize network stack and file system
- Enter EFFS context for main and FTP tasks
- Initialize flash card interface
- Time Setup
- Attempt NTP time synchronization
- Fall back to manual time setting if NTP fails
- Configure timezone (PST/PDT default)
- Service Startup
- Start FTP server on port 21
- Display initial file system statistics
- Run read/write test with "TestFile.txt"
- Interactive Operation
- Present command menu
- Process user commands
- Execute file operations
Command Interface
Available Commands
- D: Display Directory contents
- E: Display TestFile.txt contents
- F: Format SD flash card (WARNING: data loss!)
- R: Reboot system
- S: Display space usage statistics
- T: Display current system time
- W: Run file read/write speed test
- ?: Display command menu
Command Examples
Directory Listing:**
Directory Contents:
TestFile.txt 1024
config.dat 512
data/ [DIR]
End of listing
Space Usage:**
Flash card space statistics:
Total: 32GB
Used: 1.2GB
Free: 30.8GB
Key Components
Files Structure
EffsSDHC/
|- src/
| |-- main.cpp # Main application logic
| |-- FileSystemUtils.h # File system utilities
| |-- cardtype.h # Card type definitions
| |-- ftp_f.h # FTP function declarations
| |-- effs_time.h # Time management functions
| +-- dev_test.h # Device test functions
|-- makefile # Build configuration
+-- README.md # This documentation
Platform-Specific Configuration
Multi-Drive Support (MOD5441X):**
#if (defined(MOD5441X))
#define MULTI_MMC TRUE
#include <effs_fat/multi_drive_mmc_mcf.h>
SDHC Interface:**
#elif (defined(USE_SDHC) && (defined(NANO54415) || defined(SB800EX)))
#include <effs_fat/sdhc_mcf.h>
Standard MMC/SD:**
#elif (defined(USE_MMC))
#include <effs_fat/mmc_mcf.h>
Core Functions
File System Management:**
Time Management
NTP Synchronization
if (SetTimeNTP()) {
tzsetchar(
"PST8PDT7,M3.2.0/02:00:00,M11.1.0/02:00:00");
} else {
SetTimeManual(month, day, dow, year, hour, min, sec);
}
void tzsetchar(const char *tzenv)
Set the system local time.
Timezone Options
Available timezone configurations:
- Eastern:
"EST5EDT4,M3.2.0/02:00:00,M11.1.0/02:00:00"
- Central:
"CST6CDT5,M3.2.0/02:00:00,M11.1.0/02:00:00"
- Mountain:
"MST7MDT6,M3.2.0/02:00:00,M11.1.0/02:00:00"
- Pacific:
"PST8PDT7,M3.2.0/02:00:00,M11.1.0/02:00:00"
FTP Server Integration
Server Configuration
- Port: 21 (standard FTP)
- Priority: Higher than UserMain() (MAIN_PRIO - 2)
- File System: Shared access with main application
- Authentication: Platform-dependent default settings
FTP Operations
# Connect to NetBurner FTP server
ftp <device_ip_address>
# Upload files
put local_file.txt remote_file.txt
# Download files
get remote_file.txt local_file.txt
# Directory operations
ls # List files
cd dirname # Change directory
mkdir name # Create directory
Long Filename Support
if (F_LONGFILENAME == 1)
iprintf("Long file names are supported\r\n");
else
iprintf("Long file names are not supported- only 8.3 format\r\n");
Performance Testing
Speed Test Requirements
- Place file named "TEST.BIN" on flash card
- Use FTP to upload test file, or copy from another device
- Execute 'W' command from serial console
- Results displayed through debug serial port
Test Parameters
int res = SpeedTest("TEST.BIN", 10 * 1024 * 1024);
Expected Performance
- SPI Interface: 1-5 MB/s typical
- SDHC Interface: 10-25 MB/s typical
- Actual Speed: Depends on card class and system loading
Building and Deployment
Build Commands
# Build for specific platform and interface type
make PLATFORM=MOD5441X # Multi-drive MMC
make PLATFORM=NANO54415 # SDHC interface
make PLATFORM=SB800EX # SDHC interface
# Load to device
make load DEVIP=<device_ip_address>
Conditional Compilation
The build system automatically selects the appropriate interface:
#if (defined(MOD5441X))
#elif (defined(USE_SDHC) && (defined(NANO54415) || defined(SB800EX)))
#elif (defined(USE_MMC))
#endif
Required Libraries
# EFFS FAT library (usually auto-included)
XTRALIB += -lFatFile
Usage Instructions
Initial Setup
- Prepare Flash Card:
- Format card as FAT32 (recommended) or FAT16
- Optionally create test files
- Insert into appropriate socket
- Network Configuration:
- Ensure device has network connectivity
- Note device IP address for FTP access
- Serial Console:
- Connect serial terminal (115200 baud)
- Use for interactive commands and monitoring
Typical Operation Session
Console Output:**
===== Starting EFFS FTP SD/SDHC Program =====
Initializing Flash Card...complete
External Flash opened.
NTP time synchronization successful
Current
time: Wed May 14 11:35:00 2025
Flash card space statistics:
Total: 32GB, Used: 1.2GB, Free: 30.8GB
Started FTP Server
Long file names are supported
--- Main Menu ---
D - Display Directory
E - Display TestFile.txt
F - Format SD Flash card
R - Reboot
S - Display Space usage
T - Display system Time
W - Run File Read/Write Speed Test
? - Display Menu
time_t time(time_t *pt)
Gets the current system GMT time.
FTP Access Example
From Windows Command Prompt:**
C:> ftp 192.168.1.100
Connected to 192.168.1.100
220 NetBurner FTP Server Ready
User: admin
Password: admin
230 User logged in
ftp> ls
200 PORT command successful
150 Opening data connection
TestFile.txt 1024
config.dat 512
226 Transfer complete
ftp> get TestFile.txt
200 PORT command successful
150 Opening data connection
226 Transfer complete
1024 bytes received
Troubleshooting
Common Issues
- Flash Card Not Detected:
- Check card insertion and formatting
- Verify card compatibility (SD/MMC/SDHC)
- Ensure proper voltage levels (3.3V)
- Try different cards to isolate hardware issues
- FTP Server Won't Start:
Error: [code]. Could not start FTP Server
- Check network connectivity
- Verify no other FTP server running on port 21
- Ensure sufficient system resources
- File System Errors:
- Reformat flash card (FAT32 recommended)
- Check card for physical damage
- Verify file system integrity with PC tools
- Time Synchronization Failure:
NTP failed, setting time manually
- Check network connectivity to NTP servers
- Verify DNS resolution working
- Manual time setting used as fallback
- Speed Test Failure:
Test execution failed! Error [code]
- Ensure TEST.BIN file exists on card
- Check available free space
- Verify file read permissions
Debug Techniques
File System Status:**
iprintf("Free space: %ld KB\n", GetFreeSpace() / 1024);
iprintf("Card type: %s\n", GetCardType());
FTP Diagnostics:**
iprintf("Active FTP sessions: %d\n", GetFTPSessionCount());
Performance Monitoring:**
uint32_t startTime = Secs;
PerformFileOperation();
iprintf("Operation took %ld seconds\n", Secs - startTime);
Advanced Features
Custom File Operations
Batch File Processing:**
void ProcessAllFiles() {
DIR *dir = opendir(".");
struct dirent *entry;
while((entry = readdir(dir)) != NULL) {
if(entry->d_type == DT_REG) {
ProcessFile(entry->d_name);
}
}
closedir(dir);
}
Directory Recursion:**
void ProcessDirectoryRecursive(const char *path) {
DIR *dir = opendir(path);
struct dirent *entry;
while((entry = readdir(dir)) != NULL) {
if(entry->d_type == DT_DIR && strcmp(entry->d_name, ".") != 0) {
char newPath[256];
snprintf(newPath, sizeof(newPath), "%s/%s", path, entry->d_name);
ProcessDirectoryRecursive(newPath);
}
}
closedir(dir);
}
Extended FTP Features
Custom FTP Commands:**
void HandleCustomFTPCommand(const char *cmd, int clientFd) {
if(strcmp(cmd, "STATUS") == 0) {
SendFTPResponse(clientFd, "200 System Status OK\r\n");
}
}
Authentication Enhancement:**
bool AuthenticateUser(const char *username, const char *password) {
return ValidateCredentials(username, password);
}
Data Logging Applications
Sensor Data Logging:**
void LogSensorData() {
F_FILE *fp =
f_open(
"sensor_log.csv",
"a");
if(fp) {
f_fprintf(fp, "%ld,%f,%f,%f\n",
time(NULL), temperature, humidity, pressure);
}
}
#define f_close(filehandle)
Closes an opened file.
Definition api_f.h:487
#define f_open(filename, mode)
Opens a file in the file system.
Definition api_f.h:512
System Event Logging:**
void LogEvent(const char *event) {
F_FILE *fp =
f_open(
"system_log.txt",
"a");
if(fp) {
f_fprintf(fp, "[%s] %s\n", GetTimeString(), event);
}
}
Performance Optimization
High-Speed File I/O
#define BUFFER_SIZE 32768
static char fileBuffer[BUFFER_SIZE];
void OptimizedFileCopy(const char *src, const char *dst) {
F_FILE *srcFp =
f_open(src,
"rb");
F_FILE *dstFp =
f_open(dst,
"wb");
int bytesRead;
while((bytesRead =
f_read(fileBuffer, 1, BUFFER_SIZE, srcFp)) > 0) {
f_write(fileBuffer, 1, bytesRead, dstFp);
}
}
#define f_read(buf, size, size_st, filehandle)
Read data from the current position in a file.
Definition api_f.h:526
#define f_write(buf, size, size_st, filehandle)
Write data to the file at the current position.
Definition api_f.h:538
Memory Management
void ProcessLargeFileInChunks(const char *filename) {
F_FILE *fp =
f_open(filename,
"rb");
char chunk[4096];
while(
f_read(chunk, 1,
sizeof(chunk), fp) > 0) {
ProcessChunk(chunk, sizeof(chunk));
}
}
Concurrent Access Management
OS_SEM fileSemaphore;
void SafeFileWrite(const char *filename, const char *data) {
fileSemaphore.Pend();
F_FILE *fp =
f_open(filename,
"a");
f_fprintf(fp, "%s", data);
fileSemaphore.Post();
}
Integration Examples
Web Interface Integration
void HandleFileUpload(int httpFd, const char *filename) {
F_FILE *fp =
f_open(filename,
"wb");
SaveUploadedFile(httpFd, fp);
}
Database-Like Operations
void StoreKeyValue(const char *key, const char *value) {
F_FILE *fp =
f_open(
"database.txt",
"a");
f_fprintf(fp, "%s=%s\n", key, value);
}
char *GetValue(const char *key) {
return FindValueInFile("database.txt", key);
}
Related Examples
- EFFS Examples: Additional file system operations and utilities
- FTP Examples: Enhanced FTP server implementations
- Data Logging: Specialized logging and data acquisition systems
- Network Storage: Network-attached storage implementations
- Backup Systems: Automated backup and synchronization tools