cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H743 HRTIM Clock Configuration Bug from Stm32 CubeMx

JDoug
Associate

MCU Reference STM32H743XIHx

Firmware Package Name and version: STM32CUME FW_H7 V1.7.0

CubeMx Version 5.6.1

Bug exists in stm32H743xx.h and/or stm32h7xx_hal_rcc_ex.c

Clock selection always compiles as Tim2_Ck even when Cpu_Ck is selected on the clock configuration page.

This is due to stm32h7xx_hal_rcc_ex.c looking for a definition of HRTIM (see line 1580). stm32H743xx.h has a defition of HRTIM1 (line 2393).

I worked around for now with a #define HRTIM HRTIM1

Cheers

James

2 REPLIES 2

Hello @JDoug​ 

Could you please explain more the scenario to check the issue.

Best regards,

Nesrine

JDoug
Associate

Hi Nesrine,

When trying to configure the HRTIM from CubeMx, the clock source cannot be set to 'Cpu_Ck' from the Clock Configuration Page. via the HRTIM Clock Mux. The clock always defaults back to Tim2_Ck when generating code.

This seems to be because The HRTIM1 Clock Configuration section of the stm32H7xx_hal_rcc_ex.c is checking if HRTIM is defined (see snippet below).

//stm32H7xx_hal_rxx_ex.c Line 1474
#if defined(HRTIM)  
  /*------------------------------ HRTIM1 clock Configuration ----------------*/
  if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_HRTIM1) == RCC_PERIPHCLK_HRTIM1)
  {
    /* Check the parameters */
    assert_param(IS_RCC_HRTIM1CLKSOURCE(PeriphClkInit->Hrtim1ClockSelection));
 
    /* Configure the HRTIM1 clock source */
    __HAL_RCC_HRTIM1_CONFIG(PeriphClkInit->Hrtim1ClockSelection);
  }
#endif  /*HRTIM*/

This HRTIM definition is also tested later on:

//stm32H7xx_hal_rcc_ex.c line 1581
  #if defined(HRTIM)
  PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_HRTIM1;
#endif /* HRTIM */

The HRTIM definition doesn't exist so this code doesn't get called correctly.

HRTIM1 however is defined in the device header files, e.g. stm32h750xx.h or stm32H743xx.h

//stm32H750xx.h line 2466
#define HRTIM1              ((HRTIM_TypeDef *) HRTIM1_BASE)
#define HRTIM1_TIMA         ((HRTIM_Timerx_TypeDef *) HRTIM1_TIMA_BASE)
#define HRTIM1_TIMB         ((HRTIM_Timerx_TypeDef *) HRTIM1_TIMB_BASE)
#define HRTIM1_TIMC         ((HRTIM_Timerx_TypeDef *) HRTIM1_TIMC_BASE)
#define HRTIM1_TIMD         ((HRTIM_Timerx_TypeDef *) HRTIM1_TIMD_BASE)
#define HRTIM1_TIME         ((HRTIM_Timerx_TypeDef *) HRTIM1_TIME_BASE)
#define HRTIM1_COMMON       ((HRTIM_Common_TypeDef *) HRTIM1_COMMON_BASE)

I edited the device file to add a definition of HRTIM as below:

//stm32H750xx.h line 2466
#define HRTIM1              ((HRTIM_TypeDef *) HRTIM1_BASE)
#define HRTIM 				HRTIM1		//Hack to define HRTIM
#define HRTIM1_TIMA         ((HRTIM_Timerx_TypeDef *) HRTIM1_TIMA_BASE)
#define HRTIM1_TIMB         ((HRTIM_Timerx_TypeDef *) HRTIM1_TIMB_BASE)
#define HRTIM1_TIMC         ((HRTIM_Timerx_TypeDef *) HRTIM1_TIMC_BASE)
#define HRTIM1_TIMD         ((HRTIM_Timerx_TypeDef *) HRTIM1_TIMD_BASE)
#define HRTIM1_TIME         ((HRTIM_Timerx_TypeDef *) HRTIM1_TIME_BASE)
#define HRTIM1_COMMON       ((HRTIM_Common_TypeDef *) HRTIM1_COMMON_BASE)

So I think the bug is in the stm32h7xx_hal_rcc_ex.c testing if HRTIM is defined in two locations, rather than testing if HRTIM1 is defined.

Unless I've done something silly? :D

Cheers,

James