How to a make a proper delay inside a microcontroller?
I see a lot of people using a basic for-loop
for(int i = 0; i < 100000; i++){}
As a delay, but how can I create a proper delay inside of a microcontroller?
If I can take an example. Let's assume that I'm going to use SysTick in STM32 and I want to activate the SysTick register. Which register should I use then?
I have the STM32F401RE processor and here is the clock tree.
https://www.st.com/resource/en/reference_manual/rm0368-stm32f401xbc-and-stm32f401xde-advanced-armbased-32bit-mcus-stmicroelectronics.pdf
According to page 95
The RCC feeds the external clock of the Cortex System Timer (SysTick) with the AHB clock
(HCLK) divided by 8. The SysTick can work either with this clock or with the Cortex clock
(HCLK), configurable in the SysTick control and status register
So that means? How can I activate SysTick?
STM32 is not a microcontroller but a SoC, stitched together from various components, one of which is the processor (in your case Cortex-M4). That is not provided by ST, but ARM, and it has a separate sets of documents. SysTick is part of the processor, so its description is not in the STM32F4xx Reference Manual to which you've linked, but in so called STM32 Cortex-M4 Programming Manual (see chapter 4.5 SysTick timer (STK) therein); and, ultimately, in ARM's Technical Reference Manual to the Cortex-M4 processor.