2024-04-09 08:35 PM
This is my main program:
int main(void)
{
HAL_Init();
/* USER CODE BEGIN Init */
TaskHandle_t task1_handler;
TaskHandle_t task2_handler;
BaseType_t status;
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
MX_GPIO_Init();
MX_RTC_Init();
//MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
status = xTaskCreate(task1_handler,"Task1",150,"Hello world From task1",2,&task1_handler);
configASSERT( status == pdPASS);
status = xTaskCreate(task2_handler,"Task2",150,"Hello world From task2",2,&task2_handler);
configASSERT( status == pdPASS);
vTaskStartScheduler();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
}
/* USER CODE END 3 */
}
And this is my tasks' code:
static void task1_handler(void * parameters)
{
while(1)
{
GPIOC->BSRR |= (uint32_t)1<<13;
//vTaskDelay(pdMS_TO_TICKS(100));
taskYIELD();
}
}
static void task2_handler(void * parameters)
{
while(1)
{
GPIOC->BSRR = (uint32_t)1<<29;
//vTaskDelay(pdMS_TO_TICKS(100));
taskYIELD();
}
}
It seems that xTaskCreate() is causing hardfault. Do you have any idea?
Solved! Go to Solution.
2024-04-10 04:31 AM - edited 2024-04-10 04:32 AM
It seemed to be a heap size issue, when I lowered the heap size for the two task allocations hardfault resolved. Why would two 150 heap cause a stack with a total size of 1000 to overflow? Anyway thanks for the suggestions guys!
2024-04-09 08:38 PM
And here is my FreeRTOSConfig.h:
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ ( SystemCoreClock )
#define configTICK_RATE_HZ ( ( TickType_t ) 500 )
#define configMAX_PRIORITIES ( 5 )
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 60 )
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 1000 ) )
#define configMAX_TASK_NAME_LEN ( 5 )
#define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 8
#define configCHECK_FOR_STACK_OVERFLOW 0
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_MALLOC_FAILED_HOOK 0
#define configUSE_APPLICATION_TASK_TAG 0
#define configUSE_COUNTING_SEMAPHORES 1
#define configGENERATE_RUN_TIME_STATS 0
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* Software timer definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( 2 )
#define configTIMER_QUEUE_LENGTH 5
#define configTIMER_TASK_STACK_DEPTH ( 80 )
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
2024-04-09 08:53 PM
Debug it like any other Hard Fault, look at the code that's faulting and the registers.
Clear the local/auto variables
2024-04-10 12:08 AM - edited 2024-04-10 01:52 AM
Hello,
From the code snippet you shared l can see code generated by CubeMx for peripherals init but I can’t see cmsis os for RTOS APIs calls. Did you integrate freertos lib manually to your project?
2024-04-10 04:21 AM
YES. I'm actually learning FreeRTOS based on an Udemy course. I'm sorry to ask such a *** question here, my debugger tells me that the CPU has been inside vTaskStartScheduler(), but I'm not sure where it's stuck because all that seems to be executing after stepping into the debug is some systick related code, so I can't pinpoint the the exact problem.
2024-04-10 04:27 AM - edited 2024-04-10 04:30 AM
I don't recommend to add manually FreeRTOS as you are a beginner. I suggest you to enable FreeRTOS in CubeMx.
See this video on Youtube.
2024-04-10 04:31 AM - edited 2024-04-10 04:32 AM
It seemed to be a heap size issue, when I lowered the heap size for the two task allocations hardfault resolved. Why would two 150 heap cause a stack with a total size of 1000 to overflow? Anyway thanks for the suggestions guys!