Rev 81 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 81 | Rev 171 | ||
---|---|---|---|
1 | /*#######################################################################################*/ |
1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
3 | /*#######################################################################################*/ |
3 | /*#######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + Copyright (c) 2008 Ingo Busker, Holger Buss |
5 | // + Copyright (c) 2008 Ingo Busker, Holger Buss |
6 | // + Nur für den privaten Gebrauch |
6 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
7 | // + FOR NON COMMERCIAL USE ONLY |
7 | // + FOR NON COMMERCIAL USE ONLY |
8 | // + www.MikroKopter.com |
8 | // + www.MikroKopter.com |
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
10 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
10 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
11 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
11 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
15 | // + Verkauf von Luftbildaufnahmen, usw. |
15 | // + Verkauf von Luftbildaufnahmen, usw. |
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
17 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
17 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
18 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
18 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
20 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
20 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
21 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
21 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
22 | // + eindeutig als Ursprung verlinkt werden |
22 | // + eindeutig als Ursprung verlinkt werden |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
25 | // + Benutzung auf eigene Gefahr |
25 | // + Benutzung auf eigene Gefahr |
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
28 | // + Die PORTIERUNG der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
28 | // + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
29 | // + mit unserer Zustimmung zulässig |
29 | // + mit unserer Zustimmung zulässig |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
31 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
32 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
32 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
33 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
34 | // + this list of conditions and the following disclaimer. |
34 | // + this list of conditions and the following disclaimer. |
35 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
35 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
36 | // + from this software without specific prior written permission. |
36 | // + from this software without specific prior written permission. |
37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
38 | // + for non-commercial use (directly or indirectly) |
38 | // + for non-commercial use (directly or indirectly) |
39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
40 | // + with our written permission |
40 | // + with our written permission |
41 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
41 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
42 | // + clearly linked as origin |
42 | // + clearly linked as origin |
43 | // + * PORTING this software (or part of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed |
43 | // + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
44 | // |
44 | // |
45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
55 | // + POSSIBILITY OF SUCH DAMAGE. |
55 | // + POSSIBILITY OF SUCH DAMAGE. |
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
57 | //#include <stdio.h> |
57 | //#include <stdio.h> |
58 | #include "91x_lib.h" |
58 | #include "91x_lib.h" |
59 | #include "uart1.h" |
59 | #include "uart1.h" |
60 | 60 | ||
61 | /********************************************************/ |
61 | /********************************************************/ |
62 | /* Initialize UART2 */ |
62 | /* Initialize UART2 */ |
63 | /********************************************************/ |
63 | /********************************************************/ |
64 | void UART2_Init(void) |
64 | void UART2_Init(void) |
65 | { |
65 | { |
66 | UART_InitTypeDef UART_InitStructure; |
66 | UART_InitTypeDef UART_InitStructure; |
67 | GPIO_InitTypeDef GPIO_InitStructure; |
67 | GPIO_InitTypeDef GPIO_InitStructure; |
68 | 68 | ||
69 | SerialPutString("\r\n UART2 init..."); |
69 | SerialPutString("\r\n UART2 init..."); |
70 | 70 | ||
71 | SCU_APBPeriphClockConfig(__UART2, ENABLE); // Enable the UART2 Clock |
71 | SCU_APBPeriphClockConfig(__UART2, ENABLE); // Enable the UART2 Clock |
72 | 72 | ||
73 | SCU_APBPeriphClockConfig(__GPIO5, ENABLE); // Enable the GPIO5 Clock |
73 | SCU_APBPeriphClockConfig(__GPIO5, ENABLE); // Enable the GPIO5 Clock |
74 | /*Configure UART2_Rx pin GPIO5.2*/ |
74 | /*Configure UART2_Rx pin GPIO5.2*/ |
75 | GPIO_StructInit(&GPIO_InitStructure); |
75 | GPIO_StructInit(&GPIO_InitStructure); |
76 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
76 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
77 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; |
77 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; |
78 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
78 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
79 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; |
79 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; |
80 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; // UART2_RxD |
80 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; // UART2_RxD |
81 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
81 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
82 | 82 | ||
83 | SCU_APBPeriphClockConfig(__GPIO3, ENABLE); // Enable the GPIO3 Clock |
83 | SCU_APBPeriphClockConfig(__GPIO3, ENABLE); // Enable the GPIO3 Clock |
84 | /*Configure UART2_Tx pin GPIO3.0*/ |
84 | /*Configure UART2_Tx pin GPIO3.0*/ |
85 | GPIO_StructInit(&GPIO_InitStructure); |
85 | GPIO_StructInit(&GPIO_InitStructure); |
86 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
86 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
87 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; |
87 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; |
88 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
88 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
89 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; // UART2_TX |
89 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; // UART2_TX |
90 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
90 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
91 | 91 | ||
92 | 92 | ||
93 | /* UART2 configured as follow: |
93 | /* UART2 configured as follow: |
94 | - Word Length = 8 Bits |
94 | - Word Length = 8 Bits |
95 | - One Stop Bit |
95 | - One Stop Bit |
96 | - No parity |
96 | - No parity |
97 | - BaudRate = 57600 baud |
97 | - BaudRate = 57600 baud |
98 | - Hardware flow control Disabled |
98 | - Hardware flow control Disabled |
99 | - Receive and transmit enabled |
99 | - Receive and transmit enabled |
100 | - Receive and transmit FIFOs are Disabled |
100 | - Receive and transmit FIFOs are Disabled |
101 | */ |
101 | */ |
102 | UART_StructInit(&UART_InitStructure); |
102 | UART_StructInit(&UART_InitStructure); |
103 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
103 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
104 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
104 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
105 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
105 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
106 | UART_InitStructure.UART_BaudRate = BAUD_RATE; |
106 | UART_InitStructure.UART_BaudRate = BAUD_RATE; |
107 | UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
107 | UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
108 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
108 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
109 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
109 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
110 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
110 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
111 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; |
111 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; |
112 | 112 | ||
113 | UART_DeInit(UART2); // reset uart 2 to default |
113 | UART_DeInit(UART2); // reset uart 2 to default |
114 | UART_Init(UART2, &UART_InitStructure); // initialize uart 2 |
114 | UART_Init(UART2, &UART_InitStructure); // initialize uart 2 |
115 | 115 | ||
116 | // enable uart 2 interrupts selective |
116 | // enable uart 2 interrupts selective |
117 | UART_ITConfig(UART2, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE); |
117 | UART_ITConfig(UART2, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE); |
118 | UART_Cmd(UART2, ENABLE); // enable uart 2 |
118 | UART_Cmd(UART2, ENABLE); // enable uart 2 |
119 | // configure the uart 2 interupt line as an IRQ with priority 9 (0 is highest) |
119 | // configure the uart 2 interupt line as an IRQ with priority 9 (0 is highest) |
120 | VIC_Config(UART2_ITLine, VIC_IRQ, 9); |
120 | VIC_Config(UART2_ITLine, VIC_IRQ, 9); |
121 | // enable the uart 2 IRQ |
121 | // enable the uart 2 IRQ |
122 | VIC_ITCmd(UART2_ITLine, ENABLE); |
122 | VIC_ITCmd(UART2_ITLine, ENABLE); |
123 | 123 | ||
124 | SerialPutString("ok"); |
124 | SerialPutString("ok"); |
125 | } |
125 | } |
126 | 126 | ||
127 | 127 | ||
128 | void UART2_Deinit(void) |
128 | void UART2_Deinit(void) |
129 | { |
129 | { |
130 | GPIO_InitTypeDef GPIO_InitStructure; |
130 | GPIO_InitTypeDef GPIO_InitStructure; |
131 | 131 | ||
132 | SerialPutString("\r\n UART2 deinit..."); |
132 | SerialPutString("\r\n UART2 deinit..."); |
133 | VIC_ITCmd(UART2_ITLine, DISABLE); // disable the uart 2 IRQ |
133 | VIC_ITCmd(UART2_ITLine, DISABLE); // disable the uart 2 IRQ |
134 | UART_Cmd(UART2, DISABLE); // disable uart 2 |
134 | UART_Cmd(UART2, DISABLE); // disable uart 2 |
135 | UART_DeInit(UART2); // reset uart 0 to default |
135 | UART_DeInit(UART2); // reset uart 0 to default |
136 | 136 | ||
137 | SCU_APBPeriphClockConfig(__UART2, DISABLE); // disable the UART2 Clock |
137 | SCU_APBPeriphClockConfig(__UART2, DISABLE); // disable the UART2 Clock |
138 | 138 | ||
139 | SCU_APBPeriphClockConfig(__GPIO5, ENABLE); |
139 | SCU_APBPeriphClockConfig(__GPIO5, ENABLE); |
140 | // unmap UART2 from FC |
140 | // unmap UART2 from FC |
141 | // set port pin 5.2 (serial data from FC) to input and disconnect from IP |
141 | // set port pin 5.2 (serial data from FC) to input and disconnect from IP |
142 | GPIO_StructInit(&GPIO_InitStructure); |
142 | GPIO_StructInit(&GPIO_InitStructure); |
143 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
143 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
144 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; |
144 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; |
145 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
145 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
146 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable; |
146 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable; |
147 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
147 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
148 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
148 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
149 | 149 | ||
150 | SCU_APBPeriphClockConfig(__GPIO3, ENABLE); |
150 | SCU_APBPeriphClockConfig(__GPIO3, ENABLE); |
151 | // set port pin 3.0 (serial data to FC) to input and disconnect from IP |
151 | // set port pin 3.0 (serial data to FC) to input and disconnect from IP |
152 | GPIO_StructInit(&GPIO_InitStructure); |
152 | GPIO_StructInit(&GPIO_InitStructure); |
153 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
153 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
154 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; |
154 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; |
155 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
155 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
156 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable; |
156 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable; |
157 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
157 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
158 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
158 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
159 | 159 | ||
160 | SerialPutString("ok"); |
160 | SerialPutString("ok"); |
161 | } |
161 | } |
162 | 162 | ||
163 | /********************************************************/ |
163 | /********************************************************/ |
164 | /* UART2 Interrupt Handler */ |
164 | /* UART2 Interrupt Handler */ |
165 | /********************************************************/ |
165 | /********************************************************/ |
166 | void UART2_IRQHandler(void) |
166 | void UART2_IRQHandler(void) |
167 | { |
167 | { |
168 | // if receive irq or receive timeout irq has occured |
168 | // if receive irq or receive timeout irq has occured |
169 | if((UART_GetITStatus(UART2, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART2, UART_IT_ReceiveTimeOut) != RESET) ) |
169 | if((UART_GetITStatus(UART2, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART2, UART_IT_ReceiveTimeOut) != RESET) ) |
170 | { |
170 | { |
171 | UART_ClearITPendingBit(UART2, UART_IT_Receive); // clear receive interrupt flag |
171 | UART_ClearITPendingBit(UART2, UART_IT_Receive); // clear receive interrupt flag |
172 | UART_ClearITPendingBit(UART2, UART_IT_ReceiveTimeOut); // clear receive timeout interrupt flag |
172 | UART_ClearITPendingBit(UART2, UART_IT_ReceiveTimeOut); // clear receive timeout interrupt flag |
173 | 173 | ||
174 | // if debug UART is UART2 |
174 | // if debug UART is UART2 |
175 | if (DebugUART == UART2) |
175 | if (DebugUART == UART2) |
176 | { // forward received data to the UART1 tx buffer |
176 | { // forward received data to the UART1 tx buffer |
177 | while(UART_GetFlagStatus(UART2, UART_FLAG_RxFIFOEmpty) != SET) |
177 | while(UART_GetFlagStatus(UART2, UART_FLAG_RxFIFOEmpty) != SET) |
178 | { |
178 | { |
179 | // wait for space in the tx buffer of the UART1 |
179 | // wait for space in the tx buffer of the UART1 |
180 | while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) == SET) {}; |
180 | while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) == SET) {}; |
181 | // move the byte from the rx buffer of UART2 to the tx buffer of UART1 |
181 | // move the byte from the rx buffer of UART2 to the tx buffer of UART1 |
182 | UART_SendData(UART1, UART_ReceiveData(UART2)); |
182 | UART_SendData(UART1, UART_ReceiveData(UART2)); |
183 | } |
183 | } |
184 | } |
184 | } |
185 | else |
185 | else |
186 | { |
186 | { |
187 | // ignore serial data from the FC |
187 | // ignore serial data from the FC |
188 | while(UART_GetFlagStatus(UART2, UART_FLAG_RxFIFOEmpty) != SET) |
188 | while(UART_GetFlagStatus(UART2, UART_FLAG_RxFIFOEmpty) != SET) |
189 | UART_ReceiveData(UART2); |
189 | UART_ReceiveData(UART2); |
190 | } |
190 | } |
191 | } // eof receive irq or receive timeout irq |
191 | } // eof receive irq or receive timeout irq |
192 | } |
192 | } |
193 | 193 |