+ Baud rate calculation function
This commit is contained in:
parent
37f1174946
commit
9bc2570d00
|
@ -1,7 +1,6 @@
|
||||||
with STM32.F429Z; use STM32.F429Z;
|
with STM32.F429Z; use STM32.F429Z;
|
||||||
use STM32.F429Z.Modules.GPIO;
|
use STM32.F429Z.Modules.GPIO;
|
||||||
use STM32.F429Z.Modules.USART;
|
use STM32.F429Z.Modules.USART;
|
||||||
use STM32.F429Z.Modules.RCC;
|
|
||||||
|
|
||||||
with Ada.Real_Time; use Ada.Real_Time;
|
with Ada.Real_Time; use Ada.Real_Time;
|
||||||
|
|
||||||
|
@ -23,8 +22,8 @@ procedure UART_429Disco is
|
||||||
end;
|
end;
|
||||||
|
|
||||||
APB2_Frequency : constant := 90_000_000; -- Set by board support
|
APB2_Frequency : constant := 90_000_000; -- Set by board support
|
||||||
Baud_Rate : constant := 115_200;
|
Baud : constant := 115_200;
|
||||||
Ratio : constant := (APB2_Frequency + Baud_Rate / 2) / Baud_Rate;
|
--Ratio : constant := (APB2_Frequency + Baud_Rate / 2) / Baud_Rate;
|
||||||
|
|
||||||
Period: constant Time_Span := Milliseconds(100);
|
Period: constant Time_Span := Milliseconds(100);
|
||||||
Now: Time := Clock;
|
Now: Time := Clock;
|
||||||
|
@ -92,7 +91,8 @@ begin
|
||||||
UART_Module.CR3 := R;
|
UART_Module.CR3 := R;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
UART_Module.BRR := (DIV_Mantissa => Ratio / 16, DIV_Fraction => Ratio mod 16, others => 0);
|
--UART_Module.BRR := (DIV_Mantissa => Ratio / 16, DIV_Fraction => Ratio mod 16, others => 0);
|
||||||
|
UART_Module.BRR := Baud_Rate (Speed => Baud, OVER8 => False, Bus_Frequency => APB2_Frequency);
|
||||||
|
|
||||||
declare
|
declare
|
||||||
R : Control_Register_1 := UART_Module.CR1;
|
R : Control_Register_1 := UART_Module.CR1;
|
||||||
|
@ -109,4 +109,4 @@ begin
|
||||||
delay until Now;
|
delay until Now;
|
||||||
end loop;
|
end loop;
|
||||||
|
|
||||||
end UART_429Disco;
|
end UART_429Disco;
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package body STM32.F4.USART is
|
||||||
|
|
||||||
|
function Baud_Rate (
|
||||||
|
Speed: Positive;
|
||||||
|
OVER8: Boolean;
|
||||||
|
Bus_Frequency: Positive)
|
||||||
|
return Baud_Rate_Register
|
||||||
|
is
|
||||||
|
Ratio : Natural := (Bus_Frequency + Speed / 2) / Speed;
|
||||||
|
Oversampling : Positive := (if OVER8 then 8 else 16);
|
||||||
|
begin
|
||||||
|
return (DIV_Mantissa => Ratio / Oversampling,
|
||||||
|
DIV_Fraction => Ratio mod Oversampling,
|
||||||
|
others => 0);
|
||||||
|
end;
|
||||||
|
|
||||||
|
end STM32.F4.USART;
|
|
@ -251,4 +251,10 @@ package STM32.F4.USART is
|
||||||
GTPR at 16#18# range 0 .. 31;
|
GTPR at 16#18# range 0 .. 31;
|
||||||
end record;
|
end record;
|
||||||
|
|
||||||
|
function Baud_Rate (
|
||||||
|
Speed: Positive;
|
||||||
|
OVER8: Boolean;
|
||||||
|
Bus_Frequency: Positive)
|
||||||
|
return Baud_Rate_Register;
|
||||||
|
|
||||||
end STM32.F4.USART;
|
end STM32.F4.USART;
|
||||||
|
|
Loading…
Reference in New Issue