95ce2328
李外
完成USB移植,测试正常,
|
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
|
/*!
\file main.c
\brief construct a USB custom HID device
\version 2020-08-01, V3.0.0, firmware for GD32F30x
*/
/*
Copyright (c) 2020, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "custom_hid_core.h"
|
3a54a732
李外
V100.0.16 GD32F3...
|
36
|
#include "drv_usb_hw.h"
|
95ce2328
李外
完成USB移植,测试正常,
|
37
38
39
40
41
42
|
#include "platform.h"
#include "base_core_user.h"
#include "function_interface.h"
#include "platform_interface.h"
#include "HW_MCUIO.h"
|
88180837
李外
1、移植何工名单管理功能;
|
43
|
#include "function.h"
|
95ce2328
李外
完成USB移植,测试正常,
|
44
45
46
47
48
|
//????"function.h" ???"base_config.h"??????,????????1K?????,
//???????????,????????????????????1K?????1mS,
//??????????????20220624
#include "function.h"//#include "base_config.h"
|
dcc9b193
李外
V100.0.2 完成基站升级功能。
|
49
50
|
#define VECT_TAB_OFFSET 0x8000 //???????8K
|
3a54a732
李外
V100.0.16 GD32F3...
|
51
|
usb_core_driver custom_hid;
|
95ce2328
李外
完成USB移植,测试正常,
|
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
void TIMER1_Init(void);
void TIMER2_Init(void);
void GPIO_Init(void);
extern hid_fop_handler fop_handler;
/*!
\brief main routine
\param[in] none
\param[out] none
\retval none
|
df8068e7
李外
其他基本完成,扩展信标还有SDK信...
|
66
|
|
95ce2328
李外
完成USB移植,测试正常,
|
67
68
69
70
|
*/
int main(void)
{
|
dcc9b193
李外
V100.0.2 完成基站升级功能。
|
71
|
nvic_vector_table_set(NVIC_VECTTAB_FLASH, VECT_TAB_OFFSET);
|
a0293f87
李外
1、用新写法替换所有开关总中断的语句;
|
72
73
|
__enable_irq();
PLATFORM_DISABLE_IRQ();//__disable_irq();
|
95ce2328
李外
完成USB移植,测试正常,
|
74
|
/* system clocks configuration */
|
0897ce2d
李外
rf 的 SPI暂未调通,还是有问题
|
75
|
|
95ce2328
李外
完成USB移植,测试正常,
|
76
|
rcu_config();
|
3a54a732
李外
V100.0.16 GD32F3...
|
77
78
|
usb_timer_init();
|
95ce2328
李外
完成USB移植,测试正常,
|
79
80
81
|
// /* GPIO configuration */
// gpio_config();
|
3a54a732
李外
V100.0.16 GD32F3...
|
82
83
84
85
|
custom_hid_itfop_register(&custom_hid, &fop_handler);
PLATFORM_ENABLE_IRQ();//__enable_irq();
|
95ce2328
李外
完成USB移植,测试正常,
|
86
|
/* USB device configuration */
|
3a54a732
李外
V100.0.16 GD32F3...
|
87
|
usbd_init (&custom_hid, USB_CORE_ENUM_FS, &custom_hid_desc, &usbd_custom_hid_cb);
|
95ce2328
李外
完成USB移植,测试正常,
|
88
89
|
/* NVIC configuration */
|
3a54a732
李外
V100.0.16 GD32F3...
|
90
|
usb_intr_config();//nvic_config();
|
95ce2328
李外
完成USB移植,测试正常,
|
91
|
|
3a54a732
李外
V100.0.16 GD32F3...
|
92
93
|
// /* GPIO configuration */
// gpio_config();
|
88180837
李外
1、移植何工名单管理功能;
|
94
|
systick_config();
|
95ce2328
李外
完成USB移植,测试正常,
|
95
96
97
|
GPIO_Init();
/* enabled USB pull-up */
|
3a54a732
李外
V100.0.16 GD32F3...
|
98
|
// usbd_connect(&custom_hid);
|
95ce2328
李外
完成USB移植,测试正常,
|
99
100
101
|
HW_RF_SPI_Init();
|
3a54a732
李外
V100.0.16 GD32F3...
|
102
103
|
// void gpio_config(void);
// gpio_config();
|
4fe99ff7
李外
SPI移植完成,RF功能测试通过,...
|
104
105
106
|
base_core.core_init();////???????????
function.aes__init();
|
95ce2328
李外
完成USB移植,测试正常,
|
107
|
|
3a54a732
李外
V100.0.16 GD32F3...
|
108
|
// PLATFORM_ENABLE_IRQ();//__enable_irq();
|
4fe99ff7
李外
SPI移植完成,RF功能测试通过,...
|
109
110
|
TIMER1_Init();
TIMER2_Init();
|
3a54a732
李外
V100.0.16 GD32F3...
|
111
112
113
|
// while (USBD_CONFIGURED != custom_hid.cur_status) {
// /* wait for standard USB enumeration is finished */
// }
|
95ce2328
李外
完成USB移植,测试正常,
|
114
|
|
1e904e01
李外
V100.0.23
|
115
116
117
118
119
|
/* confiure FWDGT counter clock: 40KHz(IRC40K) / 64 = 0.625 KHz */
fwdgt_config(2*500,FWDGT_PSC_DIV64);
/* After 1.6 seconds to generate a reset */
fwdgt_enable();// watch dog 1.6 S
|
95ce2328
李外
完成USB移植,测试正常,
|
120
|
while(1){
|
1e904e01
李外
V100.0.23
|
121
|
fwdgt_counter_reload();//reload watch dog
|
95ce2328
李外
完成USB移植,测试正常,
|
122
|
base_core.core_loop();
|
1e904e01
李外
V100.0.23
|
123
|
// msg_polling();//function.msg__polling();
|
95ce2328
李外
完成USB移植,测试正常,
|
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
//uint8_t Send_buf[64] = {0x00};
//custom_hid_report_send (&usbd_custom_hid, Send_buf, 64U);
}
}
void TIMER1_Init(void)
{
timer_parameter_struct initpara = {0};
initpara.prescaler = 1200 - 1;// 120M / 1200 = 100KHz
initpara.alignedmode = TIMER_COUNTER_EDGE;
initpara.counterdirection = TIMER_COUNTER_UP;
initpara.period = 250 - 1;
initpara.clockdivision = TIMER_CKDIV_DIV1;
initpara.repetitioncounter = 0;
timer_init(TIMER1, &initpara);
|
d791c667
李外
V0.1.2
|
141
|
nvic_irq_enable(TIMER1_IRQn, 3U, 0U);//(TIMER1_IRQn, 3U, 0U);
|
95ce2328
李外
完成USB移植,测试正常,
|
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
timer_counter_value_config(TIMER1, 0);
timer_prescaler_config(TIMER1, 1200 - 1, TIMER_PSC_RELOAD_NOW);
timer_autoreload_value_config(TIMER1, 250 - 1);
timer_interrupt_disable(TIMER1, TIMER_INT_UP);
timer_interrupt_flag_clear(TIMER1, TIMER_INT_FLAG_UP);
timer_interrupt_enable(TIMER1, TIMER_INT_UP);
timer_enable(TIMER1);
}
void TIMER2_Init(void)
{
timer_parameter_struct initpara = {0};
initpara.prescaler = 1200 - 1;// 120M / 1200 = 100KHz
initpara.alignedmode = TIMER_COUNTER_EDGE;
initpara.counterdirection = TIMER_COUNTER_UP;
initpara.period = 2000 - 1;
initpara.clockdivision = TIMER_CKDIV_DIV1;
initpara.repetitioncounter = 0;
timer_init(TIMER2, &initpara);
|
88180837
李外
1、移植何工名单管理功能;
|
164
|
nvic_irq_enable(TIMER2_IRQn, 4U, 0U);
|
95ce2328
李外
完成USB移植,测试正常,
|
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
timer_counter_value_config(TIMER2, 0);
timer_prescaler_config(TIMER2, 1200 - 1, TIMER_PSC_RELOAD_NOW);
timer_autoreload_value_config(TIMER2, 2000 - 1);
timer_interrupt_disable(TIMER2, TIMER_INT_UP);
timer_interrupt_flag_clear(TIMER2, TIMER_INT_FLAG_UP);
timer_interrupt_enable(TIMER2, TIMER_INT_UP);
timer_enable(TIMER2);
}
void GPIO_Init(void)
{
HW_GPIO_InitTypeDef GPIO_InitStruct;
|
3a54a732
李外
V100.0.16 GD32F3...
|
179
180
|
// /*Configure GPIO pin Output Level */
HW_GPIO_ResetPin(GPIOC, GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6);
|
95ce2328
李外
完成USB移植,测试正常,
|
181
|
|
3a54a732
李外
V100.0.16 GD32F3...
|
182
183
|
// /*Configure GPIO pin Output Level */
HW_GPIO_ResetPin(GPIOA, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_8);
|
95ce2328
李外
完成USB移植,测试正常,
|
184
|
|
3a54a732
李外
V100.0.16 GD32F3...
|
185
186
|
// /*Configure GPIO pin Output Level */
HW_GPIO_ResetPin(GPIOB, GPIO_PIN_8|GPIO_PIN_9);
|
95ce2328
李外
完成USB移植,测试正常,
|
187
188
189
190
191
192
193
194
195
|
/*Configure GPIO pins : PC1 PC4 PC5 PC6 */
GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6;
GPIO_InitStruct.Mode = HW_GPIO_MODE_OUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = HW_GPIO_SPEED_VERY_HIGH;
HW_GPIO_Init(GPIOC, &GPIO_InitStruct);
/*Configure GPIO pins : PA0 PA1 PA2 PA8 */
|
1e904e01
李外
V100.0.23
|
196
|
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10;
|
95ce2328
李外
完成USB移植,测试正常,
|
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
GPIO_InitStruct.Mode = HW_GPIO_MODE_OUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = HW_GPIO_SPEED_VERY_HIGH;
HW_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : PC7 */
GPIO_InitStruct.Pin = GPIO_PIN_7;
GPIO_InitStruct.Mode = HW_GPIO_MODE_FLOATING;//GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HW_GPIO_Init(GPIOC, &GPIO_InitStruct);
/*Configure GPIO pins : PB8 PB9 */
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
GPIO_InitStruct.Mode = HW_GPIO_MODE_OUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = HW_GPIO_SPEED_VERY_HIGH;
HW_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
3a54a732
李外
V100.0.16 GD32F3...
|
214
215
|
HW_GPIO_SetPin(GPIOA, GPIO_PIN_8);//USB 1.5K Pull_up
|
1e904e01
李外
V100.0.23
|
216
217
218
219
220
|
#ifdef DEBUG_IO
HW_GPIO_ResetPin(GPIOA, GPIO_PIN_9);
HW_GPIO_ResetPin(GPIOA, GPIO_PIN_10);
#endif
|
95ce2328
李外
完成USB移植,测试正常,
|
221
|
|
4fe99ff7
李外
SPI移植完成,RF功能测试通过,...
|
222
|
|
95ce2328
李外
完成USB移植,测试正常,
|
223
|
}
|