前言
这篇应用笔记描述了如何在AT32 MCU上使用FPU功能,支持型号列表:
支持型号列表:
支持型号
AT32F403xx
AT32F403Axx
AT32F407xx
AT32F413xx
目录
必要的代码准备… 5
程序中开启 FPU … 5
Keil 中配置 FPU … 6
开启 FPU… 6
关闭 FPU… 7
IAR 中配置 FPU… 8
开启 FPU… 8
关闭 FPU… 9
1、必要的代码准备
程序中开启 FPU打开system_at32f4xx.c文件,找到函数void SystemInit (void),确保内核有开启FPU功能,如图1黑斜
体字部分。
注意:程序中开启 FPU 是必要条件。若仅开启 Keil 或 IAR 上的 FPU,程序中未开启,则程序运行时会进入
hardfault.
图 1. 程序中开启 FPU
void SystemInit (void)
{
#if defined (AT32F415xx)
/* Enable low power mode, 0x40007050[bit2] */
RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_PWR, ENABLE);
*(volatile uint8_t )(0x40007050) |= (uint8_t)(0x1 << 2);
RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_PWR, DISABLE);
#endif
#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 RCC clock configuration to the default reset state(for debug purpose) /
/ Set HSIEN bit /
BIT_SET(RCC->CTRL, RCC_CTRL_HSIEN);
/ Reset SW, AHBPSC, APB1PSC, APB2PSC, ADCPSC and CLKOUT bits /
BIT_CLEAR(RCC->CFG, RCC_CFG_SYSCLKSEL | RCC_CFG_AHBPSC |
RCC_CFG_APB1PSC | RCC_CFG_APB2PSC |
RCC_CFG_ADCPSC | RCC_CFG_CLKOUT);
…
#ifdef VECT_TAB_SRAM
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; / Vector Table Relocation in Internal SRAM. /
#else
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; / Vector Table Relocation in Internal FLASH. */
#endif
}
2、Keil 中配置 FPU
开启 FPU
Options for Target->Target->Floating Point Hardware,选择Use Single Precision
图 2. Keil 开启 FPU
关闭 FPU
Options for Target->Target->Floating Point Hardware,选择Not Used
3、IAR 中配置 FPU
开启 FPU
Options ->General Options->FPU,选择VFPv4 single precision
关闭 FPU
Options ->General Options->FPU,选择None
图 5. IAR 关闭 FPU
这篇应用笔记描述了如何在AT32 MCU上使用FPU功能支持型号 AT32F403xx AT32F403Axx AT32F407xx AT32F413xx
于 2022-06-04 03:18:45 首次发布