Difference between revisions of "ARM Embedded Tutorial - Raspberry Pi Pico running at full CPU speed"

From Free Pascal wiki
Jump to navigationJump to search
(Add page template; add categories in page template; add syntax highlighting; fix typos)
(Replaced content with "{{ARM Embedded Tutorial - Raspberry Pi Pico running at full CPU speed}} This tutorial is not needed anymore, now Pico is enabled to run at full speed in Initialization Co...")
Tag: Replaced
Line 1: Line 1:
 
{{ARM Embedded Tutorial - Raspberry Pi Pico running at full CPU speed}}
 
{{ARM Embedded Tutorial - Raspberry Pi Pico running at full CPU speed}}
  
In the simple Blinky example we did the bare minimum that is necessary to blink a LED.
+
This tutorial is not needed anymore, now Pico is enabled to run at full speed in Initialization Code.
  
Now we increase CPU speed to full power with the help of the init_clock procedure from <tt>clocks.c.obj</tt>.
+
[[ARM Embedded Tutorial - FPC and the Raspberry Pi Pico|Back to main Pico Page]]
 
 
First step we need to do is to add the <tt>clocks.c.obj</tt> file to our code. When we do that and compile the code we are left again with linking errors because <tt>clocks.c.obj</tt> has dependencies on other code parts.
 
 
 
After fiddling arround a bit we end up with the needed list of dependencies to link in:
 
 
 
<syntaxhighlight lang=pascal>
 
    program Blinky;
 
    {$L platform.c.obj}
 
    {$L gpio.c.obj}
 
    {$L clocks.c.obj}
 
    {$L xosc.c.obj}
 
    {$L pll.c.obj}
 
    {$L platform.c.obj}
 
    {$L watchdog.c.obj}
 
</syntaxhighlight>
 
 
 
Now we add clocks_init to our code and we are also now able to initialize all peripherals:
 
 
 
<syntaxhighlight lang=pascal>
 
    procedure runtime_init;
 
    const
 
      RESETS_SAFE_BITS=    %1111111111100110110111111;
 
      RESETS_PRECLOCK_BITS= %0001111000100110110111110;
 
      RESETS_POSTCLOCK_BITS=%1110000111000000000000001;
 
    begin
 
      resets.reset_set := RESETS_SAFE_BITS;
 
      resets.reset_clr := RESETS_PRECLOCK_BITS;
 
      repeat
 
      until (resets.reset_done and RESETS_PRECLOCK_BITS) = RESETS_PRECLOCK_BITS;
 
      clocks_init;
 
      resets.reset_clr := RESETS_POSTCLOCK_BITS;
 
      repeat
 
      until (resets.reset_done and RESETS_POSTCLOCK_BITS) = RESETS_POSTCLOCK_BITS;
 
    end;
 
</syntaxhighlight>
 
 
 
We start the compiler again and there is still one dependency missing, so we add a bit of code to get this fixed:
 
 
 
<syntaxhighlight lang=pascal>
 
    function __aeabi_uidiv(const numerator : uint32; denominator : uint32):uint32;  public name '__aeabi_uidiv';
 
    begin
 
      Result := numerator div denominator;
 
    end;
 
</syntaxhighlight>
 
 
 
This dependency comes with the gcc compiler but we are lazy and use this simple (likely slower) alternative.
 
 
 
After this final step we are able to blink the LED's at full CPU speed, so we increase our delay loop because we are now faster with waiting:
 
 
 
<syntaxhighlight lang=pascal>
 
    program Blinky;
 
 
 
    {$L platform.c.obj}
 
    {$L gpio.c.obj}
 
    {$L clocks.c.obj}
 
    {$L xosc.c.obj}
 
    {$L pll.c.obj}
 
    {$L watchdog.c.obj}
 
 
 
    procedure clocks_init; external;
 
    procedure gpio_init(gpio : longWord); external;
 
 
 
    function __aeabi_uidiv(const numerator : uint32; denominator : uint32):uint32;  public name '__aeabi_uidiv';
 
    begin
 
      Result := numerator div denominator;
 
    end;
 
 
 
    procedure runtime_init;
 
    const
 
      RESETS_SAFE_BITS=    %1111111111100110110111111;
 
      RESETS_PRECLOCK_BITS= %0001111000100110110111110;
 
      RESETS_POSTCLOCK_BITS=%1110000111000000000000001;
 
    begin
 
      resets.reset_set := RESETS_SAFE_BITS;
 
      resets.reset_clr := RESETS_PRECLOCK_BITS;
 
      repeat
 
      until (resets.reset_done and RESETS_PRECLOCK_BITS) = RESETS_PRECLOCK_BITS;
 
      clocks_init;
 
      resets.reset_clr := RESETS_POSTCLOCK_BITS;
 
      repeat
 
      until (resets.reset_done and RESETS_POSTCLOCK_BITS) = RESETS_POSTCLOCK_BITS;
 
    end;
 
 
 
    procedure gpio_set_dir(gpio : longWord; &out : longbool);
 
    var
 
      mask : longWord;
 
    begin
 
      mask := 1 shl  gpio;
 
      if out = true then
 
        sio.gpio_oe_set := mask
 
      else
 
        sio.gpio_oe_clr := mask;
 
    end;
 
 
 
    procedure gpio_put(gpio : longWord; value : boolean);
 
    var
 
      mask : longWord;
 
    begin
 
      mask := 1 shl gpio;
 
      if value=true then
 
        sio.gpio_set := mask
 
      else
 
        sio.gpio_clr := mask;
 
    end;
 
 
 
    const
 
      LED_PIN=25;
 
      GPIO_OUT=true;
 
    var
 
      i : longWord;
 
    begin
 
      runtime_init;
 
      gpio_init(LED_PIN);
 
      gpio_set_dir(LED_PIN,GPIO_OUT);
 
      repeat
 
        gpio_put(LED_PIN,true);
 
        for i := 0 to 3000000 do ;
 
        gpio_put(LED_PIN,false);
 
        for i := 0 to 3000000 do ;
 
      until 1=0;
 
    end.
 
</syntaxhighlight>
 

Revision as of 02:31, 1 March 2021

English (en)


This tutorial is not needed anymore, now Pico is enabled to run at full speed in Initialization Code.

Back to main Pico Page