cancel
Showing results for 
Search instead for 
Did you mean: 

how to setup clock when STM32CubeIDE empty project is used?

ERABALF
Associate III

hi All.

My name is Alfredo, I just have got a Blue_Pill_STM32F103C8 board.

I just installed STM32CubeIDE (Version: 1.3.0), i wrote a small project as toggle led using the CubeIDE configuration and everything is fine. but now i am trying to do the same thing using an empty project (it means, not using Cube configuration), after some hours, the project is compiled, and it is working if I debugged it using my ST-Link, so I can see the led on-off,running the program step by step (loading a var manually with a value to move the program forward), but when the debugger is disconnected, Led is not blinking anymore. I tested the program just setting the port and the led is ON, later i changed the program and I reset the port and the led is OFF.

I have never set the clock in my project, I do not how to do it (i was looking for this setting) but i could find it.

can you help please.

As i am using a for in order to spend time, I tested A<=5000000, A<=50000,A<=500,A<=5 and always the Led si ON or off

if the first line into main is GPIOC->BSRR = (1<<13); led is ON ( no toggle) and if it is GPIOC->BSRR = (1<<29); led is always OFF, it is like the program is not running after that....

here is the code used....(as i told you this is my firsts little program)

#include "stm32f10x_conf.h"

int main(void)

{

RCC->APB2ENR |= (1<<4);      //1° Activamos el clock al Advanced Peripheral Bus, 2 porque ahi esta el GPIOC

GPIOC ->CRH |= ((1<<21)|(1<<20)); //2° definimos el MODE 11: Output mode, max speed 50 MHz.

GPIOC ->CRH &=~((1<<23)|(1<<22)); //2° definimos el CNFy 00: General purpose output push-pull

 while (1)

 {

GPIOC->BSRR = (1<<13); //bit 13 GPIOC_13 l3ed  bit 13= SET Port bit set/reset register (GPIOx_BSRR

for (int a=0;a<=5000000;a++)

GPIOC->BSRR = (1<<29); // (13 + 16)bit GPIOC_13 led  bit 29= RESET Port bit set/reset register (GPIOx_BSRR

for (int a=0;a<=5000000;a++)

{}

 }

}

i guess this is the problem (not clock set), any comments it will be helpful.

I am sorry if the question is SO basic, but i am just starting with STM32.

br

Alfredo

1 ACCEPTED SOLUTION

Accepted Solutions
berendi
Principal

CPU and peripheral clocks are configured in runtime, as part of the firmware initialization after reset. There is a default clock active after reset (usually HSI), and there is no way to change this default through some option bits or fuses, only through software.

The procedure for the STM32F1 series is

  • Increase flash wait state, see the Reading the Flash memory section of the reference manual.
  • (optional) if there is an external crystal, activate HSE through RCC_CR_HSEON, and wait for RCC_CR_HSERDY
  • Set PLL parameters in RCC->CFGR
  • Enable PLL through RCC_CR_PLLON and wait for it to become ready by checking RCC_CR_PLLRDY
  • Set system clock source through RCC_CFGR_SW and wait for it to become ready by checking RCC_CFGR_SWS

See the reset and clock control (RCC) chapter in the reference manual for details. If the PLL parameters look confusing, create a scratch project with CubeMX, and use the Clock Configuration tab to see which settings make sense.

View solution in original post

4 REPLIES 4
ERABALF
Associate III

Hi all.

now the led is blinking, i made a mistake, it was missing ";" in for command.

now

#include "stm32f10x_conf.h"

int main(void)

{

RCC->APB2ENR |= (1<<4);      //1° Activamos el clock al Advanced Peripheral Bus, 2 porque ahi esta el GPIOC

GPIOC ->CRH |= ((1<<21)|(1<<20)); //2° definimos el MODE 11: Output mode, max speed 50 MHz.

GPIOC ->CRH &=~((1<<23)|(1<<22)); //3° definimos el CNFy 00: General purpose output push-pull

 while (1)

 {

GPIOC->BSRR = (1<<13); //bit 13 GPIOC_13 l3ed  bit 13= SET Port bit set/reset register (GPIOx_BSRR

for (int a=0;a<=1000000;a++);

GPIOC->BSRR = (1<<29); // (13 + 16)bit GPIOC_13 led  bit 29= RESET Port bit set/reset register (GPIOx_BSRR

for (int a=0;a<=1000000;a++);

 }

}

I defined the GPIO SPeed but not CPU clock, as I said I could not find where define that in STM32CubeIDE....

Any comment is welcome

Br

Alfredo

> I defined the GPIO SPeed but not CPU clock, as I said I could not find where define that in STM32CubeIDE....

Why would you need to define that?

You set up CPU clock in RCC, see RCC chapter in RM.

Some toolchains like to set it up in some automagic way, usually through the startup code; I tend to get rid of that and set it up myself.

JW

berendi
Principal

CPU and peripheral clocks are configured in runtime, as part of the firmware initialization after reset. There is a default clock active after reset (usually HSI), and there is no way to change this default through some option bits or fuses, only through software.

The procedure for the STM32F1 series is

  • Increase flash wait state, see the Reading the Flash memory section of the reference manual.
  • (optional) if there is an external crystal, activate HSE through RCC_CR_HSEON, and wait for RCC_CR_HSERDY
  • Set PLL parameters in RCC->CFGR
  • Enable PLL through RCC_CR_PLLON and wait for it to become ready by checking RCC_CR_PLLRDY
  • Set system clock source through RCC_CFGR_SW and wait for it to become ready by checking RCC_CFGR_SWS

See the reset and clock control (RCC) chapter in the reference manual for details. If the PLL parameters look confusing, create a scratch project with CubeMX, and use the Clock Configuration tab to see which settings make sense.

ERABALF
Associate III

ok I understood it.

so, i will follow your comments in order to have the full control of clock too, as you comment, now the clock used is internal and external crystal is not used, I need to set ip up using RCC (clock control register) .

thanks a lot.

br

Alfredo