Merge branch 'master' of git.disroot.org:Vovanium/stm32-ada

This commit is contained in:
Vovanium 2024-03-28 19:45:30 +03:00
commit 9f57a6c53b
28 changed files with 130 additions and 131 deletions

View File

@ -6,7 +6,7 @@ LIBRARY_TARGET = \
light_stm32f4_library \
light_tasking_stm32f4_library \
light_tasking_stm32f429disco_library \
stm32f4
all: library examples
@ -21,7 +21,7 @@ clean: $(LIBRARY_TARGET:%=%-clean)
gprclean -P library/gpr/$*.gpr
examples:
cd examples; make all
cd examples; $(MAKE) all
test:
echo $(TARGET)

View File

@ -1,8 +1,8 @@
all :
cd lcd_demo; make all
cd led_flasher; make all
cd sdram_test; make all
cd spi_lcd; make all
cd uart; make all
cd lcd_demo; $(MAKE) all
cd led_flasher; $(MAKE) all
cd sdram_test; $(MAKE) all
cd spi_lcd; $(MAKE) all
cd uart; $(MAKE) all
.PHONY: all
.PHONY: all

View File

@ -1,11 +1,9 @@
with STM32.GPIO, STM32.Reset_and_Clock;
use STM32.GPIO, STM32.Reset_and_Clock;
with STM32.GPIO.Ports, STM32.Reset_and_Clock;
use STM32.GPIO, STM32.Reset_and_Clock;
package Board is
LED_Port : GPIO_Registers renames GPIOC;
LED_Bit : constant Port_Bit_Number := 13;
LED_On : constant Boolean := False;
package LED is new Ports.GPIO_Port_Boolean (GPIOC, 13, Invert => True);
LED_RCC_EN : Boolean renames RCC.AHB1ENR (Index.GPIOC);

View File

@ -1,13 +0,0 @@
with STM32.GPIO, STM32.Reset_and_Clock;
use STM32.GPIO, STM32.Reset_and_Clock;
package Board is
LED_Port : GPIO_Registers renames GPIOD;
LED_Bit : constant Port_Bit_Number := 3;
LED_On : constant Boolean := False;
LED_RCC_EN : Boolean renames RCC.AHB1ENR (Index.GPIOD);
APB2_Frequency : constant := 84_000_000; -- Set by board support
end Board;

View File

@ -0,0 +1,11 @@
with STM32.GPIO.Ports, STM32.Reset_and_Clock;
use STM32.GPIO, STM32.Reset_and_Clock;
package Board is
package LED is new Ports.GPIO_Port_Boolean (GPIOD, 3, Invert => True);
LED_RCC_EN : Boolean renames RCC.AHB1ENR (Index.GPIOD);
APB2_Frequency : constant := 84_000_000; -- Set by board support
end Board;

View File

@ -1,19 +1,15 @@
with STM32.GPIO, STM32.Reset_and_Clock;
use STM32.GPIO, STM32.Reset_and_Clock;
with STM32.GPIO.Ports, STM32.Reset_and_Clock;
use STM32.GPIO, STM32.Reset_and_Clock;
package Board is
-- LED
LED_Port : GPIO_Registers renames GPIOG;
LED_Bit : constant Port_Bit_Number := 13;
LED_On : constant Boolean := True;
package LED is new Ports.GPIO_Port_Boolean (GPIOG, 13, Invert => False);
LED_RCC_EN : Boolean renames RCC.AHB1ENR (Index.GPIOG);
LED_2_Port : GPIO_Registers renames GPIOG;
LED_2_Bit : constant Port_Bit_Number := 14;
LED_2_On : constant Boolean := True;
package LED_2 is new Ports.GPIO_Port_Boolean (GPIOG, 14, Invert => False);
LED_2_RCC_EN : Boolean renames RCC.AHB1ENR (Index.GPIOG);

View File

@ -1,16 +1,15 @@
with Board; use Board;
with STM32.Reset_and_Clock; use STM32.Reset_and_Clock;
with STM32.GPIO.Ports;
use STM32.GPIO.Ports, STM32.GPIO;
with STM32.GPIO;
use STM32.GPIO;
with Ada.Real_Time; use Ada.Real_Time;
procedure LED_Flasher is
Period: constant Time_Span := Milliseconds(250);
On_Time: constant Time_Span := Milliseconds(10);
Now: Time := Clock;
package LED is new GPIO_Port_Boolean(LED_Port, LED_Bit);
Period : constant Time_Span := Milliseconds(250);
On_Time : constant Time_Span := Milliseconds(10);
Now : Time := Clock;
begin
LED_RCC_EN := True;
@ -19,9 +18,9 @@ begin
LED.Set_OSPEEDR (Very_High_Speed);
LED.Set_PUPDR (No_Pull);
loop
LED.Set (LED_On);
LED.Set (True);
delay until Now + On_Time;
LED.Set (not LED_On);
LED.Set (False);
Now := Now + Period;
delay until Now;
end loop;

View File

@ -1,36 +0,0 @@
with "../../library/gpr/stm32f4.gpr";
project LED_Flasher_429disco is
type Board_Type is ("401c_blackpill", "407z_piswords", "429disco");
Board : Board_Type := external ("BOARD");
case Board is
when "401c_blackpill" =>
for Runtime("Ada") use "light-tasking-stm32f401";
when "429disco" =>
for Runtime("Ada") use "light-tasking-stm32f429disco";
when others =>
for Runtime("Ada") use "light-tasking-stm32f4";
end case;
for Languages use("Ada");
for Main use("led_flasher.adb");
for Object_Dir use "objects/" & Board;
for Target use "arm-eabi";
for Source_Dirs use(".", "../common/" & Board);
package Compiler is
for Default_Switches("Ada") use ("-gnatwa.X", "-gnatQ", "-gnatn", "-O2");
end Compiler;
package Builder is
for Default_Switches("Ada") use ("-ggdb");
end Builder;
package IDE is
for Program_Host use "localhost:4242";
for Communication_Protocol use "remote";
for Connection_Tool use "st-util";
end IDE;
end LED_Flasher_429disco;

View File

@ -1,4 +1,4 @@
with "../../library/gpr/light_tasking_stm32f4_library.gpr";
with "../../library/gpr/light_tasking_stm32f401_library.gpr";
project LED_Flasher_401c_BlackPill is
for Languages use("Ada");

View File

@ -6,7 +6,7 @@ project LED_Flasher_407z_PiSwords is
for Object_Dir use "objects/407z_piswords";
for Target use "arm-eabi";
for Runtime("Ada") use "light-tasking-stm32f4";
for Source_Dirs use(".", "../common/407z-piswords");
for Source_Dirs use(".", "../common/407z_piswords");
package Compiler is
for Default_Switches("Ada") use ("-gnatwa.X", "-gnatQ", "-gnatn", "-O2");

View File

@ -1,12 +1,11 @@
with Board; use Board;
with STM32.Reset_and_Clock; use STM32.Reset_and_Clock;
with STM32.GPIO.Ports;
use STM32.GPIO.Ports, STM32.GPIO;
with STM32.GPIO;
use STM32.GPIO;
procedure LED_Flasher is
package LED is new GPIO_Port_Boolean(LED_Port, LED_Bit);
procedure Dly (X : Positive) is
begin
@ -22,9 +21,9 @@ begin
LED.Set_OSPEEDR (Very_High_Speed);
LED.Set_PUPDR (No_Pull);
loop
LED.Set (LED_On);
LED.Set (True);
Dly (1000000);
LED.Set (not LED_On);
LED.Set (False);
Dly (3000000);
end loop;
end Led_Flasher;

View File

@ -1,4 +1,4 @@
with "../../library/gpr/light_stm32f4_library.gpr";
with "../../library/gpr/light_stm32f401_library.gpr";
project LED_Flasher_401c_Blackpill is
for Languages use("Ada");

View File

@ -6,7 +6,7 @@ project Number_Game_407Z_PiSwords is
for Object_Dir use "objects/407z_piswords";
for Target use "arm-eabi";
for Runtime("Ada") use "light-tasking-stm32f4";
for Source_Dirs use(".", "../common", "../common/f4", "../common/407z-piswords");
for Source_Dirs use(".", "../common", "../common/f4", "../common/407z_piswords");
package Compiler is
for Default_Switches("Ada") use ("-gnatwa.X", "-gnatQ", "-gnatn", "-O2");

View File

@ -0,0 +1,12 @@
project Light_STM32F401_Library extends "stm32f4_library" is
Runtime := "light-stm32f401";
for Target use "arm-eabi";
for Runtime("ada") use Runtime;
for Object_Dir use STM32_Common'Object_Dir & "/" & Runtime;
for Library_Dir use STM32_Common'Library_Dir & "/" & Runtime;
for Source_Dirs use STM32F4_Library'Source_Dirs;
for Library_Name use "stm32";
end Light_STM32F401_Library;

View File

@ -0,0 +1,12 @@
project Light_Tasking_STM32F401_Library extends "stm32f4_library" is
Runtime := "light-tasking-stm32f401";
for Target use "arm-eabi";
for Runtime("ada") use Runtime;
for Object_Dir use STM32_Common'Object_Dir & "/" & Runtime;
for Library_Dir use STM32_Common'Library_Dir & "/" & Runtime;
for Source_Dirs use STM32F4_Library'Source_Dirs;
for Library_Name use "stm32";
end Light_Tasking_STM32F401_Library;

View File

@ -1,10 +0,0 @@
project STM32F4 extends "stm32f4_library" is
for Target use "arm-eabi";
for Runtime("ada") use "light-stm32f4"; -- Only CPU flags should make sense there
for Object_Dir use STM32_Common'Object_Dir & "/stm32f4";
for Library_Dir use STM32_Common'Library_Dir & "/stm32f4";
for Source_Dirs use STM32F4_Library'Source_Dirs;
for Library_Name use "stm32f4";
end STM32F4;

View File

@ -9,6 +9,9 @@ package STM32.Address_Map is
CCM_RAM : constant Address := To_Address (16#1000_0000#);
Option_Bytes : constant Address := To_Address (16#1FFE_C000#);
System_Memory : constant Address := To_Address (16#1FFF_0000#);
Unique_Id : constant Address := System_Memory + 16#7A10#;
Flash_Size : constant Address := System_Memory + 16#7A22#;
Package_Id : constant Address := System_Memory + 16#7BF0#;
Option_Bytes_2 : constant Address := To_Address (16#1FFF_C000#);
SRAM_1 : constant Address := To_Address (16#2000_0000#);
SRAM_2 : constant Address := To_Address (16#2001_C000#);

View File

@ -1,26 +1,14 @@
with STM32.Device_IDs;
with STM32.Address_Map;
-- Debug support
package STM32.Debug is
-- IDCODE
type Device_ID is mod 2**12;
DEV_ID_STM32F405 : constant Device_ID := 16#413#;
DEV_ID_STM32F407 : constant Device_ID := 16#413#;
DEV_ID_STM32F415 : constant Device_ID := 16#413#;
DEV_ID_STM32F417 : constant Device_ID := 16#413#;
DEV_ID_STM32F427 : constant Device_ID := 16#419#;
DEV_ID_STM32F429 : constant Device_ID := 16#419#;
DEV_ID_STM32F437 : constant Device_ID := 16#419#;
DEV_ID_STM32F439 : constant Device_ID := 16#419#;
type Revision_ID is range 0 .. 2**16 - 1;
type Device_ID_Register is record
DEV_ID : Device_ID; -- Device identifier
DEV_ID : Device_IDs.Device_ID; -- Device identifier
Unused_12 : Unused_4_Bits;
REV_ID : Revision_ID; -- Revision identifier
end record with Size => 32;

View File

@ -6,7 +6,7 @@ package body STM32.GPIO.Ports is
begin
Register.BSRR := (
BR => 2**Bit,
BS => 2**Bit * Boolean'Pos(Value)
BS => 2**Bit * Boolean'Pos(Value xor Invert)
);
end;
@ -44,20 +44,20 @@ package body STM32.GPIO.Ports is
package body GPIO_Port_Modular is
Size: constant Positive := 1 + Last_Bit - First_Bit;
Mask: constant Unsigned_16 := 2**(Last_Bit + 1) - 2**First_Bit;
Size : constant Positive := 1 + Last_Bit - First_Bit;
Mask : constant Unsigned_16 := 2**(Last_Bit + 1) - 2**First_Bit;
procedure Set(Value: Value_Type) is
procedure Set(Value : Value_Type) is
begin
Register.BSRR := (
BR => Mask,
BS => 2**First_Bit * Unsigned_16(Value)
BS => 2**First_Bit * Unsigned_16(Value xor Invert)
);
end;
function Value return Value_Type is
begin
return Value_Type((Register.IDR / 2**First_Bit) and (2**Size - 1));
return Value_Type((Register.IDR / 2**First_Bit) and (2**Size - 1)) xor Invert;
end;
procedure Set_MODER (Mode : Port_Mode) is

View File

@ -2,8 +2,9 @@ package STM32.GPIO.Ports is
-- Single GPIO pin
generic
Register : in out GPIO_Registers;
Bit : Port_Bit_Number;
Register : in out GPIO_Registers;
Bit : Port_Bit_Number;
Invert : Boolean := False;
package GPIO_Port_Boolean is
procedure Set (Value : Boolean) with Inline; -- Output to port
function Value return Boolean with Inline; -- Read port
@ -19,9 +20,10 @@ package STM32.GPIO.Ports is
-- Multi-pin GPIO
generic
type Value_Type is mod <>;
Register: in out GPIO_Registers;
First_Bit: Port_Bit_Number;
Last_Bit: Port_Bit_Number;
Register : in out GPIO_Registers;
First_Bit : Port_Bit_Number;
Last_Bit : Port_Bit_Number;
Invert : Value_Type := 0;
package GPIO_Port_Modular is
procedure Set(Value: Value_Type) with Inline;
function Value return Value_Type with Inline;

View File

@ -175,15 +175,15 @@ package STM32.GPIO is
with Pack, Size => 64;
type GPIO_Registers is record
MODER: Port_Mode_Register;
OTYPER: Output_Type_Register;
OSPEEDR: Output_Speed_Register;
PUPDR: Port_Pull_Register;
IDR: Interfaces.Unsigned_32;
ODR: Interfaces.Unsigned_32;
BSRR: Bit_Set_Reset_Register;
LCKR: Configuration_Lock_Register;
AFR: Alternate_Function_Register;
MODER : Port_Mode_Register;
OTYPER : Output_Type_Register;
OSPEEDR : Output_Speed_Register;
PUPDR : Port_Pull_Register;
IDR : Interfaces.Unsigned_32;
ODR : Interfaces.Unsigned_32;
BSRR : Bit_Set_Reset_Register;
LCKR : Configuration_Lock_Register;
AFR : Alternate_Function_Register;
end record with Volatile;
for GPIO_Registers use record

View File

@ -255,15 +255,23 @@ package STM32.I2Cs is
type I2C_Registers is record
CR1 : Control_Register_1;
pragma Volatile_Full_Access (CR1);
CR2 : Control_Register_2;
pragma Volatile_Full_Access (CR2);
OAR1 : Own_Address_Register_1;
pragma Volatile_Full_Access (OAR1);
OAR2 : Own_Address_Register_2;
pragma Volatile_Full_Access (OAR2);
DR : Integer range 0 .. 2**8 - 1 := 0;
SR1 : Status_Register_1;
pragma Volatile_Full_Access (SR1);
SR2 : Status_Register_2;
pragma Volatile_Full_Access (SR2);
CCR : Clock_Control_Register;
pragma Volatile_Full_Access (CCR);
TRISE : Integer range 0 .. 2**6 - 1 := 2;
FLTR : Filter_Register;
pragma Volatile_Full_Access (FLTR);
end record;
for I2C_Registers use record
CR1 at 16#00# range 0 .. 15;

View File

@ -0,0 +1,30 @@
package STM32.Device_IDs with Pure is
-- Device identifiers are retrived through DBG unit.
-- See Debug package.
type Device_ID is mod 2**12;
-- IDCODE
STM32F4x5_4x7 : constant Device_ID := 16#413#;
STM32F405 : constant Device_ID := STM32F4x5_4x7;
STM32F407 : constant Device_ID := STM32F4x5_4x7;
STM32F415 : constant Device_ID := STM32F4x5_4x7;
STM32F417 : constant Device_ID := STM32F4x5_4x7;
STM32F42x_43x : constant Device_ID := 16#419#;
STM32F427 : constant Device_ID := STM32F42x_43x;
STM32F429 : constant Device_ID := STM32F42x_43x;
STM32F437 : constant Device_ID := STM32F42x_43x;
STM32F439 : constant Device_ID := STM32F42x_43x;
STM32F446 : constant Device_ID := 16#421#;
STM32F401xB_xC : constant Device_ID := 16#423#;
STM32F401xD_xE : constant Device_ID := 16#433#;
STM32F411xC_xE : constant Device_ID := 16#431#;
STM32F46x_F47x : constant Device_ID := 16#434#;
STM32F412 : constant Device_ID := 16#441#;
STM32F410 : constant Device_ID := 16#458#;
STM32F413_F423 : constant Device_ID := 16#463#;
STM32F413 : constant Device_ID := STM32F413_F423;
STM32F423 : constant Device_ID := STM32F413_F423;
end STM32.Device_IDs;