Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Commit

Permalink
Initialize SPI driver
Browse files Browse the repository at this point in the history
ref #187
  • Loading branch information
Isabell Zorr committed Jun 17, 2020
1 parent 7748b46 commit 45987aa
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/core/nRF52832/spi.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package body Spi with
SPARK_Mode
is
package SSE renames System.Storage_Elements;
use type SSE.Integer_Address;

Base : constant SSE.Integer_Address := 16#40003000#;

ENABLE : Reg_Enable with
Import,
Address => SSE.To_Address (Base + 16#500#);

SPI_CONFIG_CPOL : Reg_SPI_CONFIG_CPOL with
Import,
Address => SSE.To_Address (Base + 16#554#);

PSEL_SCK : Reg_PSEL_SCK with
Import,
Address => SSE.To_Address (Base + 16#508#);

PSEL_MOSI : Reg_PSEL_MOSI with
Import,
Address => SSE.To_Address (Base + 16#50C#);

SPI_TXD : Reg_SPI_TXD with
Import,
Address => SSE.To_Address (Base + 16#51C#);

SPI_FREQUENCY : Reg_SPI_Frequency with
Import,
Address => SSE.To_Address (Base + 16#524#);

procedure Initialize is
begin
ENABLE := (ENABLE => Disabled);
GPIO.Configure (26, GPIO.Port_Out);
GPIO.Write (26, GPIO.High);
GPIO.Configure (27, GPIO.Port_Out);
GPIO.Write(27, GPIO.High);
PSEL_SCK := (CONNECT => Connected, PIN => 26);
PSEL_MOSI := (CONNECT => Connected, PIN => 27);
SPI_CONFIG_CPOL := (CPOL => ActiveHIGH);
SPI_FREQUENCY := (FREQUENCY => M8);
ENABLE := (ENABLE => Enabled);
end Initialize;


end Spi;
83 changes: 83 additions & 0 deletions src/core/nRF52832/spi.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
with Componolit.Runtime.Drivers.GPIO;

package Spi with
SPARK_Mode
is
package GPIO renames Componolit.Runtime.Drivers.GPIO;
procedure Initialize;

private

type SPI_CONFIG_CPOL is (ActiveHIGH, ActiveLOW) with
Size => 1;

for SPI_CONFIG_CPOL use (ActiveHIGH => 0,
ActiveLOW => 1);

type Reg_SPI_CONFIG_CPOL is record
CPOL : SPI_CONFIG_CPOL;
end record with
Size => 1;

type SPI_Enable is (Disabled, Enabled) with
Size => 4;

for SPI_Enable use (Disabled => 0,
Enabled => 1;)

type Reg_Enable is record
ENABLE : SPI_Enable;
end record with
Size => 4;

type PSEL_SCK_Connected is (Connected, Disconnected) with
Size => 32;

for PSEL_SCK_Connected use (Connected => 0,
Disconnected => 1);

type Reg_PSEL_SCK is record
CONNECT : PSEL_SCK_Connected;
PIN : GPIO.Pin;
end record with
Size => 32;

type PSEL_MOSI_Connected is (Connected, Disconnected) with
Size => 32;

for PSEL_MOSI_Connected use (Connected => 0,
Disconnected => 1);

type Reg_PSEL_MOSI is record
CONNECT : PSEL_MOSI_Connected;
PIN : GPIO.Pin;
end record with
Size => 32;

type SPI_TXD_Connected is (Connected, Disconnected) with
Size => 1;

for SPI_TXD_Connected use (Connected => 0,
Disconnected => 1);
type Reg_SPI_TXD is record
CONNECT : SPI_TXD_Connected;
end record with
Size => 8;

type SPI_Frequency is (K125,K250, K500, M1, M2, M4, M8) with
Size =>32;

for SPI_Frequency use (K125 => 16#02000000#,
K250 => 16#04000000#,
K500 => 16#08000000#,
M1 => 16#10000000#,
M2 => 16#20000000#,
M4 => 16#40000000#,
M8 => 16#80000000#);

type Reg_SPI_Frequency is record
FREQUENCY : SPI_Frequency;
end record with
Size => 32;

end Spi;

0 comments on commit 45987aa

Please sign in to comment.