Home

ST AN2931 Application Note

image

Contents

1. Figure 3 DFU File Manager source browser E Multi Bin injection File Loading the DFU image To load the DFU image into the NOR Flash memory you have to 1 connect the STM3210E EVAL board to a PC using a USB cable 2 load and run the device firmware upgrade DFU demonstration on the STM3210E EVAL board You can find this firmware in the STM3210xxx USB development kit 3 start the DfuSe software on the PC see Figure 4 Doc ID 15349 Rev 2 ky AN2931 Implementation example 2 4 Figure 4 DfuSe software DfuSe Demo v2 2 1 Available DFU and compatible HID Devices STM Device in DFU Mode vi Application Mode DFU Mode Vendor ID Vendor ID 0483 Supports Upload Manifestation tolerant Supports Download Accelerated Upload ST Procuct ID Procuct ID DF11 Can Detach Version eS Version 0200 Leave DFU mode Actions Select T arget s TargetId Name Available Sectors Double Click for more 00 Intemal Flash 256 sectors 01 SPI Flash M25P64 128 sectors NOR Flash M29w 128G 128 sectors Upload Action Upgrade or Verify Action File File Vendor ID f Targets in file Procuct ID Transfered data size OKB O Bytes of 0 KB O Bytes Version C Verify after download C Optimize Upgrade duration Remove some FFs Time duration 00 00 00 Select the NOR Flash memory as target then click on
2. The advantage of ADPCM is that the difference between the predicted signal value and the actual signal value is usually quite small which means it can be represented using fewer bits than the corresponding PCM value Depending on the desired quality and compression ratio the differential signal is quantized using 4 2 bit 8 3 bit 16 4 bit or 32 5 bit levels Many implementations of the ADPCM algorithm exist They differ by the quantization and the prediction patterns In this application note we provide a 4 bit quantization algorithm developed by the Interactive Multimedia Association IMA IMA ADPCM IMA ADPCM was chosen for several reasons itcan operate at different sampling rates between 8 kHz and 44 10 kHz it guarantees good quality with low CPU usage and memory size requirements ithas widespread implementations for instance in the Windows and MAC operating systems The IMA ADPCM algorithm is fully described in a document published by the IMA Digital Audio Focus and Technical Working Groups Recommended Practices for Enhancing Digital Audio Compatibility in Multimedia Systems revision 3 ADPCM algorithm implementation The IMA ADPCM algorithm provided in this application note is used to encode audio files that have the following specification Audio format PCM Audio sample size 16 bits Channels 1 mono Audio sample rate from 8 kHz to 44 1 kHz Each 16 bit PCM sample is encoded into
3. kyf AN2931 Application note Implementing the ADPCM algorithm in high density STM32F103xx microcontrollers Introduction This application note describes the ADPCM audio firmware codec and provides a demonstration firmware showing how to play ADPCM files using the high density STM32F103xx I S feature with an external DAC This application note is based on AN2739 How to use the high density STM32F103xx microcontroller to play audio files with an external I S audio codec The features linked to the SPI IS and the external DAC will be skipped here because they are already explained in AN2739 It is therefore highly recommended to refer to AN2739 to fully understand this application note April 2009 Doc ID 15349 Rev 2 1 15 www st com Contents AN2931 Contents 1 ADPCM algorithm 5 1 1 General overview 5 1 2 ADPCM algorithm implementation 5 12 ADPCM algorithm functions 6 1 3 1 ADPCM_Encode function 6 1 3 2 ADPCM Decode function maai KA aa EE ee ee RR eee 6 2 Implementation example 8 2 1 BE eie les SERE AG HERE AO EE EE EI ALT 8 22 ADPCMfile generation 8 23 ADPCM file loading 9 2 4 ADPCM file
4. playing 11 3 GCONCIUSION sis os EER aa EES N eases siete DE GEEN REG RR Ms 13 4 Revision history 14 2 15 Doc ID 15349 Rev 2 ky AN2931 List of tables List of tables Table 1 ADPCM algorithm functions 6 Table 2 ADPCM Encode TUNCHON s iet ee eae awed ak srta Err Eer eee Pee EPG be le dee 6 Table 3 ADPCM DaeodefuncHON sive N eae eee a a a ee ee ee Se RE He 7 Table 4 Document revision history 14 ky Doc ID 15349 Rev 2 3 15 List of figures AN2931 List of figures Figure 1 ADPCM file generator 8 Figure 2 DFU File Manager icr sicrit Errr riea nrin EA eee 10 Figure 3 DFU File Manager sourcebrowser 10 Figure 4 DfuSesoftware 11 4 15 Doc ID 15349 Rev 2 ky AN2931 ADPCM algorithm 1 1 1 2 ADPCM algorithm General overview Adaptive differential pulse code modulation or simply ADPCM is an audio algorithm for waveform coding which consists in predicting the current signal value from previous values and transmitting only the difference between the real and the predicted value In plain pulse code modulation PCM the real or actual signal value is transmitted
5. AS AUTOMOTIVE GRADE MAY ONLY BE USED IN AUTOMOTIVE APPLICATIONS AT USER S OWN RISK Resale of ST products with provisions different from the statements and or technical features set forth in this document shall immediately void any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever any liability of ST ST and the ST logo are trademarks or registered trademarks of ST in various countries Information in this document supersedes and replaces all information previously supplied The ST logo is a registered trademark of STMicroelectronics All other names are the property of their respective owners 2009 STMicroelectronics All rights reserved STMicroelectronics group of companies Australia Belgium Brazil Canada China Czech Republic Finland France Germany Hong Kong India Israel Italy Japan Malaysia Malta Morocco Philippines Singapore Spain Sweden Switzerland United Kingdom United States of America www st com ki Doc ID 15349 Rev 2 15 15
6. a 4 bit ADPCM sample which gives a compression rate equal to 1 4 The implementation of the IMA ADPCM algorithm consists in two functions one that codes and the other that decodes the audio samples The ADPCM firmware is composed of two files a adpcm c it contains the source code of the two ADPCM functions that perform the coding and decoding b adpcm h it is the header file of adpmc c It should be included in the files where the ADPCM functions are called Doc ID 15349 Rev 2 5 15 ADPCM algorithm AN2931 1 3 1 3 1 1 3 2 6 15 ADPCM algorithm functions Table 1 describes the ADPCM functions Table 1 ADPCM algorithm functions Function name Description ADPCM_Encode Encodes a 16 bit PCM sample into a 4 bit ADPCM sample ADPCM_Decode Decodes a 4 bit ADPCM sample into a 16 bit PCM sample ADPCM Encode function Table 2 describes the ADPCM_Encode function Table 2 ADPCM Encode function Function name ADPCM_Encode Prototype uint8 t ADPCM_Encode int16_t sample Behavior description Encodes a 16 bit PCM sample into 4 bit ADPCM sample Input parameter Sample a 16 bit PCM sample Output parameter None Return parameter The encoded ADPCM 4 bit sample loaded into a byte The ADPCM_Encode function returns a byte containing the 4 bit ADPCM sample The software has to store every two ADPCM samples into one byte to save memory space Example Input
7. ed Recover wav and it is generated in the same directory as your WAV source file In this way you can listen to both the original WAV file and the recovered one to compare the sound quality ADPCM file loading Use the DfuSe software to load the ADPCM file into the NOR Flash memory To do so two steps are necessary 1 generating the dfu image 2 loading the dfu image into the NOR Flash memory Generating the dfu image To generate the dfu image you have to use the DFU File Manager software provided within the DfuSe package For that open the DFU File Manager program and choose the DFU file generation option The window shown in Figure 2 opens You have to select 2 for the target ID meaning that the file is loaded into the NOR Flash memory Then click on the Multi BIN button to open the source browser and select your ADPCM file Doc ID 15349 Rev 2 9 15 Implementation example AN2931 10 15 Figure 2 DFU File Manager E DFU File Manager V2 2 1 Generation Device Images Vendor ID Ox 10483 Product ID Ox 0000 Target ID 2 519 or Hex Version Ox 0000 Target Name ST Deletion Delete selected Image The NOR Flash memory is mapped on the FSMC interface from address 0x6400 0000 which is the start address of the ADPCM file storage area So you have to set the address of the dfu image to 0x6400 0000 see Figure 3 Finally click on Add to list and then Generate to finish the DFU file generation
8. mp Ox0OF Decode the first ADPCM sample pcem_samplel ADPCM Decode code Extract the second ADPCM sample code adpcm_byte gt gt 4 Decode the second ADPCM sample pcem_sample2 ADPCM Decode code Doc ID 15349 Rev 2 7 15 Implementation example AN2931 2 2 1 2 2 8 15 Implementation example Description You can run the provided example on the STM3210E EVAL board It is a typical audio application that consists in e first encoding a PCM file into the ADPCM format using a PC software This software is called muse exe and was developed by ST It implements the same ADPCM algorithm encoder as the one that runs on STM32F103xx performance line devices muse exe is included in the zipped software package that comes with this application note please refer to Section 2 2 for how to use this tool e then loading the encoded file into a Flash memory and finally decoding the file and playing it using the high density STM32F 103xx microcontroller On the STM3210E EVAL board the 128 Mbit NOR Flash memory stores the ADPCM file and the firmware decoder that runs on STM32F103xx devices It then decodes the stream and with the I S external DAC plays back the audio samples The hardware environment is based on the application note AN2739 How to use the high density STM32F103xx microcontroller to play audio files with an external I S audio codec so please
9. pcm samplel and pcm_sample2 two 16 bit PCM samples Output adpcm_byte two 4 bit ADPCM samples stored into one byte uint8_t code Encode the first 16 bit sample code ADPCM Encode pcm samplel Store the first 4 bit sample adpcm byte code Encode the second 16 bit sample code ADPCM Encode pcm sample2 Store the second 4 bit sample adpcm byte code lt lt 4 The adpcm_byte contains two 4 bit ADPCM samples ADPCM Decode function Table 3 describes the ADPCM Decode function 4 Doc ID 15349 Rev 2 AN2931 ADPCM algorithm 4 Table 3 ADPCM Decode function Function name Prototype ADPCM Decode int16 t ADPCM Decode uint8 t code Behavior description Decodes a 4 bit ADPCM sample into a 16 bit PCM sample Code an 8 bit data item whose 4 LSBs contain the encoded ADPCM rameter Input paramete sample Output parameter None A 16 bit PCM sample Return parameter The input of the ADPCM_Decode function is a byte that contains the 4 bit ADPCM sample The software has to extract the 4 bit ADPCM data and store them into a byte before calling the ADPCM_Decode function Example Input adpcm_byte two 4 bit ADPCM samples stored into one byte Output pcm samplel and pcm_sample2 two 16 bit PCM samples uint8_t code Extract the first ADPCM 4 bit sample code adpcm byte a
10. refer to that application note for more information To run this demo three steps are required 1 generating the ADPCM file 2 loading the ADPCM file into the NOR Flash memory 3 playing the ADPCM file ADPCM file generation The application note package contains a PC software called Muse to encode PCM files into the ADPCM format Figure 1 ADPCM file generator Muse v1 0 1 Source File Browse Converted File Make a recovered PCM file Exit Doc ID 15349 Rev 2 ky AN2931 Implementation example 2 3 If you run the Muse exe program and press the Source File Browse button the File Selection dialog appears prompting you to select a WAV source file As mentioned before the WAV file should meet the following requirements Audio format PCM Audio sample size 16 bits Channels 1 mono Audio sample rate from 8 kHz to 44 1 kHz If your WAV file does not satisfy these conditions you must previously convert it using an audio converter tool like sndrec32 exe which is the Microsoft default program for audio records Once you have selected the file to be converted the New File Selection dialog appears prompting you to select the save location of your ADPCM converted file You can retrieve the PCM format of the encoded audio file by ticking the Make a recovered PCM file check box In this case the generated ADPCM file is decoded and formatted into a WAV file This WAV file is call
11. se of the ST products and services described herein and ST assumes no liability whatsoever relating to the choice selection or use of the ST products and services described herein No license express or implied by estoppel or otherwise to any intellectual property rights is granted under this document If any part of this document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products or services or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such third party products or services or any intellectual property contained therein UNLESS OTHERWISE SET FORTH IN ST S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY WITH RESPECT TO THE USE AND OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIED WARRANTIES OF MERCHANTABILITY FITNESS FOR A PARTICULAR PURPOSE AND THEIR EQUIVALENTS UNDER THE LAWS OF ANY JURISDICTION OR INFRINGEMENT OF ANY PATENT COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT UNLESS EXPRESSLY APPROVED IN WRITING BY AN AUTHORIZED ST REPRESENTATIVE ST PRODUCTS ARE NOT RECOMMENDED AUTHORIZED OR WARRANTED FOR USE IN MILITARY AIR CRAFT SPACE LIFE SAVING OR LIFE SUSTAINING APPLICATIONS NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALFUNCTION MAY RESULT IN PERSONAL INJURY DEATH OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE ST PRODUCTS WHICH ARE NOT SPECIFIED
12. so provides an example of use that consists in decoding an ADPCM encoded audio stream stored in a Flash memory and playing back the decoded samples The high density STM32F103xx was used in this application note because it features an I S interface that allows communication with the external DAC available on the STM3210E EVAL evaluation board It is however possible to run this ADPCM firmware codec and play audio files with other STM32F100 devices that do not feature an I S peripheral by using the PWM output In this case you simply need to update the provided decoding example for the STM3210B EVAL evaluation board and use the PWM output for audio playback Doc ID 15349 Rev 2 13 15 Revision history AN2931 A 14 15 Revision history Table 4 Document revision history Date Revision Changes 04 Mar 2009 1 Initial release 30 Apr 2009 2 In code u8 and s16 updated to uint8_t and int16_t respectively Doc ID 15349 Rev 2 AN2931 Please Read Carefully Information in this document is provided solely in connection with ST products STMicroelectronics NV and its subsidiaries ST reserve the right to make changes corrections modifications or improvements to this document and the products and services described herein at any time without notice All ST products are sold pursuant to ST s terms and conditions of sale Purchasers are solely responsible for the choice selection and u
13. the Choose button located in the Upgrade or Verify Action area to select your ADPCM DFU image Finally click on Upgrade to perform the download ADPCM file playing At this point you have succeeded in loading the ADPCM file into the NOR Flash memory It is now time to start the playback demo Go to the application note package and open the ADPCM AN folder Open the folder project select the suitable project workspace and open it in your toolchain Build all the source files load the project image and then run the program The LCD on the STM3210E EVAL board will display the audio commands while the joystick and the key buttons will be used to control the demo The allowed audio commands are play pause stop forward rewind and volume setting You can select the audio output interface which can be the speaker provided on the STM3210E EVAL board or headphones Better audio quality is achieved with headphones You can connect them to the STM3210E EVAL board via the audio jack Doc ID 15349 Rev 2 11 15 Implementation example AN2931 Note that to rewind and forward through the audio file you have to use the joystick buttons as follows push the joystick to the right to forward push the joystick to the left to rewind 12 15 Doc ID 15349 Rev 2 ky AN2931 Conclusion 3 Conclusion This application note describes how to implement the IMA ADPCM firmware audio codec dedicated to STM32F103xx devices It al

Download Pdf Manuals

image

Related Search

ST AN2931 Application Note application note an-ss1 application note an-1162

Related Contents

  DENON PMA-SA1 INTEGRATED STEREO AMPLIFIER Manual                  

Copyright © All rights reserved.
DMCA: DMCA_mwitty#outlook.com.