The problem with keeping a gpio output high all the time in freertos

I created a new freertos task and initially pulled a gpio pin high in the task, it was very simple. But when I monitor the waveform of this pin with an oscilloscope, I found that this pin is not always high, when freertos does time slice task scheduling and switches tasks, this pin will return to the low initial state, I tried a lot methods, such as using preemptive scheduling instead, or setting this pin in all tasks, but none solved the problem.
Here is my code:

void testTask1(void* *pvParameters)
{
	while(1)
	{
		gpio_bit_set(GPIOD, GPIO_PIN_4);
	}
	
}

void main(void)
{
	rcu_periph_clock_enable(RCU_GPIOD);
	
	gpio_init(GPIOD, GPIO_MODE_OUT_PP, GPIO_OSPEED_MAX, GPIO_PIN_4);

	xTaskCreate(testTask5, "test_task5", 128, NULL, 1, NULL);
	
	vTaskStartScheduler();
}

but the task function in your post is testTask1.
I guess there are some more tasks manipulating the GPIO pin.
I don’t know what you’re trying to test but manipulating the same GPIO controller with it’s pins in multiple tasks requires some access protection (a mutex).

1 Like