Hardfault Exception on function return and IBUSERR

Hi Guys,

I am still a newbie when it comes to STM32F4 MCU, mbed and Yotta, so hopefully someone can help me with issues I encountered during the debugging of the simple LEDBlink example I followed from the mbed website.

I am using STM32F411RE-Nucleo Board. I used the stm32f411re-nucleo-gcc as my Yotta target. I encountered some compilation errors along the way, but was able to resolve those by supplying the files the build was looking:

  • device.h
  • target_config.h
  • stm32f411xe.h
  • startup_stm32f4xx.s
  • system_stm32f4xx.c
  • STM32F411XE.ld

Now that i started to debug the firmware using Eclipse + OpenOCD + GDB setup, i encountered a HardFault exception. Tracing HardFault registers, these are the values:

  • HFSR (HardFault Status Register) = 0x40000000 which means a Forced Fault
  • CSFR (Configurable Fault Status Reg) = 0x100 which means IBUSERR or instruction bus error

Here is where the hardfault always happen. During debugging and I stepped into HAL_TIM_OC_Init(&TimMasterHandle); and when I reached at the exit point of the HAL_TIM_OC_Init(&TimMasterHandle); function, it will raise the HardFault exception.

// Reconfigure the HAL tick using a standard timer instead of systick.
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) {
_ (void)TickPriority;_

_ // Enable timer clock_
_ TIM_MST_RCC;_

_ // Reset timer_
_ TIM_MST_RESET_ON;_
_ TIM_MST_RESET_OFF;_

_ // Update the SystemCoreClock variable_
_ SystemCoreClockUpdate();_

_ // Get clock configuration_
_ RCC_ClkInitTypeDef RCC_ClkInitStruct;_
_ uint32_t PclkFreq;_
_ // Note: PclkFreq contains here the Latency (not used after)_
_ HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &PclkFreq);_
_ // Get TIM1 clock value_
_ PclkFreq = HAL_RCC_GetPCLK1Freq();_
_ // TIMxCLK = PCLKx when the APB prescaler = 1 else TIMxCLK = 2 * PCLKx_
_ if (RCC_ClkInitStruct.APB1CLKDivider != RCC_HCLK_DIV1) {_
_ PclkFreq *= 2;_
_ }_

_ // Configure time base_
_ TimMasterHandle.Instance = TIM_MST;_
_ TimMasterHandle.Init.Period = 0xFFFFFFFF;_
_ TimMasterHandle.Init.Prescaler = (uint32_t)(PclkFreq / 1000000) - 1; // 1 us tick_
_ TimMasterHandle.Init.ClockDivision = 0;_
_ TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP;_
_ TimMasterHandle.Init.RepetitionCounter = 0;_
HAL_TIM_OC_Init(&TimMasterHandle);

_ NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler);_
_ NVIC_EnableIRQ(TIM_MST_IRQ);_

_ // Channel 1 for mbed timeout_
_ HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1);_

_ // Channel 2 for HAL tick_
_ HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2);_
_ PreviousVal = _HAL_TIM_GetCounter(&TimMasterHandle);
_ _HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY);
_ _HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);

#if 0 // For DEBUG only
_ GPIOB_CLK_ENABLE();
_ GPIO_InitTypeDef GPIO_InitStruct;

_ GPIO_InitStruct.Pin = GPIO_PIN_6;_
_ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;_
_ GPIO_InitStruct.Pull = GPIO_PULLUP;_
_ GPIO_InitStruct.Speed = GPIO_SPEED_FAST;_
_ HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);_
#endif

_ return HAL_OK;_
}

Is there something I messed up in the build/compile/link environment (most especially stack)? Or i just missed to do some additional build configuration?

Thanks.

@Felvie What are the compilation issues? Please report them to the modules (they should have github repositories).

cc @bcostm

Hi Martin,

Thanks for dropping by.

The very first error that I encountered after setting up the simple LEDBlink project as pointed at the Yotta tutorial was: "Please select first the STM32F4XX device used in your application (in stm32f4xx.h file).

I downloaded the stm32f411re-nucleo-gcc as target and mbed-drivers as dependencies/modules.

So, I searched for fix on that error and I stumbled upon this link: Yotta and CMAKE not build - #3 by RoToRx88

It seems that this target is not supported yet, so I proceeded on trying to fix the error by myself.

I also did contacted the ST Micro guys and they said that they don’t have plan to migrate to Yotta and mbed-OS because they only support FreeRTOS (I have the email coming from our vendor), however, the Nucleo board, it says that it’s mbed-enabled.

Anyway, what else I need to do or to provide in order to get some suggestion or idea on how to fix my problem?

Thank you.