Skip to content
Closed
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
10 changes: 5 additions & 5 deletions arch/ARM/STM32/drivers/sai/stm32-sai.ads
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
------------------------------------------------------------------------------
-- --
-- Copyright (C) 2016, AdaCore --
-- Copyright (C) 2016-2026, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
Expand Down Expand Up @@ -188,7 +188,7 @@ package STM32.SAI is
(FS_Frame,
FS_Frame_And_Channel_Identification)
with Size => 1;
-- Meaningless and is not used in AC97 or SPDIF audio block
-- Meaningless and is not used in AC'97 or SPDIF audio block
-- configuration. It must be configured when the audio block is disabled.
--
-- In case of FS_Frame_And_Channel_Identification, the number of slots
Expand All @@ -206,7 +206,7 @@ package STM32.SAI is
FS_Active_High)
with Size => 1;
-- It is used to configure the level of the start of frame on the FS
-- signal. It is meaningless and is not used in AC97 or SPDIF audio
-- signal. It is meaningless and is not used in AC'97 or SPDIF audio
-- block configuration.
--
-- FS_Active_Low: FS is active low (falling edge)
Expand All @@ -216,7 +216,7 @@ package STM32.SAI is
(First_Bit,
Before_First_Bit)
with Size => 1;
-- Meaningless and is not used in AC97 or SPDIF audio block
-- Meaningless and is not used in AC'97 or SPDIF audio block
-- configuration. This bit must be configured when the audio block
-- is disabled.
-- First_Bit: FS is asserted on the first bit of the slot 0.
Expand All @@ -231,7 +231,7 @@ package STM32.SAI is
-- The slot size must be higher or equal to the data size. If this
-- condition is not respected, the behavior of the SAI will be
-- undetermined.
-- Ignored in AC97 or SPDIF mode.
-- Ignored in AC'97 or SPDIF mode.
-- Data_Size: The slot size is equivalent to the data size (specified in
-- DS[3:0] in the SAI_xCR1 register).

Expand Down
89 changes: 67 additions & 22 deletions arch/ARM/STM32/drivers/stm32-dac.adb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
------------------------------------------------------------------------------
-- --
-- Copyright (C) 2015, AdaCore --
-- Copyright (C) 2015-2026, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
Expand Down Expand Up @@ -115,11 +115,9 @@ package body STM32.DAC is
when DAC_Resolution_12_Bits =>
case Alignment is
when Left_Aligned =>
This.DHR12L1.DACC1DHR :=
UInt12 (Value and Max_12bit_Resolution);
This.DHR12L1.DACC1DHR := UInt12 (Value and Max_12bit_Resolution);
when Right_Aligned =>
This.DHR12R1.DACC1DHR :=
UInt12 (Value and Max_12bit_Resolution);
This.DHR12R1.DACC1DHR := UInt12 (Value and Max_12bit_Resolution);
end case;
when DAC_Resolution_8_Bits =>
This.DHR8R1.DACC1DHR := UInt8 (Value and Max_8bit_Resolution);
Expand All @@ -130,11 +128,9 @@ package body STM32.DAC is
when DAC_Resolution_12_Bits =>
case Alignment is
when Left_Aligned =>
This.DHR12L2.DACC2DHR :=
UInt12 (Value and Max_12bit_Resolution);
This.DHR12L2.DACC2DHR := UInt12 (Value and Max_12bit_Resolution);
when Right_Aligned =>
This.DHR12R2.DACC2DHR :=
UInt12 (Value and Max_12bit_Resolution);
This.DHR12R2.DACC2DHR := UInt12 (Value and Max_12bit_Resolution);
end case;
when DAC_Resolution_8_Bits =>
This.DHR8R2.DACC2DHR := UInt8 (Value and Max_8bit_Resolution);
Expand All @@ -143,6 +139,35 @@ package body STM32.DAC is
end case;
end Set_Output;

-----------------------------
-- Set_Dual_Channel_Output --
-----------------------------

procedure Set_Dual_Channel_Output
(This : in out Digital_To_Analog_Converter;
Channel_2_Data : UInt16;
Channel_1_Data : UInt16;
Resolution : DAC_Resolution;
Alignment : Data_Alignment)
is
begin
-- See RM0385 Rev 8, sections 16.5.9 .. 16.5.11 for these registers
case Resolution is
when DAC_Resolution_12_Bits =>
case Alignment is
when Left_Aligned =>
This.DHR12LD.DACC2DHR := UInt12 (Channel_2_Data and Max_12bit_Resolution);
This.DHR12LD.DACC1DHR := UInt12 (Channel_1_Data and Max_12bit_Resolution);
when Right_Aligned =>
This.DHR12RD.DACC2DHR := UInt12 (Channel_2_Data and Max_12bit_Resolution);
This.DHR12RD.DACC1DHR := UInt12 (Channel_1_Data and Max_12bit_Resolution);
end case;
when DAC_Resolution_8_Bits =>
This.DHR8RD.DACC2DHR := UInt8 (Channel_2_Data and Max_8bit_Resolution);
This.DHR8RD.DACC1DHR := UInt8 (Channel_1_Data and Max_8bit_Resolution);
end case;
end Set_Dual_Channel_Output;

------------------------------------
-- Trigger_Conversion_By_Software --
------------------------------------
Expand Down Expand Up @@ -194,21 +219,15 @@ package body STM32.DAC is
when DAC_Resolution_12_Bits =>
case Alignment is
when Left_Aligned =>
This.DHR12LD.DACC1DHR :=
UInt12 (Channel_1_Value and Max_12bit_Resolution);
This.DHR12LD.DACC2DHR :=
UInt12 (Channel_2_Value and Max_12bit_Resolution);
This.DHR12LD.DACC1DHR := UInt12 (Channel_1_Value and Max_12bit_Resolution);
This.DHR12LD.DACC2DHR := UInt12 (Channel_2_Value and Max_12bit_Resolution);
when Right_Aligned =>
This.DHR12RD.DACC1DHR :=
UInt12 (Channel_1_Value and Max_12bit_Resolution);
This.DHR12RD.DACC2DHR :=
UInt12 (Channel_2_Value and Max_12bit_Resolution);
This.DHR12RD.DACC1DHR := UInt12 (Channel_1_Value and Max_12bit_Resolution);
This.DHR12RD.DACC2DHR := UInt12 (Channel_2_Value and Max_12bit_Resolution);
end case;
when DAC_Resolution_8_Bits =>
This.DHR8RD.DACC1DHR :=
UInt8 (Channel_1_Value and Max_8bit_Resolution);
This.DHR8RD.DACC2DHR :=
UInt8 (Channel_2_Value and Max_8bit_Resolution);
This.DHR8RD.DACC1DHR := UInt8 (Channel_1_Value and Max_8bit_Resolution);
This.DHR8RD.DACC2DHR := UInt8 (Channel_2_Value and Max_8bit_Resolution);
end case;
end Set_Dual_Output_Voltages;

Expand Down Expand Up @@ -682,10 +701,36 @@ package body STM32.DAC is
when DAC_Resolution_8_Bits =>
Result := This.DHR8R2'Address;
end case;

end case;

return Result;
end Data_Address;

----------------------------------
-- Data_Address_Dual_Conversion --
----------------------------------

function Data_Address_Dual_Conversion
(This : Digital_To_Analog_Converter;
Resolution : DAC_Resolution;
Alignment : Data_Alignment)
return Address
is
Result : Address;
begin
case Resolution is
when DAC_Resolution_12_Bits =>
case Alignment is
when Left_Aligned =>
Result := This.DHR12LD'Address;
when Right_Aligned =>
Result := This.DHR12RD'Address;
end case;
when DAC_Resolution_8_Bits =>
Result := This.DHR8RD'Address;
end case;

return Result;
end Data_Address_Dual_Conversion;

end STM32.DAC;
32 changes: 29 additions & 3 deletions arch/ARM/STM32/drivers/stm32-dac.ads
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
------------------------------------------------------------------------------
-- --
-- Copyright (C) 2015, AdaCore --
-- Copyright (C) 2015-2026, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
Expand Down Expand Up @@ -51,7 +51,9 @@ package STM32.DAC is

type DAC_Channel is (Channel_1, Channel_2);

-- Note that Channel 1 is tied to GPIO pin PA4, and Channel 2 to PA5
-- Note that Channel 1 is tied to GPIO pin PA4, and Channel 2 to PA5.
-- Note that Channel 1 is mapped to DMA1 Stream 5 channel 7.
-- Note that Channel 2 is mapped on DMA1 Stream 6 channel 7.

procedure Enable
(This : in out Digital_To_Analog_Converter;
Expand Down Expand Up @@ -88,6 +90,8 @@ package STM32.DAC is
Max_8bit_Resolution : constant := 16#00FF#;

type Data_Alignment is (Left_Aligned, Right_Aligned);
-- These only apply when using 12-bit resolution. For 8-bit resolution the
-- alignment is always right-aligned.

procedure Set_Output
(This : in out Digital_To_Analog_Converter;
Expand All @@ -102,6 +106,18 @@ package STM32.DAC is
-- the reference input voltage and the 'n' of Max_nbit_Counts is either 12
-- or 8.

procedure Set_Dual_Channel_Output
(This : in out Digital_To_Analog_Converter;
Channel_2_Data : UInt16;
Channel_1_Data : UInt16;
Resolution : DAC_Resolution;
Alignment : Data_Alignment);
-- This routine writes the 32-bit value, composed from the two 16-bit
-- values, with the necessary layout (8/12left-right alignment) to
-- the appropriate output register for conversion on both channels
-- simultaneously. DMA is the alternative to software calling this
-- procedure.

procedure Trigger_Conversion_By_Software
(This : in out Digital_To_Analog_Converter;
Channel : DAC_Channel)
Expand Down Expand Up @@ -328,7 +344,17 @@ package STM32.DAC is
Alignment : Data_Alignment)
return Address;
-- Returns the address of the Data Holding register within This, for the
-- specified Channel, at the specified Resolution and Alignment.
-- specified Channel, given the specified Resolution and Alignment.
--
-- This function is stricly for use with DMA, all others use the API above.

function Data_Address_Dual_Conversion
(This : Digital_To_Analog_Converter;
Resolution : DAC_Resolution;
Alignment : Data_Alignment)
return Address;
-- Returns the address of the Data Holding register within This, for the
-- dual conversion case, given the specified Resolution and Alignment.
--
-- This function is stricly for use with DMA, all others use the API above.

Expand Down
19 changes: 12 additions & 7 deletions arch/ARM/STM32/drivers/stm32-rng-polling.adb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
------------------------------------------------------------------------------
-- --
-- Copyright (C) 2015, AdaCore --
-- Copyright (C) 2015-2026, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
Expand Down Expand Up @@ -50,9 +50,7 @@ package body STM32.RNG.Polling is
begin
Enable_RNG_Clock;
Enable_RNG;

-- Discard the first randomly generated number, according to STM32F4
-- docs.
-- Discard the first generated number, according to STM32F4 docs.
Discard := Random;
end Initialize_RNG;

Expand All @@ -61,10 +59,17 @@ package body STM32.RNG.Polling is
------------

function Random return UInt32 is
Max_Attempts : constant := 1000;
-- The above is arbitrary. It needs to be long enough that normal
-- behavior will not be flagged. Longer than that is fine. The point
-- is to not hang forever.
begin
while not RNG_Data_Ready loop
null;
end loop;
Await_Ready : for K in 1 .. Max_Attempts loop
exit when RNG_Data_Ready;
if K = Max_Attempts then
raise Program_Error with "RNG data not ready";
end if;
end loop Await_Ready;
return RNG_Data;
end Random;

Expand Down
Loading
Loading