cancel
Showing results for 
Search instead for 
Did you mean: 

FreeRTOS Hard Fault issue

NicRoberts
Senior II

NUCLEO F411RE

I'm checking to see if I've got FreeRTOS integrated properly. So I've set up 2 tasks each with their own counter. In debug I was expecting to see the counter for Task1 to count up whilst Task2 never gets updated.

When I step through the scheduler appears to set up just fine but when its to the call to start the first task (prvPortStartFirstTask()) it falls fowl to the HardFault_Handler.

I initially had a stack size of 100 for each task & thought that maybe an issue but reducing the stack size to 30 hasn't made any difference.
Any pointers (pun intended)?


My code...

* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "arm_math.h"
#include "FreeRTOS.h"
#include "task.h"
#include <stdint.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 */
uint32_t task1Profiler = 0;
uint32_t task2Profiler = 0;
void Task1(void *pvParameters);
void Task2(void *pvParameters);
/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */

/* 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 */

  /* 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 */
  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  xTaskCreate(Task1, "Task1", 30, NULL, 2, NULL);
  xTaskCreate(Task2, "Task2", 30, NULL, 1, NULL);
  vTaskStartScheduler();
  while (1)
  {
    /* USER CODE END WHILE */

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


/* RCC setup etc */

/* USER CODE BEGIN 4 */
void Task1(void *pvParameters)
{
	while(1)
	{
		task1Profiler++;
	}
}

/**
  * @brief Task 2
  *  None
  * @retval None
  */
void Task2(void *pvParameters)
{
	while(1)
	{
		task2Profiler++;
	}
}
/* USER CODE END 4 */
1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Super User

prvPortStartFirstTask works by triggering the SVC interrupt. Check that the SVC handler is not redefined and not disabled (so that it does not elevate to HF).

 

 

View solution in original post

4 REPLIES 4
TDK
Super User

Stack size of 100 might be insufficient. I don't see why reducing it would solve anything.

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

Indeed, I tried increasing it to 300 as well, same issue.

Pavel A.
Super User

prvPortStartFirstTask works by triggering the SVC interrupt. Check that the SVC handler is not redefined and not disabled (so that it does not elevate to HF).

 

 

OK that's making sense of another issue I was having too. When I first added the FreeRTOS middleware & built the project there were a lot of redefine errors associated with the SVC handler. I commented out the defines in the RTOS files & the errors went away.

Now I'm guessing I should have commented out the defines in stm32f4xx_it.c as these appear to be empty templates?

 

Yes that was it, thanks!