Having difficulty porting code from HAL project to LL project, specifically with Timer4
I have a STM32G431 project that was originally created with STM32CubeMX using HAL drivers. I need to port some of this code to another project that was originally built by CubeMX using LL Drivers by another engineer.
The specific problem I have is my initialization of Timer4 is not working in the new project. What I mean is I can step through MX_TIM4_Init() in the new project using the HAL drivers and everything goes okay but when I execute
if (HAL_TIM_Base_Init(&htim4) != HAL_OK)
{
Error_Handler();
}
It returns without error but no registers are changed in Timer4. If I step through the same code in my first project the registers are updated when I execute the above command.
Here is the init function:
static void MX_TIM4_Init(void)
{
/* USER CODE BEGIN TIM4_Init 0 */
/* USER CODE END TIM4_Init 0 */
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
/* USER CODE BEGIN TIM4_Init 1 */
/* USER CODE END TIM4_Init 1 */
htim4.Instance = TIM4;
htim4.Init.Prescaler = 65535;
htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
htim4.Init.Period = 2594;
htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim4) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim4, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM4_Init 2 */
/* USER CODE END TIM4_Init 2 */
}I have verified the structure contents of TIM_HandleTypeDef htim4 are the same in both programs.
I have checked the file stm32g4xx_hal_conf to ensure the same HAL modules are enabled in the new project as in the old project.
Is there anything else to watch out for when mixing HAL and LL drivers in the same project?
Thanks,
Brian
