简体   繁体   English

STM32F4处理器中的FPU

[英]FPU in STM32F4 Processors

Relevant Specs : 相关规格

  • STM32F407IG Processor with FPv4-SP FPU (Cortex M4F); 带有FPv4-SP FPU(Cortex M4F)的STM32F407IG处理器;
  • STM32F40G-EVAL dev board; STM32F40G-EVAL开发板;
  • IAR Embedded Workbench - ARM, v6.50 IAR嵌入式工作台-ARM,v6.50

Question : How might I programmatically turn the FPU on prior to FP computations, and turn it off again when finished? :在进行FP计算之前,如何以编程方式打开FPU,并在完成后再次将其关闭?

  • IAR EWARM provides the ability to turn off/on the FPU in project options prior to building IAR EWARM提供了在构建之前关闭/打开项目选项中的FPU的功能
  • In SystemInit() , which is called prior to main , the following code is executed: main之前调用的SystemInit() ,执行以下代码:

     #if (__FPU_PRESENT == 1) && (__FPU_USED == 1) SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */ #endif 

    Note that this sets CPACR bits [23:20] to 1. This is required, or else a HardFault IRQ will be called upon the next FPU assembler instruction. 请注意,这会将CPACR位[23:20]设置为1。这是必需的,否则将在下一条FPU汇编器指令后调用HardFault IRQ。 But does disabling this have any additional implications, such as lower power-consumption, etc, or does this register just police the coprocessor (FPU)? 但是,禁用此功能是否还会带来其他影响,例如更低的功耗等,还是该寄存器仅用于监管协处理器(FPU)?

  • If there is no further implication, then perhaps "turning it off", via CPACR, doesn't accomplish anything, indicating that FPU only draws additional power while executing FPU Instruction Set commands. 如果没有进一步的含义,则通过CPACR进行“关闭”可能没有任何作用,这表明FPU在执行FPU指令集命令时仅消耗额外的功率。

    Thanks, 谢谢,

You will get a Usage Fault (or promoted Hard Fault if Usage Faults are disabled) if an instruction attempts to access a coprocessor (like the FPU) and it is disabled. 如果一条指令试图访问协处理器(例如FPU)并且被禁用,则会出现“使用错误”(如果禁用了“使用错误”,则将升级为“硬错误”)。 You can inspect the NOCP bit in the Usage Fault Status Register to see if that is the source of the fault. 您可以检查“使用故障状态寄存器”中的NOCP位,以查看是否是故障源。 You can then use the Usage Fault as a trap to enable the FPU and resume execution. 然后,您可以将“用法故障”用作陷阱,以启用FPU并恢复执行。

My approach would be as follows: 我的方法如下:

  • Enable FPU in IAR project (think will allow IAR to target the FPU) 在IAR项目中启用FPU(认为将允许IAR定位到FPU)
  • Enable FPU at startup (you want it enabled until your fault handler is configured) 在启动时启用FPU(您希望在配置故障处理程序之前启用它)
  • Disable FPU for power savings once the fault handler is configured and enabled. 配置并启用故障处理程序后,请禁用FPU以节省功率。
  • On fault (usage or hard fault) inspect the NOCP bit in the Usage Fault Status Register. 发生故障(使用或硬故障)时,检查使用故障状态寄存器中的NOCP位。
  • If NOCP is set, enable the FPU, return from fault. 如果设置了NOCP,则启用FPU,从故障返回。
  • In the background application, disable FPU when you complete your calculations or use a timer to disable it periodically. 在后台应用程序中,当您完成计算或使用计时器定期禁用它时,请禁用FPU。

If you use an RTOS, you will need to look at their implementation of context switching, as it may also attempt to hook into the Usage Fault/Hard Fault if it uses lazy stacking (see reference) rather than active stacking. 如果使用RTOS,则需要查看其上下文切换的实现,因为如果RTOS使用惰性堆栈(请参阅参考资料)而不是活动堆栈,它也可能尝试挂接到“用法故障/硬故障”。

One thing to consider if power is a concern would be whether floating point is needed. 如果要考虑电源,要考虑的一件事是是否需要浮点数。 If you can represent your number space as fixed point in a 32-bit value, using fixed point math instead of floating point may result in overall lower power consumption, as there would be no overhead to enabling/disabling the FPU or stacking FPU registers on context switch. 如果您可以将数字空间表示为32位值中的固定点,则使用固定点数学而不是浮点数可能会导致总体功耗降低,因为启用/禁用FPU或在其上堆叠FPU寄存器不会产生开销上下文切换。 The trade-off is that the fixed point math may be a few instructions longer per operation 权衡取舍的是,定点数学运算每次可能要多一些指令

Reference: ARM AppNote 298 参考: ARM AppNote 298

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM