Search code examples
cembeddedstm32gpiomicroprocessors

What is a good strategy for understanding an embedded processor? How to use its GPIOs for example


I have an STM32F407G discovery board and I am trying to turn on an LED without using any example code.

I happen to know that the GPIOs require the RCC AHB1 clock to be enabled because I read about it online a long time ago.

But this information is not very obvious from the reference manual (at least not to me, any tips appreciated). The GPIO and RCC sections are miles apart. What is the procedure for learning a processor like this one other than "hope it has a large community and search online forums when stuck"!.

Here is a link to the reference manual.

Edit:

Typical that after asking this question I stumbled on a part of the manual that says (section 2.1.11):

After each device reset, all peripheral clocks are disabled (except for the SRAM and Flash memory interface). Before using a peripheral you have to enable its clock in the RCC_AHBxENR or RCC_APBxENR register

I think my question still stands however- the manual is over 1500 pages, is there a good strategy for relatively quickly conquering a processor through its reference manual?


Solution

    • First of all, check the MCU web site for application notes, errata and code samples. It's a very sound habit to always check the silicon errata before using a new hardware peripheral, particularly when you are dealing with a recently released MCU.
    • If you are lucky there is sample code provided by the silicon vendor through application notes or libraries etc. Then you can look at that code while writing your own. It wasn't that long ago when we pretty much never got any such code to look at though, every single user of a MCU re-inventing the wheel locally, by reading the manual.
    • In the manual, check the peripheral overview of the MCU and what options it got for pin routing/muxing. This is typically mentioned early on. Very likely the GPIO is sharing pins with other hardware, so this is pretty much always something you need to investigate.
    • Similarly, modern MCUs often have options for clock routing to peripherals. So you will have to check the clock/PLL sections too, which you'll have to read anyway for understanding how to setup the system clock and oscillator options.
    • And then finally, read the GPIO chapter.

    A general hint when reading those 1500+ pages thick tomes is to focus on the register descriptions. That gives a good place to start, and when you don't understand what certain bits in the register is for, you can read about those more in-depth at the point where you need to know about them. This way you can filter out various special features of a hardware peripheral that are of no interest for your specific project.