cancel
Showing results for 
Search instead for 
Did you mean: 

Cube MX Timer init Error on STM32F050R8

Leonardo Volponi
Associate II
Posted on April 04, 2017 at 16:29

Using the attached cube project TestSTM32F051R8_TimError.ioc

When I generate the source codes the CubeMx version  4.20.0 produces the following initialization code for the timers (I used only TIM1 and TIM3) but the error is exactly the same for both of them.

..............

void MX_TIM1_Init(void)

{

TIM_ClockConfigTypeDef sClockSourceConfig;

TIM_MasterConfigTypeDef sMasterConfig;

htim1.Instance = TIM1;

htim1.Init.Prescaler = 4800;

htim1.Init.CounterMode = TIM_COUNTERMODE_UP;

htim1.Init.Period = 65535;

htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

htim1.Init.RepetitionCounter = 0;

htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;  <--- Error this field is not defined in the structure and also the TIM_AUTORELOAD_PRELOAD_ENABLE is not defined anywhere in the HAL libraries.

if (HAL_TIM_Base_Init(&htim1) != HAL_OK)

{

Error_Handler();

}

sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;

if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)

{

Error_Handler();

}

.....................

Just a suggestion for the CubeMX development team:

It sould be a good idea to accept user's code just before calling the HAL_ functions, I mean something like this:

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;

RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12;

RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;

/* USER CODE BEGIN HAL_RCC_OscConfig */     <-- Begin of the added User code section

   The user can write its own code here and can be saved between code regenerations....     

   This way can be avoided the problem to adjust everytime the generated code in the actual version of the CubeMx that 

   sometimes (in my case always) fail to create initialization code for the clock system for the STM32F407 with external  crystal oscillator.

/* USER CODE END HAL_RCC_OscConfig */         <-- End of the added User code section

if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

{

Error_Handler();

}

other example  should be:

htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

htim1.Init.RepetitionCounter = 0;

/* USER CODE BEGIN HAL_TIM_Base_Init( &htim1) */   <-- Begin of the added User code section

    User code can be written here..... and the CubeMX will keep it between code regeneration

    and this will permit to create particular initialization code not directly available from the various CubeMx options.

    just for example I can add a statement like this: 

htim1.Init.ClockDivision = VariableClockDivisionValue;

       

/* USER CODE END HAL_TIM_Base_Init( &htim1) */       <-- End of the added User code section

if (HAL_TIM_Base_Init(&htim1) != HAL_OK)

{

Error_Handler();

}

Thank you very much for this forum !

Best regards to all !

Leonardo.

#cubemx #stm32f050x
4 REPLIES 4
Khouloud GARSI
Lead II
Posted on April 04, 2017 at 16:57

Hi

Volponi.Leonardo

‌,

Your feedback is reported internally for review. I will keep you posted about the updates.

Thanks a lot for your suggestion. They will be forwarded to our teams.

Khouloud.

Khouloud GARSI
Lead II
Posted on April 04, 2017 at 18:05

Dear Leonardo,

You are using an old version of firmware.

0690X00000606dAQAQ.png

Please use the firmware package ''stm32cube_fw_f0_v1.7.0'' which is compatible with the CubeMX version 4.20.0.

You may refer to

http://www.st.com/content/ccc/resource/technical/document/release_note/b2/02/4b/e3/81/32/49/c4/DM00107607.pdf/files/DM00107607.pdf/jcr:content/translations/en.DM00107607.pdf

table5 for further details about the supported firmware package versions.

In the updated firmware, the ''TIM_AUTORELOAD_PRELOAD_ENABLE'' is defined in ''stm32f0xx_hal_tim.h''

Khouloud.

Khouloud GARSI
Lead II
Posted on April 04, 2017 at 19:34

Hi Leonardo,

I supposed that the migration process should change 'automatically' the reference to the correct HAL Libraries

-> Correct. This is already implemented in the CubeMX tool.

Khouloud.

Posted on April 04, 2017 at 19:08

Thank you very much for your suggestion

Khouloud

, unfortunately, I had the F0_V1.5.0 installed in my PC and because of this I didn't get any error message.

Originally the project was made with an old version of the CubeMx and HAL Libraries.

Probably there was a problem, -without any message-, during the migration process.

I supposed that the migration process should change 'automatically' the reference to the correct HAL Libraries.

Now I disinstalled all the old versions of the HAL Libraries, and I will keep only the last one available, at least in this way for the future releases I should get the message you show to warn me about wrong version of the library.

I changed the reference to the correct library version in the project.

With this modification, I solved the problem and there are no more errors in the generated code.

It should be nice to have an error or at least a warning message from the CubeMx also if the old library referenced from the project is already installed in the PC.

I never get any message about old version of the referenced library by the project.

Thank you very much for your very quick reply !