Electrical – Hardfault exception on stm32f7 arm microprocessor at RTX thread creation

armcrtosstm32

I'm running a simple RTX thread program as follows. The problem is when it's running on STM32F7 DISCOVERY BOARDv through debug interface, it seems right after running the osThreadCreate (osThread(Thread), NULL); the program jumps to hardfault interrupt. It used to run fine before.

void Thread (void const *argument);         
osThreadId tid_Thread;                                   
osThreadDef (Thread, osPriorityNormal, 1, 0);          

int Init_Thread (void) {

  tid_Thread = osThreadCreate (osThread(Thread), NULL);
  if (!tid_Thread) return(-1);

  return(0);
}

and my clock configuration is as follows:

static void SystemClock_Config(void)
{
  RCC_ClkInitTypeDef RCC_ClkInitStruct;
  RCC_OscInitTypeDef RCC_OscInitStruct;

  /* Enable HSE Oscillator and activate PLL with HSE as source */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.HSIState = RCC_HSI_OFF;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = 25;
  RCC_OscInitStruct.PLL.PLLN = 432;  
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = 9;
  if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  /* activate the OverDrive to reach the 216 Mhz Frequency */
  if(HAL_PWREx_EnableOverDrive() != HAL_OK)
  {
    Error_Handler();
  }

  RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;  
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;  
  if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7) != HAL_OK)
  {
    Error_Handler();
  }
}

and this is the handler my program jumps to(at stm32_746xx.s):

HardFault_Handler\
PROC
EXPORT  HardFault_Handler          [WEAK]
B       .
ENDP

Best Answer

If you use stm32cube classic for configuration, the problem might be by MPU_Config function. I just switched the MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE; line with MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;. This is about sharing memory by several processes or threads but I don't know the details. if your program runs on one thread or you handle the memory access by yourself, you can make the code run by that change.

Related Topic