title: can I change "delay until" granularity on cortex-m4?
body: <p>I'm scheduling a loop with a "delay until" clause on an STM32F4 discovery board, and when I increase the frequency, the thing stop respecting the time constraint. After some digging, I am under the impression that it's the scheduler granularity that is not up to task. One of the signs is that when I go very slow the time is mostly respected, and the faster I go, the more bonkers it go. But the tardiness seems to be discrete, like falling on the scheduling frequency limit.</p>
  
  <p>here is my test code:</p>
  
  <pre><code>  task body PWM is
        onPeriod   : Time_Span;
        offPeriod  : Time_Span;
        period     : Time_Span;
        Next_Start : Time    := Clock;
        PWM_On     : Boolean := True;
    begin
        loop
            period    := Microseconds (1_000_000) / PWMFrequency;
            onPeriod  := period / 3;
            offPeriod := 2 * period / 3;
            if (PWM_On) then
                Off (Pattern (Next_LED));
                PWM_On     := False;
                Next_Start := Next_Start + offPeriod;
            else
                On (Pattern (Next_LED));
                PWM_On     := True;
                Next_Start := Next_Start + onPeriod;
            end if;
            delay until Next_Start;
        end loop;
   end PWM;
  </code></pre>
  
  <p>I'm not showing the oscilloscope traces, it's too complicated, suffice to say that the higher the frequency, the less the duty cycle is close to 33.3% (or even stable).</p>
  
  <p>After poking around in the gnat distribution, I found that in s-bbbosu.adb:</p>
  
  <pre><code>--  We use the Sys_Tick timer as a periodic timer with 1 kHz rate. This
  --  is a trade-off between accurate delays, limited overhead and maximum
  --  time that interrupts may be disabled.
  
  Tick_Period   : constant Timer_Interval := Clock_Frequency / 1000;
  </code></pre>
  
  <p>(and some connections to that in a function called Delay_Until in s-bbtime.adb)</p>
  
  <p>Am I forced to use a native MCU timer by hand or is there some higher speed scheduling facility provided in the system?
  I'm a beginner in Ada, so the answer might be obvious.</p>