VSF Documented
device.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18/*============================ INCLUDES ======================================*/
19/*============================ MACROS ========================================*/
20
21#ifdef __VSF_HEADER_ONLY_SHOW_ARCH_INFO__
22
23/*\note first define basic info for arch. */
25# define VSF_ARCH_PRI_NUM 8
26# define VSF_ARCH_PRI_BIT 3
27
28# define VSF_DEV_COMMON_SWI_NUM 32
29
30#elif defined(__VSF_HAL_SHOW_VENDOR_INFO__)
31
32/*\note __VSF_HAL_SHOW_VENDOR_INFO__ is defined to include vendor information only.
33 * Vendor information means the registers/structures/macros from vendor SDK.
34 * Usually these information are not visible from user side to avoid name-space pollution.
35 */
36
37# define __VSF_HEADER_ONLY_SHOW_VENDOR_INFO__
38# include "./vendor/libraries/cmsis/cm4/device_support/at32f402_405.h"
39
40#else
41
42#ifndef __HAL_DEVICE_COMMON_ATTERY_AT32F402_405_H__
43#define __HAL_DEVICE_COMMON_ATTERY_AT32F402_405_H__
44
45/*============================ MACROS ========================================*/
46
47// user configurations with default value
48
49// HW definition
50
51// SWI
52
53#define VSF_DEV_COMMON_SWI_LIST \
54 43, 46, 47, 48, 49, 50, 61, 62, \
55 63, 64, 65, 66, 70, 78, 79, 80, \
56 84, 86, 87, 88, 89, 90, 91, 93, \
57 95, 96, 97, 98, 99, 100, 101, 102
58
59// RAM
60
61#ifndef VSF_HW_RAM_COUNT
62# define VSF_HW_RAM_COUNT 1
63#endif
64#if VSF_HW_RAM_COUNT >= 1 && !defined(VSF_HW_RAM0_ADDR)
65# define VSF_HW_RAM0_ADDR 0x20000000
66#endif
67
68// FLASH
69
70#ifndef VSF_HW_FLASH_COUNT
71# define VSF_HW_FLASH_COUNT 1
72#endif
73#if VSF_HW_FLASH_COUNT >= 1 && !defined(VSF_HW_FLASH0_ADDR)
74# define VSF_HW_FLASH0_ADDR 0x08000000
75#endif
76
77// GPIO: PORT0..PORT3, PORT5
78
79#ifndef VSF_HW_GPIO_PORT_MASK
80# ifdef VSF_HW_GPIO_PORT_COUNT
81# define VSF_HW_GPIO_PORT_MASK ((1 << VSF_HW_GPIO_PORT_COUNT) - 1)
82# else
83# define VSF_HW_GPIO_PORT_MASK 0x2F
84# endif
85#endif
86#if VSF_HW_GPIO_PORT_MASK & ~0x2F
87# error invalid VSF_HW_GPIO_PORT_MASK
88#endif
89
90#ifndef VSF_HW_GPIO_PIN_COUNT
91# define VSF_HW_GPIO_PIN_COUNT 16
92#endif
93#ifndef VSF_HW_GPIO_FUNCTION_MAX
94# define VSF_HW_GPIO_FUNCTION_MAX 16
95#endif
96
97#if VSF_HW_GPIO_PORT_MASK & (1 << 0)
98# define VSF_HW_GPIO_PORT0_REG GPIOA
99# ifndef VSF_HW_GPIO_PORT0_MASK
100# define VSF_HW_GPIO_PORT0_MASK 0xFFFF
101# elif VSF_HW_GPIO_PORT0_MASK & ~0xFFFF
102# error invalid VSF_HW_GPIO_PORT0_MASK
103# endif
104#endif
105#if VSF_HW_GPIO_PORT_MASK & (1 << 1)
106# define VSF_HW_GPIO_PORT1_REG GPIOB
107# ifndef VSF_HW_GPIO_PORT1_MASK
108# define VSF_HW_GPIO_PORT1_MASK 0xFFFF
109# elif VSF_HW_GPIO_PORT1_MASK & ~0xFFFF
110# error invalid VSF_HW_GPIO_PORT1_MASK
111# endif
112#endif
113#if VSF_HW_GPIO_PORT_MASK & (1 << 2)
114# define VSF_HW_GPIO_PORT2_REG GPIOC
115# ifndef VSF_HW_GPIO_PORT2_MASK
116# define VSF_HW_GPIO_PORT2_MASK 0xFFFF
117# elif VSF_HW_GPIO_PORT2_MASK & ~0xFFFF
118# error invalid VSF_HW_GPIO_PORT2_MASK
119# endif
120#endif
121#if VSF_HW_GPIO_PORT_MASK & (1 << 3)
122# define VSF_HW_GPIO_PORT3_REG GPIOD
123# ifndef VSF_HW_GPIO_PORT3_MASK
124# define VSF_HW_GPIO_PORT3_MASK 0x0004
125# elif VSF_HW_GPIO_PORT3_MASK & ~0xFFFF
126# error invalid VSF_HW_GPIO_PORT3_MASK
127# endif
128#endif
129#if VSF_HW_GPIO_PORT_MASK & (1 << 5)
130# define VSF_HW_GPIO_PORT5_REG GPIOF
131# ifndef VSF_HW_GPIO_PORT5_MASK
132# define VSF_HW_GPIO_PORT5_MASK 0x08F3
133# elif VSF_HW_GPIO_PORT5_MASK & ~0x08F3
134# error invalid VSF_HW_GPIO_PORT5_MASK
135# endif
136#endif
137
138// USART: USART1..USART8
139
140#ifndef VSF_HW_USART_MASK
141# ifdef VSF_HW_USART_COUNT
142# define VSF_HW_USART_MASK ((1 << VSF_HW_USART_COUNT) - 1)
143# else
144# define VSF_HW_USART_MASK 0x01FE
145# endif
146#endif
147#if VSF_HW_USART_MASK & ~0x01FE
148# error invalid VSF_HW_USART_MASK
149#endif
150
151#if VSF_HW_USART_MASK & (1 << 1)
152# define VSF_HW_USART1_REG USART1
153# define VSF_HW_USART1_CLK VSF_HW_CLK_USART1
154# define VSF_HW_USART1_EN VSF_HW_EN_USART1
155# define VSF_HW_USART1_RST VSF_HW_RST_USART1
156# define VSF_HW_USART1_SYNC true
157# define VSF_HW_USART1_IRQN USART1_IRQn
158# define VSF_HW_USART1_IRQHandler USART1_IRQHandler
159#endif
160#if VSF_HW_USART_MASK & (1 << 2)
161# define VSF_HW_USART2_REG USART2
162# define VSF_HW_USART2_CLK VSF_HW_CLK_USART2
163# define VSF_HW_USART2_EN VSF_HW_EN_USART2
164# define VSF_HW_USART2_RST VSF_HW_RST_USART2
165# define VSF_HW_USART2_SYNC true
166# define VSF_HW_USART2_IRQN USART2_IRQn
167# define VSF_HW_USART2_IRQHandler USART2_IRQHandler
168#endif
169#if VSF_HW_USART_MASK & (1 << 3)
170# define VSF_HW_USART3_REG USART3
171# define VSF_HW_USART3_CLK VSF_HW_CLK_USART3
172# define VSF_HW_USART3_EN VSF_HW_EN_USART3
173# define VSF_HW_USART3_RST VSF_HW_RST_USART3
174# define VSF_HW_USART3_SYNC true
175# define VSF_HW_USART3_IRQN USART3_IRQn
176# define VSF_HW_USART3_IRQHandler USART3_IRQHandler
177#endif
178#if VSF_HW_USART_MASK & (1 << 4)
179# define VSF_HW_USART4_REG USART4
180# define VSF_HW_USART4_CLK VSF_HW_CLK_USART4
181# define VSF_HW_USART4_EN VSF_HW_EN_USART4
182# define VSF_HW_USART4_RST VSF_HW_RST_USART4
183# define VSF_HW_USART4_SYNC true
184# define VSF_HW_USART4_IRQN USART4_IRQn
185# define VSF_HW_USART4_IRQHandler USART4_IRQHandler
186#endif
187#if VSF_HW_USART_MASK & (1 << 5)
188# define VSF_HW_USART5_REG USART5
189# define VSF_HW_USART5_CLK VSF_HW_CLK_USART5
190# define VSF_HW_USART5_EN VSF_HW_EN_USART5
191# define VSF_HW_USART5_RST VSF_HW_RST_USART5
192# define VSF_HW_USART5_SYNC true
193# define VSF_HW_USART5_IRQN USART5_IRQn
194# define VSF_HW_USART5_IRQHandler USART5_IRQHandler
195#endif
196#if VSF_HW_USART_MASK & (1 << 6)
197# define VSF_HW_USART6_REG USART6
198# define VSF_HW_USART6_CLK VSF_HW_CLK_USART6
199# define VSF_HW_USART6_EN VSF_HW_EN_USART6
200# define VSF_HW_USART6_RST VSF_HW_RST_USART6
201# define VSF_HW_USART6_SYNC true
202# define VSF_HW_USART6_IRQN USART6_IRQn
203# define VSF_HW_USART6_IRQHandler USART6_IRQHandler
204#endif
205#if VSF_HW_USART_MASK & (1 << 7)
206# define VSF_HW_USART7_REG UART7
207# define VSF_HW_USART7_CLK VSF_HW_CLK_UART7
208# define VSF_HW_USART7_EN VSF_HW_EN_UART7
209# define VSF_HW_USART7_RST VSF_HW_RST_UART7
210# define VSF_HW_USART7_SYNC false
211# define VSF_HW_USART7_IRQN UART7_IRQn
212# define VSF_HW_USART7_IRQHandler UART7_IRQHandler
213#endif
214#if VSF_HW_USART_MASK & (1 << 8)
215# define VSF_HW_USART8_REG UART8
216# define VSF_HW_USART8_CLK VSF_HW_CLK_UART8
217# define VSF_HW_USART8_EN VSF_HW_EN_UART8
218# define VSF_HW_USART8_RST VSF_HW_RST_UART8
219# define VSF_HW_USART8_SYNC false
220# define VSF_HW_USART8_IRQN UART8_IRQn
221# define VSF_HW_USART8_IRQHandler UART8_IRQHandler
222#endif
223
224// SPI: SPI1..SPI3
225
226#ifndef VSF_HW_SPI_MASK
227# ifdef VSF_HW_SPI_COUNT
228# define VSF_HW_SPI_MASK ((1 << VSF_HW_SPI_COUNT) - 1)
229# else
230# define VSF_HW_SPI_MASK 0x0E
231# endif
232#endif
233#if VSF_HW_SPI_MASK & ~0x0E
234# error invalid VSF_HW_SPI_MASK
235#endif
236
237#if VSF_HW_SPI_MASK & (1 << 1)
238# define VSF_HW_SPI1_REG SPI1
239# define VSF_HW_SPI1_CLK VSF_HW_CLK_SPI1
240# define VSF_HW_SPI1_EN VSF_HW_EN_SPI1
241# define VSF_HW_SPI1_RST VSF_HW_RST_SPI1
242# define VSF_HW_SPI1_IRQN SPI1_IRQn
243# define VSF_HW_SPI1_IRQ SPI1_IRQHandler
244#endif
245#if VSF_HW_SPI_MASK & (1 << 2)
246# define VSF_HW_SPI2_REG SPI2
247# define VSF_HW_SPI2_CLK VSF_HW_CLK_SPI2
248# define VSF_HW_SPI2_EN VSF_HW_EN_SPI2
249# define VSF_HW_SPI2_RST VSF_HW_RST_SPI2
250# define VSF_HW_SPI2_IRQN SPI2_IRQn
251# define VSF_HW_SPI2_IRQ SPI2_IRQHandler
252#endif
253#if VSF_HW_SPI_MASK & (1 << 3)
254# define VSF_HW_SPI3_REG SPI3
255# define VSF_HW_SPI3_CLK VSF_HW_CLK_SPI3
256# define VSF_HW_SPI3_EN VSF_HW_EN_SPI3
257# define VSF_HW_SPI3_RST VSF_HW_RST_SPI3
258# define VSF_HW_SPI3_IRQN SPI3_IRQn
259# define VSF_HW_SPI3_IRQ SPI3_IRQHandler
260#endif
261
262// I2C: I2C1..I2C3
263
264#ifndef VSF_HW_I2C_MASK
265# ifdef VSF_HW_I2C_COUNT
266# define VSF_HW_I2C_MASK ((1 << VSF_HW_I2C_COUNT) - 1)
267# else
268# define VSF_HW_I2C_MASK 0x0E
269# endif
270#endif
271#if VSF_HW_I2C_MASK & ~0x0E
272# error invalid VSF_HW_I2C_MASK
273#endif
274
275#if VSF_HW_I2C_MASK & (1 << 1)
276# define VSF_HW_I2C1_REG I2C1
277# define VSF_HW_I2C1_CLK VSF_HW_CLK_I2C1
278# define VSF_HW_I2C1_EN VSF_HW_EN_I2C1
279# define VSF_HW_I2C1_RST VSF_HW_RST_I2C1
280# define VSF_HW_I2C1_EVENT_IRQN I2C1_EVT_IRQn
281# define VSF_HW_I2C1_EVENT_IRQHandler I2C1_EVT_IRQHandler
282# define VSF_HW_I2C1_ERROR_IRQN I2C1_ERR_IRQn
283# define VSF_HW_I2C1_ERROR_IRQHandler I2C1_ERR_IRQHandler
284#endif
285#if VSF_HW_I2C_MASK & (1 << 2)
286# define VSF_HW_I2C2_REG I2C2
287# define VSF_HW_I2C2_CLK VSF_HW_CLK_I2C2
288# define VSF_HW_I2C2_EN VSF_HW_EN_I2C2
289# define VSF_HW_I2C2_RST VSF_HW_RST_I2C2
290# define VSF_HW_I2C2_EVENT_IRQN I2C2_EVT_IRQn
291# define VSF_HW_I2C2_EVENT_IRQHandler I2C2_EVT_IRQHandler
292# define VSF_HW_I2C2_ERROR_IRQN I2C2_ERR_IRQn
293# define VSF_HW_I2C2_ERROR_IRQHandler I2C2_ERR_IRQHandler
294#endif
295#if VSF_HW_I2C_MASK & (1 << 3)
296# define VSF_HW_I2C3_REG I2C3
297# define VSF_HW_I2C3_CLK VSF_HW_CLK_I2C3
298# define VSF_HW_I2C3_EN VSF_HW_EN_I2C3
299# define VSF_HW_I2C3_RST VSF_HW_RST_I2C3
300# define VSF_HW_I2C3_EVENT_IRQN I2C3_EVT_IRQn
301# define VSF_HW_I2C3_EVENT_IRQHandler I2C3_EVT_IRQHandler
302# define VSF_HW_I2C3_ERROR_IRQN I2C3_ERR_IRQn
303# define VSF_HW_I2C3_ERROR_IRQHandler I2C3_ERR_IRQHandler
304#endif
305
306// USB OTG
307
308#ifndef VSF_HW_USB_OTG_MASK
309# ifdef VSF_HW_USB_OTG_COUNT
310# define VSF_HW_USB_OTG_MASK ((1 << VSF_HW_USB_OTG_COUNT) - 1)
311# else
312# define VSF_HW_USB_OTG_MASK 0x03
313# endif
314#endif
315
316// required by dwcotg, define the max ep number of dwcotg include ep0
317#ifndef USB_DWCOTG_MAX_EP_NUM
318# define USB_DWCOTG_MAX_EP_NUM 16
319#endif
320
321#if VSF_HW_USB_OTG_MASK & (1 << 0)
322# define VSF_HW_USB_OTG0_IRQHandler OTGFS1_IRQHandler
323# define VSF_HW_USB_OTG0_CONFIG \
324 .dc_ep_num = 8 << 1, \
325 .hc_ep_num = 16, \
326 .reg = (void *)OTGFS1_BASE, \
327 .irq = OTGFS1_IRQn, \
328 .en = VSF_HW_EN_OTGFS1, \
329 .phyclk = &VSF_HW_CLK_HICK, \
330 .phyclk_freq_required = 48 * 1000 * 1000, \
331 /* vk_dwcotg_hw_info_t */ \
332 .buffer_word_size = 320, \
333 .speed = USB_SPEED_FULL, \
334 .dma_en = false, \
335 .ulpi_en = false, \
336 .utmi_en = false, \
337 .vbus_en = false,
338#endif
339
340#if VSF_HW_USB_OTG_MASK & (1 << 1)
341// TODO: 修复DMA模式BUG, 修复高速模式的BUG
342# define VSF_HW_USB_OTG1_IRQHandler OTGHS_IRQHandler
343# define VSF_HW_USB_OTG1_CONFIG \
344 .dc_ep_num = 8 << 1, \
345 .hc_ep_num = 16, \
346 .reg = (void *)OTGHS_BASE, \
347 .irq = OTGHS_IRQn, \
348 .en = VSF_HW_EN_OTGHS, \
349 .phyclk = &VSF_HW_CLK_HEXT, \
350 .phyclk_freq_required = 12 * 1000 * 1000, \
351 /* vk_dwcotg_hw_info_t */ \
352 .buffer_word_size = 1024, \
353 .speed = USB_SPEED_HIGH, \
354 .dma_en = false, \
355 .ulpi_en = false, \
356 .utmi_en = false, \
357 .vbus_en = false,
358#endif
359
360/*============================ INCLUDES ======================================*/
361
362// Include common irq and af headers after peripherals are defined, so that
363// irq and af can be adjusted according to the dedicated device configuration.
364
365#include "./common.h"
366#include "./device_irq.h"
367#include "./device_af.h"
368
369/*============================ MACROS ========================================*/
370
371/*============================ MACROFIED FUNCTIONS ===========================*/
372/*============================ TYPES =========================================*/
373/*============================ GLOBAL VARIABLES ==============================*/
374/*============================ LOCAL VARIABLES ===============================*/
375/*============================ PROTOTYPES ====================================*/
376
377#endif // __HAL_DEVICE_COMMON_ATTERY_AT32F402_405_H__
378#endif // __VSF_HEADER_ONLY_SHOW_ARCH_INFO__
379
380/* EOF */
Generated from commit: vsfteam/vsf@3f091ef