How To: Create an MQX RTOS for KSDK project with Processor Expert in Kinetis Design Studio IDE

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

How To: Create an MQX RTOS for KSDK project with Processor Expert in Kinetis Design Studio IDE

How To: Create an MQX RTOS for KSDK project with Processor Expert in Kinetis Design Studio IDE

How To: Create an MQX RTOS project with Processor Expert in Kinetis Design Studio IDE

(This is an update and extension of Derek Snell's post:MQX with KSDK and Processor Expert.  Thanks Derek!)

There are a few different methods to get started with MQX RTOS for Kinetis SDK.  One of which is using Kinetis Design Studio with Processor Expert.  Processor Expert provides a graphical interface for configuring your project and adding useful software components.

Important Note #1:  In the past, Processor Expert included MQX Lite and MQX components.  With the release of the Kinetis SDK, there is a new MQX_KSDK component that is suitable for configuring the version of MQX RTOS that comes with the Kinetis SDK.    Be sure to use the new component! 

Important Note #2: New Kinetis Design Studio projects enabled with Kinetis SDK and Processor Expert use an Operating System Abstraction (OSA) component which is used to select which RTOS (or no RTOS – baremetal) option you are using.  The OSA component will inherit in the selected RTOS component for you. So, don’t add in MQX_KSDK yourself. Let the OSA do it.          

The following instructions are based on Kinetis SDK v1.1 and Kinetis Design Studio IDE v2.0

Steps


Install Updates

See section 5.2 in the Getting Started with Kinetis SDK guide.


Create a New Kinetis Design Studio Project

image001.png

Name it.

image002.png

Click Next.

Select a Board (or Processor if you prefer - this changes the steps slightly.)

image003.png

Click Next.

Choose Kinetis SDK and Processor Expert

image004.png

Click Finish.

Now you have a new Kinetis SDK project that is ready to be configured with Processor Expert.

image005.png

In the Components window, under Components, open the OSA component

image006.png

The Component Inspector window will now show you the Properties and Methods for that component.

From the OS dropdown list, choose MQX_KSDK as your OS

image007.png

Now you need to set up the MQX_KSDK component for use in your project.

Open the MQX_KSDK component (inherited by the OSA component)

image008.png

Select the Configuration parameters tab

In the Configuration set, you have the choice of MQX Lite and MQX Standard.

For this first example, I will chose MQX Lite.

MQX Lite is a light weight configuration of MQX RTOS offering a subset of capabilities.  MQX Lite uses static memory allocation by default.  If you want to use the RTCS TCP/IP stack, MFS file system, dynamic memory allocation, or some of the advanced features of MQX RTOS, use MQX Standard.

image009.png

Now select the Shared components tab.  You can see that it uses the DbgCs1 component for serial communications.

image010.png

image011.png

Click on the DbgCs1 component

You need to tell it which UART should be used for the DbgCs1 component (default serial port).

On the FRDM-K64F, UART 0 connects to the on-board debug circuit for virtual com port to the host PC. It is a bit confusing, but the signal names on the schematic, on the debug circuit side, say UART1_RX_TRGMCU and UART1_TX_TRGMCU

For Device, choose UART0. Then pick a baud rate – I chose 115200.  Then select the Pins to be used.  This uses the net names for the signals on the schematic.

image012.png

For the selected baud rate 115200, I get an error that says that not all of the clock configurations of the system can support it.

Timing setting failed in Clock configuration 3 – it is impossible to set the following items: selected value

The CPU component comes pre-configured with 4 clock configurations that can be utilized in your system.  These are very useful for switching between different clock modes in your application for power savings.

One of these clock configurations can’t do 115200, so I need to either change the baud rate or change the clock configuration.  For this example, I am just going to delete the clock configuration because I am not going to use it.

Click the Cpu component.

image013.png

Click Clock configurations

image014.png

Then select Clock configuration 3.  Click the down arrow v to lower it to the bottom of the list.

image015.png

Then click to remove.

image016.png

There is one more configuration required in the DbgCs1 component.   It is related to its inherited component, the fsl_uart_hal (hardware abstraction layer for the UART).

Click on the DbgCs1 component again.

image011.png

Click on the arrow next to fsl_uart_hal.

image017.png

And choose UART 0

image018.png

Now you should have no errors.

Now, add some tasks.  Processor Expert provides an OS_Task Component that will configure and generate the code framework for tasks.

Click Components Library.

image019.png

Under Operating Systems, double click OS_Task to add tasks.

image020.png

Click on the task components to configure them.

image021.png

image022.png

Click the Generate Processor Expert Code button.

image023.png

The code will generate (update the configuration files for the Kinetis SDK).  Wait until that finishes.

image024.png

The MQX source code is here.

image025.png

The task code is here.

image026.png

Write your tasks!  You can write native MQX RTOS function calls as well as Kinetis SDK driver and HAL calls.  Just make sure to include the appropriate header file for the MQX or KSDK feature you use and add to the paths if necessary.

image027.png

Now click the build button

image028.png

Your new project will compile and link into a file for downloading and debugging on the target.

image029.png

Hope this helps!  Send me your feedback!

Mac L

Comments

Hi Mac L,

thank you for this manual! It helps by basic creation of an MQX/ MQX lite application. I would like to change the tick time value to 500µs. Is it possible in PE?

Hi Menko,

The MQX4.1.1 BSP hardware header (ex: twrk60f120m.h) has the following comments (same for all Kinetis K devices…Kinetis L family I have seen default (100)):

/** MGCT:  */

/*

    • The clock tick rate in miliseconds - be cautious to keep this value such

    • that it divides 1000 well

**

    • MGCT: <option type="number" min="1" max="1000"/>

*/

#ifndef BSP_ALARM_FREQUENCY

    #define BSP_ALARM_FREQUENCY            (200)

#endif

So setting to 500us (or BSP_ALARM_FREQUENCY (2000) is out of range.  Since it is software though…you can always try and see what happens.

In KDS for KSDK/MQX/PE the BSP_ALARM_FREQUENCY is set in the bsp_config.h header and has same comments as above.

Regards,

David

Hi,

Thanks, your tuto is perfect.

But I got one thing that i don't understand:

I use the main instead of tasks because the two tasks were not initialized correctly, I got the message on terminal: assertion "!status" failed: file "C:/Freescale/KSDK_1.1.0

I made the project with MQX Lite (as tuto) for FRDM_K64F, I can compile, debug, but I can't light on the RGB LED with this source: (RTOS is not started)

int main(void)

/*lint -restore Enable MISRA rule (6.3) checking. */

{

  /* Write your local variable definition here */

long i=0;

  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/

  PE_low_level_init();

  /*** End of Processor Expert internal initialization.                    ***/

  /* Write your code here */

  /* For example: for(;;) { } */

  GPIO_DRV_SetPinOutput(LEDRGB_BLUE);// !status C:/Freescale/KSDK_1.1

  GPIO_DRV_SetPinOutput(LEDRGB_GREEN);// !status C:/Freescale/KSDK_1.1

for(;;){

    GPIO_DRV_TogglePinOutput(LEDRGB_BLUE);

    for(i=0;i<1000000;i++);// cpu at 120Mhz

}

  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/

  /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/

  #ifdef PEX_RTOS_START

    PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */

  #endif

  /*** End of RTOS startup code.  ***/

  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/

  for(;;){}

  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/

} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

I made another project with KSDK1.1.0 without MQX lite, with the same main(), LEDs works fine.

Do you have any idea about the MQX lite configuration?

Hi,

My project works fine with MQX Standart. LEDs are blinking without use of main().

With this OSA layer, How to use Ethernet on FRDMK64F??

(Sample programs with RTCS or lwIP inside KSDK don't use OSA layer.)

Do you have a tuto?

Hi Bernard,

I'm not sure about the answer to your first problem.  I recommend adding your code to the tasks.  You should be able to set them to auto-start or require explicit start (task_create).  I need to dig into this more. 

About using the ethernet on FRDM-K64F, the OSA does not cover TCP/IP, so there is no single abstraction layer supporting multiple TCP/IP stacks.  So, to do networking you have to write your app to make native function calls to either rtcs or lwip (using the examples as a guide).  Note that rtcs requires mqx as the rtos. 

Thanks,
Mac

By the way, if you select MQX Standard in the MQX_KSDK Configuration parameters, the remaining steps will look like this.  This is because the MQX Standard configuration uses the more full featured fsl_uart component for serial communication, while the MQX Lite configuration uses the simpler DbgCs debug console component.


Select MQX Standard.

2015-01-27_15-27-15.png

Click on the DbgCs1 component.

2015-01-27_15-28-43.png

Disable it by un-checking the Component Enabled checkbox.

2015-01-27_15-28-11.png

Now configure the fsl_uart component (used in place of DbgCs1).

2015-01-27_15-30-03.png

Select the UART to use and the pins.

2015-01-27_15-29-42.png

On the Configurations tab, select a baud rate.  Note:  You may have to tweak the clock configurations to work with your selected baud rate or vice versa (see above).

2015-01-27_15-31-21.png

Now generate the code as in the steps above and write your tasks!

With MQX Standard, you can now access the tcp/ip stack, file system, posix io subsystem, and other advanced features included with MQX RTOS. 

First -- outstanding tutorial.  Thank you!

It's only been a couple of months since the original post, and already the Clock Configurations section was significantly different.  I didn't have to delete any configurations (there was only one created), but I did have to update the fsl_mcg_hal, fsl_sim_hal, fsl_osc_hal and fsl_lptmr_hal components to clear their errors.

Also, to build without errors, I had to manually update the linker libraries.

Select menu Project > Properties

Select C/C++ Build > Settings

    Select Cross ARM C++ Linker > Libraries

    Add new Libraries (-I)...

        ksdk_platform_mqx

        _mqx

        _mqx_stdlib

    Add new Library search path (-L)...

        "${KSDK_PATH}/lib/ksdk_mqx_lib/kds/K64F12/Debug"

        "${KSDK_PATH}/rtos/mqx/lib/frdmk64f.kds/debug/mqx"

        "${KSDK_PATH}/rtos/mqx/lib/frdmk64f.kds/debug/mqx_stdlib"

- Audi

I created my first MQX_KSDK project with PE on a TWR-K65F180M board following this good tutorial.

I am using KDS 3.0.0 and KSDK 1.3.0.

I selected MQX Standard in the MQX_KSDK Configuration parameters.

Now I see the systick timer is configured with a 5 ms period. I would like a 1 ms systick, but the systick timer (fsl_hwtimer) configuration is unchangeable. Why? It is not allowed to modify the fsl_hwtimer_InitConfig0 configuration nor to add a new one.

In the fsl_hwtimer1.h file generated by PE the macro FSL_FSL_HWTIMER1_PERIOD_CNF0 is set to 5000: I think the systick timer period in microseconds is set with this macro, right?

Is manually changing that macro the only way to get the desired systick period for MQX Standard type?

Systick topic answered on following post:

Systick Timer and Debug Console with MQX_KSDK 1.3.0 + PEx in KDS 3.0.0

Regards,

David 

No ratings
Version history
Last update:
‎01-22-2015 07:47 AM
Updated by: