How to change the clock speed of STM32L476RG nucleo board?

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?

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
Sat Nov 25, 2017 7:16 pm
Thanks the HSI (16MHz), it could operate up to 80MHz.

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
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.
extern "C" void SystemClock_Config(void) {...}


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:

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);

}


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.

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);

}


stevestrong
Sun Nov 26, 2017 12:14 pm
[SHARANYA – 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
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?

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);

}


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”.
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);
....}

SHARANYA
Sun Nov 26, 2017 2:20 pm
I suspected that.Thanks a lot for the reply.Now I scoped and got a speed of 40MHz for each segment of the code!But one thing I would like to ask.
Why the signals are Sinusoidal type in nature?I scoped a signal coming out of a AVR at 2MHz that was perfectly square.Is this happening due to the scope’s bandwidth?My scope is Rigol DS1102E which has a 100MHz bandwidth!

Pito
Sun Nov 26, 2017 2:36 pm
Do switch your probe to 1:10.

SHARANYA
Sun Nov 26, 2017 3:20 pm
I am already measuring in 1:10 mode.I also tried with 1:1 mode but everything remains the same!

The max frequency you may see on your oscope is F_CPU/6 (you need 6clocks to toggle once)

But how the speed is 48Mhz here?


Pito
Sun Nov 26, 2017 3:43 pm
I edited my post on FCPU/6..
With a 100MHz BW you cannot expect to see a 48MHz digital signal with great edges.. You would need >300MHz BW to be happy..

SHARANYA
Sun Nov 26, 2017 5:18 pm
I edited my post on FCPU/6..

Pito
Sun Nov 26, 2017 6:09 pm
I didn’t understand!

STM32F103 chips (Cortex M3, 72MHz one) like BluePill have got 2 wait states while reading from flash memory. It means they do not usually perform 1 instruction per clock.

STM32F4xx chips (Cortex M4) like L476 have got “ART accelerator” – a special 256bit flash cache – which allows to provide “1 instruction per clock” most times.

Adaptive real-time accelerator (ART Accelerator™) allowing 0-wait-state execution from Flash memory

Thus the counting of cycles in F103 and F4xx may differ. That was my point I added to my previous post you have not read.


fpiSTM
Mon Nov 27, 2017 5:55 am
[SHARANYA – Sun Nov 26, 2017 5:18 pm] –
One more problem i am facing in the arduino IDE.Each time I close arduino IDE and reopen it,the settings regarding nucleo board/processor etc are getting vanished.The default board is getting selected as Arduino yun.Also i am unable to find the nucleo64 boards in the list.Then i have to reopen the boards manager and after the boards manager is getting refreshed,the nucleo boards are reappearing in the main boards list!Why is this happening.Pardon me for my silly questions as i am not familiar with Arduino IDE.
All my setting/downloaded files for the stm32 core is saved in the C:\Users\SHARANYA\AppData\Local\Arduino15\packages\STM32 folder by default.

Seems strange. Have you tried to clear the local json file? (C:\Users\SHARANYA\AppData\Local\Arduino15\package_stm_index.json*)
Which Arduino IDE version you used and on which OS?


Leave a Reply

Your email address will not be published. Required fields are marked *