Skip to content

Commit 7232cb4

Browse files
committed
Add STM32 F4VE board.
1 parent 945dde1 commit 7232cb4

File tree

9 files changed

+616
-0
lines changed

9 files changed

+616
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-- This package was generated by the Ada_Drivers_Library project wizard script
2+
package ADL_Config is
3+
Architecture : constant String := "ARM"; -- From board definition
4+
Board : constant String := "STM32_F4VE"; -- From command line
5+
CPU_Core : constant String := "ARM Cortex-M4F"; -- From mcu definition
6+
Device_Family : constant String := "STM32F4"; -- From board definition
7+
Device_Name : constant String := "STM32F407VGTx"; -- From board definition
8+
Has_Ravenscar_Full_Runtime : constant String := "True"; -- From board definition
9+
Has_Ravenscar_SFP_Runtime : constant String := "True"; -- From board definition
10+
Has_ZFP_Runtime : constant String := "False"; -- From board definition
11+
High_Speed_External_Clock : constant := 8000000; -- From board definition
12+
Max_Mount_Name_Length : constant := 128; -- From default value
13+
Max_Mount_Points : constant := 2; -- From default value
14+
Max_Path_Length : constant := 1024; -- From default value
15+
Number_Of_Interrupts : constant := 0; -- From default value
16+
Runtime_Name : constant String := "embedded-stm32f4"; -- From default value
17+
Runtime_Name_Suffix : constant String := "stm32f4"; -- From board definition
18+
Runtime_Profile : constant String := "embedded"; -- From default value
19+
Use_Startup_Gen : constant Boolean := False; -- From default value
20+
Vendor : constant String := "STMicro"; -- From board definition
21+
end ADL_Config;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-- This package was generated by the Ada_Drivers_Library project wizard script
2+
package ADL_Config is
3+
Architecture : constant String := "ARM"; -- From board definition
4+
Board : constant String := "STM32_F4VE"; -- From command line
5+
CPU_Core : constant String := "ARM Cortex-M4F"; -- From mcu definition
6+
Device_Family : constant String := "STM32F4"; -- From board definition
7+
Device_Name : constant String := "STM32F407VGTx"; -- From board definition
8+
Has_Ravenscar_Full_Runtime : constant String := "True"; -- From board definition
9+
Has_Ravenscar_SFP_Runtime : constant String := "True"; -- From board definition
10+
Has_ZFP_Runtime : constant String := "False"; -- From board definition
11+
High_Speed_External_Clock : constant := 8000000; -- From board definition
12+
Max_Mount_Name_Length : constant := 128; -- From default value
13+
Max_Mount_Points : constant := 2; -- From default value
14+
Max_Path_Length : constant := 1024; -- From default value
15+
Number_Of_Interrupts : constant := 0; -- From default value
16+
Runtime_Name : constant String := "light-tasking-stm32f4"; -- From command line
17+
Runtime_Name_Suffix : constant String := "stm32f4"; -- From board definition
18+
Runtime_Profile : constant String := "embedded"; -- From default value
19+
Use_Startup_Gen : constant Boolean := False; -- From default value
20+
Vendor : constant String := "STMicro"; -- From board definition
21+
end ADL_Config;
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
------------------------------------------------------------------------------
2+
-- --
3+
-- Copyright (C) 2023, AdaCore --
4+
-- --
5+
-- Redistribution and use in source and binary forms, with or without --
6+
-- modification, are permitted provided that the following conditions are --
7+
-- met: --
8+
-- 1. Redistributions of source code must retain the above copyright --
9+
-- notice, this list of conditions and the following disclaimer. --
10+
-- 2. Redistributions in binary form must reproduce the above copyright --
11+
-- notice, this list of conditions and the following disclaimer in --
12+
-- the documentation and/or other materials provided with the --
13+
-- distribution. --
14+
-- 3. Neither the name of STMicroelectronics nor the names of its --
15+
-- contributors may be used to endorse or promote products derived --
16+
-- from this software without specific prior written permission. --
17+
-- --
18+
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
19+
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
20+
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
21+
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
22+
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
23+
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
24+
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
25+
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
26+
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
27+
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
28+
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
29+
-- --
30+
------------------------------------------------------------------------------
31+
32+
with HAL.SPI;
33+
34+
package body STM32.Board is
35+
36+
------------------
37+
-- All_LEDs_Off --
38+
------------------
39+
40+
procedure All_LEDs_Off is
41+
begin
42+
Set (All_LEDs);
43+
end All_LEDs_Off;
44+
45+
-----------------
46+
-- All_LEDs_On --
47+
-----------------
48+
49+
procedure All_LEDs_On is
50+
begin
51+
Clear (All_LEDs);
52+
end All_LEDs_On;
53+
54+
--------------------------------
55+
-- Configure_User_Button_GPIO --
56+
--------------------------------
57+
58+
procedure Configure_User_Button_GPIO is
59+
begin
60+
Enable_Clock (All_Buttons);
61+
Configure_IO (All_Buttons, (Mode_In, Resistors => Floating));
62+
end Configure_User_Button_GPIO;
63+
64+
---------------------
65+
-- Initialize_LEDs --
66+
---------------------
67+
68+
procedure Initialize_LEDs is
69+
begin
70+
Enable_Clock (All_LEDs);
71+
72+
Configure_IO
73+
(All_LEDs,
74+
(Mode_Out,
75+
Resistors => Floating,
76+
Output_Type => Push_Pull,
77+
Speed => Speed_100MHz));
78+
79+
All_LEDs_Off;
80+
end Initialize_LEDs;
81+
82+
-----------------------------
83+
-- Initialize_Flash_Memory --
84+
-----------------------------
85+
86+
procedure Initialize_Flash_Memory is
87+
SPI : STM32.SPI.SPI_Port renames STM32.Device.SPI_1;
88+
89+
SPI_SCK : STM32.GPIO.GPIO_Point renames STM32.Device.PB3;
90+
SPI_MISO : STM32.GPIO.GPIO_Point renames STM32.Device.PB4;
91+
SPI_MOSI : STM32.GPIO.GPIO_Point renames STM32.Device.PB5;
92+
SPI_CS : STM32.GPIO.GPIO_Point renames STM32.Device.PA15;
93+
94+
SPI_Pins : constant STM32.GPIO.GPIO_Points :=
95+
(SPI_SCK, SPI_MISO, SPI_MOSI);
96+
begin
97+
STM32.Device.Enable_Clock (SPI_Pins & SPI_CS);
98+
99+
STM32.GPIO.Configure_IO
100+
(SPI_CS,
101+
(Mode => STM32.GPIO.Mode_Out,
102+
Resistors => STM32.GPIO.Floating,
103+
Output_Type => STM32.GPIO.Push_Pull,
104+
Speed => STM32.GPIO.Speed_100MHz));
105+
106+
STM32.GPIO.Configure_IO
107+
(SPI_Pins,
108+
(Mode => STM32.GPIO.Mode_AF,
109+
Resistors => STM32.GPIO.Pull_Up,
110+
AF_Output_Type => STM32.GPIO.Push_Pull,
111+
AF_Speed => STM32.GPIO.Speed_100MHz,
112+
AF => STM32.Device.GPIO_AF_SPI1_5));
113+
114+
STM32.Device.Enable_Clock (SPI);
115+
116+
STM32.SPI.Configure
117+
(SPI,
118+
(Direction => STM32.SPI.D2Lines_FullDuplex,
119+
Mode => STM32.SPI.Master,
120+
Data_Size => HAL.SPI.Data_Size_8b,
121+
Clock_Polarity => STM32.SPI.High, -- Mode 3
122+
Clock_Phase => STM32.SPI.P2Edge,
123+
Slave_Management => STM32.SPI.Software_Managed,
124+
Baud_Rate_Prescaler => STM32.SPI.BRP_2,
125+
First_Bit => STM32.SPI.MSB,
126+
CRC_Poly => 0));
127+
-- SPI1 sits on APB2, which is 84MHz, so SPI rate in 84/2=42MHz
128+
end Initialize_Flash_Memory;
129+
130+
end STM32.Board;
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
------------------------------------------------------------------------------
2+
-- --
3+
-- Copyright (C) 2015-2023, AdaCore --
4+
-- --
5+
-- Redistribution and use in source and binary forms, with or without --
6+
-- modification, are permitted provided that the following conditions are --
7+
-- met: --
8+
-- 1. Redistributions of source code must retain the above copyright --
9+
-- notice, this list of conditions and the following disclaimer. --
10+
-- 2. Redistributions in binary form must reproduce the above copyright --
11+
-- notice, this list of conditions and the following disclaimer in --
12+
-- the documentation and/or other materials provided with the --
13+
-- distribution. --
14+
-- 3. Neither the name of STMicroelectronics nor the names of its --
15+
-- contributors may be used to endorse or promote products derived --
16+
-- from this software without specific prior written permission. --
17+
-- --
18+
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
19+
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
20+
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
21+
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
22+
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
23+
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
24+
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
25+
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
26+
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
27+
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
28+
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
29+
-- --
30+
------------------------------------------------------------------------------
31+
32+
-- This file provides declarations for devices on the STM32 F4VE board
33+
-- manufactured by DevEBox.
34+
35+
with Ada.Interrupts.Names; use Ada.Interrupts;
36+
37+
with System;
38+
39+
with STM32.Device; use STM32.Device;
40+
with STM32.DMA; use STM32.DMA;
41+
with STM32.DMA.Interrupts; use STM32.DMA.Interrupts;
42+
with STM32.GPIO; use STM32.GPIO;
43+
with STM32.SPI; use STM32.SPI;
44+
45+
with SDCard;
46+
with W25Q16;
47+
48+
package STM32.Board is
49+
pragma Elaborate_Body;
50+
51+
subtype User_LED is GPIO_Point;
52+
53+
D1_LED : User_LED renames PA6;
54+
D2_LED : User_LED renames PA7;
55+
56+
All_LEDs : GPIO_Points := (D1_LED, D2_LED);
57+
LCH_LED : GPIO_Point renames D1_LED;
58+
59+
procedure Initialize_LEDs;
60+
-- MUST be called prior to any use of the LEDs
61+
62+
procedure Turn_On (This : in out User_LED) renames STM32.GPIO.Clear;
63+
procedure Turn_Off (This : in out User_LED) renames STM32.GPIO.Set;
64+
procedure Toggle (This : in out User_LED) renames STM32.GPIO.Toggle;
65+
66+
procedure All_LEDs_Off with Inline;
67+
procedure All_LEDs_On with Inline;
68+
procedure Toggle_LEDs (These : in out GPIO_Points)
69+
renames STM32.GPIO.Toggle;
70+
71+
--------------------------
72+
-- micro SD card reader --
73+
--------------------------
74+
75+
SD_Detect_Pin : STM32.GPIO.GPIO_Point renames PC11;
76+
-- There is no dedicated pin for card detection, reuse DAT3 pin
77+
78+
SD_DMA : DMA_Controller renames DMA_2;
79+
SD_DMA_Rx_Stream : DMA_Stream_Selector renames Stream_3;
80+
SD_DMA_Rx_Channel : DMA_Channel_Selector renames Channel_4;
81+
SD_DMA_Tx_Stream : DMA_Stream_Selector renames Stream_6;
82+
SD_DMA_Tx_Channel : DMA_Channel_Selector renames Channel_4;
83+
SD_Pins : constant GPIO_Points :=
84+
(PC8, PC9, PC10, PC11, PC12, PD2);
85+
SD_Pins_AF : constant GPIO_Alternate_Function := GPIO_AF_SDIO_12;
86+
SD_Pins_2 : constant GPIO_Points := (1 .. 0 => <>);
87+
SD_Pins_AF_2 : constant GPIO_Alternate_Function := GPIO_AF_SDIO_12;
88+
SD_Interrupt : Ada.Interrupts.Interrupt_ID renames
89+
Ada.Interrupts.Names.SDIO_Interrupt;
90+
91+
DMA2_Stream3 : aliased DMA_Interrupt_Controller
92+
(DMA_2'Access, Stream_3,
93+
Ada.Interrupts.Names.DMA2_Stream3_Interrupt,
94+
System.Interrupt_Priority'Last);
95+
96+
DMA2_Stream6 : aliased DMA_Interrupt_Controller
97+
(DMA_2'Access, Stream_6,
98+
Ada.Interrupts.Names.DMA2_Stream6_Interrupt,
99+
System.Interrupt_Priority'Last);
100+
101+
SD_Rx_DMA_Int : DMA_Interrupt_Controller renames DMA2_Stream3;
102+
SD_Tx_DMA_Int : DMA_Interrupt_Controller renames DMA2_Stream6;
103+
104+
SDCard_Device : aliased SDCard.SDCard_Controller (SDIO'Access);
105+
106+
---------------
107+
-- SPI2 Pins --
108+
---------------
109+
110+
-- External TFT connector
111+
112+
TFT_RS : GPIO_Point renames PC5;
113+
TFT_BLK : GPIO_Point renames PB1; -- LCD backlight
114+
TFT_CS : GPIO_Point renames PB12;
115+
SPI2_SCK : GPIO_Point renames PB13;
116+
SPI2_MISO : GPIO_Point renames PB14;
117+
SPI2_MOSI : GPIO_Point renames PB15;
118+
119+
TFT_SPI : SPI_Port renames SPI_2;
120+
121+
------------------
122+
-- User buttons --
123+
------------------
124+
125+
K0_Button_Point : GPIO_Point renames PE4;
126+
K1_Button_Point : GPIO_Point renames PE3;
127+
Wake_Up_Button_Point : GPIO_Point renames PA0;
128+
User_Button_Point : GPIO_Point renames Wake_Up_Button_Point;
129+
User_Button_Interrupt : constant Interrupt_ID := Names.EXTI0_Interrupt;
130+
131+
All_Buttons : GPIO_Points :=
132+
(K0_Button_Point, K1_Button_Point, Wake_Up_Button_Point);
133+
134+
procedure Configure_User_Button_GPIO;
135+
-- Configures the GPIO port/pin for user buttons. Sufficient
136+
-- for polling the button, and necessary for having the button generate
137+
-- interrupts.
138+
139+
------------------
140+
-- Flash memory --
141+
------------------
142+
143+
Flash : W25Q16.Flash_Memory
144+
(SPI => STM32.Device.SPI_1'Access,
145+
CS => STM32.Device.PA15'Access);
146+
147+
procedure Initialize_Flash_Memory;
148+
-- MUST be called prior to any use of the Flash
149+
150+
end STM32.Board;

0 commit comments

Comments
 (0)