stm32-ada/examples/uart/source/uart_429disco.adb

112 lines
2.4 KiB
Ada

with STM32.F429Z; use STM32.F429Z;
use STM32.F429Z.Modules.GPIO;
use STM32.F429Z.Modules.USART;
use STM32.F429Z.Modules.RCC;
with Ada.Real_Time; use Ada.Real_Time;
procedure UART_429Disco is
UART_Port: GPIO_Registers renames GPIOA;
UART_TX_Bit: constant Port_Bit_Number := 9;
UART_RX_Bit: constant Port_Bit_Number := 10;
UART_Module: USART_Registers renames USART1;
procedure UART_Transmit(Data : String) is
begin
for I of Data loop
while not UART_Module.SR.TXE loop
null;
end loop;
UART_Module.DR := Character'Pos(I);
end loop;
end;
APB2_Frequency : constant := 90_000_000; -- Set by board support
Baud_Rate : constant := 115_200;
Ratio : constant := (APB2_Frequency + Baud_Rate / 2) / Baud_Rate;
Period: constant Time_Span := Milliseconds(100);
Now: Time := Clock;
begin
RCC.AHB1ENR.GPIOA := True;
RCC.APB2ENR.USART1 := True;
RCC.APB2RSTR.USART1 := True;
RCC.APB2RSTR.USART1 := False;
UART_Port.AFR(UART_TX_Bit) := Alternate_Functions.USART1;
UART_Port.MODER(UART_TX_Bit) := Alternate_Mode;
UART_Port.OSPEEDR(UART_TX_Bit) := Low_Speed;
UART_Port.OTYPER(UART_TX_Bit) := Push_Pull_Type;
UART_Port.PUPDR(UART_TX_Bit) := Pull_Down;
UART_Port.AFR(UART_RX_Bit) := Alternate_Functions.USART1;
UART_Port.MODER(UART_RX_Bit) := Alternate_Mode;
UART_Port.OSPEEDR(UART_RX_Bit) := Low_Speed;
UART_Port.OTYPER(UART_RX_Bit) := Push_Pull_Type;
UART_Port.PUPDR(UART_RX_Bit) := Pull_Down;
declare
R : Control_Register_1 := UART_Module.CR1;
begin
R.UE := False;
UART_Module.CR1 := R;
end;
declare
R : Control_Register_1 := UART_Module.CR1;
begin
R.M := Word_8_Bits;
R.PCE := False;
R.PS := Even_Parity;
R.TE := True;
R.RE := True;
R.OVER8 := False;
UART_Module.CR1 := R;
end;
declare
R : Control_Register_2 := UART_Module.CR2;
begin
R.STOP := Stop_1_Bit;
R.LINEN := False;
R.CLKEN := False;
UART_Module.CR2 := R;
end;
declare
R : Control_Register_3 := UART_Module.CR3;
begin
R.SCEN := False;
R.HDSEL := False;
R.IREN := False;
R.RTSE := False;
R.CTSE := False;
UART_Module.CR3 := R;
end;
UART_Module.BRR := (DIV_Mantissa => Ratio / 16, DIV_Fraction => Ratio mod 16, others => 0);
declare
R : Control_Register_1 := UART_Module.CR1;
begin
R.UE := True;
UART_Module.CR1 := R;
end;
loop
UART_Transmit("Hello World! ... ");
Now := Now + Period;
delay until Now;
end loop;
end UART_429Disco;