没有开浮点处理器时
开了处理器时
开FPU主要分两步
1.编译器打开浮点数产生指令
2.在初始化函数中打开FPU
//system_stm32f4xx.cvoid SystemInit(void){/* FPU settings ------------------------------------------------------------*/#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */#endif...}//FPU_PRESENT 在 stm32f4xx.h定义//__FPU_USED 在 Cortex_M4.h定义
注意:SCB->CPACR
Cortex_M4 手册的解释是
//Access privileges for coprocessor n. The possible values of each field are:
//0b00 = Access denied. Any attempted access generates a NOCP UsageFault.
//0b01 = Privileged access only. An unprivileged access generates a NOCP fault.
//0b10 = Reserved. The result of any access is Unpredictable.
//0b11 = Full access.
//意思是说,如果没有设置为11,当使用它进行浮点运算时,会产生异常,在程序中的体现则会产生
HardFault_Handler,也就是说当编译器产生了浮点处理指令(汇编上有体现),
但是没有开启浮点处理器时,进行浮点运算就会产生硬件错误。