LoginSignup
0
0

More than 1 year has passed since last update.

STM32CubeIDEを使ってみよう STM32H7でAzureRTOS編2

Posted at

STM32CubeIDEを使ってみよう STM32H7でAzureRTOS編 の続きです。

今回は、複数のスレッドを動かしてみます。

Thread2個

Threadを2個に増やしてみます。
Threadを1個の時と同じような内容を追加します。
image.png
image.png

Thread3個

今度はThreadを3個に増やしてみます。
image.png
image.png

スレッド内容を比較する

今回は同じ内容を複数のスレッドにしました。
ただし、優先度✖を微妙に変えてLED1,2,3が動作しています。

tx_thread_create(&thread_ptr,"my_thread",my_thread_entry,0x1234,thread_stack,THREAD_STACK_SIZE,x,x,1,TX_AUTO_START);

追加したプログラム

追加したコードを比較してみましょう。

1スレッド

uint8_t thread_stack[THREAD_STACK_SIZE];
TX_THREAD thread_ptr;

void my_thread_entry2(ULONG initial_input);

tx_thread_create(&thread_ptr,"my_thread",my_thread_entry,0x1234,thread_stack,THREAD_STACK_SIZE,14,14,1,TX_AUTO_START);

void my_thread_entry(ULONG initial_input)
{
	while(1){
		HAL_GPIO_TogglePin(LD1_GPIO_Port, LD1_Pin);
		tx_thread_sleep(50);
	}
}

2スレッド

uint8_t thread_stack2[THREAD_STACK_SIZE];
TX_THREAD thread_ptr2;

void my_thread_entry(ULONG initial_input);

tx_thread_create(&thread_ptr2,"my_thread2",my_thread_entry2,0x1234,thread_stack2,THREAD_STACK_SIZE,15,15,1,TX_AUTO_START);

void my_thread_entry2(ULONG initial_input)
{
	while(1){
		HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
		tx_thread_sleep(20);
	}
}

3スレッド

uint8_t thread_stack3[THREAD_STACK_SIZE];
TX_THREAD thread_ptr3;

void my_thread_entry3(ULONG initial_input);

tx_thread_create(&thread_ptr3,"my_thread3",my_thread_entry3,0x1234,thread_stack3,THREAD_STACK_SIZE,15,15,1,TX_AUTO_START);

void my_thread_entry3(ULONG initial_input)
{
	while(1){
		HAL_GPIO_TogglePin(LD3_GPIO_Port, LD3_Pin);
		tx_thread_sleep(20);
	}
}

基本は同じプログラム内容です。
単純なスレッドなら容易に作れましたね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0