Using Azure RTOS (ThreadX) with MCUXpresso SDK

cancel
Showing results for 
Search instead for 
Did you mean: 

Using Azure RTOS (ThreadX) with MCUXpresso SDK

No ratings

Using Azure RTOS (ThreadX) with MCUXpresso SDK

Introduction

 

Azure RTOS is a comprehensive suite of multithreading facilities, middleware and Windows tools for developing embedded IoT applications. It features Azure RTOS ThreadX, a small, fast, reliable real-time operating system that is already powering more than 6.2 billion devices worldwide. Most of the volume are components in smart phones, cellular modems, WiFi, Bluetooth, GPS, etc.

Now Azure RTOS is integrated into MCUXpresso SDK2.8.5 and is available from our SDK builder site (https://mcuxpresso.nxp.com) and also directly from MCUXpresso IDE. Support is currently available for i.MX RT1050, i.MX RT1060 and i.MX RT1064 MCUs.

Please select Azure RTOS before you download it.

 

download.png

 

Code Structure

 

Below picture is the code structure of evkmimxrt1064_threadx_demo. Azure RTOS kernel is provided as a library, libthreadx.a.  You can import the evkmimxrt1064_threadx_lib to generate this library.

 

struc.png

  

Tx_initialize_low_level.S : an assembly file that contains the low level initialization for ThreadX. The primary function of this file is to set up the System Tick handler, which controls the internal timing of ThreadX.

 

Tx_user.h   configuration options.

Options defined in tx_user.h are applied only if the application and ThreadX library are built with TX_INCLUDE_USER_DEFINE_FILE defined.

Thread_demo.c

The Thread_demo.c file contains the application entry point main(). This function is responsible for the following:

  • Entering the ThreadX kernel
  • Initializing the board
  • Start the main application thread

 

Create a ThreadX application

 

There are four steps required to build a ThreadX application

  • Include the tx_api.h file in all application files that uses ThreadX services or data structures.
  • Create the standard C main function. This function must eventually call  tx_kernel_enter to start ThreadX.

Tx_kernel_enter: The entry function coordinates initialization of various ThreadX data structures and then call the application’s definition function tx_application_define.

  • Create the tx_application_define function. It executes after the basic ThreadX initialization is complete. It is responsible for setting up all of the initial system resources, including threads, queues, semaphores, mutexes, event flags, and memory pools.

After tx_application_define completes, control is transferred to the thread scheduler and from there to each individual thread.

 

The small Example system is as below picture shows.

 

#include "tx_api.h"

unsigned long my_thread_counter = 0;

TX_THREAD my_thread;

main( )

{

/* Enter the ThreadX kernel. */

tx_kernel_enter( );

}

void tx_application_define(void *first_unused_memory)

{

/* Create my_thread! */

tx_thread_create(&my_thread, "My Thread",

my_thread_entry, 0x1234, first_unused_memory, 1024,

3, 3, TX_NO_TIME_SLICE, TX_AUTO_START);

}

void my_thread_entry(ULONG thread_input)

{

/* Enter into a forever loop. */

while(1)

{

/* Increment thread counter. */

my_thread_counter++;

/* Sleep for 1 tick. */

tx_thread_sleep(1);

}

}

 

4  Compile evkmimxrt1064_threadx_demo and debug

 

Console output:

 

THREADX example ...

start thread 0 ...

start thread 5 ...

start thread 3 ...

start thread 4 ...

start thread 6 ...

start thread 7 ...

start thread 1 ...

start thread 2 ...

 

 

Version history
Revision #:
1 of 1
Last update:
‎11-17-2020 08:04 AM
Updated by:
 
Contributors