2023-10-23 07:58 PM
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?
Solved! Go to Solution.
2023-10-23 10:15 PM - edited 2023-10-23 10:15 PM
@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.
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.
2023-10-23 08:42 PM
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.
2023-10-23 08:48 PM
Yep, this is exactly it. TIM12 was not a master timer on very old HAL versions. It is fixed in the latest version.
2023-10-23 10:15 PM - edited 2023-10-23 10:15 PM
@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.
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.