How to change the clock speed of STM32L476RG nucleo board?

STM32F103 Nucleo boards e.g. STM Nucleo F103RB
SHARANYA
Posts: 13
Joined: Fri Aug 18, 2017 8:24 pm

How to change the clock speed of STM32L476RG nucleo board?

Post by SHARANYA » Sat Nov 25, 2017 6:46 pm

Hi experts
I was just wondering about the speed of the stm32l476rg nucleo board!
For say,the arduino uno operates on 16Mhz.What is the clock speed of the stm32l476 in the Arduino environment?
Last edited by SHARANYA on Sat Nov 25, 2017 10:25 pm, edited 1 time in total.

zmemw16
Posts: 1684
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: What is the speed of STM32L476RG nucleo board?

Post by zmemw16 » Sat Nov 25, 2017 7:14 pm

http://www.st.com/en/evaluation-tools/n ... 476rg.html
user manual is UM1724. Crystal i noticed is 8MHz if it's fitted :!: brief glance suggested not as there's a detailed paragraph about it's required characteristics.

obtain CubeMX, also the F7 libraries(there's an update menu for doing this in CubeMX), probably need to acquire ARM tools compiler gcc 6.x.x
have a play in the configuration window, change the hse clock value and see what happens.
you will need to register in order to download the CubeMX package and click to accept license.

scanning the datasheet suggests 80MHz, highest frency in the current consumption table, i think lowest was 100KHz, maybe even 32kHz
stephen

fpiSTM
Posts: 316
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: What is the speed of STM32L476RG nucleo board?

Post by fpiSTM » Sat Nov 25, 2017 7:16 pm

Thanks the HSI (16MHz), it could operate up to 80MHz.

SHARANYA
Posts: 13
Joined: Fri Aug 18, 2017 8:24 pm

Re: What is the speed of STM32L476RG nucleo board?

Post by SHARANYA » Sat Nov 25, 2017 7:47 pm

I used to program the stm32l476 using hal and cube mx before so I have an idea.But how to define the clock speed in the arduino environment?
Also is there a way to know what the current speed the cpu is operating on?

fpiSTM
Posts: 316
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: What is the speed of STM32L476RG nucleo board?

Post by fpiSTM » Sat Nov 25, 2017 8:07 pm

Which Arduino core you used?

If it is this one: https://github.com/stm32duino/Arduino_Core_STM32

You could redefine the void SystemClock_Config(void) in the sketch.

Code: Select all

extern "C" void SystemClock_Config(void) {...}

To know the cpu speed, you could use this global variable:

Code: Select all

SystemCoreClock

SHARANYA
Posts: 13
Joined: Fri Aug 18, 2017 8:24 pm

Re: What is the speed of STM32L476RG nucleo board?

Post by SHARANYA » Sat Nov 25, 2017 10:07 pm

Can you please give an code example.I am not very fluent in the arduino thing!
I tried like this below in the arduino:

Code: Select all

void setup() {
  // put your setup code here, to run once:
  #define F_CPU 80000000
  SystemCoreClockUpdate();
  pinMode(13,OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:

  digitalWrite(13,HIGH);
  digitalWrite(13,LOW);

}
But it is not changing anything in the scope!!
Last edited by SHARANYA on Sun Nov 26, 2017 10:54 am, edited 1 time in total.

SHARANYA
Posts: 13
Joined: Fri Aug 18, 2017 8:24 pm

Re: How to change the clock speed of STM32L476RG nucleo board?

Post by SHARANYA » Sun Nov 26, 2017 10:52 am

Ok.....now i am able to get the current CPU core clock speed by writting this small piece of code.

Code: Select all

void setup() {
  // put your setup code here, to run once:
extern uint32_t SystemCoreClock;
Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:

Serial.println(SystemCoreClock);
delay(1000);

}
Also i was toggling pin-D13 by writting digitalWrite high/low and hooked up a scope to that pin.But I could only get a frequency of about 400khz(Instead the cpu is running at 80MHz).Why it is so slow?Is there a way to make it fast by directly accessing the GPIO registers?

stevestrong
Posts: 2067
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: How to change the clock speed of STM32L476RG nucleo board?

Post by stevestrong » Sun Nov 26, 2017 12:14 pm

SHARANYA wrote:
Sun Nov 26, 2017 10:52 am
Also i was toggling pin-D13 by writting digitalWrite high/low and hooked up a scope to that pin.But I could only get a frequency of about 400khz(Instead the cpu is running at 80MHz).Why it is so slow?Is there a way to make it fast by directly accessing the GPIO registers?
Search the forum for fast GPIO access.
For example: viewtopic.php?f=18&t=2888

SHARANYA
Posts: 13
Joined: Fri Aug 18, 2017 8:24 pm

Re: How to change the clock speed of STM32L476RG nucleo board?

Post by SHARANYA » Sun Nov 26, 2017 1:22 pm

I tried this code below.But i'm getting the speed of 2.72MHz max.The off time is much more longer than on time.Why is this happening?

Code: Select all

void setup() {
  // put your setup code here, to run once:

  pinMode(13,OUTPUT);
  Serial.begin(9600);
  

}

void loop() {
  // put your main code here, to run repeatedly:
GPIOA->BSRR = (1<<5);
GPIOA->BRR = (1<<5);

}
Attachments
Waveform.jpg
Waveform.jpg (71.1 KiB) Viewed 211 times

User avatar
Pito
Posts: 1739
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: How to change the clock speed of STM32L476RG nucleo board?

Post by Pito » Sun Nov 26, 2017 1:44 pm

Here
viewtopic.php?f=18&t=2888&p=37578#p37593
you may see a for-loop takes 417ns with toggling 1/0 (BRR/BSRR registers) at 72MHz, that is 2.39MHz toggling freq..
In order to maximize your io pin frequency you must "unroll the loop".

Code: Select all

void loop() {
  // put your main code here, to run repeatedly:
GPIOA->BSRR = (1<<5);
GPIOA->BRR = (1<<5);
GPIOA->BSRR = (1<<5);
GPIOA->BRR = (1<<5);
GPIOA->BSRR = (1<<5);
GPIOA->BRR = (1<<5);
GPIOA->BSRR = (1<<5);
GPIOA->BRR = (1<<5);
....}
The max frequency you may see on your oscope is F_CPU/6 (you need 6clocks to toggle once), provided your unrolled loop is large enough.. :)
EDIT: F_CPU/6 with F103, with F476 it may differ (art accelerator).
Last edited by Pito on Sun Nov 26, 2017 2:33 pm, edited 1 time in total.
Pukao Hats Cleaning Services Ltd.

Post Reply