Skip to main content
Visitor II
March 23, 2021
Question

Having difficulty porting code from HAL project to LL project, specifically with Timer4

  • March 23, 2021
  • 5 replies
  • 1250 views

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

    This topic has been closed for replies.

    5 replies

    Super User
    March 23, 2021

    > It returns without error but no registers are changed in Timer4.

    Is TIM4 clock enabled in RCC?

    JW

    BTrem.1Author
    Visitor II
    March 23, 2021

    Argh! I thought I was through HAL_MspInit() but in CubeIDE even though STM32g4xx_hal_msp.c was in the project folder it was not IN the project so I was using a _weak function that doesn't do anything. I did the file "import" in CubeIDE but the filename is greyed out and any intentional errors in the file don't create a build error. Any secrets to doing the file import to make it part of the project?

    Super User
    March 24, 2021

    I don't know, I don't Cube nor Eclipse.

    Is there any manual?

    JW

    BTrem.1Author
    Visitor II
    March 24, 2021

    Added info, here is the view of my project files in STM32CubeIDE showing stm32g4xx_hal_msp.c greyed out.

    0693W000008xjhjQAA.jpg

    Super User
    March 24, 2021

    Try perhaps starting a new CubeIDE-specific thread here https://community.st.com/s/topic/0TO0X000000y2j7WAA/stm32cubeide .

    JW

    BTrem.1Author
    Visitor II
    March 24, 2021