STM32 Journal - Digikey
STM32 Journal - Digikey
STM32 Journal - Digikey
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>STM32</strong> <strong>Journal</strong><br />
the option of bringing floatingpoint<br />
efficiency to an extensive<br />
range of low-cost embedded<br />
applications. The <strong>STM32</strong> F4<br />
integrates a floating-point unit<br />
(FPU) to execute these operations<br />
natively in hardware. The FPU is<br />
fully compliant with the IEEE.754<br />
standard and has its own 32-<br />
bit single-precision registers to<br />
handle operands and results.<br />
These registers can be viewed<br />
as double-word registers to<br />
enable more efficient load and<br />
store operations. The context<br />
of the FPU can be saved to<br />
the CPU stack using several<br />
methods based on the application<br />
architecture and whether registers<br />
need to be preserved or not.<br />
The FPU supports the five different<br />
classes of numbers defined by<br />
the 754 standard—normalized,<br />
denormalized, zeros, infinites,<br />
and NaNs (Not-a-Number). It also<br />
supports the five exceptions of the<br />
standard—overflow, underflow,<br />
inexact, divide by zero and invalid<br />
operation—allowing applications<br />
to handle operations such as trying<br />
to compute the square root of a<br />
negative number (i.e., resulting in<br />
NaN + invalid operation exception).<br />
Exceptions are “untrapped”,<br />
meaning that the FPU will return<br />
the result as specified by the 754<br />
standard and raise an exception<br />
float function1(float number1, float number2)<br />
{<br />
float temp1, temp2;<br />
}<br />
temp1 = number1 + number2;<br />
temp2 = number1/temp1;<br />
return temp2;<br />
# float function1(float number1, float number2)<br />
# {<br />
# float temp1, temp2;<br />
#<br />
# temp1 = number1 + number2;<br />
VADD.F32 S1,S0,S1<br />
# temp2 = number1/temp1;<br />
VDIV.F32 S0,S0,S1<br />
#<br />
# return temp2;<br />
BX LR<br />
# }<br />
Figure 1 There is a significant reduction in code size when an integrated FPU is available (code on left) than when one is not (code on right).<br />
flag. If needed, developers can also<br />
use the <strong>STM32</strong> F4 floating-point<br />
global interrupt to address the issue.<br />
The integrated FPU of the<br />
<strong>STM32</strong> F4 offers a number<br />
of advantages to embedded<br />
designers:<br />
〉〉 Access to the more useful<br />
range and precision that<br />
floating-point brings<br />
〉〉 Reduced coding complexity by<br />
being able to work with numbers<br />
in a more natural format<br />
FPU assembly code generation<br />
1 assembly instruction<br />
〉〉 Greater throughput compared to<br />
software floating-point libraries.<br />
〉〉 Accelerated application<br />
development as C code<br />
generated by high-level<br />
tools can be used without<br />
modification or wrappers<br />
〉〉 Smaller code footprint since<br />
instructions that used to be<br />
multiple lines of code in software<br />
libraries are now implemented<br />
with a single instruction<br />
# float function1(float number1, float number2)<br />
# {<br />
PUSH {R4,LR}<br />
MOVS R4,R0<br />
MOVS R0,R1<br />
MOVS R1,R4<br />
BL __aeabi_fadd<br />
MOVS R1,R0<br />
MOVS R0,R4<br />
BL __aeabi_fdiv<br />
POP {R4,PC}<br />
Call Soft-FPU<br />
〉〉 Simplified debugging as macro<br />
calls in floating-point libraries<br />
are eliminated<br />
Effectively, the <strong>STM32</strong> F4’s FPU<br />
reverses the value proposition<br />
between fixed- and floating-point<br />
for many MCU-based designs.<br />
Seamless Integration<br />
Figure 1 shows the difference<br />
between the assembly code<br />
generated when an FPU<br />
is available on an MCU as<br />
22