FPU Enable - STM32f401CCU6
Posted: Mon May 09, 2022 6:40 am
Hi, I am trying to enable the FPU on stm32f401CCU6 .
I keept the following setting as Default in STM Official Core - Duino.
Tools----->Optimize------>Smallest(-Os default).
Tools-----> Debug Symbols ------> None
Tools ------> C Runtime Library ----->Newlib nano (default)
Really what is the exact use of use of above setting ? i do not know and it was working as default . It will be useful if there is brief information of above setting .
i thought of use FPU and i was read forum discussion and attempt to use fpu .
i have tested the following setting condition giving different result for the below attached main code (without FPU enable code ).
Tools----->Optimize------>Smallest(-Os default) = Float sum (ms): 0
Tools----->Optimize------>Smallest(-Os ) with LTO= Float sum (ms): 0
Tools----->Optimize------>Fast(-O1 ) = Float sum (ms): 17
Tools----->Optimize------>Fast(-O1 ) with LTO= Float sum (ms): 17
Tools----->Optimize------>Faster(-O2 ) = Float sum (ms): 0
Tools----->Optimize------>Faster(-O2 ) with LTO= Float sum (ms): 0
Tools----->Optimize------>Fastest-O3 ) = Float sum (ms): 0
Tools----->Optimize------>Fastest(-O3 ) with LTO= Float sum (ms): 0
Tools----->Optimize------>Debug(-Og)= Float sum (ms): 35 .
the below attached main code is working with followed Setting included with FPU enabling code .
Tools----->Optimize------>Fast(-O1 ) = Float sum (ms): 17
Tools----->Optimize------>Fast(-O1 ) with LTO= Float sum (ms): 17
Tools----->Optimize------>Debug(-Og)= Float sum (ms): 35 .
the below attached main code is "" Not working “ - Getting Freeze with followed setting included with FPU enabling code .
Tools----->Optimize------>Smallest(-Os default)
Tools----->Optimize------>Faster(-Os )
Tools----->Optimize------>Faster(-O2 ) with LTO
Tools----->Optimize------>Fastest(-O3 )
Tools----->Optimize------>Fastest(-O3 ) with LTO
Please Identify where i am doing mistake and suggest me FPU Enabling and setting usage .
I keept the following setting as Default in STM Official Core - Duino.
Tools----->Optimize------>Smallest(-Os default).
Tools-----> Debug Symbols ------> None
Tools ------> C Runtime Library ----->Newlib nano (default)
Really what is the exact use of use of above setting ? i do not know and it was working as default . It will be useful if there is brief information of above setting .
i thought of use FPU and i was read forum discussion and attempt to use fpu .
i have tested the following setting condition giving different result for the below attached main code (without FPU enable code ).
Tools----->Optimize------>Smallest(-Os default) = Float sum (ms): 0
Tools----->Optimize------>Smallest(-Os ) with LTO= Float sum (ms): 0
Tools----->Optimize------>Fast(-O1 ) = Float sum (ms): 17
Tools----->Optimize------>Fast(-O1 ) with LTO= Float sum (ms): 17
Tools----->Optimize------>Faster(-O2 ) = Float sum (ms): 0
Tools----->Optimize------>Faster(-O2 ) with LTO= Float sum (ms): 0
Tools----->Optimize------>Fastest-O3 ) = Float sum (ms): 0
Tools----->Optimize------>Fastest(-O3 ) with LTO= Float sum (ms): 0
Tools----->Optimize------>Debug(-Og)= Float sum (ms): 35 .
Code: Select all
int sensorValue = 0;
void setup() {
Serial.begin(9600);
float fl_2, fl_3;
unsigned long tloop,tf,to ;
uint32_t itop = 1000000;
fl_2 = 1.00;
fl_3 = 0.00;
to = micros();
for (uint32_t i = 0; i < itop; i++)
{
fl_2 = fl_2 + fl_3;
fl_3 = fl_2 + fl_3;
}
tf = micros() - to;
Serial.print("Float sum (ms): ");
Serial.print((tf - tloop)/2000);
Serial.println();
Serial.println();
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(ATEMP);
Serial.println(sensorValue);
delay(1000);
}
Tools----->Optimize------>Fast(-O1 ) = Float sum (ms): 17
Tools----->Optimize------>Fast(-O1 ) with LTO= Float sum (ms): 17
Tools----->Optimize------>Debug(-Og)= Float sum (ms): 35 .
the below attached main code is "" Not working “ - Getting Freeze with followed setting included with FPU enabling code .
Tools----->Optimize------>Smallest(-Os default)
Tools----->Optimize------>Faster(-Os )
Tools----->Optimize------>Faster(-O2 ) with LTO
Tools----->Optimize------>Fastest(-O3 )
Tools----->Optimize------>Fastest(-O3 ) with LTO
Code: Select all
int sensorValue = 0;
void setup() {
enablefpu();
Serial.begin(9600);
float fl_2, fl_3;
unsigned long tloop,tf,to ;
uint32_t itop = 1000000;
fl_2 = 1.00;
fl_3 = 0.00;
to = micros();
for (uint32_t i = 0; i < itop; i++)
{
fl_2 = fl_2 + fl_3;
fl_3 = fl_2 + fl_3;
}
tf = micros() - to;
Serial.print("Float sum (ms): ");
Serial.print((tf - tloop)/2000);
Serial.println();
Serial.println();
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(ATEMP);
Serial.println(sensorValue);
delay(1000);
}
void enablefpu() {
__asm volatile
(
" ldr.w r0, =0xE000ED88 \n" /* The FPU enable bits are in the CPACR. */
" ldr r1, [r0] \n" /* read CAPCR */
" orr r1, r1, #( 0xf << 20 )\n" /* Set bits 20-23 to enable CP10 and CP11 coprocessors */
" str r1, [r0] \n" /* Write back the modified value to the CPACR */
" dsb \n" /* wait for store to complete */
" isb" /* reset pipeline now the FPU is enabled */
);
}