cancel
Showing results for 
Search instead for 
Did you mean: 

how to solve semaphore issues: button toggling issue

Akshay_
Associate II
/* USER CODE END Header_Normal_init */
void Normal_init(void const * argument)
{
  /* USER CODE BEGIN 5 */
  /* Infinite loop */
  for(;;)
  {
//while(HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13));
 
char *msg1 =  "hello mid\r\n";
HAL_UART_Transmit(&huart3, (uint8_t *)msg1, strlen (msg1), 100);
 
while(HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13));
 
char *msg2 =  "bye mid\r\n";
HAL_UART_Transmit(&huart3, (uint8_t *)msg2, strlen (msg2), 100);
osDelay(2000);
  }
  /* USER CODE END 5 */
}
 
/* USER CODE BEGIN Header_High_init */
/**
* @brief Function implementing the HighTask thread.
* @PAram argument: Not used
* @retval None
*/
/* USER CODE END Header_High_init */
void High_init(void const * argument)
{
  /* USER CODE BEGIN High_init */
  /* Infinite loop */
  for(;;)
  {
char *msg1 =  "hello high\r\n";
HAL_UART_Transmit(&huart3, (uint8_t *)msg1, strlen(msg1), 100);
char *msg2 =  "bye high\r\n";
HAL_UART_Transmit(&huart3, (uint8_t *)msg2, strlen(msg2), 100);
    osDelay(1000);
  }
  /* USER CODE END High_init */
}
 
/* USER CODE BEGIN Header_Low_init */
/**
* @brief Function implementing the LowTask thread.
* @PAram argument: Not used
* @retval None
*/
/* USER CODE END Header_Low_init */
void Low_init(void const * argument)
{
  /* USER CODE BEGIN Low_init */
  /* Infinite loop */
  for(;;)
  {
char *msg1 =  "hello low\r\n";
HAL_UART_Transmit(&huart3, (uint8_t *)msg1, strlen(msg1), 100);
char *msg2 =  "bye low\r\n";
HAL_UART_Transmit(&huart3, (uint8_t *)msg2, strlen(msg2), 100);
osDelay(800);
  }
  /* USER CODE END Low_init */
}

Greetings!
I have defined 3 tasks high priority normal priority and a low priority,
The actual procedure is first the high priority task will execute and leave the high task after that it will just enter the medium priority task and will wait until the user button is pressed after it's pressed it will enter the low task and exit, if the button is not pressed it will go back executing the high priority task.
I'm not able to achieve that here, can somebody assist me?

I referred this video for this FreeRTOS Tutorial 3.0 || Binary Semaphore || STM32 || CMSIS || CUBEIDE (youtube.com)

1 REPLY 1
TDK
Guru

Using UART3 in multiple threads is not advised--at best the call will fail.

Do you know how to start tasks in RTOS? Should be plenty of examples and tutorials around for that.

If you feel a post has answered your question, please click "Accept as Solution".