2022-05-20 11:30 AM
I'm using STM32CubeMX to develop an app for the STM32F030. I've done this many times and thought I understood the various issues - but I'm having a hell of a time getting a basic timer (TIM6) to run (interrupt-driven).
The generated init code is:
htim6.Instance = TIM6;
htim6.Init.Prescaler = 0;
htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
htim6.Init.Period = 816;
htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
{
Error_Handler();
}
Then I start it with this: (The GPIO is for debugging - see below).
HAL_GPIO_WritePin(TP5_GPIO_Port, TP5_Pin, GPIO_PIN_SET); //!!!
HAL_GPIO_WritePin(TP5_GPIO_Port, TP5_Pin, GPIO_PIN_RESET); //!!!
// Start the system timer
HAL_TIM_Base_Start_IT(&htim6);
HAL_GPIO_WritePin(TP5_GPIO_Port, TP5_Pin, GPIO_PIN_SET); //!!!
HAL_GPIO_WritePin(TP5_GPIO_Port, TP5_Pin, GPIO_PIN_RESET); //!!!
Finally, my interrupt handler simply asserts a GPIO test point and increments a global variable:
/**
* @brief This function handles TIM6 global interrupt.
*/
void TIM6_IRQHandler(void)
{
/* USER CODE BEGIN TIM6_IRQn 0 */
HAL_GPIO_WritePin(TP5_GPIO_Port, TP5_Pin, GPIO_PIN_SET);
swTimerTick++;
/* USER CODE END TIM6_IRQn 0 */
HAL_TIM_IRQHandler(&htim6);
/* USER CODE BEGIN TIM6_IRQn 1 */
HAL_GPIO_WritePin(TP5_GPIO_Port, TP5_Pin, GPIO_PIN_RESET);
/* USER CODE END TIM6_IRQn 1 */
}
When I run this, it goes into the ditch. On the oscilloscope, I see only the first test point pulse (before the call to HAL_TIM_Base_Start_IT(). If I run it in the debugger, I can step through that _Start call seemingly without issues, but when I tell it to run it hangs. If I stop the debugger, it's looping in the HardFault_Handler.
I feel like I must be missing something obvious.... Any thoughts?
Solved! Go to Solution.
2022-05-20 05:10 PM
You should go through the standard interrupt troubleshooting, part of which is checking whether address of the ISR is properly inserted into the vector table.
My guess is that it is not. Some 'F030 e.g. 'F030x6 officially do not have TIM6.
Use a different timer.
JW
2022-05-20 01:46 PM
What does the fault analyzer say if you hit the hard fault in the debugger?
Have you tried to find the error by bisection, i.e. repeatedly setting breakpoints at intermediate code points?
Some init code is missing, like enabling the clock. Is HAL_TIM_Base_MspInit properly called?
hth
KnarfB
2022-05-20 05:10 PM
You should go through the standard interrupt troubleshooting, part of which is checking whether address of the ISR is properly inserted into the vector table.
My guess is that it is not. Some 'F030 e.g. 'F030x6 officially do not have TIM6.
Use a different timer.
JW
2022-05-20 05:46 PM
Interesting... I wonder if this is a bug in CubeMX, then. Because it certainly didn't complain when I enabled that timer...
2022-05-21 03:12 AM
OK and is it this case at all? Which STM32F030 exactly do you use?
The 'F030 are in fact 3 different chips with slightly different set of peripherals, depending on the package. TIM6 is available only in STM32F030x8/C.
JW
2022-05-21 07:26 AM
Got it. Yes, I'm using the STM32F030C8T6.
2022-05-23 12:44 PM
I migrated my project to use SMT32CubeIDE and it seems to be working now.
Before, I was using STM32CubeMX along with Keil uVision.
I can't explain it, but I'm going to chalk it up to some obscure bug and move on.
Thanks for all the responses!