MQX中使能FPU功能

在MQX如何开启FPU功能呢?以FRDM_K22F+MQX4.2+MDK5.15 为例来说明。
MQX4.2中默认已经使能了芯片的FPU功能
这里写图片描述

MQXCFG_ENABLE_FP 宏用来打开芯片的FPU功能。
以下为具体实现:

#if MQXCFG_ENABLE_FP && PSP_HAS_FPU
        /* CPACR is located at address 0xE000ED88 */
        LDR.W   R0, =0xE000ED88
        /* Read CPACR */
        LDR     R1, [R0]
        /* Set bits 20-23 to enable CP10 and CP11 coprocessors */
        ORR     R1, R1, #(0xF << 20)
        /* Write back the modified value to the CPACR */
        STR     R1, [R0]
        /* turn off fpu register stacking in exception entry */
        ldr r0, =0xE000EF34     /* FPCCR */
        mov r1, #0
        str r1, [r0]
#endif
LDR.W   R0, =0xE000ED88
LDR     R1, [R0]
ORR     R1, R1, #(0xF << 20)
STR     R1, [R0]

这四句话是将CPACR寄存器中的CP10和CP11设置为0x11(CPACR 复位后的值是Unknown的)
这里写图片描述
这里写图片描述
这里写图片描述

ldr r0, =0xE000EF34     /* FPCCR */
mov r1, #0
str r1, [r0]

这三句是将FPCCR寄存器清0

现在只需要打开编译器的FPU功能。
1)打开hello 工程,更改器件型号,FRDM_K22F上的芯片是 MK22FN512VLH12,默认的选择是错误的。
这里写图片描述
默认选择的是MK22DN512xxx12,它是不带FPU的,所以在target
中没有使能FPU的选项
这里写图片描述
只要选择带FPU的芯片后,才显示是否开启FPU功能。
这里写图片描述

2)选择Using Single Precision

3)选择生成汇编文件。
这里写图片描述

4)打开生成的txt文件或者在线调试,在汇编代码中可以看到生成FPU的汇编指令。
这里写图片描述

参考:
http://blog.chinaaet.com/jihceng0622/p/39733
http://www.eefocus.com/constyu/blog/15-03/310765_2a082.html

Kinetis MCU such as K21F/K22F/K70F include the floating point unit, which is an implementation of the single precision variant of the ARMv7-M Floating-Point Extension (FPv4-SP). To enable the floating-point calculation, two steps are required:
1. Enable the FPU option in compiler.
Take IAR as an example, select VFPv4 FPU in Project Options ->General Options, then single precision floating point arithmetic statement is compiled into assembly instructions with V beginning.
2. Enable the FPU unit on chip.
If MQX is running, it is easy to open the FPU unit by enabling the corresponding macro. If it is a baremetal project and implements the initialization process manually, below code need be added to enable the FPU during initialization.
LDR.W R0, =0xE000ED88 ; Enable the FPU
LDR R1, [R0]
ORR R1, R1, #(0xF << 20)
STR R1, [R0]
If the compiler enables the FPU option, and FPU unit is not enabled, the program with floating point statement will run abnormal. If the compiler does not enable the FPU option, and FPU unit is enabled, the program will run as FPU unit is not enabled.

编译器开 芯片使能 V-
编译器开 芯片未使能 hardware fault
编译器未开 芯片使能 正常
编译器未开 芯片未使能 正常

补充:
顺便说一下KSDK中如何打开FPU功能。
KSDK中的宏是__FPU_PRESENT

#define __FPU_PRESENT                  1         /**< Defines if an FPU is present or not */

在SymtemInit函数中 同样是设置CPACR寄存器

void SystemInit (void) {
#if ((__FPU_PRESENT == 1) && (__FPU_USED == 1))
  *SCB->CPACR |= ((3UL << 10*2) | (3UL << 11*2));    /* set CP10, CP11 Full Access */*
#endif /* ((__FPU_PRESENT == 1) && (__FPU_USED == 1)) */
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值