Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enable, reset, configuration routines for Eth periph #432

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions arch/ARM/STM32/devices/stm32f40x/stm32-device.adb
Original file line number Diff line number Diff line change
Expand Up @@ -805,4 +805,30 @@ package body STM32.Device is
RCC_Periph.AHB1RSTR.CRCRST := False;
end Reset;

----------------
-- Enable_Eth --
----------------

procedure Enable_Eth
(MAC : Boolean := True;
MAC_TX : Boolean := True;
MAC_RX : Boolean := True;
MAC_PTP : Boolean := True) is
begin
RCC_Periph.AHB1ENR.ETHMACEN := MAC;
RCC_Periph.AHB1ENR.ETHMACTXEN := MAC_TX;
RCC_Periph.AHB1ENR.ETHMACRXEN := MAC_RX;
RCC_Periph.AHB1ENR.ETHMACPTPEN := MAC_PTP;
end Enable_Eth;

---------------
-- Reset_Eth --
---------------

procedure Reset_Eth is
begin
RCC_Periph.AHB1RSTR.ETHMACRST := True;
RCC_Periph.AHB1RSTR.ETHMACRST := False;
end Reset_Eth;

end STM32.Device;
18 changes: 18 additions & 0 deletions arch/ARM/STM32/devices/stm32f40x/stm32-device.ads
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,24 @@ package STM32.Device is

RTC : aliased RTC_Device;

--------------
-- Ethernet --
--------------

procedure Enable_Eth
(MAC : Boolean := True;
MAC_TX : Boolean := True;
MAC_RX : Boolean := True;
MAC_PTP : Boolean := True);
-- Enable/disable Ethernet MAC clocks:
-- * MAC - Ethernet MAC clock enable
-- * MAC_TX - Ethernet Transmission clock enable
-- * MAC_RX - Ethernet Reception clock enable
-- * MAC_PTP - Ethernet PTP clock enable

procedure Reset_Eth;
-- Ethernet MAC reset

private

GPIO_AF_RTC_50Hz_0 : constant GPIO_Alternate_Function := 0;
Expand Down
26 changes: 26 additions & 0 deletions arch/ARM/STM32/devices/stm32f42x/stm32-device.adb
Original file line number Diff line number Diff line change
Expand Up @@ -935,4 +935,30 @@ package body STM32.Device is
RCC_Periph.AHB1RSTR.CRCRST := False;
end Reset;

----------------
-- Enable_Eth --
----------------

procedure Enable_Eth
(MAC : Boolean := True;
MAC_TX : Boolean := True;
MAC_RX : Boolean := True;
MAC_PTP : Boolean := True) is
begin
RCC_Periph.AHB1ENR.ETHMACEN := MAC;
RCC_Periph.AHB1ENR.ETHMACTXEN := MAC_TX;
RCC_Periph.AHB1ENR.ETHMACRXEN := MAC_RX;
RCC_Periph.AHB1ENR.ETHMACPTPEN := MAC_PTP;
end Enable_Eth;

---------------
-- Reset_Eth --
---------------

procedure Reset_Eth is
begin
RCC_Periph.AHB1RSTR.ETHMACRST := True;
RCC_Periph.AHB1RSTR.ETHMACRST := False;
end Reset_Eth;

end STM32.Device;
18 changes: 18 additions & 0 deletions arch/ARM/STM32/devices/stm32f42x/stm32-device.ads
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,24 @@ package STM32.Device is

RTC : aliased RTC_Device;

--------------
-- Ethernet --
--------------

procedure Enable_Eth
(MAC : Boolean := True;
MAC_TX : Boolean := True;
MAC_RX : Boolean := True;
MAC_PTP : Boolean := True);
-- Enable/disable Ethernet MAC clocks:
-- * MAC - Ethernet MAC clock enable
-- * MAC_TX - Ethernet Transmission clock enable
-- * MAC_RX - Ethernet Reception clock enable
-- * MAC_PTP - Ethernet PTP clock enable

procedure Reset_Eth;
-- Ethernet MAC reset

private

GPIO_AF_RTC_50Hz_0 : constant GPIO_Alternate_Function := 0;
Expand Down
26 changes: 26 additions & 0 deletions arch/ARM/STM32/devices/stm32f46_79x/stm32-device.adb
Original file line number Diff line number Diff line change
Expand Up @@ -1080,4 +1080,30 @@ package body STM32.Device is
RCC_Periph.AHB1RSTR.CRCRST := False;
end Reset;

----------------
-- Enable_Eth --
----------------

procedure Enable_Eth
(MAC : Boolean := True;
MAC_TX : Boolean := True;
MAC_RX : Boolean := True;
MAC_PTP : Boolean := True) is
begin
RCC_Periph.AHB1ENR.ETHMACEN := MAC;
RCC_Periph.AHB1ENR.ETHMACTXEN := MAC_TX;
RCC_Periph.AHB1ENR.ETHMACRXEN := MAC_RX;
RCC_Periph.AHB1ENR.ETHMACPTPEN := MAC_PTP;
end Enable_Eth;

---------------
-- Reset_Eth --
---------------

procedure Reset_Eth is
begin
RCC_Periph.AHB1RSTR.ETHMACRST := True;
RCC_Periph.AHB1RSTR.ETHMACRST := False;
end Reset_Eth;

end STM32.Device;
18 changes: 18 additions & 0 deletions arch/ARM/STM32/devices/stm32f46_79x/stm32-device.ads
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,24 @@ package STM32.Device is

RTC : aliased RTC_Device;

--------------
-- Ethernet --
--------------

procedure Enable_Eth
(MAC : Boolean := True;
MAC_TX : Boolean := True;
MAC_RX : Boolean := True;
MAC_PTP : Boolean := True);
-- Enable/disable Ethernet MAC clocks:
-- * MAC - Ethernet MAC clock enable
-- * MAC_TX - Ethernet Transmission clock enable
-- * MAC_RX - Ethernet Reception clock enable
-- * MAC_PTP - Ethernet PTP clock enable

procedure Reset_Eth;
-- Ethernet MAC reset

private

GPIO_AF_RTC_50Hz_0 : constant GPIO_Alternate_Function := 0;
Expand Down
26 changes: 26 additions & 0 deletions arch/ARM/STM32/devices/stm32f7x/stm32-device.adb
Original file line number Diff line number Diff line change
Expand Up @@ -1063,4 +1063,30 @@ package body STM32.Device is
RCC_Periph.AHB2RSTR.DCMIRST := False;
end Reset_DCMI;

----------------
-- Enable_Eth --
----------------

procedure Enable_Eth
(MAC : Boolean := True;
MAC_TX : Boolean := True;
MAC_RX : Boolean := True;
MAC_PTP : Boolean := True) is
begin
RCC_Periph.AHB1ENR.ETHMACEN := MAC;
RCC_Periph.AHB1ENR.ETHMACTXEN := MAC_TX;
RCC_Periph.AHB1ENR.ETHMACRXEN := MAC_RX;
RCC_Periph.AHB1ENR.ETHMACPTPEN := MAC_PTP;
end Enable_Eth;

---------------
-- Reset_Eth --
---------------

procedure Reset_Eth is
begin
RCC_Periph.AHB1RSTR.ETHMACRST := True;
RCC_Periph.AHB1RSTR.ETHMACRST := False;
end Reset_Eth;

end STM32.Device;
18 changes: 18 additions & 0 deletions arch/ARM/STM32/devices/stm32f7x/stm32-device.ads
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,24 @@ package STM32.Device is

RTC : aliased RTC_Device;

--------------
-- Ethernet --
--------------

procedure Enable_Eth
(MAC : Boolean := True;
MAC_TX : Boolean := True;
MAC_RX : Boolean := True;
MAC_PTP : Boolean := True);
-- Enable/disable Ethernet MAC clocks:
-- * MAC - Ethernet MAC clock enable
-- * MAC_TX - Ethernet Transmission clock enable
-- * MAC_RX - Ethernet Reception clock enable
-- * MAC_PTP - Ethernet PTP clock enable

procedure Reset_Eth;
-- Ethernet MAC reset

private

HSE_VALUE : constant UInt32 := ADL_Config.High_Speed_External_Clock;
Expand Down
9 changes: 9 additions & 0 deletions arch/ARM/STM32/drivers/stm32-syscfg.adb
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,13 @@ package body STM32.SYSCFG is
Clear_External_Interrupt (External_Line_Number'Val (GPIO_Pin'Pos (Pin)));
end Clear_External_Interrupt;

--------------------
-- Configure_RMII --
--------------------

procedure Configure_RMII (RMII : Boolean := True) is
begin
STM32_SVD.SYSCFG.SYSCFG_Periph.PMC.MII_RMII_SEL := RMII;
end Configure_RMII;

end STM32.SYSCFG;
5 changes: 5 additions & 0 deletions arch/ARM/STM32/drivers/stm32-syscfg.ads
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@ package STM32.SYSCFG is

procedure Clear_External_Interrupt (Pin : GPIO_Pin) with Inline;

procedure Configure_RMII (RMII : Boolean := True);
-- Ethernet PHY interface selection:
-- * RMII=False - MII
-- * RMII=True - RMII

end STM32.SYSCFG;
56 changes: 24 additions & 32 deletions components/eth/stm32-eth.adb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
------------------------------------------------------------------------------
with STM32.GPIO;
with STM32.Device;
with STM32_SVD.RCC;
with STM32_SVD.SYSCFG;
with STM32.RCC;
with STM32.SYSCFG;
with STM32_SVD.Ethernet; use STM32_SVD.Ethernet;
with STM32.SDRAM;
with Ada.Real_Time;
Expand Down Expand Up @@ -61,7 +61,13 @@ package body STM32.Eth is
is
use STM32.GPIO;
use STM32.Device;
use STM32_SVD.RCC;

Config : constant GPIO_Port_Configuration :=
(Mode_AF,
Floating,
Push_Pull,
Speed_100MHz,
GPIO_AF_ETH_11);
begin
-- Enable GPIO clocks

Expand All @@ -70,41 +76,27 @@ package body STM32.Eth is
Enable_Clock (GPIO_G);

-- Enable SYSCFG clock
RCC_Periph.APB2ENR.SYSCFGEN := True;
STM32.RCC.SYSCFG_Clock_Enable;

-- Select RMII (before enabling the clocks)
STM32_SVD.SYSCFG.SYSCFG_Periph.PMC.MII_RMII_SEL := True;

Configure_Alternate_Function (PA1, GPIO_AF_ETH_11); -- RMII_REF_CLK
Configure_Alternate_Function (PA2, GPIO_AF_ETH_11); -- RMII_MDIO
Configure_Alternate_Function (PA7, GPIO_AF_ETH_11); -- RMII_CRS_DV
Configure_Alternate_Function (PC1, GPIO_AF_ETH_11); -- RMII_MDC
Configure_Alternate_Function (PC4, GPIO_AF_ETH_11); -- RMII_RXD0
Configure_Alternate_Function (PC5, GPIO_AF_ETH_11); -- RMII_RXD1
Configure_Alternate_Function (PG2, GPIO_AF_ETH_11); -- RMII_RXER
Configure_Alternate_Function (PG11, GPIO_AF_ETH_11); -- RMII_TX_EN
Configure_Alternate_Function (PG13, GPIO_AF_ETH_11); -- RMII_TXD0
Configure_Alternate_Function (PG14, GPIO_AF_ETH_11); -- RMII_TXD1
Configure_IO (PA1, (Mode_AF, Push_Pull, Speed_100MHz, Floating));
Configure_IO (PA2, (Mode_AF, Push_Pull, Speed_100MHz, Floating));
Configure_IO (PA7, (Mode_AF, Push_Pull, Speed_100MHz, Floating));
Configure_IO (PC1, (Mode_AF, Push_Pull, Speed_100MHz, Floating));
Configure_IO (PC4, (Mode_AF, Push_Pull, Speed_100MHz, Floating));
Configure_IO (PC5, (Mode_AF, Push_Pull, Speed_100MHz, Floating));
Configure_IO (PG2, (Mode_AF, Push_Pull, Speed_100MHz, Floating));
Configure_IO (PG11, (Mode_AF, Push_Pull, Speed_100MHz, Floating));
Configure_IO (PG13, (Mode_AF, Push_Pull, Speed_100MHz, Floating));
Configure_IO (PG14, (Mode_AF, Push_Pull, Speed_100MHz, Floating));
STM32.SYSCFG.Configure_RMII (RMII => True);

Configure_IO (PA1, Config); -- RMII_REF_CLK
Configure_IO (PA2, Config); -- RMII_MDIO
Configure_IO (PA7, Config); -- RMII_CRS_DV
Configure_IO (PC1, Config); -- RMII_MDC
Configure_IO (PC4, Config); -- RMII_RXD0
Configure_IO (PC5, Config); -- RMII_RXD1
Configure_IO (PG2, Config); -- RMII_RXER
Configure_IO (PG11, Config); -- RMII_TX_EN
Configure_IO (PG13, Config); -- RMII_TXD0
Configure_IO (PG14, Config); -- RMII_TXD1

-- Enable clocks
RCC_Periph.AHB1ENR.ETHMACEN := True;
RCC_Periph.AHB1ENR.ETHMACTXEN := True;
RCC_Periph.AHB1ENR.ETHMACRXEN := True;
RCC_Periph.AHB1ENR.ETHMACPTPEN := True;
STM32.Device.Enable_Eth;

-- Reset
RCC_Periph.AHB1RSTR.ETHMACRST := True;
RCC_Periph.AHB1RSTR.ETHMACRST := False;
STM32.Device.Reset_Eth;

-- Software reset
Ethernet_DMA_Periph.DMABMR.SR := True;
Expand Down
Loading