NetBurner 3.5.6
PDF Version
SDHC Flash Card

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:**

  • MOD54415/MOD54417: On-board microSD (SPI), MOD-DEV-70 dev board (SPI)
  • NANO54415: Development board (SPI)
  • Compatible with standard EFFS examples

    SDHC Interface:**

  • NANO54415: On-board microSD (SDHC)
  • SB800EX: On-board microSD (SDHC)
  • Higher performance, dedicated hardware controller

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

  1. File System Operations: Directory listing, file display, space management
  2. FTP Server: Network-based file transfer capabilities
  3. Performance Testing: File read/write speed benchmarking
  4. Time Management: NTP synchronization with manual fallback
  5. Interactive Menu System: Serial console command interface

Program Flow

  1. System Initialization
    • Initialize network stack and file system
    • Enter EFFS context for main and FTP tasks
    • Initialize flash card interface
  2. Time Setup
    • Attempt NTP time synchronization
    • Fall back to manual time setting if NTP fails
    • Configure timezone (PST/PDT default)
  3. Service Startup
    • Start FTP server on port 21
    • Display initial file system statistics
    • Run read/write test with "TestFile.txt"
  4. 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:**

  • f_enterFS(): Enter file system context (required per task)
  • InitExtFlash(): Initialize flash card interface
  • DumpDir(): Display directory contents
  • DisplayEffsSpaceStats(): Show storage usage

    FTP Operations:**

  • FTPDStart(): Start FTP server with specified priority
  • Network-based file upload/download capabilities
  • Long filename support detection

    Performance Testing:**

  • SpeedTest(): File I/O performance measurement
  • ReadWriteTest(): Basic file operation verification

Time Management

NTP Synchronization

if (SetTimeNTP()) {
// Set timezone (PST/PDT example)
tzsetchar("PST8PDT7,M3.2.0/02:00:00,M11.1.0/02:00:00");
} else {
// Manual time setting fallback
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

  1. Place file named "TEST.BIN" on flash card
  2. Use FTP to upload test file, or copy from another device
  3. Execute 'W' command from serial console
  4. Results displayed through debug serial port

Test Parameters

int res = SpeedTest("TEST.BIN", 10 * 1024 * 1024); // 10MB test

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))
// Multi-drive MMC support
#elif (defined(USE_SDHC) && (defined(NANO54415) || defined(SB800EX)))
// SDHC interface
#elif (defined(USE_MMC))
// Standard MMC/SD
#endif

Required Libraries

# EFFS FAT library (usually auto-included)
XTRALIB += -lFatFile

Usage Instructions

Initial Setup

  1. Prepare Flash Card:
    • Format card as FAT32 (recommended) or FAT16
    • Optionally create test files
    • Insert into appropriate socket
  2. Network Configuration:
    • Ensure device has network connectivity
    • Note device IP address for FTP access
  3. 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

  1. 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
  2. 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
  3. File System Errors:
    • Reformat flash card (FAT32 recommended)
    • Check card for physical damage
    • Verify file system integrity with PC tools
  4. Time Synchronization Failure:
    NTP failed, setting time manually
    • Check network connectivity to NTP servers
    • Verify DNS resolution working
    • Manual time setting used as fallback
  5. 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:**

// Add debugging output
iprintf("Free space: %ld KB\n", GetFreeSpace() / 1024);
iprintf("Card type: %s\n", GetCardType());

FTP Diagnostics:**

// Monitor FTP connections
iprintf("Active FTP sessions: %d\n", GetFTPSessionCount());

Performance Monitoring:**

// Time file operations
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) { // Regular file
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:**

// Add application-specific FTP commands
void HandleCustomFTPCommand(const char *cmd, int clientFd) {
if(strcmp(cmd, "STATUS") == 0) {
SendFTPResponse(clientFd, "200 System Status OK\r\n");
}
}

Authentication Enhancement:**

// Custom user authentication
bool AuthenticateUser(const char *username, const char *password) {
// Implement custom authentication logic
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);
f_close(fp);
}
}
#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);
f_close(fp);
}
}

Performance Optimization

High-Speed File I/O

// Use larger buffers for better performance
#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);
}
f_close(srcFp);
f_close(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

// Efficient memory usage for large files
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));
}
f_close(fp);
}

Concurrent Access Management

// Thread-safe file operations
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);
f_close(fp);
fileSemaphore.Post();
}

Integration Examples

Web Interface Integration

// Web-based file management
void HandleFileUpload(int httpFd, const char *filename) {
F_FILE *fp = f_open(filename, "wb");
// Handle HTTP file upload
SaveUploadedFile(httpFd, fp);
f_close(fp);
}

Database-Like Operations

// Simple key-value storage
void StoreKeyValue(const char *key, const char *value) {
F_FILE *fp = f_open("database.txt", "a");
f_fprintf(fp, "%s=%s\n", key, value);
f_close(fp);
}
char *GetValue(const char *key) {
// Search through database.txt and return value
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