-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy paths-stm32.ads
More file actions
197 lines (163 loc) · 7.16 KB
/
s-stm32.ads
File metadata and controls
197 lines (163 loc) · 7.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- Copyright (C) 2012-2020, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This file provides register definitions for the STM32Fx (ARM Cortex M4/7)
-- microcontrollers from ST Microelectronics.
with Interfaces.STM32;
package System.STM32 is
pragma No_Elaboration_Code_All;
pragma Preelaborate (System.STM32);
subtype Frequency is Interfaces.STM32.UInt32;
type RCC_System_Clocks is record
SYSCLK : Frequency;
HCLK : Frequency;
PCLK1 : Frequency;
PCLK2 : Frequency;
TIMCLK1 : Frequency;
TIMCLK2 : Frequency;
end record;
function System_Clocks return RCC_System_Clocks;
-- MODER constants
subtype GPIO_MODER_Values is Interfaces.STM32.UInt2;
Mode_IN : constant GPIO_MODER_Values := 0;
Mode_OUT : constant GPIO_MODER_Values := 1;
Mode_AF : constant GPIO_MODER_Values := 2;
Mode_AN : constant GPIO_MODER_Values := 3;
-- OTYPER constants
subtype GPIO_OTYPER_Values is Interfaces.STM32.Bit;
Push_Pull : constant GPIO_OTYPER_Values := 0;
Open_Drain : constant GPIO_OTYPER_Values := 1;
-- OSPEEDR constants
subtype GPIO_OSPEEDR_Values is Interfaces.STM32.UInt2;
Speed_2MHz : constant GPIO_OSPEEDR_Values := 0; -- Low speed
Speed_25MHz : constant GPIO_OSPEEDR_Values := 1; -- Medium speed
Speed_50MHz : constant GPIO_OSPEEDR_Values := 2; -- Fast speed
Speed_100MHz : constant GPIO_OSPEEDR_Values := 3; -- High speed
-- PUPDR constants
subtype GPIO_PUPDR_Values is Interfaces.STM32.UInt2;
No_Pull : constant GPIO_PUPDR_Values := 0;
Pull_Up : constant GPIO_PUPDR_Values := 1;
Pull_Down : constant GPIO_PUPDR_Values := 2;
-- AFL constants
AF_USART1 : constant Interfaces.STM32.UInt4 := 7;
AF_USART6 : constant Interfaces.STM32.UInt4 := 8;
type MCU_ID_Register is record
DEV_ID : Interfaces.STM32.UInt12;
Reserved : Interfaces.STM32.UInt4;
REV_ID : Interfaces.STM32.UInt16;
end record with Pack, Size => 32;
-- RCC constants
type PLL_Source is
(PLL_SRC_HSI,
PLL_SRC_HSE)
with Size => 1;
type SYSCLK_Source is
(SYSCLK_SRC_HSI,
SYSCLK_SRC_HSE,
SYSCLK_SRC_PLL)
with Size => 2;
type AHB_Prescaler_Enum is
(DIV2, DIV4, DIV8, DIV16,
DIV64, DIV128, DIV256, DIV512)
with Size => 3;
type AHB_Prescaler is record
Enabled : Boolean := False;
Value : AHB_Prescaler_Enum := AHB_Prescaler_Enum'First;
end record with Size => 4;
for AHB_Prescaler use record
Enabled at 0 range 3 .. 3;
Value at 0 range 0 .. 2;
end record;
AHBPRE_DIV1 : constant AHB_Prescaler := (Enabled => False, Value => DIV2);
type APB_Prescaler_Enum is
(DIV2, DIV4, DIV8, DIV16)
with Size => 2;
type APB_Prescaler is record
Enabled : Boolean;
Value : APB_Prescaler_Enum;
end record with Size => 3;
for APB_Prescaler use record
Enabled at 0 range 2 .. 2;
Value at 0 range 0 .. 1;
end record;
type I2S_Clock_Selection is
(I2SSEL_PLL,
I2SSEL_CKIN)
with Size => 1;
type MCO1_Clock_Selection is
(MCO1SEL_HSI,
MCO1SEL_LSE,
MCO1SEL_HSE,
MCO1SEL_PLL)
with Size => 2;
type MCO2_Clock_Selection is
(MCO2SEL_SYSCLK,
MCO2SEL_PLLI2S,
MCO2SEL_HSE,
MCO2SEL_PLL)
with Size => 2;
type MCOx_Prescaler is
(MCOxPRE_DIV1,
MCOxPRE_DIV2,
MCOxPRE_DIV3,
MCOxPRE_DIV4,
MCOxPRE_DIV5)
with Size => 3;
for MCOx_Prescaler use
(MCOxPRE_DIV1 => 0,
MCOxPRE_DIV2 => 2#100#,
MCOxPRE_DIV3 => 2#101#,
MCOxPRE_DIV4 => 2#110#,
MCOxPRE_DIV5 => 2#111#);
-- Constants for RCC CR register
subtype PLLM_Range is Integer range 2 .. 63;
subtype PLLN_Range is Integer range 50 .. 432;
subtype PLLP_Range is Integer range 2 .. 8
with Static_Predicate => (case PLLP_Range is
when 2 | 4 | 6 | 8 => True,
when others => False);
subtype PLLQ_Range is Integer range 2 .. 15;
subtype HSECLK_Range is Integer range 1_000_000 .. 26_000_000;
subtype PLLIN_Range is Integer range 950_000 .. 2_000_000;
subtype PLLVC0_Range is Integer range 168_000_000 .. 432_000_000;
subtype PLLOUT_Range is Integer range 24_000_000 .. 216_000_000;
subtype SYSCLK_Range is Integer range 1 .. 216_000_000;
subtype HCLK_Range is Integer range 1 .. 216_000_000;
subtype PCLK1_Range is Integer range 1 .. 54_000_000;
subtype PCLK2_Range is Integer range 1 .. 108_000_000;
subtype SPII2S_Range is Integer range 1 .. 37_500_000;
pragma Unreferenced (SPII2S_Range);
-- These internal low and high speed clocks are fixed (do not modify)
HSICLK : constant := 16_000_000;
LSICLK : constant := 32_000;
MCU_ID : MCU_ID_Register with Volatile,
Address => System'To_Address (16#E004_2000#);
-- Only 32-bits access supported (read-only)
DEV_ID_STM32F40xxx : constant := 16#413#; -- STM32F40xxx/41xxx
DEV_ID_STM32F42xxx : constant := 16#419#; -- STM32F42xxx/43xxx
DEV_ID_STM32F46xxx : constant := 16#434#; -- STM32F469xx/479xx
DEV_ID_STM32F74xxx : constant := 16#449#; -- STM32F74xxx/75xxx
end System.STM32;