cancel
Showing results for 
Search instead for 
Did you mean: 

Getting errors while building a FreeRTOS project for STM32F411RE

rahulrajsharma123
Associate

Hi,

I am working on a project where I am using FreeRTOS. It was working fine but after adding a couple of more features there are strange errors.

It says that the particular variable doesn't exist but the variable is actually initialized in the same code/file.

 

Please help

Thanks

Rahul

see the code below: the error is 

rahulrajsharma123_0-1696150864918.png

 

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2023 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
 
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <FreeRTOS.h>
#include "task.h"
#include <stdio.h>
#include <SEGGER_RTT.h>
/* USER CODE END Includes */
 
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
 
/* USER CODE END PTD */
 
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
 
/* USER CODE END PD */
 
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
 
/* USER CODE END PM */
 
/* Private variables ---------------------------------------------------------*/
 
/* USER CODE BEGIN PV */
#define DWT_CTRL (*(volatile uint32_t*)0xE0001000)
/* USER CODE END PV */
 
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
 
/* USER CODE BEGIN PFP */
void LEDHandler1(void* param);
void LEDHandler2(void* param);
void LEDHandler3(void* param);
void ButtonHandler(void* param);
extern void SEGGER_UART_init(uint32_t);
/* USER CODE END PFP */
 
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
 
/* USER CODE END 0 */
 
/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */
  TaskHandle_t task1_handle;
  TaskHandle_t task2_handle;
  TaskHandle_t task3_handle;
  TaskHandle_t  next_task;
  TaskHandle_t button_handle;
 
 
  BaseType_t status;
  /* USER CODE END 1 */
 
  /* MCU Configuration--------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* USER CODE BEGIN Init */
 
  /* USER CODE END Init */
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* USER CODE BEGIN SysInit */
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  /* USER CODE BEGIN 2 */
  SEGGER_UART_init(500000);
  //CYCLCNT enable
  DWT_CTRL |= (1 << 0);
  SEGGER_SYSVIEW_Conf();
 
  status = xTaskCreate(LEDHandler1, "LED1 Handler", 200, NULL, 2, &task1_handle);
  configASSERT(status == pdPASS);
  next_task = task1_handle;
 
  status = xTaskCreate(LEDHandler2, "LED2 Handler", 200, NULL, 2, &task2_handle);
  configASSERT(status == pdPASS);
 
  status = xTaskCreate(LEDHandler3, "LED3 Handler", 200, NULL, 2, &task3_handle);
  configASSERT(status == pdPASS);
 
  status = xTaskCreate(ButtonHandler, "Button Handler", 200, NULL, 4, &button_handle);
  configASSERT(status == pdPASS);
 
  vTaskStartScheduler();
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}
 
/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
 
  /** Configure the main internal regulator output voltage
  */
  __HAL_RCC_PWR_CLK_ENABLE();
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
 
  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.PLL.PLLM = 16;
  RCC_OscInitStruct.PLL.PLLN = 336;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
  RCC_OscInitStruct.PLL.PLLQ = 4;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
 
  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
 
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  {
    Error_Handler();
  }
}
 
/**
  * @brief GPIO Initialization Function
  * @PAram None
  * @retval None
  */
static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */
 
  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOH_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();
 
  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);
 
  /*Configure GPIO pin : B1_Pin */
  GPIO_InitStruct.Pin = B1_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
 
  /*Configure GPIO pins : USART_TX_Pin USART_RX_Pin */
  GPIO_InitStruct.Pin = USART_TX_Pin|USART_RX_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
  /*Configure GPIO pin : LD2_Pin */
  GPIO_InitStruct.Pin = LD2_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct);
 
/* USER CODE BEGIN MX_GPIO_Init_2 */
/* USER CODE END MX_GPIO_Init_2 */
}
 
/* USER CODE BEGIN 4 */
void LEDHandler1(void* param)
{
BaseType_t status;
extern TaskHandle_t next_task;
extern TaskHandle_t task2_handle;
while(1)
{
SEGGER_SYSVIEW_PrintfTarget("Toggling LED from Task 1");
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
status = xTaskNotifyWait(0, 0, NULL, pdMS_TO_TICKS(1000));
if(status == pdTRUE)
  {
    next_task = task2_handle;
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
    vTaskDelete(NULL);
  }
}
}
 
void LEDHandler2(void* param)
{
BaseType_t status;
 
while(1)
{
SEGGER_SYSVIEW_PrintfTarget("Toggling LED from Task 2");
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
status = xTaskNotifyWait(0, 0, NULL, pdMS_TO_TICKS(800));
if(status == pdTRUE)
  {
    //next_task = task3_handle;
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
    vTaskDelete(NULL);
  }
}
}
 
void LEDHandler3(void* param)
{
  BaseType_t status;
while(1)
{
SEGGER_SYSVIEW_PrintfTarget("Toggling LED from Task 3");
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
status = xTaskNotifyWait(0, 0, NULL, pdMS_TO_TICKS(200));
if(status == pdTRUE)
  {
    //next_task = NULL;
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
    vTaskDelete(NULL);
    //vTaskDelete(&button_handle);
  }
}
}
 
void ButtonHandler(void* param)
{
  uint8_t button_read = 0, prev_read = 0;
 
  while(1)
  {
      button_read = HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13);
 
      if(!button_read)
{
  if(prev_read)
    {
      //xTaskNotify(next_task, 0, eNoAction);
    }
}
  prev_read = button_read;
  vTaskDelay(pdMS_TO_TICKS(10));
  }
 
}
/* USER CODE END 4 */
 
/**
  * @brief  Period elapsed callback in non blocking mode
  * @note   This function is called  when TIM5 interrupt took place, inside
  * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
  * a global variable "uwTick" used as application time base.
  * @PAram  htim : TIM handle
  * @retval None
  */
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
  /* USER CODE BEGIN Callback 0 */
 
  /* USER CODE END Callback 0 */
  if (htim->Instance == TIM5) {
    HAL_IncTick();
  }
  /* USER CODE BEGIN Callback 1 */
 
  /* USER CODE END Callback 1 */
}
 
/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}
 
#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @PAram  file: pointer to the source file name
  * @PAram  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

 

2 REPLIES 2
Imen.D
ST Employee

Hello @rahulrajsharma123 ,

Maybe the issue is with your project configuration and you're missing some include files defining the functions.​

You'd want to review the defines and include paths used.

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Bob S
Principal
int main(void)
{
  /* USER CODE BEGIN 1 */
  TaskHandle_t task1_handle;
  TaskHandle_t task2_handle;
  TaskHandle_t task3_handle;
  TaskHandle_t  next_task;
  TaskHandle_t button_handle;
  // more code that doesn't matter.....

You declare these ^^^^ variables as LOCAL to main().  There is no way to access them from other functions, not even with "extern" declarations.  Move these declarations outside main() to make them global variables.  Then remove the "extern" declarations in the other functions (not needed as long as those functions are in the same source file as the declarations).