cancel
Showing results for 
Search instead for 
Did you mean: 

Why does the STM32 not start as stand alone, but it starts connected with STM32CubeIDE?

Me-Controller
Associate

Hi,

we work with Nucleo STM32G031K8 board and STM32CubeIDE. The example program Blinky (its full name is GPIO_InfiniteLedToggling_Init) is working as expected. The LED is toggling also with extern power supply instaed of USB power.

Now we have programmed our own blinky, as following (main.c)

#include "stm32g0xx.h"

int main(void){

//Timer 2 config

   RCC->APBENR1 |= RCC_APBENR1_TIM2EN; //clock for timer 2

   TIM2->PSC = 15999; //Prescaler t 15999+1, clock periode 1 msek

   TIM2->ARR = 0xFFFF; 

   TIM2->CR1 = TIM_CR1_CEN; //Timer enable

//GPIO PC6 set to output

   RCC->IOPENR |= RCC_IOPENR_GPIOCEN; //Clock enable Port A

   GPIOC->MODER &= ~(0b11 << (2*6));

   GPIOC->MODER |= 0b01 << (2*6); //ModeRegister: PC6 '01' (=output)

   

TIM2->CNT = 0;  //Tim2 reset

  while(1){   //infinite loop

       if(TIM2->CNT>500){

          GPIOC->ODR ^= (1 << 6); //toggling the port

          TIM2->CNT = 0;

       }

   }

}

This is the whole code at main.c and it works very good (the green LED is toggling every half second).

But, and here comes the problem:

After disconnecting USB and connecting again with USB the LED isn't toggling. The LED is slow lighting because of digital AC signal of about 10kHz frequency at the assigned GPIO port.

If we add to the main.c the following line after line 7 (Timer enable):

for (volatile unsigned int i = 10000; i > 0; i--);

the nucleo board works fine, also after disconnecting from USB and with external power.

The involved code makes nothing than waiting for several milliseconds. With reducing the end value to 5000 the error is back again.

A similar problem is also observable with the example-blinky (GPIO_InfiniteLedToggling_Init): if we decraese the delay time of the function LL_mDelay(4) below 4 ms, the same error will occur.

We have tryed to solve this problem since days, with different timers, with different Nucleo-Boards and with different PCs, and now we haven't any more idea.

What do we wrong?

0 REPLIES 0