Skip to content

Commit 7093afd

Browse files
committed
Updated STM tests to use Ada Drivers Library.
* test-stm32f4/README.md: new. * test-stm32f429i/README.md: new. * test-stm32f4/generate_hard_fault.adb: uses System.Hardfault_Handling. * test-stm32f4/heartbeat.adb: uses Ada_Drivers_Library GPIO features. * test-stm32f429i/heartbeat.adb: likewise. * test-stm32f4/testbed.gpr: withs Ada_Drivers_Library. * test-stm32f429i/testbed.gpr: likewise.
1 parent 6b3abf5 commit 7093afd

File tree

7 files changed

+238
-85
lines changed

7 files changed

+238
-85
lines changed

test-stm32f4/README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# STM32F4 tests and demos #
2+
3+
There are four programs built by `make` or `gprbuild`.
4+
5+
* `testbed` runs several tasks, each of which repeatedly tests a language or library feature:
6+
* Containers
7+
* Dispatching
8+
* Floating Point
9+
* `'Image`
10+
* Can build with `Interfaces.C.Strings`
11+
* Interrupts
12+
* Generalized iteration
13+
* `Ada.Numerics.Elementary_Functions`
14+
* Suspension Objects
15+
* Streams
16+
* Secondary Stack
17+
* `action_after_delay` demonstrates that, given two tasks of the same priority, if one of them loops indefinitely without reaching a dispatching point, the other never runs
18+
* `delay_in_po` demonstrates that it's illegal to execute a `delay` inside a protected subprogram
19+
* `generate_hard_fault` demonstrates HardFault decoding
20+
21+
The tests interact with the STM32F4 hardware using the [Ada\_Drivers\_Library](https://github.com/AdaCore/Ada_Drivers_Library). Configure it using that library's `project_wizard.py`:
22+
```
23+
Welcome to the Ada Drivers Library (ADL) project wizard. This script will
24+
ask you some questions to define the ADL configuration of your project. It will
25+
then generate the different files required to use ADL based on this
26+
configuration.
27+
Board
28+
- (0) Custom_Board
29+
- (1) STM32F407_Discovery
30+
- (2) STM32F429_Discovery
31+
- (3) STM32F469_Discovery
32+
- (4) STM32F746_Discovery
33+
- (5) STM32F769_Discovery
34+
- (6) STM32_H405
35+
- (7) NUCLEO_F446ZE
36+
- (8) Crazyflie
37+
- (9) Feather_STM32F405
38+
- (10) OpenMV2
39+
- (11) MicroBit
40+
- (12) NRF52_DK
41+
- (13) HiFive1
42+
- (14) HiFive1_rev_B
43+
- (15) Unleashed
44+
- (16) Native
45+
? 1
46+
For key 'Architecture', take value 'ARM' from board definition
47+
For key 'Vendor', take value 'STMicro' from board definition
48+
For key 'Device_Family', take value 'STM32F4' from board definition
49+
For key 'Device_Name', take value 'STM32F407VGTx' from board definition
50+
For key 'High_Speed_External_Clock', take value '8000000' from board definition
51+
Number_Of_Interrupts [default: 0]
52+
82
53+
For key 'Has_ZFP_Runtime', take value 'False' from board definition
54+
For key 'Has_Ravenscar_SFP_Runtime', take value 'True' from board definition
55+
For key 'Has_Ravenscar_Full_Runtime', take value 'True' from board definition
56+
Runtime_Profile
57+
- (0) ravenscar-full
58+
- (1) ravenscar-sfp
59+
? 0
60+
For key 'Runtime_Name_Suffix', take value 'stm32f4' from board definition
61+
Runtime_Name [default: 'ravenscar-full-stm32f4']
62+
? ../../../local/stm32f4
63+
Use_Startup_Gen [y/N]
64+
65+
Max_Path_Length [default: 1024]
66+
67+
Max_Mount_Points [default: 2]
68+
69+
Max_Mount_Name_Length [default: 128]
70+
71+
The configuration is now finished.
72+
Let's generate some files:
73+
-> Writing gprbuild project file.
74+
-> Writing the Ada configuration file.
75+
Your Ada Drivers Library project is now ready to use.
76+
```
77+
After selecting the `STM32F407_Discovery`, the default (RET) is OK for most answers. The only odd one is that for `Runtime_Name`; the output files are created in the directory `Ada_Drivers_Library`, so the generated `ada_drivers_library.gpr` is one level down, and to select the locally-installed runtime you have to go up three levels and down 2.

test-stm32f4/generate_hard_fault.adb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Copyright (C) 2017 Free Software Foundation, Inc.
1+
-- Copyright (C) 2017-2021 Free Software Foundation, Inc.
22

33
-- This file is part of the Cortex GNAT RTS package.
44
--
@@ -22,8 +22,10 @@
2222

2323
with Ada.Real_Time;
2424

25-
with Hardfault_Handling;
26-
pragma Unreferenced (Hardfault_Handling);
25+
pragma Warnings (Off, "is an internal GNAT unit");
26+
with System.Hardfault_Handling;
27+
pragma Warnings (On, "is an internal GNAT unit");
28+
pragma Unreferenced (System.Hardfault_Handling);
2729

2830
with Faulting_Task;
2931
pragma Unreferenced (Faulting_Task);

test-stm32f4/heartbeat.adb

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Copyright (C) 2016, 2017 Free Software Foundation, Inc.
1+
-- Copyright (C) 2016-2021 Free Software Foundation, Inc.
22

33
-- This file is part of the Cortex GNAT RTS package.
44
--
@@ -17,63 +17,62 @@
1717
-- <http://www.gnu.org/licenses/>.
1818

1919
with Ada.Real_Time;
20-
with STM32F40x.GPIO; use STM32F40x.GPIO;
21-
with STM32F40x.RCC; use STM32F40x.RCC;
20+
with STM32.Device;
21+
with STM32.GPIO;
2222

2323
package body Heartbeat is
2424

25+
type LED is (Green, Orange, Red, Blue);
26+
for LED use (Green => 12,
27+
Orange => 13,
28+
Red => 14,
29+
Blue => 15);
30+
31+
LEDs : STM32.GPIO.GPIO_Points
32+
:= (Green'Enum_Rep => (Periph => STM32.Device.GPIO_D'Access,
33+
Pin => STM32.GPIO.Pin_12),
34+
Orange'Enum_Rep => (Periph => STM32.Device.GPIO_D'Access,
35+
Pin => STM32.GPIO.Pin_13),
36+
Red'Enum_Rep => (Periph => STM32.Device.GPIO_D'Access,
37+
Pin => STM32.GPIO.Pin_14),
38+
Blue'Enum_Rep => (Periph => STM32.Device.GPIO_D'Access,
39+
Pin => STM32.GPIO.Pin_15));
40+
2541
task Beat
26-
with Storage_Size => 1024
27-
is
28-
pragma Task_Name ("heartbeat.beat");
29-
end Beat;
42+
with Storage_Size => 1024;
3043

3144
task body Beat is
3245
use type Ada.Real_Time.Time;
3346
begin
3447
for J in 1 .. 5 loop
35-
GPIOD_Periph.BSRR.BS := (As_Array => True,
36-
Arr => (12 => 1, others => 0));
48+
STM32.GPIO.Set (LEDs (Green'Enum_Rep));
3749
delay until Ada.Real_Time.Clock + Ada.Real_Time.Milliseconds (100);
38-
GPIOD_Periph.BSRR.BR := (As_Array => True,
39-
Arr => (12 => 1, others => 0));
50+
STM32.GPIO.Clear (LEDs (Green'Enum_Rep));
4051
delay until Ada.Real_Time.Clock + Ada.Real_Time.Milliseconds (100);
4152
end loop;
4253
loop
43-
declare
44-
Set : BSRR_BS_Field_Array;
45-
Reset : BSRR_BR_Field_Array;
46-
begin
47-
for J in 12 .. 15 loop
48-
Set := (others => 0);
49-
Set (J) := 1;
50-
GPIOD_Periph.BSRR.BS := (As_Array => True,
51-
Arr => Set);
52-
delay until
53-
Ada.Real_Time.Clock + Ada.Real_Time.Milliseconds (100);
54-
Reset := (others => 0);
55-
Reset (J) := 1;
56-
GPIOD_Periph.BSRR.BR := (As_Array => True,
57-
Arr => Reset);
58-
delay until
59-
Ada.Real_Time.Clock + Ada.Real_Time.Milliseconds (900);
60-
end loop;
61-
end;
54+
for P of LEDs loop
55+
STM32.GPIO.Set (P);
56+
delay until Ada.Real_Time.Clock + Ada.Real_Time.Milliseconds (100);
57+
STM32.GPIO.Clear (P);
58+
delay until Ada.Real_Time.Clock + Ada.Real_Time.Milliseconds (900);
59+
end loop;
6260
end loop;
6361
end Beat;
6462

65-
begin
66-
-- Enable GPIOD
67-
declare
68-
AHB1ENR : STM32F40x.RCC.AHB1ENR_Register;
63+
procedure Initialize;
64+
procedure Initialize is
65+
use STM32.Device;
66+
use STM32.GPIO;
6967
begin
70-
AHB1ENR := RCC_Periph.AHB1ENR;
71-
AHB1ENR.GPIODEN := 1;
72-
RCC_Periph.AHB1ENR := AHB1ENR;
73-
end;
68+
Enable_Clock (GPIO_D);
69+
Configure_IO (LEDs,
70+
Config => (Mode => Mode_Out,
71+
Resistors => Pull_Up,
72+
others => <>));
73+
Clear (LEDs);
74+
end Initialize;
7475

75-
-- PD12 is the green LED, PD13 the orange, PD14 the red, PD15 the blue.
76-
GPIOD_Periph.MODER := (As_Array => True,
77-
Arr => (12 .. 15 => 1,
78-
others => 0));
76+
begin
77+
Initialize;
7978
end Heartbeat;

test-stm32f4/testbed.gpr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Copyright (C) 2016-2020 Free Software Foundation, Inc.
1+
-- Copyright (C) 2016-2021 Free Software Foundation, Inc.
22
--
33
-- This file is part of the Cortex GNAT RTS package.
44
--
@@ -16,6 +16,8 @@
1616
-- along with this program; see the file COPYING3. If not, see
1717
-- <http://www.gnu.org/licenses/>.
1818

19+
with "Ada_Drivers_Library/ada_drivers_library";
20+
1921
project Testbed is
2022

2123
for Main use ("testbed.adb",

test-stm32f429i/README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# STM32F4 tests and demos #
2+
3+
`make` or `gprbuild` build one program:
4+
5+
* `testbed` runs several tasks, each of which repeatedly tests a language or library feature:
6+
* Containers
7+
* Dispatching
8+
* Floating Point
9+
* `'Image`
10+
* Can build with `Interfaces.C.Strings`
11+
* Interrupts
12+
* Generalized iteration
13+
* `Ada.Numerics.Elementary_Functions`
14+
* Suspension Objects
15+
* Streams
16+
* Secondary Stack
17+
18+
The tests interact with the STM32F4 hardware using the [Ada\_Drivers\_Library](https://github.com/AdaCore/Ada_Drivers_Library). Configure it using that library's `project_wizard.py`:
19+
```
20+
Welcome to the Ada Drivers Library (ADL) project wizard. This script will
21+
ask you some questions to define the ADL configuration of your project. It will
22+
then generate the different files required to use ADL based on this
23+
configuration.
24+
Board
25+
- (0) Custom_Board
26+
- (1) STM32F407_Discovery
27+
- (2) STM32F429_Discovery
28+
- (3) STM32F469_Discovery
29+
- (4) STM32F746_Discovery
30+
- (5) STM32F769_Discovery
31+
- (6) STM32_H405
32+
- (7) NUCLEO_F446ZE
33+
- (8) Crazyflie
34+
- (9) Feather_STM32F405
35+
- (10) OpenMV2
36+
- (11) MicroBit
37+
- (12) NRF52_DK
38+
- (13) HiFive1
39+
- (14) HiFive1_rev_B
40+
- (15) Unleashed
41+
- (16) Native
42+
? 2
43+
For key 'Architecture', take value 'ARM' from board definition
44+
For key 'Vendor', take value 'STMicro' from board definition
45+
For key 'Device_Family', take value 'STM32F4' from board definition
46+
For key 'Device_Name', take value 'STM32F429ZITx' from board definition
47+
For key 'High_Speed_External_Clock', take value '8000000' from board definition
48+
Number_Of_Interrupts [default: 0]
49+
91
50+
For key 'Has_ZFP_Runtime', take value 'False' from board definition
51+
For key 'Has_Ravenscar_SFP_Runtime', take value 'True' from board definition
52+
For key 'Has_Ravenscar_Full_Runtime', take value 'True' from board definition
53+
Runtime_Profile
54+
- (0) ravenscar-full
55+
- (1) ravenscar-sfp
56+
? 0
57+
For key 'Runtime_Name_Suffix', take value 'stm32f429disco' from board definition
58+
Runtime_Name [default: 'ravenscar-full-stm32f4']
59+
? ../../../local/stm32f429i
60+
Use_Startup_Gen [y/N]
61+
62+
Max_Path_Length [default: 1024]
63+
64+
Max_Mount_Points [default: 2]
65+
66+
Max_Mount_Name_Length [default: 128]
67+
68+
The configuration is now finished.
69+
Let's generate some files:
70+
-> Writing gprbuild project file.
71+
-> Writing the Ada configuration file.
72+
Your Ada Drivers Library project is now ready to use.
73+
```
74+
After selecting the `STM32F429_Discovery`, the default (RET) is OK for most answers. The only odd one is that for `Runtime_Name`; the output files are created in the directory `Ada_Drivers_Library`, so the generated `ada_drivers_library.gpr` is one level down, and to select the locally-installed runtime you have to go up three levels and down 2.

test-stm32f429i/heartbeat.adb

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Copyright (C) 2016, 2017 Free Software Foundation, Inc.
1+
-- Copyright (C) 2016-2021 Free Software Foundation, Inc.
22

33
-- This file is part of the Cortex GNAT RTS package.
44
--
@@ -17,59 +17,56 @@
1717
-- <http://www.gnu.org/licenses/>.
1818

1919
with Ada.Real_Time;
20-
with STM32F429x.GPIO; use STM32F429x.GPIO;
21-
with STM32F429x.RCC; use STM32F429x.RCC;
20+
with STM32.Device;
21+
with STM32.GPIO;
2222

2323
package body Heartbeat is
2424

25+
type LED is (Green, Red);
26+
for LED use (Green => 13,
27+
Red => 14);
28+
29+
LEDs : STM32.GPIO.GPIO_Points
30+
:= (Green'Enum_Rep => (Periph => STM32.Device.GPIO_G'Access,
31+
Pin => STM32.GPIO.Pin_13),
32+
Red'Enum_Rep => (Periph => STM32.Device.GPIO_G'Access,
33+
Pin => STM32.GPIO.Pin_14));
34+
2535
task Beat
26-
with Storage_Size => 1024
27-
is
28-
pragma Task_Name ("heartbeat.beat");
29-
end Beat;
36+
with Storage_Size => 1024;
3037

3138
task body Beat is
32-
Green_Pin : constant := 13;
33-
Red_Pin : constant := 14;
3439
use type Ada.Real_Time.Time;
3540
begin
3641
for J in 1 .. 5 loop
37-
GPIOG_Periph.BSRR.BS := (As_Array => True,
38-
Arr => (Green_Pin => 1, others => 0));
42+
STM32.GPIO.Set (LEDs (Green'Enum_Rep));
3943
delay until Ada.Real_Time.Clock + Ada.Real_Time.Milliseconds (100);
40-
GPIOG_Periph.BSRR.BR := (As_Array => True,
41-
Arr => (Green_Pin => 1, others => 0));
44+
STM32.GPIO.Clear (LEDs (Green'Enum_Rep));
4245
delay until Ada.Real_Time.Clock + Ada.Real_Time.Milliseconds (100);
4346
end loop;
4447
loop
45-
GPIOG_Periph.BSRR.BS := (As_Array => True,
46-
Arr => (Green_Pin => 1, others => 0));
47-
delay until Ada.Real_Time.Clock + Ada.Real_Time.Milliseconds (100);
48-
GPIOG_Periph.BSRR.BR := (As_Array => True,
49-
Arr => (Green_Pin => 1, others => 0));
50-
delay until Ada.Real_Time.Clock + Ada.Real_Time.Milliseconds (900);
51-
52-
GPIOG_Periph.BSRR.BS := (As_Array => True,
53-
Arr => (Red_Pin => 1, others => 0));
54-
delay until Ada.Real_Time.Clock + Ada.Real_Time.Milliseconds (100);
55-
GPIOG_Periph.BSRR.BR := (As_Array => True,
56-
Arr => (Red_Pin => 1, others => 0));
57-
delay until Ada.Real_Time.Clock + Ada.Real_Time.Milliseconds (900);
48+
for P of LEDs loop
49+
STM32.GPIO.Set (P);
50+
delay until Ada.Real_Time.Clock + Ada.Real_Time.Milliseconds (100);
51+
STM32.GPIO.Clear (P);
52+
delay until Ada.Real_Time.Clock + Ada.Real_Time.Milliseconds (900);
53+
end loop;
5854
end loop;
5955
end Beat;
6056

61-
begin
62-
-- Enable GPIOG
63-
declare
64-
AHB1ENR : STM32F429x.RCC.AHB1ENR_Register;
57+
procedure Initialize;
58+
procedure Initialize is
59+
use STM32.Device;
60+
use STM32.GPIO;
6561
begin
66-
AHB1ENR := RCC_Periph.AHB1ENR;
67-
AHB1ENR.GPIOGEN := 1;
68-
RCC_Periph.AHB1ENR := AHB1ENR;
69-
end;
62+
Enable_Clock (GPIO_G);
63+
Configure_IO (LEDs,
64+
Config => (Mode => Mode_Out,
65+
Resistors => Pull_Up,
66+
others => <>));
67+
Clear (LEDs);
68+
end Initialize;
7069

71-
-- PG13 is the green LED, PG14 is the red LED.
72-
GPIOG_Periph.MODER := (As_Array => True,
73-
Arr => (13 | 14 => 1,
74-
others => 0));
70+
begin
71+
Initialize;
7572
end Heartbeat;

0 commit comments

Comments
 (0)