enable fpu in cortex r4

Asked by adnan

in a previous post I requested the method to enable background region and I got an excellent answer.
may i know the method to enable fpu on the target. Whenever I cast long to float it causes an exception.

Question information

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Solved by:
jdobry
Solved:
Last query:
Last reply:

This question was reopened

Revision history for this message
Best jdobry (jdobry) said :
#1

You will need read this documents:
ARM Architecture Reference Manual, ARMv7-A and ARMv7-R edition (ARM DDI 0406) Chapter B4.1.57 FPEXC, Floating-Point Exception Control register, VMSA
Cortex™-R4 and Cortex-R4F Technical Reference Manual Cahpter 12.3.3 Floating-Point Exception Register, FPEXC

This code will simply enable float-point suppoort:
    vmrs r0, fpexc
    orr r0, r0, #0x40000000
    vmsr fpexc, r0 // enable VFP

Revision history for this message
adnan (m-adnanali-1) said :
#2

but the register fpexc is only available in te previlaged mode

Revision history for this message
jdobry (jdobry) said :
#3

You are right. In any case status of VFP must be saved/restored in context switch. And RTOS can do it, because usually running in privileged mode. This mean, that used RTOS must support VFP ccontext store necessarily.

Dirty hack to do it without RTOS is use VFP only in one task/process and enable it only during boot. But it is not solution, it is only trick for test.

Revision history for this message
adnan (m-adnanali-1) said :
#4

MRC p15, 0, r0, c1, c0, 2 //; Read Coprocessor Access Control Register (CPACR)
        ORR r0, r0, #(0xF << 20) //; Enable access to CP 10 & 11
        MCR p15, 0, r0, c1, c0, 2 //; Write Coprocessor Access Control Register (CPACR)
        ISB

//;==================================================================
//; Switch on the VFP hardware
//;=================================================================

        MOV r0, #0x40000000
        VMSR FPEXC, r0 //; Write FPEXC register, EN bit set

Revision history for this message
adnan (m-adnanali-1) said :
#5

thankyou very much jdobry

Revision history for this message
adnan (m-adnanali-1) said :
#6

Thanks jdobry, that solved my question.