cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G431RB seems to crash when "HAL_TIM_Base_Start_IT" and "HAL_TIM_PWM_Start_IT" are called

FBurk.1
Associate

Hello everybody,

I bought a STM32G431RB Nucleo. I created code for it with the STM32 CubeMX and modiefied the code in the STM32 CubeIDE. I want to access "HAL_TIM_PeriodElapsedCallback" and "HAL_TIM_PWM_PulseFinishedCallback", I read that this is possible by calling "HAL_TIM_Base_Start_IT" for "HAL_TIM_PeriodElapsedCallback" and "HAL_TIM_PWM_Start_IT" for "HAL_TIM_PWM_PulseFinishedCallback". But when I do that, the STM32 seems to crash.

Am I doing something wrong, or is this simply not possible?

Thank you in advance!

int main(void)
{
  /* USER CODE BEGIN 1 */
 
  /* USER CODE END 1 */
 
  /* MCU Configuration--------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* USER CODE BEGIN Init */
 
  /* USER CODE END Init */
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* USER CODE BEGIN SysInit */
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_LPUART1_UART_Init();
  MX_TIM4_Init();
  /* USER CODE BEGIN 2 */
 
  // For some reason I can't have both Base_Start_IT and PWM_Start_IT
  HAL_TIM_Base_Start_IT(&htim4); // Calls HAL_TIM_PeriodElapsedCallback
  HAL_TIM_PWM_Start_IT(&htim4, TIM_CHANNEL_1); // Calls HAL_TIM_PWM_PulseFinishedCallback
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, 1); // Never gets reached
 
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

0693W00000Dln14QAB.png

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

More than likely the interrupts are being called so frequently that your main loop cannot progress. You're calling multiple interrupts every 200 timer ticks. That's not a lot of time.

Slow the timer down by a couple of orders of magnitude and try again.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

4 REPLIES 4
TDK
Guru

More than likely the interrupts are being called so frequently that your main loop cannot progress. You're calling multiple interrupts every 200 timer ticks. That's not a lot of time.

Slow the timer down by a couple of orders of magnitude and try again.

If you feel a post has answered your question, please click "Accept as Solution".

Hello TDK,

thanks a lot for your reply, it was correct!

Yack
Associate II

I have similar problem with my code that used to work on 431KB nucleo board, but fails on my prototype with 431RB MCU. 

Debugger does not step over HAL_TIM_Base_Start_IT(&htim1);

 

 

 

static void MX_TIM1_Init(void)
{

  /* USER CODE BEGIN TIM1_Init 0 */

  /* USER CODE END TIM1_Init 0 */

  TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  TIM_MasterConfigTypeDef sMasterConfig = {0};

  /* USER CODE BEGIN TIM1_Init 1 */

  /* USER CODE END TIM1_Init 1 */
  htim1.Instance = TIM1;
  htim1.Init.Prescaler = 128;
  htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim1.Init.Period = 100000;
  htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  htim1.Init.RepetitionCounter = 0;
  htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
  {
    Error_Handler();
  }
  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
  {
    Error_Handler();
  }
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN TIM1_Init 2 */
  HAL_TIM_Base_Start_IT(&htim1);
  HAL_NVIC_EnableIRQ(TIM1_UP_TIM16_IRQn);
  /* USER CODE END TIM1_Init 2 */

}

 

 

If i step into the HAL_TIM_Base_Start_IT(&htim1); and step by step, it returns OK.

Any ideas what might be wrong? Tried using FW 1.5.1 , 1.5.2 , 1.4.0 , no difference.

Yack
Associate II

I found this to solve my problem (boot_lock) , not sure what that option byte does or if i can program it via Stm32Cube IDE

https://community.st.com/t5/stm32-mcus-embedded-software/debugger-stops-after-hal-tim-base-start-it/td-p/80750