Questions about MQXCFG_ENABLE_FP, and MQX floating point

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

Questions about MQXCFG_ENABLE_FP, and MQX floating point

Jump to solution
1,441 Views
pmt
Contributor V

If I enable floating point hardware in my compiler (in this case Keil uv5) is it mandatory that I enable MQXCFG_ENABLE_FP in my BSP assuming my code does not use any floating point?  Conversely, if I don't enable floating point hardware in my compiler, is there an impact with enabling MQXCFG_ENABLE_FP?

Does RTCS/MQX/Shell source use floating point (math or C-operators)?  Or are any of these guaranteed floating point free by design?

Does MQX task model implement lazy stacking per this application note, for processors that support it?

  http://infocenter.arm.com/help/topic/com.arm.doc.dai0298a/DAI0298A_cortex_m4f_lazy_stacking_and_cont...

Thanks!

PMT

0 Kudos
1 Solution
776 Views
RadekS
NXP Employee
NXP Employee

Hi pmt,

In that case, please edit support.S file and change “#if PSP_HAS_FPU” to “#if MQXCFG_ENABLE_FP”

and “#endif // PSP_HAS_FPU” to “#endif // MQXCFG_ENABLE_FP”.

This will cause that compiler will not try translating these functions. These functions will be not used by linker anyway because using these functions in dispatch.S depends on macro MQX_SAVE_FP_ALWAYS value.


I hope it helps you.

Have a great day,
RadekS

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

View solution in original post

0 Kudos
8 Replies
776 Views
pmt
Contributor V

I have experimented with some of the MQX build options for my target; twrk60f120m.

- When I set #define MQXCFG_ENABLE_FP  0 the MQX libraries do not build, error in dispatch.s with illegal instructions

- When disable hardware floating point in my compiler (i.e. use --cpu Cortex-M4 instead of --cpu Cortex-M4.fp) the libraries also do not build, regardless of the above setting.

Even though my CPU supports hardware floating point, is there an option to build the BSP and compile the libraries and application code without hardware floating point support, and instead rely on software floating point.

Can I build the MQX libraries but safely disable HW floating point support when I compile my application code?  This will mean MQX is linked with Cortex-M4.fp lib and application code linked with Cortex-M4 lib.

Thanks,

PMT

0 Kudos
776 Views
RadekS
NXP Employee
NXP Employee

Hi pmt,

Set MQXCFG_ENABLE_FP to 1 cause two main actions. FP unit will be enabled and initialized during boot and FP content will be stacked during context switching (task switching). So, it has at least some performance impact – we have to save/restore about 80bytes for every context switch when we enable FP.

Currently I am not sure, but I suppose that RTCS/MQX/Shell source code do not use any floating point operations.

No, lazy stacking was not implemented into MQX code.

About built errors)

Could you please let me know your version of MQX and Keil uv5 IDE?

Could you please let me know more details about that illegal instruction(s) (e.g which line of code)?

Idea: Macro MQXCFG_ENABLE_FP is typically used together with macro PSP_HAS_FPU. Could you please try set also macro PSP_HAS_FPU as 0?

In case of GCC compiler we have three FPU options ‘soft’, ‘softfp’ and ‘hard’ (-mfloat-abi=XXX option). Specifying ‘soft’ causes GCC to generate output containing library calls for floating-point operations. ‘softfp’ allows the generation of code using hardware floating-point instructions, but still uses the soft-float calling conventions. ‘hard’ allows generation of floating-point instructions and uses FPU-specific calling conventions. Unfortunately the hard-float and soft-float ABIs are not link-compatible; you must compile your entire program with the same ABI, and link with a compatible set of libraries.

I am not sure how it is with Keil compiler, but I suppose that you cannot combine libraries and applications with different FPU settings (--cpu Cortex-M4 or --cpu Cortex-M4.fp)


I hope it helps you.

Have a great day,
RadekS

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

0 Kudos
776 Views
pmt
Contributor V

RadekS,

Keil 5.14 with MQX 4.1.X.  PSP_HAS_FPU 1 which is set in kinetis.h.

OK, I double checked my configuration!  New information:

With MQXCFG_ENABLE_FP 0, and HW FP support enabled in compiler I get no errors in the build.

With MQXCFG_ENABLE_FP 0, and HW FP support disabled in the compiler I get these errors in the PSP build:

assembling support.S...

C:\PetroMar\PMT_Embedded\MQX4.1.0\mqx\source\psp\cortex_m\core\M4\support.S(60): error: A1854E: Unknown opcode 'vmrs', maybe wrong target CPU?

C:\PetroMar\PMT_Embedded\MQX4.1.0\mqx\source\psp\cortex_m\core\M4\support.S(64): error: A1854E: Unknown opcode 'vstmdb', maybe wrong target CPU?

C:\PetroMar\PMT_Embedded\MQX4.1.0\mqx\source\psp\cortex_m\core\M4\support.S(95): error: A1854E: Unknown opcode 'vldm', maybe wrong target CPU?

C:\PetroMar\PMT_Embedded\MQX4.1.0\mqx\source\psp\cortex_m\core\M4\support.S(99): error: A1854E: Unknown opcode 'vmsr', maybe wrong target CPU?

These errors will disappear if PSP_HAS_FPU=0, I'm sure, because this section of code is wrapped with '#if PSP_HAS_FPU'.

But how do these defines work?  To me PSP_HAS_FPU is a statement of fact, and that should always be true because it is in the hardware. 

Whereas MQXCFG_ENABLE_FP is a desired configuration.  It's not clear to me that PSP_HAS_FPU=0 is a valid thing to do on this processor,

even if I don't use the FPU, and even if the project successfully builds.  I think the above section of code is more properly

wrapped with #if MQXCFG_ENABLE_FP instead.  Can you clarrify if FPU=0 is valid?

Regarding the GCC soft, softfp, and hard vs. Keil:  The Keil compiler has a similar feature called 'softfp_linkage'.  Unfortunately, from

what I can tell, Keil does not provide their pre-complied c-libraries (only provided as binary) with this configuration.  Only soft and hard. 

I have a support ticket into ARM for this.

Regarding FP use in MQX code.  This is an important point.  For maximum portability you should by design not use floating point (and

state this in your documentation), or document which functions, libraries, or MQX tasks do use floating point. 

Otherwise I can't properly set the MQX_FLOATING_POINT_TASK in my task if I invoke any MQX dependencies!  I would also presume

for any MQX tasks that get started (RTCS_tcpip, FTP, telnet, etc.) that use floating point that they are setting the MQX_FLOATING_POINT_TASK

property?

Thanks!

PMT

0 Kudos
776 Views
RadekS
NXP Employee
NXP Employee

Hi pmt,

Thank you for additional information.

It seems that Keil compiler with HW FP support disabled simply do not know these NEON instructions.

I agree that condition “#if PSP_HAS_FPU” is probably not right solution in this case. Instead of that MQXCFG_ENABLE_FP or combination of MQXCFG_ENABLE_FP with PSP_HAS_FPU should be used here.

In fact, if I looked at file support.S in MQX for KSDK and I saw that somebody already change it there. Functions _psp_push_fp_context() and _psp_pop_fp_context() are wrapped with “#if MQXCFG_ENABLE_FP”.

Strange is that compiler works with these _psp_push_fp_context() and _psp_pop_fp_context() functions.

These functions are called in dispatch.S when “#if MQX_SAVE_FP_ALWAYS && PSP_HAS_FPU”.

Default value of MQX_SAVE_FP_ALWAYS in mqx_cnfg.h file is defined as 0 unless we set definition MQXCFG_MEM_COPY_NEON as 1.

Default value of MQXCFG_MEM_COPY_NEON in mqx_cnfg.h file is defined as 0 unless we change it - For example in user_config.h

In default settings MQXCFG_MEM_COPY_NEON is set to 1 only for Vybrid MCU.

Could you please look at your definitions MQXCFG_MEM_COPY_NEON and MQX_SAVE_FP_ALWAYS?

0 Kudos
776 Views
pmt
Contributor V

For reference the BSP/PSP is just a straight out of the box (MQX delivered) based on twrk60f120m, with some tweaks here and there for my particular target.  No modifications to mqx_cnfg.h, and no external overrides of the defines in question:

#define MQXCFG_MEM_COPY_NEON  0

#define MQX_SAVE_FP_ALWAYS      0

0 Kudos
777 Views
RadekS
NXP Employee
NXP Employee

Hi pmt,

In that case, please edit support.S file and change “#if PSP_HAS_FPU” to “#if MQXCFG_ENABLE_FP”

and “#endif // PSP_HAS_FPU” to “#endif // MQXCFG_ENABLE_FP”.

This will cause that compiler will not try translating these functions. These functions will be not used by linker anyway because using these functions in dispatch.S depends on macro MQX_SAVE_FP_ALWAYS value.


I hope it helps you.

Have a great day,
RadekS

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

0 Kudos
776 Views
pmt
Contributor V

RadekS,

One question remains open.  Is it safe or proper to define PSP_HAS_FPU as 0 on this target assuming I use SW FP in the compiler? 

My goal is to disable the HW FPU and have it enter power savings mode, if there is such an option for the FPU.

Thanks,

PMT

0 Kudos
776 Views
RadekS
NXP Employee
NXP Employee

Hi pmt,

Setting PSP_HAS_FPU as 0 will cause that MQX will not generate code which use FPU - nothing else. So, from this point of view, this is safe.

Of course, macro PSP_HAS_FPU has no direct influence on application code. This is in your hands.

I am not sure, but I suppose that there isn’t any way how to disable FPU in ARM M4 core.

In fact, MQX just configures access rights to coprocessor during initialization (according macro MQXCFG_ENABLE_FP). MQX do not enable coprocessor itself. Therefore I suppose that, core do not have any enable/disable bit for FPU coprocessor.

Accessing FPU coprocessor without initialization of access rights will cause hard fault error.


I hope it helps you.

Have a great day,
RadekS

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

0 Kudos