December 21, 2023

STM32H747I-DISCO "Discovery kit with STM32H747XI MCU" -- clocks (and mbed)

I wrote my first code for the H747 -- but it doesn't work. It is the usual blink demo, which involves figuring out the GPIO. My guess is that it does not work because I have more work to do with the RCC and getting clocks set up.

Clock sources

The schematic shows two:
32.768 crystal on PC14 and PC15
25 Mhz oscillator on PH0
There is also an independent 25Mhz oscillator for the ST-Link processor as well as a 24 Mhz clock for a USB chip.

As a side note, the user button ("wakeup") is on PC13.

Clocks and Buses

We have:
the AXI bus (64 bit, high performance)
AHB/APB 1,2,3 and 4

AHB = advanced high-speed bus
APB = advanced peripheral bus (lower speed and power)

See the diagram on page 109 for the following

AHB 1 and 2 are in the D2 domain (on a 32 bit AHB matrix)
AHB 3 is in the D1 domain (on a 64 bit AXI bus with flash and axi ram)
AHB 4 is in the D3 domain (looks like a low power mode)
The M7 is in the D1 domain, the M4 is in the D2 domain. Interestingly the D3 domain can function and transfer data autonomously while both CPU cores are shut down.

For clocks we have:

HSE - high speed external (our 25 Mhz oscillator)
LSE - low speed external (our 32.768 Khz crystal)
HSI - high speed internal approx 16 Mhz (could be 8,16,32,64)
LSI - low speed internal approx 32K
CSI - approx 4 Mhz
HSI48 - approx 48 Mhz
A fellow online said:
The clock tree is complex, but it's no more difficult than driving in a city with multiple intersections. You create different clocks then choose which peripheral (or CPU core) uses which clock. There are tables of different "speed limits". Some PLL internal steps have minimums and maximums, and each peripheral has some maximum.
So there are 3 PLL, and you can set them up and use them for different purposes.
Here is a swell slide show on the H7 clocks (and power control):

Mbed

I began doing some poking around to see what code was available that I could learn from. I found "STM32CubeH7" and cloned it. It does not seem to include the basic BSP that would have RCC initialization, but grepping in the files turned up links to:
stm32h7xx_hal_rcc.c
stm32h7xx_hal_rcc_ex.c
(These are in XML files with names like "Project.uvprojx" and show paths like:
../../../../../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc.c
I ran locate on my linux system and these turned up in a clone of "mbed-os" that I did back in November of 2020. They are at:
mbed-os/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/STM32H7xx_HAL_Driver/stm32h7xx_hal_rcc.c
This STM32H7xx_HAL_Driver directory has a vast amount of source code (over 100,000 lines).
A comment at the start of this file outlines what needs to be done after reset:
** Configure the system clock source if desired.
** Configure the system clock frequency and flash settings
** Configure AHB and APB bus prescalers
** Enable the clock for the desired peripheral(s).
Some peripherals are special and have clocks that are not derived from the system clock and need to be set up via clock kernel sources. I don't think the GPIO is among these.

Some more searching leads to:

targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H747xI
targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H747xI/TARGET_DISCO_H747I
targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H747xI/system_clock.c
The file "system_clock.c" is a 209 line C file that makes calls to HAL_RCC routines.
The following is a starting point for all of the STM32 stuff in mbed:
mbed-os/targets/TARGET_STM/README.md

Startup files (assembly code)

I went through some contortions and found these 6 files:
cd /u1/Projects/STM32/Mbed/mbed-os/targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H747xI

TARGET_STM32H747xI_CM4/TOOLCHAIN_ARM/startup_stm32h747xx.S
TARGET_STM32H747xI_CM4/TOOLCHAIN_GCC_ARM/startup_stm32h747xx.S
TARGET_STM32H747xI_CM4/TOOLCHAIN_IAR/startup_stm32h747xx.S

TARGET_STM32H747xI_CM7/TOOLCHAIN_ARM/startup_stm32h747xx.S
TARGET_STM32H747xI_CM7/TOOLCHAIN_GCC_ARM/startup_stm32h747xx.S
TARGET_STM32H747xI_CM7/TOOLCHAIN_IAR/startup_stm32h747xx.S
These are generally interesting and give a full list of interrupt vectors. But to stay on topic, take note of the following two lines:
/* Call the clock system intitialization function.*/
  bl  SystemInit
The game now is to find "SystemInit".
Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org