This application provides an example of Azure RTOS ThreadX stack usage, it shows how to develop an application using the ThreadX synchronization APIs. The main entry function tx_application_define() is called by ThreadX during kernel start, at this stage, the application creates 2 threads with the same priorities :
The function “Led_Toggle()” is the entry function for both threads to toggle the leds.Therefore it is considered as a “critical section” that needs protection with a ‘SyncObject’ flag in the file “app_threadx.h” Each thread is running in an infinite loop as following:
By default the ‘SyncObject’ is defined as “TX_MUTEX” .It is possible to use a binany “TX_SEMAPHORE” by tuning the compile flags in the file “app_threadx.h”.
‘LED_GREEN’ toggles every 500ms for 5 seconds then toggles every 200ms for 2 seconds.
Messages on HyperTerminal :
On failure, an error message is printed to the serial port.
None
None
To optimize the application footprint, the following ThreadX configuration options should be enabled in the tx_user.h file:
#define TX_DISABLE_PREEMPTION_THRESHOLD
#define TX_DISABLE_NOTIFY_CALLBACKS
#define TX_DISABLE_REDUNDANT_CLEARING
#define TX_DISABLE_STACK_FILLING
#define TX_NOT_INTERRUPTABLE
#define TX_TIMER_PROCESS_IN_ISR
#define TX_DISABLE_ERROR_CHECKING
place in RAM_region { last section FREE_MEM };
either define the RW_IRAM1 region in the ".sct" file
or modify the line below in "tx_initialize_low_level.S to match the memory region being used
LDR r1, =|Image$$RW_IRAM1$$ZI$$Limit|
._threadx_heap :
{
. = ALIGN(8);
__RAM_segment_used_end__ = .;
. = . + 64K;
. = ALIGN(8);
} >RAM_D1 AT> RAM_D1
The simplest way to provide memory for ThreadX is to define a new section, see ._threadx_heap above.
In the example above the ThreadX heap size is set to 64KBytes.
The ._threadx_heap must be located between the .bss and the ._user_heap_stack sections in the linker script.
Caution: Make sure that ThreadX does not need more than the provided heap memory (64KBytes in this example).
Read more in STM32CubeIDE User Guide, chapter: "Linker script".
RTOS, ThreadX, Threading, Semaphore, Mutex
This application runs on STM32C031C6Tx devices
This application has been tested with STMicroelectronics STM32C0316-DISCO boards Revision MB1716 A-02 and can be easily tailored to any other supported device and development board.
A virtual COM port appears in the HyperTerminal:
In order to make the program work, you must do the following :