MQX Floating point support on MK22FN512 part

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MQX Floating point support on MK22FN512 part

Jump to solution
846 Views
dcooper
Contributor II

We changed from a K60 part to the MK22FN512 with plans to make use of the FPU on the K22F part.

I based the bsp for the K22 board on the bsp for the FRDMK22120M.

I am using MQX 4.1.0.

I just started trying to convert some of the math from fixed point to floating, but am getting

      Unhandled Interrupt: <task name>, Task ID 0x ..., TD 0x ....  task errors the first time the processing tasks run.

I am working on the assumption that the PSP for the FRDMK22120M would have FP support (??) and have tried various combinations for the MQXCFG_ENABLE_FP and MQX_SAVE_FP_ALWAYS #defines in user_config.h as well as adding the MQX_FLOATING_POINT_TASK attribute to the task template struct, but am obviously missing something.

Can anyone enlighten me on what other steps I need to take to successfully use the FP unit.

Thanks

David

1 Solution
502 Views
DavidS
NXP Employee
NXP Employee

Hi David,

My MQX4.1.1 doesn't have FRDM-K22 supported in it so I am looking at twrk21f120m port.

But generically the boot.S in PSP has following:

#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

In PSP kinetis.h there is following:

#elif   (MQX_CPU == PSP_CPU_MK21FN1M)

    /* enable FPU for this platform */

    #define PSP_HAS_FPU                                 1

    /* enable flash swap for this platform */

    #define PSP_HAS_FLASH_SWAP                          1

Check to see if your port has or needs this entry for your frdm-k22 to set PSP_HAS_FPU set to 1.  This then should "turn on" the code in the boot.S to turn on FPU.

Regards,

David

View solution in original post

0 Kudos
3 Replies
502 Views
soledad
NXP Employee
NXP Employee

Hello David,

In addition to David's answer, I tested the Hello example  (MQX 4.2 and KDS) with the following modification and it is working.

Could you please test using MQX 4.2??

void hello_task

(

uint32_t initial_data

)

{

        float val = 1.234;

(void)initial_data; /* disable 'unused variable' warning */

printf("Hello World\n");

printf("Value = %f unit\n", val);

_task_block();

}

pastedImage_0.png

pastedImage_1.png


Have a great day,
Sol

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
502 Views
dcooper
Contributor II

David/Soledad

Thanks for the responses.

I was able to get the floating point support enabled in the BSP.

The "Unhandled Interrupt: ..." was caused by unaligned access to float values in a packed structure.

These values had been uint32 when I was using fixed point math and could not be accessed in the same way once I changed them to floats

503 Views
DavidS
NXP Employee
NXP Employee

Hi David,

My MQX4.1.1 doesn't have FRDM-K22 supported in it so I am looking at twrk21f120m port.

But generically the boot.S in PSP has following:

#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

In PSP kinetis.h there is following:

#elif   (MQX_CPU == PSP_CPU_MK21FN1M)

    /* enable FPU for this platform */

    #define PSP_HAS_FPU                                 1

    /* enable flash swap for this platform */

    #define PSP_HAS_FLASH_SWAP                          1

Check to see if your port has or needs this entry for your frdm-k22 to set PSP_HAS_FPU set to 1.  This then should "turn on" the code in the boot.S to turn on FPU.

Regards,

David

0 Kudos