You are on page 1of 9

STM32 Journal

Volume 1, Issue 2

In this Issue:
ggBringing 32-bit Performance to 8- and 16-bit Applications
ggDeveloping High-Quality Audio for Consumer Electronics Applications
ggBringing Floating-Point Performance and Precision to Embedded Applications
gg



  


gg  
 !
" 

#
$ %
 
ggIntroducing a Graphical User Interface to Your Embedded Application

STM32 Journal

Developing High-Quality Audio for


Consumer Electronics Applications
By Paul Beckmann, CEO/CTO, DSP Concepts
Dragos Davidescu, Chief System Architect, STMicroelectronics
John Knab, Application Engineer, STMicroelectronics

With the falling cost of


 &
$ '

manufacturers are considering


adding digital audio functionality
to more and more consumer
devices and other embedded
&&  (





support the wide variety of media


sources users want to access
such as an iPhone, Internet
'
% 
)*
'


)
(

 
%&
"'

"
) !
 " '


& /
& %

  

&'
.)'

'

&(

In this article, well show how


 &

 
$ 
based digital signal processing
0)4

5  &
"

(FPU) capabilities to enable


  
"
& !'

implement enhanced algorithms,


convert between multiple
Achieving high-quality sound
 !
'
 
 
output, however, is nonspeed communications without
 (
)"
+"  
&

impacting audio quality, optimize


greatly upon the final system
 " '
!

"
designs to balance quality and
to design even when prototype cost, and manage other system
!
"


&



  (
.

user interface, all with a single


addition, implementing real  (
time digital signal processing
algorithms introduces a
Consumer Audio
whole new set of concerns

 &
"

$ 
Traditionally, introducing audio

 (

 "

to an embedded application
implementing advanced filters
requires digital signal-processing
and processing algorithms,
capabilities beyond the capabilities



$ (


;& <

&"
!


&!
!

+"

 =
"


advanced audio algorithms to


achieve full performance:
Spatial enhancement: In


!
  '


&!


 
>?>@


& (

 



spacious, rich sound, spatial


enhancement is required is
to compensate for the close
&% 


&!(

Multi-channel audio: For


systems supporting more than

&!'

 
&"

signal requires processing to


create the additional audio
 (
Equalization:
)&!



be equalized to achieve better


"
+"  (
.

&!

in use change, the equalization





J" 

 (

Developers can employ a


variety of equalization methods,

including graphic and parametric


+" / (
K
 

applications, developers may


even want to design their own
equalization algorithms using a

!
*(
Peak limiting:
)&!
%

nonlinearity at louder sound


 (
*
&& 



gain and carefully controlling the


&!
 '

 

& 

louder with a minimum amount



  (
Boost: When listening to music
at low volume levels, much
detail, and therefore depth, can

 (
* 





certain other frequencies at low


volume levels using loudness
compensation or perceptual
volume-control techniques can
 = 
&
&

"
+"  (
Level matching: Level matching
eliminates the need for users to
J"

 "




11

STM32 Journal

"M
" 

 



 "(
Digital audio has commonly
been implemented in consumer
electronics and embedded
applications using a second
&
 


!(



!

&"'

however, manufacturers need to


be able to process audio on the

$ (
In general, it is easier to
& 
"


$

than it is to implement real-time


responsiveness and connectivity


)(
)'
 
% 

at processing audio, dont have


the peripherals or interrupt
responsiveness required for real 
 (
)
  "

are also typically designed for


high-end signal processing
and massive parallelism that
%

+" 



&
"
&&  (
.

addition, DSPs are not designed


to support communication
 
!
)*'
)
'


NK'


)
!

station would still require a


second processor to handle
  (

With the introduction of DSP


&  

$
 " 

 '
$ 




advanced math processing

ART Accelerator

Up to 1-Mbyte Flash memory

System
Power supply
1.2 V regulator
POR/PDR/PVD
Xtal oscillators
32 kHz + 4 ~26 MHz
Internal RC oscillators
32 kHz + 16 MHz
PLL
Clock control
RTC/AWU
SysTick timer
2x watchdogs
(independent and window)
51/82/114/140 I/Os
Cyclic redundancy
check (CRC)

Up to 192-Kbyte SRAM

STM32 F4

FSMC/SRAM/NOR/NAND/CF/LCD
parallel interface

ARM Cortex-M4
168 MHz

80-byte + 4-Kbyte backup SRAM

Floating-point unit (FPU)


Nested vector
interrupt
controller (NVIC)

Camera interface
3x SPI, 2x I2S, 3x I2C
Ethernet MAC 10/100
with IEEE 1588
2x CAN 2.0B
1x USB 2.0 OTG FS/HS
1x USB 2.0 OTG FS
SDIO
6x USART
LIN, smartcard, lrDA,
modem control

512 OTP bytes

Connectivity

MPU
JTAG/SW debug/ETM
Multi-AHB bus matrix

16-channel DMA

Control
2x 16-bit motor control
PWM
Synchronized AC timer
10x 16-bit timers
2x 32-bit timers

Crypto/hash processor

3DES, AES 256


SHA-1, MD5, HMAC
True random number generator (RNG)

Analog
2-channel 2x 12-bit DAC
3x 12-bit ADC
24 channels / 2.4 MSPS
Temperature sensor

Figure 1

)

%&
 
)R?
$ 



$ %
  "
 

 

   
&& 


 


 

$ 

& /
&'
'



 


&&  (

capabilities required to handle


not only basic audio processing
but the advanced algorithms
required to improve quality as
 (
.
 '
 


requiring developers to handcode assembly as is typical for


)
 '
$ 
O

ease-of-use and faster time-to!


" 
$
& 


&&  
(

$ 

 
&= 

architected to provide short and


deterministic interrupt latency as
well as ultra low-power operation

 &
&&  (


)R?
$
X
"

Architecture

)R?
  "


ST has been designed to



R?
$
&  

to a wide range of consumer


audio applications, including

" 
&!'
!

  '

&(


)R?
KZ'



#

$ %Z

& 


"&

>[@
\/'
 
   

capabilities such as DSP


 " 


5  &

unit to allow manufacturers


to produce consumer audio
&&  
O
+"  

& !





0
K "
>4(

12

STM32 Journal

DSP application example: MP3 audio playback

Max

General Purpose MCUs

Min

Discrete DSPs

Cortex-M4
Specialised Audio DSPs
0

10

15

20

25

30

MHz required for MP3 decode (smaller is better!)


DSP Concept

Figure 2
N 
 
$ %Z
'

)R?
KZ
O
% 
"
&
&  


%

&


 &"&
$ 

 
)(


)R?
KZ
O
% 

audio processing capabilities


0
K "
?4(
N 
 


peripheral integration, a single


)R?
KZ

&

 
O '
 &
 " 


implementing embedded audio


that combines performance,
ease-of-use, connectivity, and
signal processing to achieve
+"  
"
& !(
`

&  


)R?
KZ

for accelerating audio design,


enhancing performance, and
lowering system cost include:

Digital Signal Processing


Instructions:
N 

)R?

KZ'
 &




"&

>jk
)&=

 " (



 " 

include single-cycle multiply""  


0$4'

saturated arithmetic, and both


@

>[
).
  

& (
. 
  "


designed to enable high-quality


audio in consumer electronics
and embedded applications in a

 O 




& 
 
)(

13

STM32 Journal


  The bus
size of the processor has a
tremendous impact on both
performance and power
(


"

samples are streaming at 16


bits, the system still needs
32-bits to store intermediate
&"  (

>[
$


)'

%& '
+"


& 
0Z
" & 


R
 4
J"

&  


 
R?
%
R?
" &  (


)R?
KZ

%" 


R?
$
0" & 


accumulate) with only one


  
& (

DMA_P2

DMA_P1

DMA_MEM2

64 Kbytes SRAM

System

Data

Instructions

168 MHz
MHz
120

DMA_MEM1

GeneralGeneralEthernet
USB OTG
purpose
purpose
MAC 10/100
HS
DMA2
DMA1
DMA
DMA
8 channels 8 channels

Bus masters

100 Mbit/s
480 Mbit/s
12.5 MByte/s 60 MByte/s

Bus Slaves
FSMC
AHB2 peripheral
AHB1/APB1

AHB1 peripheral
AHB1/APB2

SRAM 16 Kbytes
SRAM 112 Kbytes
672 MByte/s D
672 MByte/s I

ART
Accelerator

Cortex-M4
with CPU

7-layer 32-bit multi-AHB bus matrix

Floating-Point Unit:

)R?

KZ

 



   
5  &
"

0K 4(
N 
  &

algorithms can be implemented


"
=%&
  '


&&

& % 



"5

5




" 
 (
.

 '
=%&
&

O


 


5  & '



& 


"
" (
N 

the integrated FPU, there is no


& 

 

&(

$


5  &


also be substantially faster and


+"



=%
&
(

D
I

Flash
1 Mbyte

Figure 3


"  
 %

  
)R?
$ 
 
&& 


 
" "

 
" & 

 

 
 "
+"
 


$ (

&
)R?
$ 
 

"
 

& 

  
&&



 !


 
& 
&(

Multi-Layer Bus Fabric:



!

  
 

processing is maintaining

 
5(
.


consumer audio device,


'

$
"

move not only signal data but


manage program memory,
communication ports, and other
 
!(

& % 

and real-time nature of audio


algorithms also requires
them to be integrated with
application code to ensure that

 

&&  
!

"

$ (
K "


"
& !
&
3 shows the high level of

 (

parallelism that can be achieved


through simultaneous transfers

)R?
  "


over a multi-layer fabric:


designed to minimize this
problem so that developers
gg

 


%" 

from Flash with data stored in


do not need to spend time
)#
04
 
&  
5 (

This is achieved through the low


gg The compressed audio stream
interrupt service overhead of
is received over USB and
)R?


 

 

)#
0 4(
the multi-layer bus fabric that
 
" & 

 
gg CPU with DSP and FPU
functionality accesses the
to occur simultaneously without
>Z

STM32 Journal
compressed audio stream for
decompression and signal
processing (green)
gg

&
R
 





$

)#

(yellow)
gg Audio data is output to I2S
" 

0 4
gg Graphical icons are transferred
from Flash to the display
" 

0 "4
Communications Interfaces:
Users want to be able to access
"
 

O
"



O
 (

N 

 
%

 
including USB (host and device),
 

. 
#'

).'

% 

 &

 
5% 

devices that support a wide


 

" 
 (
In addition to being able to
receive data without loading
the CPU, developers need to
be able to address the many
issues related to streaming
"'
 "

&! 


!

!
  (
K

%& '
)*
!
  


&
"

5



"
"O


 

"


&  (


can result in lost or dropped


&! 

&
"

+"  (




limitation, developers can utilize


&  

0)#$4(

)#$

 
""

 

 
"
&
0(('
 !

domains) while maintaining audio


=  '
& 

  

 

 !
&'



%
"

O

"(
K
&&  



)#$'

)R?
KZ

requires only 10% utilization,


leaving plenty of headroom for
 
  &
!(
Multiple Clock Sources:
Consumer audio systems require

"

O
 !

 "

$ '

)*'

.?) 

=%

frequencies and need to be


" 





J (



"


 !

for each of these can impact


&(
K
%& '



straightforward to achieve a clean


 !

>[@
\/


$ '

ZZ(>
`\/


.?)
 


Z@
\/

)*
"





"

 
 !
"(

)R?
KZ
   





 !

5%  (




"


 

 
 !

and the second PLL is available



 

" 
 !



 +"  
"(

Complete audio system


STM32 F2
CPU load

STM32 F4
CPU load

Flash
footprint

RAM
footprint

MP3 decoder

17%

6%

23k

12344

MP3 encoder

22.5%

9%

25k

16060

WMA decoder

17.5%

6%

45k

36076

AAC+ v2 decoder

25%

11%

54k

87000

Channel mixer

2.5%

2%

0.6k

16

Parametric Equalizer

16%

12%

2k

300

Loudness Control

4.5%

3.5%

3.25k

632

SRC

22.5%

10%

17.5k

1880

Figure 4

N
&" 
>[

R?
)
" '
)R?
KZ
O

?kj

& (


" '
 

&
 
 &

 



&

"

  

" 
&
"
+"  (

In addition to being able to receive data


without loading the CPU, developers need
to be able to address the many issues
related to streaming audio, including lost
&! 

!

!
  (

K
%& '
)*
!
  


&
"

5


"



 
"


&  (
15

STM32 Journal
$).)
)


  

 & (

$).)

DSP library includes a large


"

)

5  
point functions optimized for
the algorithms commonly used

"
&&  (




"&& 

#


processors built around the


$ %Z
&(
)

Concepts is the company that


 

$).)
)
(

They have leveraged their


  
!  





 

"
 !


!
"&

 
&

 
 '
"
N(
Figure 5

"
N

)
$& 
O

.
 &



 
 &

 

 
5


&&  

  
&

 !

 

"

 &
 (


  

"
O

 !

 
 




)R?
  "

to maintain a permanent USB


connection and avoid audio
/ 
"(
Integrated Audio Interfaces:

)R?
KZ


" 
"& %
.?)
 
 

 
O



j(k
& 
+"
(



 

% 
 !

input to the I2S peripheral if



% 
 +"  
"



&(
.
 


simplifying design, integrating


the I2S interfaces reduces
component count, board size,

 
 (
MCU Peripherals:

)R?

architecture includes all of the


real-time peripherals required for




$ 

&&  (


 


)R?

KZ
&  
 



level of performance to audio


&&  (


a long 32-bit multiply or


" & ""  
0$4

Audio Algorithm Design

Audio Weaver enables


 &

+"! 
 

the audio processing portion


& 


)R?
K?'




 
(('
 

%& '
!
R
 (
N 
that goes on between receiving

)R?
KZ'

& 

an audio signal and outputting



&


 
 (

 (
"
N
O


When computing 16- and 32GUI-based development



)
" '

)R?

environment that enables


KZ
O

?kj
0
K "

developers to design the signal


Z4
& (


" '

5


&&  


systems can drop into sleep


  
&
 !

mode faster to conserve power


and connecting them using
or run more algorithms to further a drag-and-drop editor (see
&
"
+"  (
K "
k4(

 !


In addition to the integrated DSP optimized code behind it, and
the tool automatically creates
&  


)R?
KZ'


+"
 
 " "(

developers have access to the


16

STM32 Journal
*"
& %
" 


built from base audio functions,



=

%" 
 


&



losses compared to hand



 (

complete reference designs are


available, with assistance from
DSP Concepts to tune them


=
&" 
 (

Companies that are comfortable


with audio processing can
!
 
"
"

 !

&


functionality and build them


into higher-level processing

.)


+"



"
&
  (

This enables engineers to


Accelerating Optimization measure how much a particular
improvement in sound quality will
To speed design, Audio Weaver
cost in terms of CPU utilization
supports cross-platform

 




 & (

  

"

the same algorithms on a PC as use of processing resources




)R?
KZ

 
when many functions have to
& 
" " (

a powerful environment in

value-add of Audio Weaver is


 
 ! (

When algorithm code is written


by hand, each design iteration
requires substantial time
investment since the code must
be optimized and tuned to
see what its actual impact on
sound quality and processing
When algorithm code is written by hand, each design

(
N 
"
N'

the design cycle is much faster,


iteration requires substantial time investment since the
giving developers the ability to
%& 

= " 


code must be optimized and tuned to see what its actual



O 


"

&

"
+"  

&

(
N 
"

quality while reducing system


 (
$

  
& /

Weaver, the design cycle is much faster, giving developers



.)


" '

"&& 
5  &


  

%& 

= " 


O 


&
"


)R?

KZ'
O
5% 
& 


"
+"  
 
"
 
 (
modules, and does not require

#)

& (



 "

>kj
O

  (

&  

which to design and tune the


"
 !'
 "

$

"

O

companies can accelerate


software in parallel with hardware 
= 

+" /


& 
.(
design using Audio Weaver as
 & (

 

&!(


= '

N 
 
!
"
N'



&

!
 

hardware is available, the code



%& '

&


has become possible to create


core components that not only


   


)R?
frequency response that is 3 dB
highly tuned audio applications
J"&  
 
 
  

KZ

=
& / 
'
O



&
 


without engineers needing


optimized code but provides a
" 

 =
 
 

= 

O

 




&
!  

development environment that


!
 (
>
*(

  
O


"
& (
K

facilitates fast prototyping and


in CPU utilization between
"
=
& / '

companies new to audio,


" (
K

&




= 


"

 &

&= 


17

STM32 Journal
to determine where to allocate
$
"

%/

"
+"  (

"
& /


)R?

  "(
K
%& '

)

 
& 
O


variety of evaluation boards


At the end of the day, however,
 
"
&  (
)
 

audio quality is not about


 

"
&&  


O

!
  

response graphs but how it


not comprised solely of audio
reference designs that provide
 " 
"

&& (
N 
& (

  
 

a representative design that


many development systems,
design, DSP Concepts also
can be used in a wide range of
 


!

&

% 
 



&&  (
J"  

'
& '
software functionality beyond its
and download code before they
K
&& 



0K.4

% 
"
" 
'





= " (

'
)
O

&& 

including:
However, to assess the impact of
iAP application, a complete
gg

#  
!


= 

+"  '


 " 


)R?
K?


gg


"
.
 
%& '
 &




)R?
KZ


 


 


 
= " 
gg

$
 
 
 +"  
"
%&(

 
 

 (

The Apple iAP application


gg Boot loader
support both simple accessory
Audio Weaver solves this
and audio streaming accessory
gg Update manager
problem by supporting a
for iPod, iPhone, and iPad
tuning interface that can
gg

K 
= 
 

(
$& 
 "
 
= 
  


  (
N 

  


gg

 

)R??%

System-level Design

)R?Z%


= "

 
 

One of the challenges to


to which developers connect
" & 
  
 

 !
adding audio to embedded
their Apple Authentication
of a button, developers can
 


 

$

Coprocessor (ACP) circuit


&

 

&!

" "
O


+" / 



O
& 
designs, audio is typically
gg Free Apple iPod Accessory
& (
 



not one of the applications


  <
04
=
 

tuning interface is seamless


"&& (

Lingoes for authentication and


and transparent, compared to
   
 
To address this shortcoming,
instrumenting code that can
gg Free USB Host Library with
&
+"  
"

% 
)

 
 = 


creating
digital
audio
resources
USB Host HID class for control



$ (
for its customers in order to
and information data

  

"
+"! 


O
&  
"


easily without recompiling can


designs as well as tools that
substantially shorten the time
enable the design of quality

!

& /

 (

K % 
"
 
& =

the optimization process for


 &


"(

For audio streaming accessories,


the Apple iAP application also
supports:
gg Free USB Host Library USB
Host Audio classes
gg

# 


control
gg Digital audio streaming
gg

"

%  
gg Flash card reader capabilities,
such as using an SD card or
$'



"

= 


(
& /

decoders are provided for this


purpose free of charge
Todays consumer audio devices

& %
 


require both high performance



"&&
+"  
& !


5%  


& 

 
!
%&  (

With its high performance


'

"  
"

fabric enabling simultaneous


data transactions, and the right
%

$
&& 


  '



)R?
KZ


an ideal architecture for many


embedded and consumer audio
&&  (
 &



 
 
O

synchronized digital audio


& !


 
+"  

"

 
$ (

18

You might also like