TransWikia.com

Running two threads at the same time is causing a hardfault

Electrical Engineering Asked by Pokloha on December 19, 2021

So i’m learning FreeRTOS on STM32 and currently following a tutorial to get things started. Following are my concerns with the first one being the most:

  • I have two threads, but upon running a scheduler, I see a hardfault. But when I run a single thread, I see no issues. I initially thought it’d be related to the stack size but each thread is taking up 130 * 4 = 520 bytes.

  • Does stack size refer to the word size in the context of rtos? (if the stack is 16-bits wide and usStackDepth is 100, then 200 bytes will be allocated for use as the task’s stack)

  • TaskHandle_t is a pointer to struct tskTaskControlBlock. Then why is the address of the xTaskBlinky passed to the last parameter of xTaskCreate(), which takes TaskHandle_t * const pxCreatedTask )?

     typedef struct tskTaskControlBlock* TaskHandle_t; // in task.h
    
     // main.c
    
     TaskHandle_t xTaskBlinky = NULL;
     TaskHandle_t xTaskBlinky1 = NULL;
    
     void vTask1_Handler(void *params);
     void vTask2_Handler(void *params);
    
     void SystemClock_Config(void);
    
     int main(void)
     {
         /* MCU Configuration--------------------------------------------------------*/
    
         /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
         HAL_Init();
    
         /* Configure the system clock */
         SystemClock_Config();
    
         xTaskCreate(vTask1_Handler, "Blinky", configMINIMAL_STACK_SIZE, NULL, 2, &xTaskBlinky);
         xTaskCreate(vTask2_Handler, "Blinky1", configMINIMAL_STACK_SIZE, NULL, 2, &xTaskBlinky1);
    
         vTaskStartScheduler();
         while (1);
     }
    
     void vTask1_Handler(void *params)
     {
         while(1);
     }
    
     void vTask2_Handler(void *params)
     {
         while(1);
     }
    

    And the program goes into the infinite loop upon running a scheduler:

      * @brief  This is the code that gets called when the processor receives an 
      *         unexpected interrupt.  This simply enters an infinite loop, preserving
      *         the system state for examination by a debugger.
      * @param  None     
      * @retval None       
     */
         .section  .text.Default_Handler,"ax",%progbits
     Default_Handler:
     Infinite_Loop:
       b  Infinite_Loop
       .size  Default_Handler, .-Default_Handler
    

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP