1 /*
2 * Copyright (c) 2006-2022, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2020-08-20 Abbcc first version
9 */
10
11 #include "board.h"
12
apm32_usart_init(void)13 void apm32_usart_init(void)
14 {
15 GPIO_Config_T GPIO_ConfigStruct;
16
17 #ifdef BSP_USING_UART1
18 RCM_EnableAPB2PeriphClock((RCM_APB2_PERIPH_T)(RCM_APB2_PERIPH_GPIOA | RCM_APB2_PERIPH_USART1));
19
20 GPIO_ConfigStruct.mode = GPIO_MODE_AF_PP;
21 GPIO_ConfigStruct.pin = GPIO_PIN_9;
22 GPIO_ConfigStruct.speed = GPIO_SPEED_50MHz;
23 GPIO_Config(GPIOA, &GPIO_ConfigStruct);
24
25 GPIO_ConfigStruct.mode = GPIO_MODE_IN_PU;
26 GPIO_ConfigStruct.pin = GPIO_PIN_10;
27 GPIO_ConfigStruct.speed = GPIO_SPEED_50MHz;
28 GPIO_Config(GPIOA, &GPIO_ConfigStruct);
29 #endif
30
31 #ifdef BSP_USING_UART2
32 RCM_EnableAPB2PeriphClock(RCM_APB2_PERIPH_GPIOA);
33 RCM_EnableAPB1PeriphClock(RCM_APB1_PERIPH_USART2);
34
35 GPIO_ConfigStruct.mode = GPIO_MODE_AF_PP;
36 GPIO_ConfigStruct.pin = GPIO_PIN_2;
37 GPIO_ConfigStruct.speed = GPIO_SPEED_50MHz;
38 GPIO_Config(GPIOA, &GPIO_ConfigStruct);
39
40 GPIO_ConfigStruct.mode = GPIO_MODE_IN_PU;
41 GPIO_ConfigStruct.pin = GPIO_PIN_3;
42 GPIO_ConfigStruct.speed = GPIO_SPEED_50MHz;
43 GPIO_Config(GPIOA, &GPIO_ConfigStruct);
44 #endif
45 }
46
apm32_msp_sdio_init(void * Instance)47 void apm32_msp_sdio_init(void *Instance)
48 {
49 GPIO_Config_T GPIO_InitStructure;
50
51 /* Enable the GPIO and DMA2 Clock */
52 RCM_EnableAPB2PeriphClock(RCM_APB2_PERIPH_GPIOC | RCM_APB2_PERIPH_GPIOD);
53
54 /* Enable the SDIO Clock */
55 RCM_EnableAHBPeriphClock(RCM_AHB_PERIPH_SDIO);
56
57 /* Configure the GPIO pin */
58 GPIO_InitStructure.pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12;
59 GPIO_InitStructure.mode = GPIO_MODE_AF_PP;
60 GPIO_InitStructure.speed = GPIO_SPEED_50MHz;
61 GPIO_Config(GPIOC, &GPIO_InitStructure);
62
63 GPIO_InitStructure.pin = GPIO_PIN_2;
64 GPIO_Config(GPIOD, &GPIO_InitStructure);
65 }
66
apm32_msp_can_init(void * Instance)67 void apm32_msp_can_init(void *Instance)
68 {
69 #if defined(BSP_USING_CAN1) || defined(BSP_USING_CAN2)
70 GPIO_Config_T GPIO_InitStructure;
71 CAN_T *CANx = (CAN_T *)Instance;
72
73 if (CAN1 == CANx)
74 {
75 RCM_EnableAPB1PeriphClock(RCM_APB1_PERIPH_CAN1);
76
77 RCM_EnableAPB2PeriphClock(RCM_APB2_PERIPH_AFIO);
78 RCM_EnableAPB2PeriphClock(RCM_APB2_PERIPH_GPIOD);
79
80 GPIO_ConfigPinRemap(GPIO_REMAP2_CAN1);
81
82 /* CAN1 Tx */
83 GPIO_InitStructure.pin = GPIO_PIN_1;
84 GPIO_InitStructure.mode = GPIO_MODE_AF_PP;
85 GPIO_InitStructure.speed = GPIO_SPEED_50MHz;
86 GPIO_Config(GPIOD, &GPIO_InitStructure);
87
88 /* CAN1 Rx */
89 GPIO_InitStructure.pin = GPIO_PIN_0;
90 GPIO_InitStructure.mode = GPIO_MODE_IN_FLOATING;
91 GPIO_Config(GPIOD, &GPIO_InitStructure);
92 }
93 else if (CAN2 == CANx)
94 {
95 RCM_EnableAPB1PeriphClock(RCM_APB1_PERIPH_CAN2);
96
97 RCM_EnableAPB2PeriphClock(RCM_APB2_PERIPH_AFIO);
98 RCM_EnableAPB2PeriphClock(RCM_APB2_PERIPH_GPIOB);
99
100 GPIO_ConfigPinRemap(GPIO_REMAP_CAN2);
101
102 /* CAN2 Tx */
103 GPIO_InitStructure.pin = GPIO_PIN_6;
104 GPIO_InitStructure.mode = GPIO_MODE_AF_PP;
105 GPIO_InitStructure.speed = GPIO_SPEED_50MHz;
106 GPIO_Config(GPIOB, &GPIO_InitStructure);
107
108 /* CAN2 Rx */
109 GPIO_InitStructure.pin = GPIO_PIN_5;
110 GPIO_InitStructure.mode = GPIO_MODE_IN_FLOATING;
111 GPIO_Config(GPIOB, &GPIO_InitStructure);
112 }
113 #endif
114 }
115