EFFS Multiple MMC Flash Card Example
Overview
This example demonstrates comprehensive multiple flash card file system operations using NetBurner's EFFS (Embedded Flash File System). The application shows how to simultaneously access both the on-board microSD card slot on the MOD5441X module and external flash card sockets on development boards, providing complete file system management for dual storage scenarios.
Supported Platform
- MOD5441X - MOD54415/MOD54417 core modules only
Hardware Requirements
Essential Components
- MOD5441X core module with on-board microSD card slot
- MOD-DEV-70CR development board with external flash card socket
- Two flash cards - MicroSD for on-board slot, SD or microSD for external socket
Hardware Connections
MOD5441X Module MOD-DEV-70CR Dev Board
=============== ==================
On-board microSD <-> [Built-in slot]
Module connector <-> Dev board socket
External SD socket <-> [External flash card]
Card Requirements
- On-board: MicroSD card (any capacity supported by EFFS)
- External: SD or microSD card with adapter
- Format: FAT16 or FAT32 file systems
- Write Protection: Cards should not be write-protected during testing
Features
Dual Flash Card Management
- On-board card access - Built-in microSD slot operations
- External card access - Development board flash card socket
- Drive switching - Dynamic switching between storage devices
- Independent operations - Separate file operations on each card
Complete File System Operations
- Drive mounting/unmounting - Proper card initialization and cleanup
- File creation and writing - Creating test files with content
- Directory operations - Listing files and directories
- Space management - Free and used space calculation
- Error handling - Comprehensive error detection and reporting
EFFS Integration
- Multi-drive support - Simultaneous access to multiple storage devices
- Task-based file system - Proper EFFS task registration
- Drive enumeration - Automatic drive detection and assignment
- Error code translation - Human-readable error descriptions
Application Workflow
Initialization Sequence
- System startup - Network and diagnostic initialization
- File system registration - Task registration with EFFS (
f_enterFS())
- Card detection - Check for presence of flash cards
- Write protection check - Verify cards are writable
Testing Sequence
On-Board Flash Card Test
1. Open on-board flash card drive
2. Mount drive and change to it (f_chdrive())
3. Create test file: "FileOnBoardSD.txt"
4. Write content: "This file written to SD card on the Module"
5. Close file and display directory contents
6. Unmount drive properly
External Flash Card Test
1. Open external flash card drive
2. Mount drive and change to it (f_chdrive())
3. Create test file: "FileOffBoardSD.txt"
4. Write content: "This file written to SD card off of the Module"
5. Close file and display directory contents
6. Unmount drive properly
Cleanup and Completion
- Release file system - Unregister task from EFFS (
f_releaseFS())
- Status report - Display completion message
- Idle loop - Wait for manual reset to repeat test
Usage Instructions
Setup Process
- Prepare hardware
- Insert microSD card into MOD5441X on-board slot
- Insert SD/microSD card into development board external socket
- Ensure both cards are NOT write-protected
- Connect MOD5441X to MOD-DEV-70CR development board
- Build and deploy
- Monitor operation
- Connect serial terminal (115200 baud, 8-N-1)
- Observe file system operations and results
- Check for any error messages during execution
Expected Console Output
===== Starting MOD5441x EFFS Flash Card Test Program =====
Testing the on-board Flash card
Card detected successfully
drive change successful
Wrote 43 bytes: [This file written to SD card on the Module]
Directory listing for on-board card:
FileOnBoardSD.txt 43 bytes
[Other files may be listed]
Testing the external Flash card
Card detected successfully
drive change successful
Wrote 46 bytes: [This file written to SD card off of the Module]
Directory listing for external card:
FileOffBoardSD.txt 46 bytes
[Other files may be listed]
Program complete. Reset to repeat
Technical Implementation
File System Architecture
Drive Management
int onBoardDrive = OpenOnBoardFlash();
int externalDrive = OpenOffBoardFlash();
int result = f_chdrive(onBoardDrive);
if (result == F_NO_ERROR) {
}
Card Detection Logic
if (get_cd(drive) == 0) {
printf("No card detected. Insert card and press <Enter>\n");
}
if (get_wp(drive) == 1) {
printf("Card is write-protected. Remove protection and press <Enter>\n");
}
File Operations Pattern
F_FILE *fp =
f_open(
"filename.txt",
"w+");
if (fp) {
const char *data = "File content";
int bytesWritten =
f_write(data, 1, strlen(data), fp);
printf("Wrote %d bytes\n", bytesWritten);
}
#define f_write(buf, size, size_st, filehandle)
Write data to the file at the current position.
Definition api_f.h:538
#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
Error Handling System
Comprehensive Error Codes
The application includes complete EFFS error code translation:
| Error Code | Description | Common Causes |
| F_NO_ERROR | Operation successful | - |
| F_ERR_INVALIDDRIVE | Invalid drive number | Drive not mounted |
| F_ERR_NOTFORMATTED | Drive not formatted | Unformatted card |
| F_ERR_CARDREMOVED | Card removed during operation | Physical card removal |
| F_ERR_WRITEPROTECT | Write protection enabled | Card lock switch |
| F_ERR_INVALIDMEDIA | Invalid media type | Unsupported card format |
| F_ERR_BUSY | Drive busy | Concurrent access |
Error Display Function
void DisplayEffsErrorCode(int code) {
if (code <= MAX_EFFS_ERRORCODE)
printf("%s\n", EffsErrorCode[code]);
else
printf("Unknown EFFS error code [%d]\n", code);
}
Drive Type Detection
The system automatically detects and configures different drive types:
#define MMC_OFF_BOARD (0)
#define MMC_ON_BOARD (1)
char driveType[20];
Memory and Performance
Resource Usage
- Static memory: Approximately 2KB for error code strings
- Dynamic memory: EFFS buffers allocated per drive
- File handles: Limited by EFFS configuration (typically 8-16)
Performance Characteristics
- Card detection: Immediate (hardware signal)
- Drive mounting: 100-500ms depending on card size
- File operations: Standard SD card speeds (Class 4-10)
- Drive switching: <10ms for drive change operations
Troubleshooting
Common Issues
Card Detection Problems
Symptoms**: "No card detected" messages Solutions**:
- Verify card is fully inserted
- Check card compatibility (FAT16/FAT32)
- Try different cards to isolate hardware issues
- Ensure development board connections are secure
Write Protection Errors
Symptoms**: F_ERR_WRITEPROTECT errors Solutions**:
- Check physical write-protect switch on SD cards
- Verify card is not corrupted
- Test with different cards
- Check for read-only file system attributes
Drive Mount Failures
Symptoms**: Drive change failed messages
Solutions**:
- Reformat cards using standard SD formatter
- Check card file system (must be FAT16 or FAT32)
- Verify sufficient free space on cards
- Test cards in standard PC card readers first
File Operation Errors
Symptoms**: File creation or write failures Solutions**:
- Check available free space on cards
- Verify cards are not corrupted
- Ensure proper drive mounting before file operations
- Check file name validity (8.3 format recommended)
Debug Procedures
- Verify card detection
printf("Card detect status: %d\n", get_cd(drive));
printf("Write protect status: %d\n", get_wp(drive));
- Check drive mounting
int result = f_chdrive(drive);
printf("Drive change result: ");
DisplayEffsErrorCode(result);
- Monitor file operations
F_FILE *fp =
f_open(
"test.txt",
"w");
if (!fp) {
printf("File open failed\n");
}
File Structure
EffsMultipleMmc/
|-- src/
| |-- main.cpp # Main application logic
| |-- FileSystemUtils.cpp # EFFS utility functions
| |-- FileSystemUtils.h # Utility function declarations
| |-- effs_time.cpp # Time utilities for EFFS
| |-- effs_time.h # Time function declarations
Dependencies
- NetBurner NNDK - Network Development Kit
- FatFile Library - EFFS FAT file system support
- MOD5441X Platform - Hardware-specific drivers
- Development Board - MOD-DEV-70CR for external card access
Learning Objectives
This example teaches:
- Multi-drive file system management - Handling multiple storage devices
- EFFS API usage - NetBurner embedded file system operations
- Error handling patterns - Comprehensive error detection and reporting
- Hardware abstraction - Platform-specific storage device access
- Task-based file systems - Proper registration and cleanup procedures
- Card detection logic - Physical media presence and status checking
Related Examples
For additional file system learning, see:
- Single flash card examples for basic EFFS operations
- File upload/download examples for network file transfer
- Data logging examples for continuous file system usage
- Web-based file manager examples for remote file access