MQX Lite and size optimization

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

MQX Lite and size optimization

806 Views
davidsherman
Senior Contributor I

I tried turning on some optimization in KDS, and ran into a problem with using the optimize size option.  I have one task that starts initially, and after getting hardware ready it starts the other tasks using _task_create_at().  It gets a hard fault after calling _task_create_internal buried down in MQX, and it doesn't even make it into the task I've defined.  Seems to work okay using the lowest level of optimization (-O1).  Has anyone else run into problems with optimizing MQX Lite?

0 Kudos
8 Replies

517 Views
RadekS
NXP Employee
NXP Employee

Unfortunately you cannot use _task_create_at() function in case of Lite configuration in MQX for KSDK.

The only configuration supported in MQX RTOS Lite is MQX_CUSTOM_MAIN set to 1. In that case you can use only create_task() function for task creating.

See chapter 5.3 MQX RTOS Lite creating tasks methodology in Freescale MQX RTOS for Kinetis SDK User's Guide.pdf

Please use create_task() function instead of _task_create_at() and test it again.

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

517 Views
davidsherman
Senior Contributor I

Unfortunately, RadekS, you seem to be mistaken.  I am not using KSDK.  I am using the MQX Lite provided with Processor Expert in Kinetis Design Studio, and according to section 1.2.2 of the MQX LIte User's Guide under "Task Managment", the _task_create_at() function MUST be used because it can't create tasks dynamically, they must be pre-defined.  Indeed, this does work with MQX Lite, the pre-defined tasks run as they should, and all is fine until the optimization level is changed to optimize for size, then it crashes.  Even if I use the lowest optimization setting (-O1) it still works.

0 Kudos

517 Views
RadekS
NXP Employee
NXP Employee

Thank you for clarification.

Yes, it was misunderstanding. I wrongly supposed that you wrote about Lite confing in MQX for KSDK.

Thank you for your bug report. I will test it and report it.

0 Kudos

517 Views
RadekS
NXP Employee
NXP Employee

I could confirm strange behavior in case of optimize for size -Os.

Also stack alignment was excluded as root cause.

I will report it.

Thank you

Radek

517 Views
davidsherman
Senior Contributor I

Thank you Radek, not a big issue for me right now, but thought it might be interesting to know why MQX Lite seems to have a problem when that optimization level is used.

0 Kudos

517 Views
RadekS
NXP Employee
NXP Employee

Observation:

I added into PE project two simply tasks task12 (with priority 9) and task13 (with priority 8) and I leave default Task1 as it is.

When I set breakpoint to task13 code, MQX doesn’t reach this breakpoint in case of optimization for size –Os which leads me to believe that something is wrong with _task_create_at() function. Instead of this, code stops after reset at Task1 even when I didn’t set any breakpoint here.

After deeper analysis, we discover that it was wrong suspicion and _task_create_at() function works correctly and problem was that code from task13 was optimized out and breakpoint was automatically moved to Task1 code.

It could be seen from the assembly code below:

assembly code.PNG.png

and because of the Optimization effect, the breakpoint in task13_task has effect in the Task1_task.

That explains why the program stops in Task1_task although we did not set breakpoint in Task1_task.


When we set breakpoint as in figure below - removing breakpoint at line 76 in green color, and use breakpoint at line 75 in red color instead, it works correctly.

task-breakpoint.PNG.png


Now the debugger will firstly stops at task12_task and then stops at task13_task as desired.

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

517 Views
davidsherman
Senior Contributor I

I'm not so sure that it's just optimizing one of the tasks.  What I'm seeing is that it never returns from calling the first _task_create_at, and it gets a hard fault exception somewhere down in the MQX code.  If I try to step over that call, it ends up in Cpu_INT_Hard_FaultInterrupt.   I had thought maybe it was faulting because I have pointers stored in an external SPI EEPROM, but it doesn't make it far enough to where it starts accessing that.

0 Kudos

517 Views
RadekS
NXP Employee
NXP Employee

Ok, it seems that root cause will be different in your case.

Could you please share here any simply project which highlights this issue? Or at least specify parameters of your task (task_template_list, stack sizes,…)?

0 Kudos