Skip to content

Commit 724b746

Browse files
committed
Add TFT LCD ILI9341 to STM32 F4VE board.
1 parent 7232cb4 commit 724b746

File tree

14 files changed

+690
-25
lines changed

14 files changed

+690
-25
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
with STM32.Board;
33+
with STM32.Device;
34+
with STM32.GPIO;
35+
36+
with Ravenscar_Time;
37+
38+
package body Display_ILI9341 is
39+
40+
----------------
41+
-- Initialize --
42+
----------------
43+
44+
procedure Initialize (This : in out Display) is
45+
begin
46+
STM32.Device.Enable_Clock (STM32.Board.TFT_BLK);
47+
48+
STM32.Board.TFT_BLK.Configure_IO
49+
((STM32.GPIO.Mode_Out,
50+
Resistors => STM32.GPIO.Floating,
51+
Output_Type => STM32.GPIO.Push_Pull,
52+
Speed => STM32.GPIO.Speed_100MHz));
53+
54+
STM32.Board.TFT_BLK.Set; -- Turn LCD backlight on
55+
56+
STM32.Board.Initialize_FSMC (STM32.Board.TFT_Pins);
57+
58+
STM32.FSMC.Configure
59+
(Bank_1 =>
60+
(1 => -- TFT is connected to sub-bank 1
61+
(Is_Set => True,
62+
Value =>
63+
(Write_Enable => True,
64+
Bus_Width => STM32.FSMC.Half_Word,
65+
Memory_Type => STM32.FSMC.SRAM,
66+
Bus_Turn => 15, -- 90ns
67+
Data_Setup => 57, -- 342ns
68+
Address_Setup => 0,
69+
Extended =>
70+
(STM32.FSMC.Mode_A,
71+
Write_Bus_Turn => 3, -- 18ns
72+
Write_Data_Setup => 2, -- 12ns
73+
Write_Address_Setup => 0),
74+
others => <>)),
75+
others => <>));
76+
77+
This.Device.Initialize (Ravenscar_Time.Delays);
78+
This.Set_Orientation (HAL.Framebuffer.Default);
79+
end Initialize;
80+
81+
---------------------
82+
-- Set_Orientation --
83+
---------------------
84+
85+
procedure Set_Orientation
86+
(This : in out Display;
87+
Orientation : HAL.Framebuffer.Display_Orientation) is
88+
begin
89+
This.Device.Set_Orientation
90+
(case Orientation is
91+
when HAL.Framebuffer.Landscape =>
92+
ILI9341_Device.Landscape_1,
93+
when others => ILI9341_Device.Portrait_2);
94+
end Set_Orientation;
95+
96+
end Display_ILI9341;
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
with System.Storage_Elements;
33+
34+
with HAL.Framebuffer;
35+
with ILI9341.Device.Bitmap;
36+
with ILI9341.Device;
37+
with ILI9341.B16_Connector;
38+
with STM32.FSMC;
39+
40+
package Display_ILI9341 is
41+
42+
type Display is tagged limited private;
43+
44+
procedure Initialize (This : in out Display);
45+
-- Configure FSMC, turn backlight on and initialize the display
46+
47+
procedure Set_Orientation
48+
(This : in out Display;
49+
Orientation : HAL.Framebuffer.Display_Orientation);
50+
51+
use System.Storage_Elements;
52+
53+
package ILI9341_Device is new ILI9341.Device
54+
(ILI9341_Connector => ILI9341.B16_Connector.ILI9341_Connector,
55+
Send_Command => ILI9341.B16_Connector.Send_Command,
56+
Connection => ILI9341.Parallel,
57+
Connector =>
58+
(Command => STM32.FSMC.Bank_1_Start (Subbank => 1),
59+
RAM => STM32.FSMC.Bank_1_Start (Subbank => 1) + 2 ** 19));
60+
-- RAM region starts when A18 = 1, TFT attached with 16 bits bus, so 2**19
61+
62+
package ILI9341_Bitmap is new ILI9341_Device.Bitmap
63+
(ILI9341.B16_Connector.Write_Pixels,
64+
ILI9341.B16_Connector.Read_Pixels);
65+
66+
subtype Bitmap_Buffer is ILI9341_Bitmap.Bitmap_Buffer;
67+
68+
function Buffer (This : in out Display) return Bitmap_Buffer;
69+
70+
private
71+
72+
type Display is tagged limited record
73+
Device : aliased ILI9341_Device.ILI9341_Device;
74+
end record;
75+
76+
function Buffer (This : in out Display) return Bitmap_Buffer is
77+
(ILI9341_Bitmap.Get_Bitmap (This.Device'Access));
78+
79+
end Display_ILI9341;

boards/stm32_f4ve/src/stm32-board.adb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,22 @@ package body STM32.Board is
127127
-- SPI1 sits on APB2, which is 84MHz, so SPI rate in 84/2=42MHz
128128
end Initialize_Flash_Memory;
129129

130+
---------------------
131+
-- Initialize_FSMC --
132+
---------------------
133+
134+
procedure Initialize_FSMC (Pins : GPIO_Points) is
135+
begin
136+
Enable_FSMC_Clock;
137+
Enable_Clock (Pins);
138+
139+
STM32.GPIO.Configure_IO
140+
(Pins,
141+
(STM32.GPIO.Mode_AF,
142+
Resistors => STM32.GPIO.Floating,
143+
AF_Output_Type => STM32.GPIO.Push_Pull,
144+
AF_Speed => STM32.GPIO.Speed_100MHz,
145+
AF => STM32.Device.GPIO_AF_FMC_12));
146+
end Initialize_FSMC;
147+
130148
end STM32.Board;

boards/stm32_f4ve/src/stm32-board.ads

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ with STM32.SPI; use STM32.SPI;
4444

4545
with SDCard;
4646
with W25Q16;
47+
with Display_ILI9341;
4748

4849
package STM32.Board is
4950
pragma Elaborate_Body;
@@ -68,6 +69,36 @@ package STM32.Board is
6869
procedure Toggle_LEDs (These : in out GPIO_Points)
6970
renames STM32.GPIO.Toggle;
7071

72+
----------
73+
-- FSMC --
74+
----------
75+
76+
FSMC_D : constant GPIO_Points :=
77+
(PD14, PD15, PD0, PD1, PE7, PE8, PE9, PE10,
78+
PE11, PE12, PE13, PE14, PE15, PD8, PD9, PD10);
79+
-- Data pins (D0 .. D15)
80+
81+
FSMC_A18 : GPIO_Point renames PD13;
82+
-- Only one address pin is connected to the TFT header
83+
84+
FSMC_NE1 : GPIO_Point renames PD7; -- Chip select pin for TFT LCD
85+
FSMC_NWE : GPIO_Point renames PD5; -- Write enable pin
86+
FSMC_NOE : GPIO_Point renames PD4; -- Output enable pin
87+
88+
TFT_Pins : constant GPIO_Points :=
89+
FSMC_A18 & FSMC_D & FSMC_NE1 & FSMC_NWE & FSMC_NOE;
90+
91+
procedure Initialize_FSMC (Pins : GPIO_Points);
92+
-- Enable FSMC and initialize given FSMC pins
93+
94+
---------
95+
-- TFT --
96+
---------
97+
98+
Display : Display_ILI9341.Display;
99+
100+
TFT_Bitmap : Display_ILI9341.Bitmap_Buffer := Display.Buffer;
101+
71102
--------------------------
72103
-- micro SD card reader --
73104
--------------------------
@@ -107,14 +138,19 @@ package STM32.Board is
107138
-- SPI2 Pins --
108139
---------------
109140

141+
SPI2_SCK : GPIO_Point renames PB13;
142+
SPI2_MISO : GPIO_Point renames PB14;
143+
SPI2_MOSI : GPIO_Point renames PB15;
144+
110145
-- External TFT connector
111146

112147
TFT_RS : GPIO_Point renames PC5;
113148
TFT_BLK : GPIO_Point renames PB1; -- LCD backlight
114149
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;
150+
151+
-----------------
152+
-- Touch Panel --
153+
-----------------
118154

119155
TFT_SPI : SPI_Port renames SPI_2;
120156

boards/stm32f4xx_m/src/stm32-board.adb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
------------------------------------------------------------------------------
3131

3232
with HAL.SPI;
33-
with STM32.SPI;
3433

3534
package body STM32.Board is
3635

boards/stm32f4xx_m/src/stm32-board.ads

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@
3535
with System;
3636
with Ada.Interrupts.Names; use Ada.Interrupts;
3737

38-
with STM32.Device; use STM32.Device;
38+
with STM32.Device; use STM32.Device;
3939
with STM32.DMA; use STM32.DMA;
4040
with STM32.DMA.Interrupts; use STM32.DMA.Interrupts;
41-
with STM32.GPIO; use STM32.GPIO;
41+
with STM32.GPIO; use STM32.GPIO;
42+
with STM32.SPI; use STM32.SPI;
4243

4344
with SDCard;
4445
with W25Q16;
@@ -100,9 +101,24 @@ package STM32.Board is
100101

101102
SDCard_Device : aliased SDCard.SDCard_Controller (SDIO'Access);
102103

103-
------------------
104-
-- User button --
105-
------------------
104+
---------------
105+
-- SPI2 Pins --
106+
---------------
107+
108+
-- External TFT connector
109+
110+
TFT_RS : GPIO_Point renames PC5;
111+
TFT_BLK : GPIO_Point renames PB1; -- LCD backlight
112+
TFT_CS : GPIO_Point renames PB12;
113+
SPI2_SCK : GPIO_Point renames PB13;
114+
SPI2_MISO : GPIO_Point renames PB14;
115+
SPI2_MOSI : GPIO_Point renames PB15;
116+
117+
TFT_SPI : SPI_Port renames SPI_2;
118+
119+
-----------------
120+
-- User button --
121+
-----------------
106122

107123
User_Button_Point : GPIO_Point renames PA0;
108124
User_Button_Interrupt : constant Interrupt_ID := Names.EXTI0_Interrupt;

0 commit comments

Comments
 (0)