-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperipheral_config.c
More file actions
119 lines (96 loc) · 3.16 KB
/
peripheral_config.c
File metadata and controls
119 lines (96 loc) · 3.16 KB
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
#include "peripheral_config.h"
/**
* \fn void Clock_Config(void)
* \brief Configure clocks
* \param None
* \return None
*/
void Clock_Config(void)
{
RCC_DeInit();
RCC_HSEConfig(RCC_HSE_OFF);
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);
RCC_HSICmd(ENABLE);
//RCC_AdjustHSICalibrationValue(16);
RCC_PLLCmd(DISABLE);
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
SysTick_Config(HSI_VALUE/1000);
}
/**
* \fn void GPIO_Config(void)
* \brief Configure used digital outputs and inputs
* \param None
* \return None
*/
void GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* LEDs as output */
RCC_AHBPeriphClockCmd(LED_GPIO_CLK, ENABLE);
GPIO_InitStructure.GPIO_Pin = LED_PIN ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(LED_GPIO_PORT, &GPIO_InitStructure);
GPIO_SetBits(LED_GPIO_PORT,LED_PIN);
/* PWRKEY as output */
RCC_AHBPeriphClockCmd(PWRKEY_GPIO_CLK, ENABLE);
GPIO_InitStructure.GPIO_Pin = PWRKEY_PIN ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(PWRKEY_GPIO_PORT, &GPIO_InitStructure);
GPIO_ResetBits(PWRKEY_GPIO_PORT,PWRKEY_PIN);
}
/**
* \fn void Config_uart(BaudRate_TypeDef BaudRate)
* \brief Configure UART1 peripheral
* \return None
*/
void UART_Config(void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable UART1 TX GPIO clock */
RCC_AHBPeriphClockCmd(U1_GPIO_CLK, ENABLE);
/* Enable USART1 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
/* Connect USART1 to AF*/
GPIO_PinAFConfig(U1TX_GPIO_PORT, U1TX_SOURCE, GPIO_AF_1);
GPIO_PinAFConfig(U1RX_GPIO_PORT, U1RX_SOURCE, GPIO_AF_1);
/* Configure USART Tx & Rx as alternate function push-pull */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = U1TX_PIN|U1RX_PIN;
GPIO_Init(U1TX_GPIO_PORT, &GPIO_InitStructure);
/* Enable USART1 IRQ */
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
/* Enable USART */
USART_Cmd(USART1, ENABLE);
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
USART_ITConfig(USART1,USART_IT_TXE,DISABLE);
}
void USART_Puts(char* str)
{
while(*str)
{
while( USART_GetFlagStatus(USART1,USART_FLAG_TXE)==0 );
USART_SendData(USART1, *str);
*str++;
}
}