cancel
Showing results for 
Search instead for 
Did you mean: 

Two bugs in LowLayer code for ADC on STM32Lxxx generated by CubeMX

WilkoL
Senior

The first one is a minor typo I guess. The init code for the ADC has these lines in it:

/* Enable ADC internal voltage regulator */
  LL_ADC_EnableInternalRegulator(ADC);
  /* Delay for ADC internal voltage regulator stabilization. */
  /* Compute number of CPU cycles to wait for, from delay in us. */
  /* Note: Variable divided by 2 to compensate partially */
  /* CPU processing cycles (depends on compilation optimization). */
  /* Note: If system core clock frequency is below 200kHz, wait time */
  /* is only a few CPU processing cycles. */
  uint32_t wait_loop_index;
  wait_loop_index = ((LL_ADC_DELAY_INTERNAL_REGUL_STAB_US * (SystemCoreClock / (100000 * 2))) / 10);
  while(wait_loop_index != 0)
  {
    wait_loop_index--;
  }

The first line should be:

  LL_ADC_EnableInternalRegulator(ADC1);

And the other bug happens when you select both the internal temperature sensor AND the vrefint on the ADC.

This does not work:

LL_ADC_REG_SetSequencerChAdd(ADC1, LL_ADC_CHANNEL_TEMPSENSOR);
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC1), LL_ADC_PATH_INTERNAL_TEMPSENSOR);
 
LL_ADC_REG_SetSequencerChAdd(ADC1, LL_ADC_CHANNEL_VREFINT);
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC1), LL_ADC_PATH_INTERNAL_VREFINT);

but this does:

LL_ADC_REG_SetSequencerChAdd(ADC1, LL_ADC_CHANNEL_TEMPSENSOR);
LL_ADC_REG_SetSequencerChAdd(ADC1, LL_ADC_CHANNEL_VREFINT);
 
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC1), LL_ADC_PATH_INTERNAL_TEMPSENSOR | LL_ADC_PATH_INTERNAL_VREFINT);

This bug was already mentioned two years ago by kurta999 in this question:

https://community.st.com/s/question/0D50X0000AU4CvOSQV/stm32cubemx-lladcsetcommonpathinternalch-generation-bug-only-one-internal-ch-is-enabled

5 REPLIES 5
Imen.D
ST Employee

Hello @Community member​ ,

Thanks for your reported issues.

I added the right topic "STM32CubeMX" in your post to be reviewed by our CubeMX experts @Khouloud OTHMAN​ , @Khouloud ZEMMELI​.

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

Hi @Community member​ ,

Thanks for your feedback.

For the first issue you have reported, I can't reproduce it from my side, LL_ADC_EnableInternalRegulator(ADC1) is correctly generated in CubeMX generated code.

Could you please share your .ioc file to investigate the problem ?

For the second point you have raised:

> And the other bug happens when you select both the internal temperature sensor AND the vrefint on the ADC

The problem is already detected and reported to our development team to be reviewed. I will come back to you as soon as possible with updates.

Thank you for your patience.

Khouloud.

Hello Khouloud,

Thanks for your reply. The problem with the line LL_ADC_EnableInternalRegulator(ADC1) is solved in the latest firmware FW_L0 V1.12.0 .

I noticed that after re-opening the .ioc file STM32CubeMX wanted to upgrade. After letting it do that, it now produces the correct code.

Odd though, is that I do not see that it does upgrade the firmware, see picture.

Wilko0693W000008wcW3QAI.jpg

Hi @Community member​ ,

First let me thank you for the correction of the first problem confirmation 😊

To explain briefly the message behind this warning popup: On project load, STM32CubeMX detects if the project was created with an older version of the tool and if this is the case, it proposes the user to either migrate to use the latest STM32CubeMX database and STM32Cube firmware version, or to continue.

You can select continue to use original firmware used at project creation and in this case it will downloaded into your repository as well as the MCU and IPs database, or you can select migrate, and in this case your project will be modified to fit the current database definition.

>Odd though, is that I do not see that it does upgrade the firmware, see picture.

It is a bit odd that this warning window is displayed while working with latest version of firmware. The expected behavior is as in the picture attached below (two different versions of firmware):

0693W000008wd7TQAQ.png 

Could please describe how did you reproduce to get this pop up? It will be really helpful for us to track the root cause of this misbehavior.

Thanks in advance,

Khouloud.

Hello Khouloud,

To reproduce the pop-up I just have to double-click the .ioc file, after having upgraded STM32CubeMX to the latest firmware.

Maybe a little background on how I use STM32CubeMX and STM32CubeIDE might help...

  • I create a new project with STM32CubeIDE in the usual way.
  • After having created the project and its code I never open the .ioc file in that folder again.
  • This is because I have been bitten a few times by STM32CubeMX and STM32CubeIDE when I did reopen the .ioc file to change someting and it deleted all my edits.
  • Yes, I know how to prevent that, by placing my code in the correct places (between the comment lines) but it STILL deleted my code.
  • So now I have the routine to create the project with STM32CubeIDE and then immediately move the .ioc file to another (sandbox) folder.
  • If I want to make changes to it, I start STM32CubeMX in this sandbox folder, make the changes, and manually copy the code to the actual project. It is a bit more work, but this way I have never lost my code again.

I'll add the not migrated .ioc file to this message, you will no doubt have the FW-L0 V1.12.0 loaded, so just doubleclick the .ioc file and the pop-up (hopefully) will appear.

Thanks for your support,

Wilko