1
\$\begingroup\$

I'm starting on learning the Cortex M, and coming from an 8 bit background.

I've got my demo board, blinking an LED and getting a working project out of STM32Cube.

I'm working my way through the system registers, but I'm a bit stymied on what to think about clock speeds for peripherals? This isn't really a consideration for any 8 bit firmware I've written.

For the ARM Cortex M0 architecture, what are the major considerations when you set clock speeds for APB1 peripherals?

Say I slow down my peripheral clock too much, what happens?

How could I go about calculating what speed I want for the peripherals?

Do the peripheral clock speeds account for much of the overall power consumption of the system?

\$\endgroup\$
5
  • \$\begingroup\$ This is a pretty broad question. But I'd say start at what you want to do with your peripheral, what clock speed you want. Then just set the divider accordingly. \$\endgroup\$
    – lakeweb
    Jan 19, 2018 at 21:34
  • \$\begingroup\$ Okay, what determines what clock speed I want for a peripheral? How do you start with that calculation? \$\endgroup\$
    – Leroy105
    Jan 19, 2018 at 21:35
  • 2
    \$\begingroup\$ Which peripheral? If it is something like UART you will select the best clock to get your desired baud rate. If it is some ADC you will select the one that will give you the desired sampling rate. If it is a timer...well, I guess you got the idea. \$\endgroup\$
    – Eugene Sh.
    Jan 19, 2018 at 21:39
  • \$\begingroup\$ @Eugene -- okay, I get that loosely. But say my SysClK is 8MHz, and my APBI Periph Clock is 0.25MHz. What is my UART baud rate now? I know nothing about bus architecture. I just make the magic bits go 0/1 in software... \$\endgroup\$
    – Leroy105
    Jan 19, 2018 at 21:41
  • \$\begingroup\$ I can't tell, but there should be a formula in the datasheet of your specific MCU in the UART section that is taking this 0.25MHz and bunch of other parameters and giving you the baud rate. \$\endgroup\$
    – Eugene Sh.
    Jan 19, 2018 at 21:43

1 Answer 1

2
\$\begingroup\$

Say I slow down my peripheral clock too much, what happens?

There will be delay accessing registers of those peripherals since you have to wait for the bus (AHB).

How could I go about calculating what speed I want for the peripherals?

Most of the time they just run full speed. Unless the energy budget requires otherwise.

Do the peripheral clock speeds account for much of the overall power consumption of the system?

That depends on the peripherals you have enabled. Some peripherals are hungry, some are not. This depends on their complexity.
The datasheet will have a table with the peripherals uA/MHz rating.
For example in the STM32F072: stm32f072 peripheral current consumption table

Looking at these number might have you decide that, when you're only using a timer to output 100 Hz PWM to put that bus at 1 MHz instead of 48 MHz going to the core itself. And maybe not use TIM1 or TIM2.

However, this affects all peripherals on that bus. Including CAN or UART, and depending on the chip complexity the memories.

There isn't much to calculate. You will have sysclk from the PLL, and from then on there are only dividers. Find the clock tree in the reference manual, and play around with the clocks page in STMCubeMX.

\$\endgroup\$
7
  • \$\begingroup\$ Appreciate that! I'll take a look at that. I know the vendor periphs are very much the vendor's "responsibility" in ARM world. I know this is like very down in the metal, but I'm trying to learn how to be efficient before I try to port my 8051 system over. I have a super energy-optimized 8051 piece of software, I want to profile against a pretty optimized CM0 piece of code and see. \$\endgroup\$
    – Leroy105
    Jan 19, 2018 at 21:44
  • \$\begingroup\$ if there is a delay accessing the peripheral register, I get that. Will you get "stale" data? Or will the MCU freeze and wait for the value on the peripheral register? \$\endgroup\$
    – Leroy105
    Jan 19, 2018 at 21:47
  • 1
    \$\begingroup\$ @Leroy105 The second one. The peripheral bus is running at a lower speed, so it takes more time for an access to complete. \$\endgroup\$
    – user39382
    Jan 19, 2018 at 22:05
  • \$\begingroup\$ @duskwuff I would imagine that the register access would depend on the bus speed, not the actual peripheral clock. I don't think the register file is clocked with that clock. But that's just my guess. I mean, it looks like you guys are talking about different clocks. You are talking about the bus clock, but the OP is talking about the peripheral clock. \$\endgroup\$
    – Eugene Sh.
    Jan 19, 2018 at 22:07
  • \$\begingroup\$ @EugeneSh. The "register file" is part of the peripheral, not a separate component -- consider registers like GPIO->IDR, for instance, which aren't explicitly stored anywhere. The full clock tree is complicated, but most peripherals share a clock with their peripheral bus. \$\endgroup\$
    – user39382
    Jan 19, 2018 at 22:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.