cancel
Showing results for 
Search instead for 
Did you mean: 

Why can't a blank CubeMX project not enter while(1) loop.

sdavi.9
Associate II

Hi

I used a NucleoF072RB and Cube MX. I use Atollic TrueStudio.

I wanted to know how to setup and AND before integrating it in another project. So I created a new blank project.

I set tup the porject as per the picture ADC_setup. No pin were activated on the MCU (except the default settings).

I generate my code. It compiles.

I test one line of code:

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

  /* USER CODE END WHILE */

 temp3++;

  /* USER CODE BEGIN 3 */

I previously wrote this right afterMX_ADC_Init():

 /* Initialize all configured peripherals */

 MX_ADC_Init();

 /* USER CODE BEGIN 2 */

 /*Calibrating the ADC*/

 ADC1->CR &= !ADC_CR_ADEN;

 ADC1->CR |= ADC_CR_ADCAL;

 while ((ADC1->CR & ADC_CR_ADCAL) != 0){

 temp++;

 }

 /* Enable ADC*/

 ADC1->CR |=ADC_CR_ADEN;

 while((ADC1->ISR & ADC_ISR_ADRDY) == 0){

 temp2++;

 }

 /* USER CODE END 2 */

temp4++;

When I pause the debugger,

temp =16

temp2 = 3

temp3 =0

temp4=1

I commented out all of my code now the debugger alway pauses at the last line on  MX_ADC_Init();

What's wrong with the my CubeMX config ?

Does MX_ADC_Init(); performs the initial calibration ?

Do I need to connect AGND and AVDD to external power sources ? (I left them floting :grinning_face_with_sweat: )

Thank you for you help

1 ACCEPTED SOLUTION

Accepted Solutions
T J
Lead

yes, AVDD and AGnd must be connected.

no, MX_ADC_Init does not run the calibration.

Calibration depends on the die temperature, you would want to be running for at least a few seconds before you calibrate.

In some projects, I re-calibrate every minute.

Try to get a serial terminal running, much easier to debug then.

also, if you enable CanBus you have to pullup the Rx pin, or main will hang before while(1);

View solution in original post

4 REPLIES 4
T J
Lead

yes, AVDD and AGnd must be connected.

no, MX_ADC_Init does not run the calibration.

Calibration depends on the die temperature, you would want to be running for at least a few seconds before you calibrate.

In some projects, I re-calibrate every minute.

Try to get a serial terminal running, much easier to debug then.

also, if you enable CanBus you have to pullup the Rx pin, or main will hang before while(1);

Thank you for your clear answers.

I connected AGND and AVDD, to an external power source and directly to the Nucleo's power. (It has to be 3.3 V and not 5V or else the ST-link connection doesn't work. )

I doubled checked, CanBus is NOT enabled. (I don't need it)

The program still hangs before the while(0);

Do you have any other ideas?

Thank you.

I found the answer!

The *@#$*@ compiler thought temp3++; was a useless command. and optimized it out.

if temp3 is declared as a volatile int. then it works!!!!!!

While debugging, optimization typically should be disabled - set it to -O0. Whereas in a final code there should not be such temporary counters.