cancel
Showing results for 
Search instead for 
Did you mean: 

Checking (HAL_TIMEx_MasterConfigSynchronization(&htim12, &sMasterConfig) != HAL_OK), halt the system

Abid
Associate II

I am using STM32F407 with eclipse IDE. And I want to generate PWM signal using TIMER12. After all the configuration, when I call,

 

"sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;

sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

if (HAL_TIMEx_MasterConfigSynchronization(&htim12, &sMasterConfig) != HAL_OK)

{

Error_Handler();

}"

 

 

inside MX_TIM12_Init(); function, the MCU just stuck and I get no print function.

On debugger console I get a the following message,

"Wrong parameters value: file ../../stm32f4-hal/stm32f4xx_hal_tim_ex.c on line 1636".

And this line refers to the following lines of codes,

 

 

"

HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim,

TIM_MasterConfigTypeDef *sMasterConfig)

{

uint32_t tmpcr2;

uint32_t tmpsmcr;



/* Check the parameters */

assert_param(IS_TIM_MASTER_INSTANCE(htim->Instance));

assert_param(IS_TIM_TRGO_SOURCE(sMasterConfig->MasterOutputTrigger));

assert_param(IS_TIM_MSM_STATE(sMasterConfig->MasterSlaveMode));



/* Check input state */

__HAL_LOCK(htim);



/* Change the handler state */

htim->State = HAL_TIM_STATE_BUSY;



/* Get the TIMx CR2 register value */

tmpcr2 = htim->Instance->CR2;



/* Get the TIMx SMCR register value */

tmpsmcr = htim->Instance->SMCR;



/* Reset the MMS Bits */

tmpcr2 &= ~TIM_CR2_MMS;

/* Select the TRGO source */

tmpcr2 |= sMasterConfig->MasterOutputTrigger;



/* Update TIMx CR2 */

htim->Instance->CR2 = tmpcr2;



if (IS_TIM_SLAVE_INSTANCE(htim->Instance))

{

/* Reset the MSM Bit */

tmpsmcr &= ~TIM_SMCR_MSM;

/* Set master mode */

tmpsmcr |= sMasterConfig->MasterSlaveMode;



/* Update TIMx SMCR */

htim->Instance->SMCR = tmpsmcr;

}



/* Change the htim state */

htim->State = HAL_TIM_STATE_READY;



__HAL_UNLOCK(htim);



return HAL_OK;

}".

 

What could be possible reason?

1 ACCEPTED SOLUTION

Accepted Solutions
Abid
Associate II

@TDK wrote:

Yep, this is exactly it. TIM12 was not a master timer on very old HAL versions. It is fixed in the latest version.

https://github.com/STMicroelectronics/STM32CubeF4/blob/55c4943bb82fce7bd64577949eebcabd20e9cf1b/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f407xx.h#L15280

 


I am not using the old version. 

And I think, I found the problem. Problem was in following statement. 

 

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @PAram  file: pointer to the source file name
  * @PAram  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

 

 In eclipse IDE it is defined in the STM32_assert.h file. I move it in main.c file and the problem is gone. 

View solution in original post

3 REPLIES 3
TDK
Guru

Probably the parameter on line 1636 is invalid. You can check the IS_TIM_* macros to be sure.

Seems like your HAL library version is quite a bit out of date as the current library has that function starting on line 1964. It could be due to a bug that has been fixed.

https://github.com/STMicroelectronics/STM32CubeF4/blob/master/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c#L1964

 

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

Yep, this is exactly it. TIM12 was not a master timer on very old HAL versions. It is fixed in the latest version.

https://github.com/STMicroelectronics/STM32CubeF4/blob/55c4943bb82fce7bd64577949eebcabd20e9cf1b/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f407xx.h#L15280

 

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

@TDK wrote:

Yep, this is exactly it. TIM12 was not a master timer on very old HAL versions. It is fixed in the latest version.

https://github.com/STMicroelectronics/STM32CubeF4/blob/55c4943bb82fce7bd64577949eebcabd20e9cf1b/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f407xx.h#L15280

 


I am not using the old version. 

And I think, I found the problem. Problem was in following statement. 

 

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @PAram  file: pointer to the source file name
  * @PAram  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

 

 In eclipse IDE it is defined in the STM32_assert.h file. I move it in main.c file and the problem is gone.