title: U-Boot: ARM: Simple delay function because of an chicken and egg problem
body: <p>I'm running into an chicken and egg problem when modifying
  (fixing) some drivers for STMicroelectronics SoC's</p>
  <p>The problem, I will implement a timeout, when accessing some
  registers. Unfortunately I cannot use the basic <code>mdelay()</code> or
  higher level functions, which use this function, because
  on these SoC's there isn't setup and enabled the timer before.
  Also the <code>ARMv7-M</code> <code>SysTick</code> timer will not be used.</p>
  <p><s>I could write a simple delay loop which counts down at the
  frequency from the processor speed.</s> But I think, this is
  not a good idea.</p>
  <p>Any suggestion, what I can do? I'm still new in U-Boot,
  so I don't know if there a simple delay function exists.</p>
  <p><strong>UPDATE:</strong><br />
  The reason why I currently cannot use the <code>SysTick</code> timer is, that it will be not linked in the current configuration. This is not a big problem. But the current implementation of the <code>SysTick</code> low-level source defines functions, which will be defined by another timer driver on these SoC series. So when I enable the <code>SysTick</code> in <code>Kconfig</code> I will be possible that I get a linker error with multiple definition of those functions.</p>
  <p>Example driver with IMHO an fatal issue (missing timeout when polling a register value):<br />
  <a href="https://github.com/u-boot/u-boot/blob/master/drivers/clk/clk_stm32h7.c" rel="nofollow noreferrer">GitHub: U-Boot: driver/clk/clk_stm32h7.c</a></p>
  <p>The driver currently requires a external <strong>working</strong> clock source
  (<code>HSE</code>). No issues in the circuit are accepted by the current
  implementation. Also a fixed (defined) frequency of the external
  clock source.</p>
  <p>In the probe function <code>stm32_clk_probe()</code> from the driver there
  will be <code>configure_clocks()</code> called. Here are the issues.</p>
  <p>A code snippet from <code>configure_clocks()</code>:</p>
  <pre><code>/* Switch on HSE */
  setbits_le32(&amp;regs-&gt;cr, RCC_CR_HSEON);
  while (!(readl(&amp;regs-&gt;cr) &amp; RCC_CR_HSERDY))
      ;
  </code></pre>
  <p><code>RCC_CR_HSERDY</code> will here never set by hardware, when there is no external clock source or an issue in the circuit. These leads in an endless loop. The loop of dead.</p>