diff --git a/examples/led_flasher/source/led_flasher.adb b/examples/led_flasher/source/led_flasher.adb index e2f493c..55fb83e 100644 --- a/examples/led_flasher/source/led_flasher.adb +++ b/examples/led_flasher/source/led_flasher.adb @@ -1,6 +1,6 @@ with STM32.STM32F407Z; use STM32.STM32F407Z; -with STM32.General_Purpose_IO; use STM32.General_Purpose_IO; -with STM32.Registers.GPIO; use STM32.Registers.GPIO; +use STM32.STM32F407Z.Modules.GPIO; +with STM32.STM32F4.GPIO.Ports; use STM32.STM32F4.GPIO.Ports; with Ada.Real_Time; use Ada.Real_Time; procedure LED_Flasher is @@ -9,6 +9,7 @@ procedure LED_Flasher is Now: Time := Clock; LED_Port: GPIO_Registers renames GPIOD; LED_Bit: constant Port_Bit_Number := 3; + LED_On: constant Boolean := False; package LED is new GPIO_Port_Boolean(LED_Port, LED_Bit); begin RCC.AHB1ENR.GPIOD := True; @@ -17,9 +18,9 @@ begin LED_Port.OSPEEDR(LED_Bit) := Very_High_Speed; LED_Port.PUPDR(LED_Bit) := No_Pull; loop - LED.Set(False); + LED.Set(LED_On); delay until Now + On_Time; - LED.Set(True); + LED.Set(not LED_On); Now := Now + Period; delay until Now; end loop; diff --git a/examples/led_flasher/source/led_flasher_429disco.adb b/examples/led_flasher/source/led_flasher_429disco.adb index 362df60..e46c0c8 100644 --- a/examples/led_flasher/source/led_flasher_429disco.adb +++ b/examples/led_flasher/source/led_flasher_429disco.adb @@ -1,6 +1,6 @@ with STM32.STM32F429Z; use STM32.STM32F429Z; -with STM32.General_Purpose_IO; use STM32.General_Purpose_IO; -with STM32.Registers.GPIO; use STM32.Registers.GPIO; +use STM32.STM32F429Z.Modules.GPIO; +with STM32.STM32F4.GPIO.Ports; use STM32.STM32F4.GPIO.Ports; with Ada.Real_Time; use Ada.Real_Time; procedure LED_Flasher_429disco is @@ -9,6 +9,7 @@ procedure LED_Flasher_429disco is Now: Time := Clock; LED_Port: GPIO_Registers renames GPIOG; LED_Bit: constant Port_Bit_Number := 13; + LED_On: constant Boolean := True; package LED is new GPIO_Port_Boolean(LED_Port, LED_Bit); begin RCC.AHB1ENR.GPIOG := True; @@ -17,9 +18,9 @@ begin LED_Port.OSPEEDR(LED_Bit) := Very_High_Speed; LED_Port.PUPDR(LED_Bit) := No_Pull; loop - LED.Set(True); + LED.Set(LED_On); delay until Now + On_Time; - LED.Set(False); + LED.Set(not LED_On); Now := Now + Period; delay until Now; end loop; diff --git a/source/stm32-general_purpose_io.ads b/source/stm32-general_purpose_io.ads deleted file mode 100644 index 5faf636..0000000 --- a/source/stm32-general_purpose_io.ads +++ /dev/null @@ -1,25 +0,0 @@ -with Interfaces; -with STM32.Registers.GPIO; - -package STM32.General_Purpose_IO is - -- Single GPIO pin - generic - Register: in out Registers.GPIO.GPIO_Registers; - Bit: Registers.GPIO.Port_Bit_Number; - package GPIO_Port_Boolean is - procedure Set(Value: Boolean) with Inline; -- Output to port - function Value return Boolean with Inline; -- Read port - end GPIO_Port_Boolean; - - -- Multi-pin GPIO - generic - type Format is mod <>; - Register: in out Registers.GPIO.GPIO_Registers; - First_Bit: Registers.GPIO.Port_Bit_Number; - Last_Bit: Registers.GPIO.Port_Bit_NUmber; - package GPIO_Port_Modular is - procedure Set(Value: Format) with Inline; - function Value return Format with Inline; - end GPIO_Port_Modular; - -end STM32.General_Purpose_IO; diff --git a/source/stm32-registers-stm32f4_map.ads b/source/stm32-stm32f4-address_map.ads similarity index 85% rename from source/stm32-registers-stm32f4_map.ads rename to source/stm32-stm32f4-address_map.ads index 8a5f4dc..fc62967 100644 --- a/source/stm32-registers-stm32f4_map.ads +++ b/source/stm32-stm32f4-address_map.ads @@ -1,4 +1,4 @@ -package STM32.Registers.STM32F4_Map is +package STM32.STM32F4.Address_Map is pragma Pure; @@ -29,6 +29,8 @@ package STM32.Registers.STM32F4_Map is CAN2: constant := 16#4000_6800#; PWR: constant := 16#4000_7000#; DAC: constant := 16#4000_7400#; + UART7: constant := 14#4000_7800#; + UART8: constant := 14#4000_7C00#; TIM1: constant := 16#4001_0000#; TIM8: constant := 16#4001_0400#; USART1: constant := 16#4001_1000#; @@ -36,6 +38,7 @@ package STM32.Registers.STM32F4_Map is ADC1_2_3: constant := 16#4001_2000#; SDIO: constant := 16#4001_2C00#; SPI1: constant := 16#4001_3000#; + SPI4: constant := 16#4001_3400#; SYSCFG: constant := 16#4001_3800#; EXTI: constant := 16#4001_3C00#; TIM9: constant := 16#4001_4000#; @@ -50,6 +53,8 @@ package STM32.Registers.STM32F4_Map is GPIOG: constant := 16#4002_1800#; GPIOH: constant := 16#4002_1C00#; GPIOI: constant := 16#4002_2000#; + GPIOJ: constant := 16#4002_2400#; + GPIOK: constant := 16#4002_2800#; CRC: constant := 16#4002_3000#; RCC: constant := 16#4002_3800#; Flash_IR: constant := 16#4002_3C00#; @@ -57,14 +62,17 @@ package STM32.Registers.STM32F4_Map is DMA1: constant := 16#4002_6000#; DMA2: constant := 16#4002_6400#; Ethernet_MAC:constant := 16#4002_8000#; + DMA2D: constant := 16#4002_B000#; USB_OTG_HS: constant := 16#4004_0000#; USB_OTG_FS: constant := 16#5000_0000#; DCMI: constant := 16#5005_0000#; + CRYP: constant := 16#5006_0000#; + HASH: constant := 16#5006_0400#; RNG: constant := 16#5006_0800#; FSMC_Bank1: constant := 16#6000_0000#; FSMC_Bank2: constant := 16#7000_0000#; FSMC_Bank3: constant := 16#8000_0000#; FSMC_Bank4: constant := 16#9000_0000#; - FSMC: constant := 16#A000_0000#; + FMC_FSMC: constant := 16#A000_0000#; -end STM32.Registers.STM32F4_Map; +end STM32.STM32F4.Address_Map; diff --git a/source/stm32-general_purpose_io.adb b/source/stm32-stm32f4-gpio-ports.adb similarity index 74% rename from source/stm32-general_purpose_io.adb rename to source/stm32-stm32f4-gpio-ports.adb index a8baecc..c37de78 100644 --- a/source/stm32-general_purpose_io.adb +++ b/source/stm32-stm32f4-gpio-ports.adb @@ -1,7 +1,7 @@ with Interfaces; use Interfaces; -package body STM32.General_Purpose_IO is +package body STM32.STM32F4.GPIO.Ports is package body GPIO_Port_Boolean is @@ -25,7 +25,7 @@ package body STM32.General_Purpose_IO is Size: constant Positive := 1 + Last_Bit - First_Bit; Mask: constant Unsigned_16 := 2**(Last_Bit + 1) - 2**First_Bit; - procedure Set(Value: Format) is + procedure Set(Value: Value_Type) is begin Register.BSRR := ( BR => Mask, @@ -33,11 +33,11 @@ package body STM32.General_Purpose_IO is ); end; - function Value return Format is + function Value return Value_Type is begin - return Format((Register.IDR / 2**First_Bit) and (2**Size - 1)); + return Value_Type((Register.IDR / 2**First_Bit) and (2**Size - 1)); end; end GPIO_Port_Modular; -end STM32.General_Purpose_IO; +end STM32.STM32F4.GPIO.Ports; diff --git a/source/stm32-stm32f4-gpio-ports.ads b/source/stm32-stm32f4-gpio-ports.ads new file mode 100644 index 0000000..08d41bd --- /dev/null +++ b/source/stm32-stm32f4-gpio-ports.ads @@ -0,0 +1,24 @@ +with Interfaces; + +package STM32.STM32F4.GPIO.Ports is + -- Single GPIO pin + generic + Register: in out GPIO_Registers; + Bit: Port_Bit_Number; + package GPIO_Port_Boolean is + procedure Set(Value: Boolean) with Inline; -- Output to port + function Value return Boolean with Inline; -- Read port + end GPIO_Port_Boolean; + + -- Multi-pin GPIO + generic + type Value_Type is mod <>; + Register: in out GPIO_Registers; + First_Bit: Port_Bit_Number; + Last_Bit: Port_Bit_Number; + package GPIO_Port_Modular is + procedure Set(Value: Value_Type) with Inline; + function Value return Value_Type with Inline; + end GPIO_Port_Modular; + +end STM32.STM32F4.GPIO.Ports; diff --git a/source/stm32-registers-gpio.ads b/source/stm32-stm32f4-gpio.ads similarity index 98% rename from source/stm32-registers-gpio.ads rename to source/stm32-stm32f4-gpio.ads index 94b364d..9a18973 100644 --- a/source/stm32-registers-gpio.ads +++ b/source/stm32-stm32f4-gpio.ads @@ -1,7 +1,7 @@ with Interfaces; use Interfaces; -package STM32.Registers.GPIO is +package STM32.STM32F4.GPIO is pragma Pure; subtype Port_Bit_Number is Natural range 0 .. 15; @@ -175,4 +175,4 @@ package STM32.Registers.GPIO is AFR at 16#20# range 0 .. 63; end record; -end STM32.Registers.GPIO; \ No newline at end of file +end STM32.STM32F4.GPIO; \ No newline at end of file diff --git a/source/stm32-stm32f4.ads b/source/stm32-stm32f4.ads new file mode 100644 index 0000000..bf744ee --- /dev/null +++ b/source/stm32-stm32f4.ads @@ -0,0 +1,3 @@ +package STM32.STM32F4 is + pragma Pure; +end STM32.STM32F4; \ No newline at end of file diff --git a/source/stm32-stm32f407z.ads b/source/stm32-stm32f407z.ads index ca74e88..843dc52 100644 --- a/source/stm32-stm32f407z.ads +++ b/source/stm32-stm32f407z.ads @@ -1,56 +1,56 @@ with System; -with STM32.Registers.GPIO; +with STM32.STM32F4.GPIO; with STM32.Registers.RCC; with STM32.Registers.EXTI; with STM32.Registers.SYSCFG; with STM32.Registers.FSMC; -with STM32.Registers.STM32F4_Map; +with STM32.STM32F4.Address_Map; package STM32.STM32F407Z is pragma Preelaborate; + package Address_Map renames STM32.STM32F4.Address_Map; + package Modules is + package EXTI renames STM32.Registers.EXTI; + package FSMC renames STM32.Registers.FSMC; + package GPIO renames STM32.STM32F4.GPIO; + --package GPIO_Ports renames STM32.STM32F4.GPIO.Ports; + package RCC renames STM32.Registers.RCC; + package SYSCFG renames STM32.Registers.SYSCFG; + end Modules; + --pragma Warnings (Off, "* may call Last_Chance_Handler"); --pragma Warnings (Off, "* may be incompatible with alignment of object"); - EXTI: Registers.EXTI.EXTI_Registers - with Volatile, Import, - Address => System'To_Address(Registers.STM32F4_Map.EXTI); + EXTI: Modules.EXTI.EXTI_Registers + with Volatile, Import, Address => System'To_Address(Address_Map.EXTI); - FSMC: Registers.FSMC.FSMC_Registers - with Volatile, Import, - Address => System'To_Address(Registers.STM32F4_Map.FSMC); + FSMC: Modules.FSMC.FSMC_Registers + with Volatile, Import, Address => System'To_Address(Address_Map.FMC_FSMC); - GPIOA: Registers.GPIO.GPIO_Registers - with Volatile, Import, - Address => System'To_Address(Registers.STM32F4_Map.GPIOA); + GPIOA: Modules.GPIO.GPIO_Registers + with Volatile, Import, Address => System'To_Address(Address_Map.GPIOA); - GPIOC: Registers.GPIO.GPIO_Registers - with Volatile, Import, - Address => System'To_Address(Registers.STM32F4_Map.GPIOC); + GPIOC: Modules.GPIO.GPIO_Registers + with Volatile, Import, Address => System'To_Address(Address_Map.GPIOC); - GPIOD: Registers.GPIO.GPIO_Registers - with Volatile, Import, - Address => System'To_Address(Registers.STM32F4_Map.GPIOD); + GPIOD: Modules.GPIO.GPIO_Registers + with Volatile, Import, Address => System'To_Address(Address_Map.GPIOD); - GPIOE: Registers.GPIO.GPIO_Registers - with Volatile, Import, - Address => System'To_Address(Registers.STM32F4_Map.GPIOE); + GPIOE: Modules.GPIO.GPIO_Registers + with Volatile, Import, Address => System'To_Address(Address_Map.GPIOE); - GPIOF: Registers.GPIO.GPIO_Registers - with Volatile, Import, - Address => System'To_Address(Registers.STM32F4_Map.GPIOF); + GPIOF: Modules.GPIO.GPIO_Registers + with Volatile, Import, Address => System'To_Address(Address_Map.GPIOF); - GPIOG: Registers.GPIO.GPIO_Registers - with Volatile, Import, - Address => System'To_Address(Registers.STM32F4_Map.GPIOG); + GPIOG: Modules.GPIO.GPIO_Registers + with Volatile, Import, Address => System'To_Address(Address_Map.GPIOG); - RCC: Registers.RCC.RCC_Registers - with Volatile, Import, - Address => System'To_Address(Registers.STM32F4_Map.RCC); + RCC: Modules.RCC.RCC_Registers + with Volatile, Import, Address => System'To_Address(Address_Map.RCC); - SYSCFG: Registers.SYSCFG.SYSCFG_Registers - with Volatile, Import, - Address => System'To_Address(Registers.STM32F4_Map.SYSCFG); + SYSCFG: Modules.SYSCFG.SYSCFG_Registers + with Volatile, Import, Address => System'To_Address(Address_Map.SYSCFG); --pragma Warnings (On, "* may call Last_Chance_Handler"); --pragma Warnings (On, "* may be incompatible with alignment of object"); diff --git a/source/stm32-stm32f429z.ads b/source/stm32-stm32f429z.ads index a8b9734..dcbdc96 100644 --- a/source/stm32-stm32f429z.ads +++ b/source/stm32-stm32f429z.ads @@ -1,66 +1,61 @@ with System; -with STM32.Registers.GPIO; +with STM32.STM32F4.GPIO; with STM32.Registers.EXTI; +with STM32.Registers.RCC; with STM32.Registers.SYSCFG; -with STM32.Registers.STM32F4_Map; +with STM32.STM32F4.Address_Map; package STM32.STM32F429Z is pragma Preelaborate; - EXTI: Registers.EXTI.EXTI_Registers - with Volatile, Import, - Address => System'To_Address(Registers.STM32F4_Map.EXTI); + package Address_Map renames STM32.STM32F4.Address_Map; + package Modules is + package EXTI renames STM32.Registers.EXTI; + package GPIO renames STM32.STM32F4.GPIO; + package RCC renames STM32.Registers.RCC; + package SYSCFG renames STM32.Registers.SYSCFG; + end Modules; - GPIOA: Registers.GPIO.GPIO_Registers - with Volatile, Import, - Address => System'To_Address(Registers.STM32F4_Map.GPIOA); + EXTI: Modules.EXTI.EXTI_Registers + with Volatile, Import, Address => System'To_Address(Address_Map.EXTI); - GPIOB: Registers.GPIO.GPIO_Registers - with Volatile, Import, - Address => System'To_Address(Registers.STM32F4_Map.GPIOB); + GPIOA: Modules.GPIO.GPIO_Registers + with Volatile, Import, Address => System'To_Address(Address_Map.GPIOA); - GPIOC: Registers.GPIO.GPIO_Registers - with Volatile, Import, - Address => System'To_Address(Registers.STM32F4_Map.GPIOC); + GPIOB: Modules.GPIO.GPIO_Registers + with Volatile, Import, Address => System'To_Address(Address_Map.GPIOB); - GPIOD: Registers.GPIO.GPIO_Registers - with Volatile, Import, - Address => System'To_Address(Registers.STM32F4_Map.GPIOD); + GPIOC: Modules.GPIO.GPIO_Registers + with Volatile, Import, Address => System'To_Address(Address_Map.GPIOC); - GPIOE: Registers.GPIO.GPIO_Registers - with Volatile, Import, - Address => System'To_Address(Registers.STM32F4_Map.GPIOE); + GPIOD: Modules.GPIO.GPIO_Registers + with Volatile, Import, Address => System'To_Address(Address_Map.GPIOD); - GPIOF: Registers.GPIO.GPIO_Registers - with Volatile, Import, - Address => System'To_Address(Registers.STM32F4_Map.GPIOF); + GPIOE: Modules.GPIO.GPIO_Registers + with Volatile, Import, Address => System'To_Address(Address_Map.GPIOE); - GPIOG: Registers.GPIO.GPIO_Registers - with Volatile, Import, - Address => System'To_Address(Registers.STM32F4_Map.GPIOG); + GPIOF: Modules.GPIO.GPIO_Registers + with Volatile, Import, Address => System'To_Address(Address_Map.GPIOF); - GPIOH: Registers.GPIO.GPIO_Registers - with Volatile, Import, - Address => System'To_Address(Registers.STM32F4_Map.GPIOH); + GPIOG: Modules.GPIO.GPIO_Registers + with Volatile, Import, Address => System'To_Address(Address_Map.GPIOG); - GPIOI: Registers.GPIO.GPIO_Registers - with Volatile, Import, - Address => System'To_Address(Registers.STM32F4_Map.GPIOI); + GPIOH: Modules.GPIO.GPIO_Registers + with Volatile, Import, Address => System'To_Address(Address_Map.GPIOH); - GPIOJ: Registers.GPIO.GPIO_Registers - with Volatile, Import, - Address => System'To_Address(Registers.STM32F4_Map.GPIOJ); + GPIOI: Modules.GPIO.GPIO_Registers + with Volatile, Import, Address => System'To_Address(Address_Map.GPIOI); - GPIOK: Registers.GPIO.GPIO_Registers - with Volatile, Import, - Address => System'To_Address(Registers.STM32F4_Map.GPIOK); + GPIOJ: Modules.GPIO.GPIO_Registers + with Volatile, Import, Address => System'To_Address(Address_Map.GPIOJ); - RCC: Registers.RCC.RCC_Registers - with Volatile, Import, - Address => System'To_Address(Registers.STM32F4_Map.RCC); + GPIOK: Modules.GPIO.GPIO_Registers + with Volatile, Import, Address => System'To_Address(Address_Map.GPIOK); - SYSCFG: Registers.SYSCFG.SYSCFG_Registers - with Volatile, Import, - Address => System'To_Address(Registers.STM32F4_Map.SYSCFG); + RCC: Modules.RCC.RCC_Registers + with Volatile, Import, Address => System'To_Address(Address_Map.RCC); + + SYSCFG: Modules.SYSCFG.SYSCFG_Registers + with Volatile, Import, Address => System'To_Address(Address_Map.SYSCFG); end STM32.STM32F429Z; diff --git a/stm32_library.gpr b/stm32_library.gpr index 79a9fde..f306de5 100644 --- a/stm32_library.gpr +++ b/stm32_library.gpr @@ -6,7 +6,7 @@ project STM32_Library is for Library_Kind use "static"; --for Library_Interface use ("STM32", "STM32.STM32F407Z"); for Target use "arm-eabi"; - --for Runtime("ada") use "ravenscar-sfp-stm32f4"; + for Runtime("ada") use "zfp-stm32f4"; package Builder is for Default_Switches("Ada") use ( "-gnato",