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

From Lazarus wiki
Jump to navigationJump to search
(Created page with "In the simple Blinky example we did the bare minimum that is necessary to blink a LED. Now we increase CPU speed to full power with the help of the init_clock procedure from...")
 
(nominate for deletion: no actual content and no addition of content intended anymore)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
In the simple Blinky example we did the bare minimum that is necessary to blink a LED.
+
{{ARM Embedded Tutorial - Raspberry Pi Pico running at full CPU speed}}
  
Now we increase CPU speed to full power with the help of the init_clock procedure from clocks.c.obj
+
This tutorial is not needed anymore, now Pico is enabled to run at full speed in Initialization Code.
  
First step we need to do is to add the clocks.c.obj file to our code. But when we do that and compile the code we are left again with linking errors because clocks.c.obj has dependencies to other code parts.
+
[[ARM Embedded Tutorial - FPC and the Raspberry Pi Pico|Back to main Pico Page]]
 
+
[[Category: Pages for deletion]]
After fiddeling arround a bit we end up with the needed list of dependencies to link in:
 
 
 
    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}
 
 
 
Now we add clocks_init to our code and we are also now able to initialize all peripherals:
 
 
 
    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;
 
 
 
we start the compiler again and there is still one dependency missing, so we add a bit of code to get this fixed:
 
 
 
 
 
    function __aeabi_uidiv(const numerator : uint32; denominator : uint32):uint32;  public name '__aeabi_uidiv';
 
    begin
 
      Result := numerator div denominator;
 
    end;
 
 
 
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:
 
 
 
    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.
 

Latest revision as of 02:55, 4 February 2023

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