|
前言 这篇应用笔记描述了如何在AT32 MCU上使用FPU功能。 支持型号列表:具备FPU的型号 备注:本文档仅作分享之用,仅供有需求的小伙伴们参考。 1 必要的代码准备1.1 程序中开启FPU打开system_at32f4xx.c文件,找到函数void SystemInit(void),确保内核有开启FPU功能,如图1黑斜体字部分。
注意:程序中开启FPU是必要条件。若仅开启Keil或IAR上的FPU,程序中未开启,则程序运行时会进入hardfault.
void SystemInit (void) { #ifdefined (__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 clockconfiguration 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 开启FPUOptions for Target->Target->Floating Point Hardware,选择Use Single Precision
2.2 关闭FPUOptions for Target->Target->Floating Point Hardware,选择Not Used
3 IAR中配置FPU3.1 开启FPUOptions ->General Options->FPU,选择VFPv4 singleprecision
3.2 关闭FPUOptions ->General Options->FPU,选择None
|