NetBurner 3.5.8
PDF Version
FTP

Example Path: examples/EFFS/Fat/Ftp

This program illustrates file system and FTP operations for SD Flash cards:

  • Mounting a flash drive
  • Determining amount of used and free file space
  • FTP access. We recommend Filezilla or WinScp

Status messages will be sent out the debug serial port.

Modules with an onboard microSD flash socket should use the multi MMC header files and functions because the modules are capable of supporting both onboard and external flash cards (even if you application only uses one).

Note
All EFFS FAT examples require that you add the Embedded Flash File System File Allocation Table (EFFS FAT) library to your project: Add a Library to a Project

FTP File System Application

Overview

This application demonstrates file system and FTP operations for SD Flash cards on NetBurner embedded systems. It provides a complete example of mounting flash drives, managing file operations, and enabling FTP access for remote file management.

Features

File System Operations

  • Mount and initialize external flash drive
  • Display directory contents and file listings
  • Read and display text files
  • Format flash cards (with confirmation prompt)
  • Monitor disk space usage (used/free space statistics)
  • Support for both long filenames and 8.3 format

FTP Server

  • Built-in FTP server running on port 21
  • Remote file access via FTP clients (recommended: FileZilla or WinSCP)
  • Concurrent file system access for local operations and FTP
  • Task-based priority management for FTP operations

System Features

  • Network initialization with DHCP support
  • NTP time synchronization with manual fallback
  • Timezone configuration support
  • Interactive command-line interface
  • System diagnostics and debug output

Supported Hardware

Flash Card Types

  • SD/MMC Cards: Secure Digital and MultiMediaCard support

Module Compatibility

  • MOD5441X: Onboard microSD flash socket
  • SBE70LC: Onboard microSD flash socket
  • Other NetBurner modules with external flash card support

Command Interface

The application provides an interactive menu system accessible via the debug serial port:

Command Description
D Display Directory - Shows all files and folders on the flash card
E Display TestFile.txt - Shows contents of the test file
F Format SD Flash card - Formats the card (WARNING: destroys all data)
R Reboot the device
S Display Space usage - Shows used and free space statistics
T Display system Time - Shows current system time and date
? Display Menu - Shows the command menu

Time Configuration

The local time zone is selected by name through the LOCAL_TIMEZONE define near the top of main.cpp. After the clock is set (via NTP, or manually if NTP fails), the application applies the zone with SetNamedTimeZone(LOCAL_TIMEZONE):

// Defaults to Pacific. Set this to any "Name" from the TZRecords[] table in
// nbrtos/source/timezones.cpp -- for example "Eastern Standard Time",
// "Central European Time", or "Tokyo Standard Time".
#define LOCAL_TIMEZONE "Pacific Standard Time"

Call ListTimeZones() to print the full list of accepted zone names to the serial console.

Setup Requirements

Library Dependencies

  • EFFS FAT Library: Embedded Flash File System with File Allocation Table support
  • FatFile Must be added to your NetBurner Eclipse project before compilation (libFatFile.a)

Hardware Setup

  1. Insert SD/MMC card into the appropriate socket
  2. Ensure network connection for DHCP and NTP functionality
  3. Connect debug serial cable for command interface

Network Configuration

  • DHCP client automatically obtains IP address
  • FTP server accessible on port 21
  • 5-second timeout for network initialization

File System Architecture

Multi-Drive Support

Modules with onboard microSD sockets use multi-MMC drivers to support both:

  • Onboard flash cards
  • External flash cards
  • Simultaneous access to multiple cards

Task Management

  • Main application runs at MAIN_PRIO
  • FTP server runs at FTP_PRIO (MAIN_PRIO - 2)
  • Up to 10 tasks can access the file system concurrently

Why every task must call f_enterFS()

The EFFS FAT file system is a single shared resource that any number of RTOS tasks may use at the same time. To make that safe, the library keeps a small amount of per-task state, and each task must register itself before it makes any file system call. That registration is what f_enterFS() does. Specifically:

  • It allocates this task's file system context. The library tracks a current drive and current working directory separately for every task, so one task changing directories with f_chdir() doesn't move another task out from under it. f_enterFS() creates the slot that holds this task's context; until it is called, the library has no place to store that state for the task.
  • It enrolls the task in the file system's locking. Concurrent access is coordinated with internal mutual-exclusion. A task has to be registered for that locking to apply to it, which is why calling any other f_* function before f_enterFS() is undefined and will fail.
  • It must be called exactly once per task, before any other file system call. Calling it more than once in the same task, or calling file functions before it, is an error.
  • Slots are a limited resource. By default up to 10 tasks may be registered at once (configurable). A task that no longer needs file access should call f_releaseFS() to free its slot for another task.

On NetBurner the file system identifies a task by its RTOS priority, so a slot is registered per priority. That is why UserMain() registers more than just itself: it calls f_enterFS() for its own priority, then briefly switches to FTP_PRIO with OSChangePrio() and calls f_enterFS() again, registering the FTP server task before the server starts. The Basic example shows the simpler single-task case, and Multiple Tasks shows several worker tasks sharing the card.

Usage Examples

Basic File Operations

  1. Start the application
  2. Wait for network initialization
  3. Use 'D' command to view directory contents
  4. Use 'S' command to check available space
  5. Use 'E' command to view test file contents

FTP Access

  1. Connect FTP client to the device's IP address on port 21
  2. Browse and transfer files using standard FTP commands
  3. Simultaneous local and remote access is supported

Formatting Flash Cards

  1. Use 'F' command from the menu
  2. Confirm with 'Y' when prompted
  3. WARNING: This will erase all data on the card

Technical Notes

  • All file system operations require prior call to f_enterFS()
  • Debug output is sent to the serial port
  • System diagnostics are enabled (disable for production)
  • NTP synchronization attempts before falling back to manual time setting
  • Long filename support depends on compilation flags

Recommended FTP Clients

  • FileZilla: Free, cross-platform FTP client
  • WinSCP: Windows-based secure file transfer client

Build Configuration

Compile-time options:

  • USE_MMC: Enable SD/MMC support
  • USE_CFC: Enable Compact Flash support
  • MOD5441X or SBE70LC: Enable multi-drive support for onboard sockets
  • F_LONGFILENAME: Enable long filename support