Loading...
 

SW4STM32 and SW4Linux fully supports the STM32MP1 asymmetric multicore Cortex/A7+M4 MPUs

   With System Workbench for Linux, Embedded Linux on the STM32MP1 family of MPUs from ST was never as simple to build and maintain, even for newcomers in the Linux world. And, if you install System Workbench for Linux in System Workbench for STM32 you can seamlessly develop and debug asymmetric applications running partly on Linux, partly on the Cortex-M4.
You can get more information from the ac6-tools website and download (registration required) various documents highlighting:

System Workbench for STM32


Problem with toggle GPIOs in 2 tasks

Hello everyone,

I’m trying to work with different tasks to understand how the priorities works in the STM32F3 and I have 2 different tasks. The first one toggle a GPIO continously, and the second one toggle other GPIO and has higher priority. The second has a loop to see that, when the task is in this loop, the first one does not work.

The problem I’m having is that the toggling is not working fine. When I use HAL_GPIO_TogglePin, the GPIO goes up, waits in the loop, and when the loop is finished and the task goes to os Delay(), the GPIO goes down again instead waiting for the next call of the task. The code is shown below:

This is the declaration of the tasks.
int main(void)
{

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

/* Configure the system clock */
SystemClock_Config();

/* Initialize all configured peripherals */
MX_GPIO_Init();

/* Create the thread(s) */
/* definition and creation of defaultTask */
osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);

/* definition and creation of newTask */
osThreadDef(newTask, SecondTask, osPriorityHigh, 0, 128);
newTaskHandle = osThreadCreate(osThread(newTask), NULL);

/* Start scheduler */
osKernelStart(NULL, NULL);

/* We should never get here as control is now taken by the scheduler */

/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}

Then the methods for each task. StartDefaultTask is the task with the lower priority.

/* StartDefaultTask function */
void StartDefaultTask(void const * argument)
{

/* USER CODE BEGIN 5 */
/* Infinite loop */
for(;;)
{
HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_0);
}
/* USER CODE END 5 */
}

int cont_delay = 0;
void SecondTask(void const * argument)
{
/* USER CODE BEGIN SecondTask */
/* Infinite loop */
for(;;)
{
HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_3);
for (int i = 0; i < 100000; i++){
contador_led++;
}
cont_delay++;
osDelay(200);
}
/* USER CODE END SecondTask */
}

In the image attached to the post is a capture of the osciloscope signal. Each square is 100 ms and it can be seen that the upper signal, which is the highest priority task, raises the value of the GPIO, waits in the loop for about 40 ms (in this time it can be seen in the lower signal that the first task is waiting for the other to end), and after that the task go to sleep, but the value of the output goes to 0 again.

I don’t understand why this output goes down without any function changing it. I thought that maybe there was a problem in the implementation of the TogglePin function, but I checked the library and it seems to work fine.

Maybe someone had the same problem and know what could be the problem.

Thanks in advance!

StartDefaultTask toggles pin without any delay? Also you mix “dummy” delays with osDelay - why?

It’s just for testing the functioning of the priorities, to check that when the highest priority task is in the for loop, the StartDefaultTask is stopped. I know is not a good implementation, but it should work anyway, and it’s not working as I expected.

Optimization of compiler nulls out useless code, even if it’s intended as dummy delay. Take this into account. Change SW4STM32 Eclipse compiler optimization and see what happens. You may also choose to declare variables with volatile as prefix. Welcome to the weird world of 21st century coding and compiling where the simpliest proof of concept code will already cause trouble. It used to work in the 1980s/1990s but today everything has changed ;)