comparison Discovery/Src/ostc.c @ 38:5f11787b4f42

include in ostc4 repository
author heinrichsweikamp
date Sat, 28 Apr 2018 11:52:34 +0200
parents
children 923c4566a2a1
comparison
equal deleted inserted replaced
37:ccc45c0e1ea2 38:5f11787b4f42
1 ///////////////////////////////////////////////////////////////////////////////
2 /// -*- coding: UTF-8 -*-
3 ///
4 /// \file Discovery/Src/ostc.c
5 /// \brief Hardware specific configuration
6 /// \author Heinrichs Weikamp gmbh
7 /// \date 05-Dec-2014
8 ///
9 /// \details
10 ///
11 /// $Id$
12 ///////////////////////////////////////////////////////////////////////////////
13 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh
14 ///
15 /// This program is free software: you can redistribute it and/or modify
16 /// it under the terms of the GNU General Public License as published by
17 /// the Free Software Foundation, either version 3 of the License, or
18 /// (at your option) any later version.
19 ///
20 /// This program is distributed in the hope that it will be useful,
21 /// but WITHOUT ANY WARRANTY; without even the implied warranty of
22 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 /// GNU General Public License for more details.
24 ///
25 /// You should have received a copy of the GNU General Public License
26 /// along with this program. If not, see <http://www.gnu.org/licenses/>.
27 //////////////////////////////////////////////////////////////////////////////
28
29 /* Includes ------------------------------------------------------------------*/
30 #include "ostc.h"
31 #include "stm32f4xx_hal.h"
32
33 #ifndef BOOTLOADER_STANDALONE
34 #include "tCCR.h"
35 #endif
36
37 /* Exported variables --------------------------------------------------------*/
38 SPI_HandleTypeDef hspiDisplay;
39 SPI_HandleTypeDef cpu2DmaSpi;
40
41
42 UART_HandleTypeDef UartHandle;
43 UART_HandleTypeDef UartPiezoTxHandle;
44 UART_HandleTypeDef UartIR_HUD_Handle;
45
46 __IO ITStatus UartReady = RESET;
47 __IO ITStatus UartReadyHUD = RESET;
48
49 /* Private types -------------------------------------------------------------*/
50
51 /* Private variables ---------------------------------------------------------*/
52
53 /* Private variables with external access via get_xxx() function -------------*/
54
55 /* Private function prototypes -----------------------------------------------*/
56
57 /* Exported functions --------------------------------------------------------*/
58
59 /** SPI init function
60 * called from HAL
61 */
62 void MX_SPI_Init(void)
63 {
64 hspiDisplay.Instance = SPI5;
65 hspiDisplay.Init.Mode = SPI_MODE_MASTER;
66 hspiDisplay.Init.Direction = SPI_DIRECTION_2LINES;
67 hspiDisplay.Init.DataSize = SPI_DATASIZE_8BIT;
68 hspiDisplay.Init.CLKPolarity = SPI_POLARITY_LOW;
69 hspiDisplay.Init.CLKPhase = SPI_PHASE_1EDGE;
70 hspiDisplay.Init.NSS = SPI_NSS_SOFT;
71 hspiDisplay.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;//SPI_BAUDRATEPRESCALER_4;//SPI_BAUDRATEPRESCALER_256;
72 hspiDisplay.Init.FirstBit = SPI_FIRSTBIT_MSB;
73 hspiDisplay.Init.TIMode = SPI_TIMODE_DISABLED;
74 hspiDisplay.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
75 HAL_SPI_Init(&hspiDisplay);
76
77 cpu2DmaSpi.Instance = SPI1;
78 cpu2DmaSpi.Init.Mode = SPI_MODE_MASTER;
79 cpu2DmaSpi.Init.Direction = SPI_DIRECTION_2LINES;
80 cpu2DmaSpi.Init.DataSize = SPI_DATASIZE_8BIT;
81 cpu2DmaSpi.Init.CLKPolarity = SPI_POLARITY_LOW;
82 cpu2DmaSpi.Init.CLKPhase = SPI_PHASE_1EDGE;
83 cpu2DmaSpi.Init.NSS = SPI_NSS_SOFT;//SPI_NSS_HARD_OUTPUT;//SPI_NSS_SOFT;
84 cpu2DmaSpi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;
85 cpu2DmaSpi.Init.FirstBit = SPI_FIRSTBIT_MSB;
86 cpu2DmaSpi.Init.TIMode = SPI_TIMODE_DISABLED;
87 cpu2DmaSpi.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
88 cpu2DmaSpi.Init.CRCPolynomial = 7;
89
90 HAL_SPI_Init(&cpu2DmaSpi);
91 }
92
93
94 void MX_GPIO_Backlight_max_static_only_Init(void)
95 {
96 GPIO_InitTypeDef GPIO_InitStruct;
97 TIM_BACKLIGHT_GPIO_ENABLE();
98
99 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
100 GPIO_InitStruct.Pull = GPIO_NOPULL;//GPIO_PULLUP; /* should be normally high */
101 GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
102
103 GPIO_InitStruct.Pin = TIM_BACKLIGHT_PIN;
104 HAL_GPIO_Init(TIM_BACKLIGHT_GPIO_PORT, &GPIO_InitStruct);
105
106 HAL_GPIO_WritePin(TIM_BACKLIGHT_GPIO_PORT,TIM_BACKLIGHT_PIN,GPIO_PIN_SET);
107 }
108
109
110 void MX_GPIO_One_Button_only_Init(void)
111 {
112 GPIO_InitTypeDef GPIO_InitStruct;
113 BUTTON_NEXT_GPIO_ENABLE();
114
115 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
116 GPIO_InitStruct.Pull = GPIO_NOPULL;//GPIO_PULLUP; /* should be normally high */
117 GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
118
119 GPIO_InitStruct.Pin = BUTTON_NEXT_PIN;
120 HAL_GPIO_Init(BUTTON_NEXT_GPIO_PORT, &GPIO_InitStruct);
121 }
122
123
124 GPIO_PinState MX_GPIO_Read_The_One_Button(void)
125 {
126 return HAL_GPIO_ReadPin(BUTTON_NEXT_GPIO_PORT, BUTTON_NEXT_PIN);
127 }
128
129 void MX_GPIO_Init(void)
130 {
131 GPIO_InitTypeDef GPIO_InitStruct;
132
133 DISPLAY_CSB_GPIO_ENABLE();
134 DISPLAY_RESETB_GPIO_ENABLE();
135 EXTFLASH_CSB_GPIO_ENABLE();
136 SMALLCPU_CSB_GPIO_ENABLE();
137 OSCILLOSCOPE_GPIO_ENABLE();
138 OSCILLOSCOPE2_GPIO_ENABLE();
139
140 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
141 GPIO_InitStruct.Pull = GPIO_PULLUP;
142 GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
143
144 GPIO_InitStruct.Pin = DISPLAY_CSB_PIN;
145 HAL_GPIO_Init(DISPLAY_CSB_GPIO_PORT, &GPIO_InitStruct);
146
147 GPIO_InitStruct.Pin = DISPLAY_RESETB_PIN;
148 HAL_GPIO_Init(DISPLAY_RESETB_GPIO_PORT, &GPIO_InitStruct);
149
150 GPIO_InitStruct.Pin = EXTFLASH_CSB_PIN;
151 HAL_GPIO_Init(EXTFLASH_CSB_GPIO_PORT, &GPIO_InitStruct);
152
153 GPIO_InitStruct.Pin = OSCILLOSCOPE_PIN;
154 HAL_GPIO_Init(OSCILLOSCOPE_GPIO_PORT, &GPIO_InitStruct);
155
156 GPIO_InitStruct.Pin = OSCILLOSCOPE2_PIN;
157 HAL_GPIO_Init(OSCILLOSCOPE2_GPIO_PORT, &GPIO_InitStruct);
158
159 #ifdef DISPLAY_BACKLIGHT_PIN
160 DISPLAY_BACKLIGHT_GPIO_ENABLE();
161 GPIO_InitStruct.Pin = DISPLAY_BACKLIGHT_PIN;
162 HAL_GPIO_Init(DISPLAY_BACKLIGHT_GPIO_PORT, &GPIO_InitStruct);
163 HAL_GPIO_WritePin(DISPLAY_BACKLIGHT_GPIO_PORT,DISPLAY_BACKLIGHT_PIN,GPIO_PIN_SET);
164 #endif
165
166 #ifdef SMALLCPU_CSB_PIN
167 SMALLCPU_CSB_GPIO_ENABLE();
168 GPIO_InitStruct.Pin = SMALLCPU_CSB_PIN;
169 HAL_GPIO_Init(SMALLCPU_CSB_GPIO_PORT, &GPIO_InitStruct);
170 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET);
171 #endif
172
173 #ifdef SMALLCPU_BOOT0_PIN
174 GPIO_InitStruct.Pull = GPIO_NOPULL;
175 SMALLCPU_BOOT0_GPIO_ENABLE();
176 GPIO_InitStruct.Pin = SMALLCPU_BOOT0_PIN;
177 HAL_GPIO_Init(SMALLCPU_BOOT0_GPIO_PORT, &GPIO_InitStruct);
178 HAL_GPIO_WritePin(SMALLCPU_BOOT0_GPIO_PORT,SMALLCPU_BOOT0_PIN,GPIO_PIN_RESET);
179 GPIO_InitStruct.Pull = GPIO_PULLUP;
180 #endif
181
182 #ifdef IR_HUD_ENABLE_PIN
183 IR_HUD_ENABLE_GPIO_ENABLE();
184 GPIO_InitStruct.Pin = IR_HUD_ENABLE_PIN;
185 GPIO_InitStruct.Pull = GPIO_NOPULL;
186 HAL_GPIO_Init(IR_HUD_ENABLE_GPIO_PORT, &GPIO_InitStruct);
187 HAL_GPIO_WritePin(IR_HUD_ENABLE_GPIO_PORT,IR_HUD_ENABLE_PIN,GPIO_PIN_SET);
188 GPIO_InitStruct.Pull = GPIO_PULLUP;
189 #endif
190
191 #ifdef BLE_NENABLE_PIN
192 BLE_NENABLE_GPIO_ENABLE();
193 MX_Bluetooth_PowerOff();
194 #endif
195
196 #ifdef TESTPIN
197 GPIO_InitStruct.Pull = GPIO_PULLUP;
198 TEST_GPIO_ENABLE();
199 GPIO_InitStruct.Pin = TEST_PIN;
200 HAL_GPIO_Init(TEST_GPIO_PORT, &GPIO_InitStruct);
201 HAL_GPIO_WritePin(TEST_GPIO_PORT,TEST_PIN,GPIO_PIN_SET);
202 GPIO_InitStruct.Pull = GPIO_PULLUP;
203 #endif
204 }
205
206
207 void MX_TestPin_High(void)
208 {
209 #ifdef TESTPIN
210 HAL_GPIO_WritePin(TEST_GPIO_PORT,TEST_PIN,GPIO_PIN_SET);
211 #endif
212 }
213
214
215 void MX_TestPin_Low(void)
216 {
217 #ifdef TESTPIN
218 HAL_GPIO_WritePin(TEST_GPIO_PORT,TEST_PIN,GPIO_PIN_RESET);
219 #endif
220 }
221
222 void MX_Bluetooth_PowerOn(void)
223 {
224 GPIO_InitTypeDef GPIO_InitStruct;
225 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
226 GPIO_InitStruct.Pull = GPIO_NOPULL;
227 GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
228 GPIO_InitStruct.Pin = BLE_NENABLE_PIN;
229 HAL_GPIO_Init(BLE_NENABLE_GPIO_PORT, &GPIO_InitStruct);
230 HAL_GPIO_WritePin(BLE_NENABLE_GPIO_PORT,BLE_NENABLE_PIN,GPIO_PIN_RESET);
231 }
232
233
234 void MX_Bluetooth_PowerOff(void)
235 {
236 GPIO_InitTypeDef GPIO_InitStruct;
237 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
238 GPIO_InitStruct.Pin = BLE_NENABLE_PIN;
239 GPIO_InitStruct.Pull = GPIO_NOPULL;
240 HAL_GPIO_Init(BLE_NENABLE_GPIO_PORT, &GPIO_InitStruct);
241 }
242
243
244 void MX_SmallCPU_Reset_To_Boot(void)
245 {
246 #ifdef SMALLCPU_NRESET_PIN
247 GPIO_InitTypeDef GPIO_InitStruct;
248
249 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
250 GPIO_InitStruct.Pull = GPIO_NOPULL;
251 GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
252
253 SMALLCPU_NRESET_GPIO_ENABLE();
254 GPIO_InitStruct.Pin = SMALLCPU_NRESET_PIN;
255 HAL_GPIO_Init(SMALLCPU_NRESET_GPIO_PORT, &GPIO_InitStruct);
256 HAL_GPIO_WritePin(SMALLCPU_NRESET_GPIO_PORT,SMALLCPU_NRESET_PIN,GPIO_PIN_RESET);
257 HAL_GPIO_WritePin(SMALLCPU_BOOT0_GPIO_PORT,SMALLCPU_BOOT0_PIN,GPIO_PIN_SET);
258 HAL_Delay(2);
259 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
260 HAL_GPIO_Init(SMALLCPU_NRESET_GPIO_PORT, &GPIO_InitStruct);
261 HAL_Delay(100);
262 HAL_GPIO_WritePin(SMALLCPU_BOOT0_GPIO_PORT,SMALLCPU_BOOT0_PIN,GPIO_PIN_RESET);
263 #endif
264 }
265
266
267 void MX_SmallCPU_NO_Reset_Helper(void)
268 {
269 #ifdef SMALLCPU_NRESET_PIN
270 GPIO_InitTypeDef GPIO_InitStruct;
271
272 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
273 GPIO_InitStruct.Pull = GPIO_NOPULL;
274 GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
275
276 SMALLCPU_NRESET_GPIO_ENABLE();
277 HAL_GPIO_Init(SMALLCPU_NRESET_GPIO_PORT, &GPIO_InitStruct);
278 HAL_GPIO_WritePin(SMALLCPU_NRESET_GPIO_PORT,SMALLCPU_NRESET_PIN,GPIO_PIN_SET);
279 // HAL_Delay(100);
280 // GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
281 // HAL_GPIO_Init(SMALLCPU_NRESET_GPIO_PORT, &GPIO_InitStruct);
282 #endif
283 }
284
285
286 void MX_SmallCPU_Reset_To_Standard(void)
287 {
288 #ifdef SMALLCPU_NRESET_PIN
289 GPIO_InitTypeDef GPIO_InitStruct;
290
291 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
292 GPIO_InitStruct.Pull = GPIO_NOPULL;
293 GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
294
295 SMALLCPU_NRESET_GPIO_ENABLE();
296 GPIO_InitStruct.Pin = SMALLCPU_NRESET_PIN;
297 HAL_GPIO_Init(SMALLCPU_NRESET_GPIO_PORT, &GPIO_InitStruct);
298 HAL_GPIO_WritePin(SMALLCPU_NRESET_GPIO_PORT,SMALLCPU_NRESET_PIN,GPIO_PIN_RESET);
299 HAL_GPIO_WritePin(SMALLCPU_BOOT0_GPIO_PORT,SMALLCPU_BOOT0_PIN,GPIO_PIN_RESET);
300 HAL_Delay(2);
301 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
302 HAL_GPIO_Init(SMALLCPU_NRESET_GPIO_PORT, &GPIO_InitStruct);
303 #endif
304 }
305
306
307 uint8_t MX_UART_ButtonAdjust(uint8_t *array)
308 {
309 #ifdef USART_PIEZO
310 uint8_t answer[4];
311 HAL_UART_Transmit(&UartPiezoTxHandle,array,4,1000);
312 HAL_UART_Receive(&UartPiezoTxHandle,answer,4,2000);
313 if( (answer[0] == array[0])
314 &&(answer[1] == array[1])
315 &&(answer[2] == array[2])
316 &&(answer[3] == array[3]))
317 return 1;
318 #endif
319 return 0;
320 }
321
322
323 void MX_UART_Init(void)
324 {
325 /*##-1- Configure the UART peripheral ######################################*/
326 /* Put the USART peripheral in the Asynchronous mode (UART Mode) */
327 /* UART1 configured as follow:
328 - Word Length = 8 Bits
329 - Stop Bit = One Stop bit
330 - Parity = None
331 - BaudRate = 9600 baud
332 - Hardware flow control disabled (RTS and CTS signals) */
333
334 #ifdef USARTx_CTS_PIN
335 UartHandle.Init.HwFlowCtl = UART_HWCONTROL_RTS_CTS;
336 #else
337 UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
338 #endif
339 UartHandle.Instance = USARTx;
340 UartHandle.Init.BaudRate = 115200;
341 UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
342 UartHandle.Init.StopBits = UART_STOPBITS_1;
343 UartHandle.Init.Parity = UART_PARITY_NONE;
344 UartHandle.Init.Mode = UART_MODE_TX_RX;
345 HAL_UART_Init(&UartHandle);
346
347 #ifdef USART_PIEZO
348 UartPiezoTxHandle.Instance = USART_PIEZO;
349 UartPiezoTxHandle.Init.BaudRate = 1200;
350 UartPiezoTxHandle.Init.WordLength = UART_WORDLENGTH_8B;
351 UartPiezoTxHandle.Init.StopBits = UART_STOPBITS_1;
352 UartPiezoTxHandle.Init.Parity = UART_PARITY_NONE;
353 UartPiezoTxHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
354 UartPiezoTxHandle.Init.Mode = UART_MODE_TX_RX;
355
356 HAL_UART_Init(&UartPiezoTxHandle);
357 #endif
358
359 #ifdef USART_IR_HUD
360 UartIR_HUD_Handle.Instance = USART_IR_HUD;
361 UartIR_HUD_Handle.Init.BaudRate = 2400;
362 UartIR_HUD_Handle.Init.WordLength = UART_WORDLENGTH_8B;
363 UartIR_HUD_Handle.Init.StopBits = UART_STOPBITS_1;
364 UartIR_HUD_Handle.Init.Parity = UART_PARITY_NONE;
365 UartIR_HUD_Handle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
366 UartIR_HUD_Handle.Init.Mode = UART_MODE_TX_RX;
367
368 HAL_UART_Init(&UartIR_HUD_Handle);
369 #endif
370 }
371
372 void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
373 {
374 if(huart == &UartHandle)
375 UartReady = SET;
376 }
377
378
379
380 //void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
381 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
382 {
383 if(huart == &UartHandle)
384 UartReady = SET;
385 else
386 if(huart == &UartIR_HUD_Handle)
387 {
388 UartReadyHUD = SET;
389 }
390 }
391
392 void MX_tell_reset_logik_alles_ok(void)
393 {
394 #ifdef RESET_LOGIC_ALLES_OK_PIN
395 GPIO_InitTypeDef GPIO_InitStruct;
396
397 RESET_LOGIC_ALLES_OK_GPIO_ENABLE();
398
399 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
400 GPIO_InitStruct.Pull = GPIO_NOPULL;
401 GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
402 GPIO_InitStruct.Pin = RESET_LOGIC_ALLES_OK_PIN;
403 HAL_GPIO_Init(RESET_LOGIC_ALLES_OK_GPIO_PORT, &GPIO_InitStruct);
404
405 HAL_GPIO_WritePin(RESET_LOGIC_ALLES_OK_GPIO_PORT,RESET_LOGIC_ALLES_OK_PIN,GPIO_PIN_RESET);
406 HAL_Delay(1);
407 HAL_GPIO_WritePin(RESET_LOGIC_ALLES_OK_GPIO_PORT,RESET_LOGIC_ALLES_OK_PIN,GPIO_PIN_SET);
408
409 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
410 HAL_GPIO_Init(RESET_LOGIC_ALLES_OK_GPIO_PORT, &GPIO_InitStruct);
411 #endif
412 }
413
414
415 #ifndef BOOTLOADER_STANDALONE
416 void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
417 {
418 if(huart == &UartIR_HUD_Handle)
419 tCCR_restart();
420 }
421 #endif