>< simplify: ADCs, DACs, CANs, SPIs, USARTs, SDIO

This commit is contained in:
Vovanium 2024-01-20 02:07:46 +03:00
parent bc0483d055
commit 2456c05c5f
21 changed files with 168 additions and 187 deletions

View File

@ -1,4 +1,4 @@
with Chip.USARTs;
with STM32.USARTs;
package Board.UART is
Port : GPIO_Registers renames GPIOA;
@ -10,7 +10,7 @@ package Board.UART is
AF : Alternate_Function renames Alternate_Functions.USART1;
Module : Chip.USARTs.USART_Base.USART_Registers renames Chip.USARTs.USART1;
Module : STM32.USARTs.USART_Registers renames STM32.USARTs.USART1;
RCC_EN : Boolean renames RCC.APB2ENR (Index.USART1);
RCC_RST : Boolean renames RCC.APB2RSTR (Index.USART1);

View File

@ -25,19 +25,19 @@ package body Board.LCD.SPI_IO is
SPI_RCC_RST := False;
declare
R : Chip.SPIs.SPI_Base.Control_Register_1 := SPI_Module.CR1;
R : STM32.SPIs.Control_Register_1 := SPI_Module.CR1;
begin
R.BR := Chip.SPIs.SPI_Base.PCLK_DIV_16;
R.CPHA := Chip.SPIs.SPI_Base.Late_Clock;
R.CPOL := Chip.SPIs.SPI_Base.Positive_Clock;
R.DFF := Chip.SPIs.SPI_Base.Frame_8_Bit;
R.BR := STM32.SPIs.PCLK_DIV_16;
R.CPHA := STM32.SPIs.Late_Clock;
R.CPOL := STM32.SPIs.Positive_Clock;
R.DFF := STM32.SPIs.Frame_8_Bit;
R.LSBFIRST := False;
R.SSM := True;
R.SSI := True;
R.MSTR := Chip.SPIs.SPI_Base.Master;
R.MSTR := STM32.SPIs.Master;
R.SPE := True;
R.RXONLY := False;
R.BIDIMODE := Chip.SPIs.SPI_Base.Unidirectional;
R.BIDIMODE := STM32.SPIs.Unidirectional;
R.BIDIOE := True;
R.CRCEN := False;
R.CRCNEXT := False;
@ -46,9 +46,9 @@ package body Board.LCD.SPI_IO is
end;
declare
R : Chip.SPIs.SPI_Base.Control_Register_2 := SPI_Module.CR2;
R : STM32.SPIs.Control_Register_2 := SPI_Module.CR2;
begin
R.FRF := Chip.SPIs.SPI_Base.Motorola_Mode;
R.FRF := STM32.SPIs.Motorola_Mode;
SPI_Module.CR2 := R;
end;

View File

@ -1,5 +1,5 @@
with Chip.SPIs;
use Chip.SPIs;
with STM32.SPIs;
use STM32.SPIs;
package Board.LCD is
@ -18,7 +18,7 @@ package Board.LCD is
SDA_Port : GPIO_Registers renames GPIOF;
SDA_Bit : constant Port_Bit_Number := 9;
SPI_Module : Chip.SPIs.SPI_Base.SPI_Registers renames SPI5;
SPI_Module : STM32.SPIs.SPI_Registers renames SPI5;
SPI_AF : Chip.General_Purpose_IOs.GPIO_Base.Alternate_Function
renames Chip.General_Purpose_IOs.GPIO_Base.Alternate_Functions.SPI5;

View File

@ -1,4 +1,4 @@
with Chip.USARTs;
with STM32.USARTs;
package Board.UART is
@ -11,7 +11,7 @@ package Board.UART is
AF : Alternate_Function renames Alternate_Functions.USART1;
Module : Chip.USARTs.USART_Base.USART_Registers renames Chip.USARTs.USART1;
Module : STM32.USARTs.USART_Registers renames STM32.USARTs.USART1;
RCC_EN : Boolean renames RCC.APB2ENR (Index.USART1);
RCC_RST : Boolean renames RCC.APB2RSTR (Index.USART1);

View File

@ -1,7 +1,7 @@
with STM32.General_Purpose_IOs.Ports;
use STM32.General_Purpose_IOs.Ports;
with Chip.USARTs;
use Chip.USARTs.USART_Base;
with STM32.USARTs;
use STM32.USARTs;
package body Board.UART.IO is
package TX is new GPIO_Port_Boolean (Port, TX_Bit);

View File

@ -39,6 +39,7 @@ package STM32.Address_Map with Pure is
FMPI2C1 : constant := 16#4000_6000#;
CAN1 : constant := 16#4000_6400#;
CAN2 : constant := 16#4000_6800#;
CAN3 : constant := 16#4000_6C00#;
PWR : constant := 16#4000_7000#;
DAC : constant := 16#4000_7400#;
UART7 : constant := 14#4000_7800#;
@ -50,6 +51,8 @@ package STM32.Address_Map with Pure is
TIM8 : constant := 16#4001_0400#;
USART1 : constant := 16#4001_1000#;
USART6 : constant := 16#4001_1400#;
UART9 : constant := 16#4001_1800#;
UART10 : constant := 16#4001_1C00#;
ADC1 : constant := 16#4001_2000#;
ADC2 : constant := 16#4001_2100#;
ADC3 : constant := 16#4001_2200#;

View File

@ -1,4 +1,11 @@
package STM32.Analog_to_Digital_Convertors with Pure is
with System.Storage_Elements;
with STM32.Address_Map;
-- Analog to Digital Convertors
--
-- Units exist in all devices. Fx0, Fx1, Fx2, Fx3 devices have 1 ADC, others 3.
package STM32.Analog_to_Digital_Convertors is
-- SR
@ -524,4 +531,16 @@ package STM32.Analog_to_Digital_Convertors with Pure is
CDR at 16#08# range 0 .. 31;
end record;
ADC1 : aliased ADC_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.ADC1);
ADC2 : aliased ADC_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.ADC2);
ADC3 : aliased ADC_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.ADC3);
ADC_Common : Common_ADC_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.ADC_Common);
end STM32.Analog_to_Digital_Convertors;

View File

@ -1,4 +1,12 @@
package STM32.CANs with Pure is
with System.Storage_Elements;
with STM32.Address_Map;
-- Controller Area Network Interfaces
--
-- Units exist in all STM32F4 devices except F4x1 and F410.
-- F4x3 devices have 3 CANs all others have 2.
package STM32.CANs is
-- bxCAN hardware
-- Correspondence in register names:
@ -525,4 +533,13 @@ package STM32.CANs with Pure is
FR at 16#0240# range 0 .. 32 * 2 * 28 - 1;
end record;
CAN1 : aliased CAN_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.CAN1);
CAN2 : aliased CAN_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.CAN2);
CAN3 : aliased CAN_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.CAN3);
end STM32.CANs;

View File

@ -1,4 +1,11 @@
package STM32.Digital_to_Analog_Convertors with Pure is
with System.Storage_Elements;
with STM32.Address_Map;
-- Digital to Analog Convertors
--
-- Units exist in all F4 devices except F4x1
package STM32.Digital_to_Analog_Convertors is
-- Correspondence in register names
-- DHR12Rx -- DHR (x).DHR12R
-- DHR12Lx -- DHR (x).DHR12L
@ -173,4 +180,7 @@ package STM32.Digital_to_Analog_Convertors with Pure is
SR at 16#34# range 0 .. 31;
end record;
DAC : DAC_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.DAC);
end STM32.Digital_to_Analog_Convertors;

View File

@ -1,21 +0,0 @@
with System.Storage_Elements;
with STM32.Address_Map;
with STM32.Analog_to_Digital_Convertors;
package STM32.F407.Analog_to_Digital_Convertors is
package ADC_Base renames STM32.Analog_to_Digital_Convertors;
ADC1 : ADC_Base.ADC_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.ADC1);
ADC2 : ADC_Base.ADC_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.ADC2);
ADC3 : ADC_Base.ADC_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.ADC3);
ADC_Common : ADC_Base.Common_ADC_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.ADC_Common);
end STM32.F407.Analog_to_Digital_Convertors;

View File

@ -1,15 +0,0 @@
with System.Storage_Elements;
with STM32.Address_Map;
with STM32.CANs;
package STM32.F407.CANs is
package CAN_Base renames STM32.CANs;
CAN1 : CAN_Base.CAN_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.CAN1);
CAN2 : CAN_Base.CAN_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.CAN2);
end STM32.F407.CANs;

View File

@ -1,18 +0,0 @@
with System.Storage_Elements;
with STM32.Address_Map;
with STM32.SPIs;
package STM32.F407.SPIs is
package SPI_Base renames STM32.SPIs;
SPI1 : aliased SPI_Base.SPI_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.SPI1);
SPI2 : aliased SPI_Base.SPI_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.SPI2_I2S2);
SPI3 : aliased SPI_Base.SPI_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.SPI3_I2S3);
end STM32.F407.SPIs;

View File

@ -1,27 +0,0 @@
with System.Storage_Elements;
with STM32.Address_Map;
with STM32.USARTs;
package STM32.F407.USARTs is
package USART_Base renames STM32.USARTs;
USART1: aliased USART_Base.USART_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address(Address_Map.USART1);
USART2: aliased USART_Base.USART_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address(Address_Map.USART2);
USART3: aliased USART_Base.USART_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address(Address_Map.USART3);
UART4: aliased USART_Base.USART_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address(Address_Map.UART4);
UART5: aliased USART_Base.USART_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address(Address_Map.UART5);
USART6: aliased USART_Base.USART_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address(Address_Map.USART6);
end STM32.F407.USARTs;

View File

@ -1,3 +0,0 @@
with STM32.F407.Analog_to_Digital_Convertors;
package STM32.F429.Analog_to_Digital_Convertors renames STM32.F407.Analog_to_Digital_Convertors;

View File

@ -1,3 +0,0 @@
with STM32.F407.CANs;
package STM32.F429.CANs renames STM32.F407.CANs;

View File

@ -1,12 +0,0 @@
with System.Storage_Elements;
with STM32.Address_Map;
with STM32.Digital_to_Analog_Convertors;
package STM32.F429.Digital_to_Analog_Convertors is
package DAC_Base renames STM32.Digital_to_Analog_Convertors;
DAC : DAC_Base.DAC_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.DAC);
end STM32.F429.Digital_to_Analog_Convertors;

View File

@ -1,30 +0,0 @@
with System.Storage_Elements;
with STM32.Address_Map;
with STM32.SPIs;
package STM32.F429.SPIs is
package SPI_Base renames STM32.SPIs;
SPI1 : SPI_Base.SPI_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.SPI1);
SPI2 : SPI_Base.SPI_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.SPI2_I2S2);
SPI3 : SPI_Base.SPI_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.SPI3_I2S3);
SPI4 : SPI_Base.SPI_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.SPI4);
SPI5 : SPI_Base.SPI_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.SPI5);
SPI6 : SPI_Base.SPI_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.SPI6);
I2S2 : SPI_Base.SPI_Registers renames SPI2;
I2S3 : SPI_Base.SPI_Registers renames SPI3;
end STM32.F429.SPIs;

View File

@ -1,33 +0,0 @@
with System.Storage_Elements;
with STM32.Address_Map;
with STM32.USARTs;
package STM32.F429.USARTs is
package USART_Base renames STM32.USARTs;
USART1: aliased USART_Base.USART_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address(Address_Map.USART1);
USART2: aliased USART_Base.USART_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address(Address_Map.USART2);
USART3: aliased USART_Base.USART_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address(Address_Map.USART3);
UART4: aliased USART_Base.USART_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address(Address_Map.UART4);
UART5: aliased USART_Base.USART_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address(Address_Map.UART5);
USART6: aliased USART_Base.USART_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address(Address_Map.USART6);
UART7: aliased USART_Base.USART_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address(Address_Map.UART7);
UART8: aliased USART_Base.USART_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address(Address_Map.UART8);
end STM32.F429.USARTs;

View File

@ -1,4 +1,11 @@
package STM32.SDIO_Interface with Pure is
with System.Storage_Elements;
with STM32.Address_Map;
-- SD / SDIO / MMC interface
--
-- This unit is in all STM32F4xx series models except F410
package STM32.SDIO_Interface is
-- POWER
@ -299,5 +306,7 @@ package STM32.SDIO_Interface with Pure is
FIFO at 16#80# range 0 .. 31;
end record;
end STM32.SDIO_Interface;
SDIO : aliased SDIO_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.SDIO);
end STM32.SDIO_Interface;

View File

@ -1,4 +1,31 @@
package STM32.SPIs with Pure is
with System.Storage_Elements;
with STM32.Address_Map;
-- Serial Peripherial Interface Controllers
--
-- Units exist an all STM32F4 devices in various combinations
--
-- Availability chart:
-- SPI# 1 2 3 4 5 6
-- F401 + + + + - -
-- F405 + + + - - -
-- F407 + + + - - -
-- F410 + + - - - -
-- F411 + + + + + -
-- F412 + + + + + -
-- F413 + + + + + -
-- F415 + + + - - -
-- F417 + + + - - -
-- F423 + + + + + -
-- F427 + + + + + +
-- F429 + + + + + +
-- F437 + + + + + +
-- F446 + + + + - -
-- F469 + + + + + +
-- F479 + + + + + +
-- They all are identical
package STM32.SPIs is
type Clock_Phase is (
Late_Clock, -- First clock transition is the first data capture edge
@ -300,4 +327,25 @@ package STM32.SPIs with Pure is
I2SPR at 16#20# range 0 .. 15;
end record;
SPI1 : aliased SPI_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.SPI1);
SPI2 : aliased SPI_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.SPI2_I2S2);
SPI3 : aliased SPI_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.SPI3_I2S3);
SPI4 : aliased SPI_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.SPI4);
SPI5 : aliased SPI_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.SPI5);
SPI6 : aliased SPI_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address (STM32.Address_Map.SPI6);
I2S2 : SPI_Registers renames SPI2;
I2S3 : SPI_Registers renames SPI3;
end STM32.SPIs;

View File

@ -1,4 +1,11 @@
package STM32.USARTs with Pure is
with System.Storage_Elements;
with STM32.Address_Map;
-- Universal (Synchronous-)Asynchronous Receivers-Transmitters
--
-- Available in all STM32F4 device in different quantities
package STM32.USARTs is
-- NOTE: USARTs ans UARTs are on APB
-- Registers should be written as a whole
@ -249,6 +256,36 @@ package STM32.USARTs with Pure is
GTPR at 16#18# range 0 .. 31;
end record;
USART1: aliased USART_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address(Address_Map.USART1);
USART2: aliased USART_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address(Address_Map.USART2);
USART3: aliased USART_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address(Address_Map.USART3);
UART4: aliased USART_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address(Address_Map.UART4);
UART5: aliased USART_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address(Address_Map.UART5);
USART6: aliased USART_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address(Address_Map.USART6);
UART7: aliased USART_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address(Address_Map.UART7);
UART8: aliased USART_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address(Address_Map.UART8);
UART9: aliased USART_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address(Address_Map.UART9);
UART10: aliased USART_Registers with Volatile, Import,
Address => System.Storage_Elements.To_Address(Address_Map.UART10);
function Baud_Rate (
Speed: Positive;
OVER8: Boolean;