1
\$\begingroup\$

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
\$\endgroup\$
  • \$\begingroup\$ What IDE are you using? \$\endgroup\$ – pgvoorhees Jul 11 '16 at 11:53
  • \$\begingroup\$ Keil uvision version 5.17 \$\endgroup\$ – AliA Jul 11 '16 at 11:58
  • 2
    \$\begingroup\$ "It used to run fine before." - before what? What is different between now and "before" (other than the HardFault)? \$\endgroup\$ – brhans Jul 11 '16 at 13:07
  • 1
    \$\begingroup\$ A HardFault is raised, because you probably access invalid memory somewhere (e.g. a null pointer or a invalid hardware register). You can try to recover the context by inspecting the stack. See for example this link. It's written for FreeRTOS, but most of it applies to ARM ABI in general. By that you can see which function and which access caused the HardFault and try to debug it. \$\endgroup\$ – erebos Jul 11 '16 at 13:08
  • 1
    \$\begingroup\$ Would you mind posting your linker script too? I have a sneaking suspicion. \$\endgroup\$ – pgvoorhees Oct 31 '16 at 11:45
1
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.