SD Card Music player example (OP-AN-020)

From openPicus Wiki
Jump to: navigation, search

The app uses Music NEST expansion board, compatible with FLYPORT Wi-Fi and FLYPORT Ethernet modules.
A microSD Card with FAT (FAT16 or FAT32) file system is needed for music files storage.



Application Note PDF

Source Code


This application note uses the Music NEST expansion board hardware to provide the following services:

  • TCP Socket (FLYPORT is the TCP Server) with player console command line
  • Serial player console command line
  • FAT32 (FatFs open source libraries) with some helpers functions and read / write operation enabled
  • player console with the following commands:
    • list directory files
    • change directory
    • select a file by its name (long file name are supported)
    • play, pause and stop
    • volume up / down

Since FLYPORT Modules act as TCP Servers, any Client can connect to their sockets. In this way, clients can keep control of all the player activities, even from remote locations

Required Hardware

  • Music NEST
  • microSD card

Required Software and Libreries


  • OpenPicus Free IDE 2.2+
  • TCP/IP Builder


  • FATFs
  • VLSICodec


The application initialize VLSI Codec and FatFs libraries.

Then, if CUSTOM Network parameters exists inside FLYPORT's memory, the module opens a connection to network with custom profile, otherwise connects to the network with default profiles(the one configured inside the TCP/IP wizard of openPicus IDE).
For FLYPORT Wi-Fi module, the default parameters provided with the application note code creates a adhoc network with SSID “music-nest” and open security.

After the network connection is successfully established, the module opens a TCP Server socket to receive player commands from remote clients.
Inside the infinite loop, FLYPORT constantly checks the state of “sddetect” signal to understand if the microSD Card is inserted of removed, and proceed with software initialization if a new card is found. FLYPORT also checks if new commands reached by TCP / Serial console, and if the flags “playFlag”, “stopFlag” and “listFlag” are enabled to performs the relative actions.

Inside the condition, the loop performs timed checks of player commands to allow user interaction during file reproduction.
 if(playFlag == TRUE)

The related code is explained above:

// Update the Ticks to know if it is needed to check commands
DWORD tick2 = TickGetDiv256();
if((tick2 - tick1) > 180) // this is done about every 180*4ms = 720ms
tick1 = tick2;
// Check TCP Server state.
// This function uses cmdNew Flag and u_cmd char array
// that are part of player.c/.h file...
if(cmdNew == FALSE) // if we received command from TCP, ignore UART incoming data...
// those functions should be executed to be sure to check user commands
// them are part of "player.h/.c" files...
if(cmdNew == TRUE)
cmdNew = FALSE;

The tick1 variable was previously set by firmware and is updated every time the currents ticks are bigger of at least 180.
This check is done about every 180 * 4 ms = 720 ms, so player commands are checked every 720 ms during file reproduction.


To test TCP Sockets connections many software can be used. For windows environment, it is suggested to use “TCP/IP Builder” ( ). This tool allows user to manually creates sockets (TCP and UDP), choose IP address, port, send and receive data like any serial monitor.

To start using this tool, just open the software, set the IP of the PC and a port (50000 or higher can be used without problems), select TCP and create the Socket.
After the setup of the PC socket it can be opened the connection with the FLYPORT module. Also in this case, set IP address and TCP port (50800 by default configuration) of FLYPORT module, then press the “Connect” button.

If everything went well, TCP/IP Builder can be used to performs player console commands requests.

Testing OP-AN-020 1.png

When a string is sent by TCP/IP Builder, it is received by FLYPORT and parsed by the player.c file functions. The very same commands can be written on UART1 (generally used for programming / debugging purposes). To test the application it is not needed to use TCP Sockets, but command can be easily written inside the Serial Monitor of openPICUS IDE, using miniUSB Programmer.

NOTE: make sure to have a FAT32 file system partition on your microSD card.
To create a FAT32 compatible file system, it is suggested to format the microSD card with a unique partition (it should be a primary partition, NOT logical partition); then copy music files inside it.
Please refer to your operating system manual to perform this basic operation.


Personal tools