1 | //INIT NOR
|
2 | void FSMC_NOR_Init(void)
|
3 | {
|
4 | FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
|
5 | FSMC_NORSRAMTimingInitTypeDef p;
|
6 | GPIO_InitTypeDef GPIO_InitStructure;
|
7 |
|
8 | // Enable FSMC, GPIOD, GPIOE, GPIOF, GPIOG and AFIO clocks //
|
9 | RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
|
10 |
|
11 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |
|
12 | RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG |
|
13 | RCC_APB2Periph_AFIO, ENABLE);
|
14 |
|
15 | /*-- GPIO Configuration ------------------------------------------------------*/
|
16 | /* NOR Data lines configuration */
|
17 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 |
|
18 | GPIO_Pin_10 | GPIO_Pin_14 | GPIO_Pin_15;
|
19 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
20 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
21 | GPIO_Init(GPIOD, &GPIO_InitStructure);
|
22 |
|
23 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |
|
24 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 |
|
25 | GPIO_Pin_14 | GPIO_Pin_15;
|
26 | GPIO_Init(GPIOE, &GPIO_InitStructure);
|
27 |
|
28 | /* NOR Address lines configuration */
|
29 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |
|
30 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12 | GPIO_Pin_13 |
|
31 | GPIO_Pin_14 | GPIO_Pin_15;
|
32 | GPIO_Init(GPIOF, &GPIO_InitStructure);
|
33 |
|
34 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 |
|
35 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;
|
36 | GPIO_Init(GPIOG, &GPIO_InitStructure);
|
37 |
|
38 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13;
|
39 | GPIO_Init(GPIOD, &GPIO_InitStructure);
|
40 |
|
41 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6;
|
42 | GPIO_Init(GPIOE, &GPIO_InitStructure);
|
43 |
|
44 | /* NOE and NWE configuration */
|
45 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
|
46 | GPIO_Init(GPIOD, &GPIO_InitStructure);
|
47 |
|
48 | /* NE2 configuration */
|
49 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
|
50 | GPIO_Init(GPIOG, &GPIO_InitStructure);
|
51 |
|
52 |
|
53 |
|
54 | /*-- FSMC Configuration ----------------------------------------------------*/
|
55 | p.FSMC_AddressSetupTime = 0x05;
|
56 | p.FSMC_AddressHoldTime = 0x00;
|
57 | p.FSMC_DataSetupTime = 0x07;
|
58 | p.FSMC_BusTurnAroundDuration = 0x00;
|
59 | p.FSMC_CLKDivision = 0x00;
|
60 | p.FSMC_DataLatency = 0x00;
|
61 | p.FSMC_AccessMode = FSMC_AccessMode_B;
|
62 |
|
63 | FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM2;
|
64 | FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
|
65 | FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_NOR;
|
66 | FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
|
67 | FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
|
68 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
|
69 | FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
|
70 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
|
71 | FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
|
72 | FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
|
73 | FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
|
74 | FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
|
75 | FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
|
76 | FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
|
77 | FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
|
78 |
|
79 | FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
|
80 |
|
81 | /* Enable FSMC Bank1_NOR Bank */
|
82 | FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM2, ENABLE);
|
83 | }
|
84 |
|
85 |
|
86 | //INIT TFT SSD1963
|
87 | void LCD_CtrlLinesConfig(void)
|
88 | {
|
89 | FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
|
90 | FSMC_NORSRAMTimingInitTypeDef p;
|
91 |
|
92 | GPIO_InitTypeDef GPIO_InitStructure;
|
93 |
|
94 | // Enable FSMC, GPIOD, GPIOE, GPIOF, GPIOG and AFIO clocks //
|
95 | RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
|
96 |
|
97 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |
|
98 | RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG |
|
99 | RCC_APB2Periph_AFIO, ENABLE);
|
100 |
|
101 | // Set PD.00(D2), PD.01(D3), PD.04(NOE), PD.05(NWE), PD.08(D13), PD.09(D14),
|
102 | // PD.10(D15), PD.14(D0), PD.15(D1) as alternate
|
103 | // function push pull //
|
104 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 |
|
105 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_14 |
|
106 | GPIO_Pin_15;
|
107 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
108 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
109 | GPIO_Init(GPIOD, &GPIO_InitStructure);
|
110 |
|
111 | //Set PE.07(D4), PE.08(D5), PE.09(D6), PE.10(D7), PE.11(D8), PE.12(D9), PE.13(D10),
|
112 | // PE.14(D11), PE.15(D12) as alternate function push pull //
|
113 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |
|
114 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 |
|
115 | GPIO_Pin_15;
|
116 | GPIO_Init(GPIOE, &GPIO_InitStructure);
|
117 |
|
118 | GPIO_WriteBit(GPIOE, GPIO_Pin_6, Bit_SET);
|
119 | //Set PF.00(A0 (RS)) as alternate function push pull //
|
120 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
|
121 | GPIO_Init(GPIOF, &GPIO_InitStructure);
|
122 |
|
123 | /// Set PG.12(NE4 (LCD/CS)) as alternate function push pull - CE3(LCD /CS) //
|
124 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
|
125 | GPIO_Init(GPIOG, &GPIO_InitStructure);
|
126 |
|
127 | //LCD Backlight PG8
|
128 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
|
129 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
130 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
131 | GPIO_Init(GPIOG, &GPIO_InitStructure);
|
132 | //LCD Backlight ON
|
133 | GPIO_SetBits(GPIOG, GPIO_Pin_8 );
|
134 |
|
135 |
|
136 |
|
137 | /*-- FSMC Configuration ------------------------------------------------------*/
|
138 | p.FSMC_AddressSetupTime = 1;
|
139 | p.FSMC_AddressHoldTime = 1;
|
140 | p.FSMC_DataSetupTime = 3;
|
141 | p.FSMC_BusTurnAroundDuration = 0;
|
142 | p.FSMC_CLKDivision = 1;
|
143 | p.FSMC_DataLatency = 0;
|
144 | p.FSMC_AccessMode = FSMC_AccessMode_A;
|
145 | /* FSMC_Bank1_NORSRAM4 configuration */
|
146 |
|
147 |
|
148 | FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM4; //
|
149 | FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; // ¹Ø±Õ×ÜÏ߸´ÓÃ
|
150 | FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; //fsmc´¢´æģʽ
|
151 | FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; // Êý¾Ý¿í¶È
|
152 | FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; // ¹Ø±ÕÍ»·¢·ÃÎÊģʽ
|
153 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; // µÈ´ýÐźÅΪµÍµçƽ
|
154 | FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; // ¹Ø±Õ»·ÈÆģʽ
|
155 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; //
|
156 | FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; // д²Ù×÷ʹÄÜ
|
157 | FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; // ¹Ø±ÕµÈ´ýÐźÅ
|
158 | FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; // ¹Ø±ÕÀ©Õ¹·½Ê½
|
159 | FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; // ¹Ø±ÕÒì²½µÈ´ý
|
160 | FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; // ¹Ø±ÕÍ»·¢Ð´
|
161 | FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; //
|
162 | FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; //
|
163 |
|
164 | FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
|
165 |
|
166 | /* Enable FSMC Bank1_SRAM Bank */
|
167 | FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE);
|
168 |
|
169 |
|
170 | }
|