[应用相关] 如何使用 FPU

[复制链接]
542|0
MCU学习帮 发表于 2025-11-19 13:20 | 显示全部楼层 |阅读模式
前言
这篇应用笔记描述了如何在AT32 MCU上使用FPU功能。
支持型号列表:具备FPU的型号
图1.程序中开启FPU.. 5
图2.Keil开启FPU.. 6
图3.Keil关闭FPU.. 7
图4.IAR开启FPU.. 8
图5.IAR关闭FPU.. 9
1                 必要的代码准备1.1           程序中开启FPU
打开system_at32f4xx.c文件,找到函数void SystemInit(void),确保内核有开启FPU功能,如图1黑斜体字部分。
注意:程序中开启FPU是必要条件。若仅开启KeilIAR上的FPU,程序中未开启,则程序运行时会进入hardfault.
图1. 程序中开启FPU
  
void SystemInit (void)
  
{
  
#if defined (__FPU_USED) && (__FPU_USED ==  1U)
  
   SCB->CPACR |= ((3U << 10U * 2U) |         /* set cp10 full access */
  
                  (3U << 11U * 2U)  );       /* set cp11 full access */
  
#endif
  
  
  /* reset the crm clock  configuration to the default reset state(for debug purpose) */
  
  /* set hicken bit */
  
  CRM->ctrl_bit.hicken =  TRUE;
  
  
  /* wait hick stable */
  
  while(CRM->ctrl_bit.hickstbl  != SET);
  
  
  /* hick used as system clock  */
  
  CRM->cfg_bit.sclksel =  CRM_SCLK_HICK;
  
  
  /* wait sclk switch status */
  
  while(CRM->cfg_bit.sclksts  != CRM_SCLK_HICK);
  
  
……………………………………………………………
  
……………………………………………………………
  
}
  

2                  Keil中配置FPU2.1           开启FPU
Options for Target->Target->Floating Point Hardware,选择Use Single Precision
2.2            关闭FPU
Options for Target->Target->Floating Point Hardware,选择Not Used
3                IAR中配置FPU3.1           开启FPU
Options ->General Options->FPU,选择VFPv4 singleprecision
3.2            关闭FPU
Options ->General Options->FPU,选择None

备注:本文档仅供有需求的伙伴们参考,如需更详细信息或操作步骤,请访问雅特力官网:https://www.arterytek.com/cn/support/index.jsp?index=1

您需要登录后才可以回帖 登录 | 注册

本版积分规则

18

主题

18

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部
0