PlayNPort: A Portable Wireless Music Player and Text Reader System
PPlayNPort: A Portable Wireless Music Player andText Reader System
Lakhan Shiva Kamireddy ∗ , Dharmik Thakkar ∗ , Lakhan Saiteja K †∗ VLSI and Embedded Systems Group, Department of Electrical and Computer Engineering, University of ColoradoBoulder, CO 80303, USA, Email: { lakhan.kamireddy, dharmik.thakkar } @colorado.edu † Department of Electronics and Electrical Communication Engineering, Indian Institute of Technology KharagpurWest Bengal 721302, India, Email: [email protected]
Abstract —Portable Consumer Electronics has made a markin the industry. With the ease of use at an accessible pricerange, they have experienced significant growth in the market.Our idea is to develop a portable wireless music player andtext reader using a Cortex-M series microcontroller and bare-metal programming techniques. We chose to use an SD card asthe storage device. The resulting electronic device is similar toa consumer grade music player available in a car. The systemcomprises an MCU, an MP3 encoder/decoder, an LCD, an audiooutput jack, an SD card and a remote control. We also presentvarious challenges involved in developing the system and solutionswe used to overcome the challenges. The intricacy of the worklies in the fact that the system was developed to be consumer-centric by providing a rich User Experience. It can be used asa personal entertainment system in a car.
I. I
NTRODUCTION
With a plethora of embedded devices, the ubiquitous natureof these systems is felt across the consumer electronics in-dustry. One such portable electronic device is a music player.A variety of music players are commercially available. Theseare usually developed by several teams, each developing a setof features. Then they are assembled, packaged and marketedto the consumer as a product in the market. However, weare curious to learn what it takes to build a consumer gradeelectronic device from scratch, by putting ourselves into theshoes of a system hardware designer, a firmware engineer, andan algorithm designer.The idea of this paper is to present the development of acomplete embedded system in the lab, and understand the pro-cesses, development methodologies involved and challenges inimplementing a complete system. We developed PlayNPort,a portable wireless music player, and text reader. It givescomplete control of the system to the user through a customremote. Its features comprise play/pause, play next/previoussong, read a text, exit to menu. We implemented the systemon a printed circuit board (PCB) and made use of off the shelfelectronic components, a TI MSP432, decoder ICs and an SDCard from a retail store. In this paper, we explained the systemdesign and implementation methodology.The paper is organized into the following sections: SectionII introduces the Board Design. In Section-III, we intro-duce the communication subsystem implementation Section-IV presents Firmware design. Challenges faced in development
Fig. 1. Block Diagram of the Embedded System are presented in Section-V. Conclusion and Future work ispresented in Section-VI.II. B
OARD D ESIGN
Fig 1. presents a block-level view of the embedded device.The system’s brain is an ARM Cortex M4F microcontroller.Following sections present board level design & componentsinvolved.
A. LCD Interface
We have used a character LCD [1] to display the menu andmessages on the screen. The character LCD only supports a5V/0V logic level. The MSP432 General Purpose IO (GPIO)pins are capable of producing 3.3V/0V logic levels. We usedbidirectional voltage level converters to convert the voltagesback and forth.
B. SD Card Interface
We used an SD card breakout board. The SD card canbe operated either in SD mode or SPI mode. For us, SPImode was more suitable as we wanted more control over thecard. An SD card has an inbuilt SD controller with an array a r X i v : . [ c s . OH ] S e p f NAND flashes. We connected the Master-In Slave-Out(MISO), Master-Out Slave-In (MOSI) and Serial Clock(SCLK) pins to port pins 3.5, 3.6, 3.7 on the MSP432 thatcorrespond to eUSCI B2 module [2]. C. IR Module
We used an IR module to give a user the control of theembedded system wirelessly using a custom IR remote thatuses a lithium coin cell battery. Internally, it makes use ofa microcontroller IC, which is a 4-bit RISC microcontrollerwith a built-in IR LED drive pin.Remote control was used for IR transmission using an IRemitter LED on the head of the remote [3]. The remote has9 buttons, each corresponding to a specific command. Theseinclude power, A, B, C, up, left, right, down and centerbuttons. These buttons are enough to give user controls likemusic play/pause, previous/next song, volume up/down andexit to menu options.
D. MP3 decoder and 3.5 mm jack
We chose to use the VS1063 MP3 decoder/encoder andcodec to decode the mp3/wav format files stored on the SDcard. The VS1063 consists of an inbuilt low-power DSP core,ROM memories, 16 kb instruction RAM, and 80 kb data RAM[4]. We used the SPI module and the common voltage bufferGBUF. The TRRS 3.5 mm jack breakout board contains Tip,Ring 1, Ring 2, Sleeve pins. All the TRRS pins were connectedto the respective contacts on the male jack.III. C
OMMUNICATION S UBSYSTEM I MPLEMENTATION
A. Serial Peripheral Interconnect (SPI)
SPI is used to establish communication between devices.SPI runs in a master/slave setup. It’s capable of being runin full duplex mode [5]. When compared to Inter IC (I2C)Communication, SPI attains better speeds, often capable ofreaching 20 Mbps. We configured the TI MSP432 as themaster, SD Card and VS1063 IC as slaves. We used EnhancedUniversal Serial Communication Interface (eUSCI) module onthe MSP432 for data transfer. In synchronous mode, eUSCIcan connect the device to an external system through eitherthree or four pins. We operate in 3-pin mode to keep matterssimple. SPI mode is selected when the USYNC bit is set andis controlled using UCMODEx bits [6].We have an option to choose LSB-first or MSB-first datatransmit and receive. In SPI, data shift and data latch are doneon opposite clock edges. Hence, there are 4 different operatingmodes. Mode 0 (Clock Phase (CKPH) = 0, Clock Polarity(CKPL) = 0) means latch on a positive edge, then shift on thenext negative edge. Mode 1 (CKPH = 0, CKPL = 1) meansshift on positive edge, then latch on the next positive edge.Mode 2 (CKPH = 1, CKPL = 0) means shift on negativeedge, then latch on the next positive edge. Please refer to thefigure in [6] for SPI modes in MSP432. The choice of mode of operation must be made appropri-ately by referring to the datasheet of the slave device (SDcard and VS1063 IC) otherwise it may lead to data corruption.Along with this, bit rate and LSB (or MSB) first choices shouldalso be made appropriately.SPI mode can be controlled by four sets of registers [5].1) General controls and bit clock generation registers2) SPI data transmit control registers.3) SPI data receiving control registers.4) SPI interrupt related control registers.In the following section, we discuss some important configu-ration registers.eUSCI Bx control word 0 register, UCBxCTLW0 is ageneral control register which is 16-bit wide [7]. Its bits canbe set accordingly to configure settings like CKPH, CKPL,MSB-first, transfer data character length, master mode select,3 or 4 pin mode select.eUSCI Bx Bit rate control word register, UCBxBRW is a bitrate clock generation register which is 16-bit wide [7]. Its bitscan be set accordingly to configure bit rate. UCBRx storesa pre-scaler value to divide the selected CKSE BRCLK tocalculate the desired frequency of SPI clock UCLK. Equation1. presents the formula used in the calculation. f uclk = f BitClock = f BRCLK /U CBRx (1)This is the bit transmit-receive rate.The operational principle of eUSCI Bx module is simple.When data is moved to UCBxTXBUF register, known as thetransmit data buffer, eUSCI module initiates the data transfer.The data in the UCBxTXBUF register is then moved to theTXS register when it is empty, initiating the data transferas configured by the UCMSB setting [6]. The data on theUCBxSOMI line is shifted into the RXS register on theopposite clock edge.When a complete character is received, the received datais moved from RXS register to the UCBxRXBUF. Data hasto be read from UCBxRXBUF when the UCBRXIFG flagis set. A set on the transmit interrupt flag UCTXIFG onlyindicates that data has been moved from the UCBxTXBUFregister to the TXS register and the UCBxTXBUF registeris ready for new data [6]. It does not indicate a completeRX/TX transaction. To receive data into the eUSCI in mastermode, dummy data must be written into the UCBxTXBUfregister (in our case 0xFFh) because both transmit and receiveoperations occur simultaneously.
B. NEC Protocol for Wireless IR Communication
The NEC is a standard protocol using pulse distance en-coding of the bits. Each pulse is 560s long. Logic bit 1 takes2.25ms to transmit and logical 0 takes 1.125ms [8].A message starts with an Automatic Gain Control (AGC)pulse. A command is transmitted only once. A repeat codeis transmitted every 110ms for as long as the key remainspressed. This repeat code is a 9ms high-speed AGC burstfollowed by a 2.25ms void space and a 560s pulse [8].V. F
IRMWARE D ESIGN
Firmware for this project comprises drivers for each of thenew hardware interfaces (SD card, Audio Codec, IR decoder)and porting the existing drivers (character LCD drivers) for8051 [10] onto MSP432 and developing application logic forplaying the songs, music control (volume control, play/pause,previous/next songs) and LCD text reader application. Thefollowing sections outline the firmware we developed forPlayNPort.
A. SPI Driver
These drivers involve writing and reading registers of eU-SCI B module. To save development time we coded the func-tions using polling technique which checks the correspondinginterrupt flag for successful completion of data transfer. Thesecan be made interrupt based by adding a circular buffer toprevent data corruption. Interrupt-based techniques improveefficiency while enabling CPU to sleep in low energy modes.A point to note here is that the driver to receive bytes makesuse of the transmit driver. In SPI, the master has to send 0xFFas (dummy) data to generate a clock signal for the slave totransmit data. TABLE I. SPI Driver functionsFunction Descriptionspi init Initializes SPI module by defining clocksource, bitrate, MSB/LSB first mode,master/slave mode, synchronous mode.Transmit Transmits datarcvr spi Receives a bytercvr spi multi Receives multiple bytes.
B. SDHC drivers
SD Card is a Non-Volatile Memory (NVM). SD cardsrespond to a set of predefined commands, that are specified bythe SD card association. Six registers are defined within thecard interface namely Operating Conditions Register (OCR),Card identification register (CID), Card specific data (CSD),RCA, Driver state register (DSR), SD card configuration reg-ister (SCR) [9]. These can be accessed only by correspondingcommands.We configured the SD card to be accessed in SPI mode[14]. All data tokens to the SD card are 8-bit and al-ways byte aligned to the CS signal. In our SPI drivers,we implemented methods to receive SD card response (re-ceive response), wait for the card to be ready (card ready),select and deselect the card (select, deselect), configure GPIOand SPI modules (power on), receive a data packet fromSD card (rcvr datablock), send a specific command to SDC(send cmd), send reset command and initialize SD in SPImode (disk initialize), get SDC status (disk status), read SDCsectors (disk read), device timer function (disk timeproc).
Fig. 2. A. Codes B. IR signals received for A, B, C, <, ∧ , > button press The following are steps to successfully initialize the SDHC[9].1) CMD0, argument: 0x0, CRC: 0x95 and the response wegot was 0x01.2) CMD8, argument: 0x000001AA, CRC: 0x87 and theresponse we got was 0x01.3) a) CMD55, argument: 0x0, CRC: 0x65, and the responsewe got was 0x01. b) ACMD41, argument: 0x40000000,CRC: 0x78, if the response if 0x0 we are OK, if it is0x01 we go to step 3.After performing an SD card sector write, we get one ofthe following responses [10].1) 010 − > Data accepted2) 101 − > Data rejected due to CRC error3) 110 − > Data rejected due to write error and bit 0 is aone
C. FAT file system drivers
A filesystem is the collection of many methods and datastructures that an operating system needs to exercise controlover the storage and retrieval of data. The file system usedon the MMC/SD Card is FAT. The MMC/SDC specificationsdefine the FAT type as FAT32 for 4GB to 32GB. As we usea 16 GB SD Card High Capacity (SDHC), the FAT type isFAT32. Only a FAT volume can co-exist on the card alongwith an FDISK partition.We have ported the generic FAT file system [11], FatFs [10]into our application and implemented the MSP432 platform-specific methods. The resultant file system drivers are used tocontrol the SDHC. We implemented the following methods.The method f mount is used to register/unregister the workarea of the volume. f open method is used to create/open afile. f close is used to close a file. f read is a method used toread data.
D. Audio decoder drivers
To enable VS1063 IC [12] for audio decoding operation,we wrote certain drivers making use of the SPI methodse implemented. Table 2. presents the functions and theirdescriptions below.TABLE II. Audio Decoder Driver functionsFunction DescriptionSpiinit Initializes SPI and GPIO modules.It sets initial SPIclock frequency as 2MHzwith MSB first and Mode 2.WriteSpiByteSDI Writes Serial Data Interface(SDI) data of the codec.WriteSdi Writes multipleSerial Data Interface(SDI) bytes. Returns 0 on success.Returns -1 if the number ofbytes is greater than 32ReadSci Reads Serial Command Interface(SCI) registers.WriteSci Writes Serial Command Interface(SCI) registers.VSTestInitHardware Hardware Initialization forVS1063. Configures CS, Reset andDREQ pins.VSTestInitSoftware Software Initialization for VS1063.Configures SMOD register andchip select for commandand data interfaces by enablingSM SDISHARE, performsa quick sanity check bywriting two registers andreading them for validity check,sets clock frequency toa higher clock, sets volume,sets WRAM address andfinally loads latestVS1063 Patches package.
E. IR Transmission, Reception and Decoding
The NEC IR transmission protocol uses pulse lengthencoding of the message bits. When a key is pressed onthe remote control, the message transmitted consists of thefollowing. A start bit, which is recognized by a 9ms leadingpulse burst. Then follows a 4.5 ms space. Then follows 8-bitaddress for the receiving device. Then follows 8-bit logicalinverse of the address. This follows 8-bit command. Thenfollows 8-bit logical inverse of the command. Then followsa 562.5 s pulse burst to signify the end of the messagetransmission [8]. As we see, 32 bits have to be read after thestart bit is received.
F. IR Decoding Logic
We used the MSP432 timer for decoding the IR codes.The timer is configured to make use of the SMCLK clock source and is configured to run in continuous up countingmode, whenever needed. Otherwise, it is halted temporarily,and its counts are reset to zero. A falling edge is initiallydetected using an interrupt. An interrupt is generated whenevera falling edge is detected on a port pin. Whenever the interruptservice routine is executed, the timer starts counting. If a startcondition is detected, then we execute the program for storingthe timer values in an array. The algorithm is described asfollows. After every bit read, we halt the timer, clear the timerregister values, start the timer in continuous mode.
Algorithm 1
Store timer data algorithm procedure D ATA S TORE2:
DetectStartCond Wait till end of start bit top : for i = 0 , i < do HaltTimer Clear Time Register StartTimer in continuous mode timer [ i ] ← timerVal i + + RaiseDataRecvFlag
We continuously poll for data received flag in our program,when the flag is raised, we decode the array to a command.The decode logic is presented in Algorithm 2 [15]. ButtonA: Starts playing music. Enters music mode. In this mode,the user has options to play/pause, play next/previous song,increase/decrease the volume. Button B: Starts reading the textfile. Enters reading mode. In this mode, the user has an optionto scroll down by choosing down arrow button. Button C: Weexit the current mode and go back to the menu.
Algorithm 2
IR Decode algorithm procedure C HARACTER D ECODE2:
Poll for data received flag Match each timer value to a bit DataRecvd : if bit [0 : 16] == then DecodeRemainingBits MatchToACommand else UnrecognizedCommand
ClearDataRecvFlagG. LCD Driver
We have written methods for LCD driver to initializeit, read data, poll LCD busy flag, put command/data onLCD’s data lines, display a character/string, go to desiredDDRAM/CGRAM address, print main menu, scroll throughtext file, clear screen, read the text file from SD card tobe displayed on LCD, populate text/music files, display acustom character, display custom character for play, pause,next, previous song. Initially, some of these methods wereritten for 8051. Then we ported them to MSP432 platformby making appropriate code tweaks.V. C
HALLENGES
We faced many challenges in making the system functionaland consumer friendly. Some of the problems and our solutionsto overcome these are presented in the following sections.
A. Issue mounting FAT file system
Initially, when we attempted to execute f mount(), itreturned FR DISK ERR. After hours of debugging, wefound that it was the following check that didn’t pass. if ( ld word ( f s − > win + BS AA )! = 0 xAA return This checked for last two bytes (byte 511 and 512) of sector0 to be equal to 0xAA55. Upon researching, we found that itis the signature of a Master Boot Record (MBR). We realizedthat somehow our sector 0 was corrupted. The solution wasthat, instead of using quick format option while formattingthe SD card, we perform a complete format. Then f mountreturned FR OK.
B. Software initialization of VS1063 Audio Decoder
Software initialization of VS1063 [12][13] included a sanitycheck in which it writes some data to registers and readsthe same data for verification. This check failed due to datacorruption, and when we analyzed it using signal analyzers,we found that the clock polarity and clock phase settings weremisconfigured. We reconfigured them, and it started working.
C. VS1063 not responding to SDI data writes
Ideally, as soon as one starts writing valid data to the SDI,SDI decodes it to generate audio output. However in ourcase, all we could hear was some noise. Eventually, we foundout that chip select for sending data is very different fromchip select for sending commands. We fixed it by modifyingfirmware appropriately.
D. Music plays in fast mode
Initially, the SPI clock frequency is set to 2MHz forinitialization. This led to the misbehavior. After initialization,we reduced the clock frequency to 120kHz, and it started toplay just fine. VI. C
ONCLUSION
In this paper, we have developed PlayNPort, a portablewireless music player, and text reader. We made use of offthe shelf electronic components, MSP432, decoder ICs anda PCB. We relied upon various datasheets, application notesand community resources in the process. By writing bare-metalfirmware code, we achieved full control over the system. Thus,we were able to provide a rich user experience, by giving auser the options to play/pause, play next/previous song, scrolldown while reading a text document. To improve the system,we can use a graphical LCD instead of a character LCD. Aswe tasked ourselves with building a complete system underbudget, we chose a minimal configuration system. The totalcost of the system is under 70$. As we know that IR is not the latest technology, in future,the system could be built using Bluetooth low energy (BLE)modules. IR needs a direct line of sight with the sensor. Bygoing for Bluetooth we eliminate this need. We could alsoexplore other VCD options that run at 3.3V, so we eliminatethe use of voltage converters. We could go for an LCDthat supports SPI communication to save many pins on themicrocontroller that we consumed for data lines.VII. A
CKNOWLEDGEMENT
We would like to thank Prof. Linden McClure for providingus with the opportunity to work in the Embedded SystemsDesign lab at the University of Colorado Boulder. We wouldalso like to thank our colleagues for being supportive throughour endeavor. We would also like to thank the ECE departmentat CU Boulder. R
EFERENCES[1]
Dot Matrix Liquid Crystal Display Controller Datasheet , Hitachi, pp167-226, 2010.[2]
Using MSP432 serial modules
IR Receiver Modules for Remote Control Systems , Vishay Semiconduc-tors, pp 1-7, 2008.[4]
VS1063a Encoder and Audio Coded circuit , VLSI Solution, pp 1-93, v1.31, 2017.[5]
Serial Peripheral Interface (SPI) User Guide , Texas Instruments, pp 1-51, 2012.[6] Bai Ying,
Microcontroller Engineering with MSP432: Fundamentalsand Applications , CRC Press, 2016.[7]
Enhanced Universal Serial Communication Interface (eUSCI) SPIMode , SLAU424F, 2012, Texas Instruments.[8]
NEC IR Remote Control Interface , Al-tium Techdocs, Online, 2017, Accessed fromhttps://techdocs.altium.com/display/FPGA/NEC+Infrared+Transmission+Protocol.[9]
Sandisk microSDHC OEM Product Manual , pp 1-25, Western DigitalInc., 2016.[10] Elm, Chang,
How to use MMC/SSD , 2010, Accessed from http://elm-chan.org/docs/mmc/mmc e.html.[11] Elm, Chang,
FAT Filesystem , 2010, Accessed from http://elm-chan.org/docs/fat e.html.[12]
VS1063 AppNote: Playback And Recording , VLSI Solution, pp 1-7, v1.10, 2016.[13]
VS1063a Patches: VLSI Solution Audio Decoder/Encoder , VLSI Solu-tion, pp 1-16, v 2.01, 2017.[14] Stefan Schauer, Christian Speck,
App Note: Interfacing the MSP430With MMC/SD Flash Memory Cards , Texas Instruments, pp 1-5, 2008.[15] K Lakhan Shiva, 2017,