forked from DiSlord/NanoVNA-D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hardware.c
129 lines (118 loc) · 3.47 KB
/
hardware.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* Copyright (c) 2019-2020, Dmitry (DiSlord) [email protected]
* Based on TAKAHASHI Tomohiro (TTRFTECH) [email protected]
* All rights reserved.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* The software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include "ch.h"
#include "hal.h"
#include "nanovna.h"
// Compact STM32 ADC library
#if HAL_USE_ADC == TRUE
#error "Error VNA use self ADC lib, define HAL_USE_ADC = FALSE in halconf.h"
#endif
#ifdef NANOVNA_F303
#include "NANOVNA_STM32_F303/adc_v3.c"
#else
#include "NANOVNA_STM32_F072/adc_v1.c"
#endif
// Compact STM32 I2C library
#if HAL_USE_I2C == TRUE
#error "Error VNA use self I2C lib, define HAL_USE_I2C = FALSE in halconf.h"
#endif
#ifdef NANOVNA_F303
#include "NANOVNA_STM32_F303/i2c_v2.c"
#else
#include "NANOVNA_STM32_F072/i2c_v2.c"
#endif
#ifdef __USE_RTC__
// Compact STM32 RTC time library
#if HAL_USE_RTC == TRUE
#error "Error VNA use self RTC lib, define HAL_USE_RTC = FALSE in halconf.h"
#endif
#ifdef NANOVNA_F303
#include "NANOVNA_STM32_F303/rtc_v2.c"
#else
#include "NANOVNA_STM32_F072/rtc_v2.c"
#endif
#endif
// Compact STM32 DAC library
#if HAL_USE_DAC == TRUE
#error "Need disable HAL_USE_DAC in halconf.h for use VNA_DAC"
#endif
#ifdef NANOVNA_F303
#include "NANOVNA_STM32_F303/dac_v1.c"
#else
#include "NANOVNA_STM32_F072/dac_v1.c"
#endif
// Compact STM32 I2S library
#if HAL_USE_I2S == TRUE
#error "Need disable HAL_USE_DAC in halconf.h for use VNA_DAC"
#endif
#ifdef NANOVNA_F303
#include "NANOVNA_STM32_F303/i2s.c"
#else
#include "NANOVNA_STM32_F072/i2s.c"
#endif
// Compact STM32 flash library
#ifdef NANOVNA_F303
#include "NANOVNA_STM32_F303/flash.c"
#else
#include "NANOVNA_STM32_F072/flash.c"
#endif
// Compact STM32 GPIO library
#if HAL_USE_PAL == FALSE
#ifdef NANOVNA_F303
#include "NANOVNA_STM32_F303/gpio_v2.c"
#else
#include "NANOVNA_STM32_F072/gpio_v2.c"
#endif
#endif
// Compact STM32 DMA library
#ifdef NANOVNA_F303
#include "NANOVNA_STM32_F303/dma_v1.c"
#else
#include "NANOVNA_STM32_F072/dma_v1.c"
#endif
// Compact STM32 EXT library
#if HAL_USE_EXT == FALSE
#ifdef NANOVNA_F303
#include "NANOVNA_STM32_F303/exti_v1.c"
#else
#include "NANOVNA_STM32_F072/exti_v1.c"
#endif
#endif
#if HAL_USE_GPT == FALSE
// Run TIM2 as us timer counter (used as STM32_ST_TIM timer in ChibiOS)
// Run TIM3 as ms timer counter
void initTimers(void) {
// rccEnableTIM2(FALSE);
rccEnableTIM3(FALSE);
// TIM2 use AHB1 bus clock (32 bit timer), use STM32_TIMCLK1 clock source
// TIM2->PSC = STM32_TIMCLK1 / (1000000U) - 1; // 1MHz tick
// TIM3 use AHB1 bus clock (16 bit timer), used in touch period handler
TIM3->PSC = STM32_TIMCLK1 / (1000U) - 1; // 1kHz tick
TIM3->CR2 = 0x20; // Generate TRIGO event for ADC watchdog
}
//
void startTimer(TIM_TypeDef *timer, uint32_t period) {
timer->ARR = period - 1;
timer->EGR = STM32_TIM_EGR_UG;
timer->CNT = 0;
timer->CR1 = STM32_TIM_CR1_URS | STM32_TIM_CR1_CEN;
}
#endif