1 | /***************************************************************************//**
|
2 | * Global macros
|
3 | ******************************************************************************/
|
4 |
|
5 | #define LED_PORT GPIOC
|
6 | #define BUTTON_PORT GPIOA
|
7 |
|
8 | #define LED_BLUE GPIO_Pin_8
|
9 | #define LED_GREEN GPIO_Pin_9
|
10 |
|
11 | #define BUTTON_BLUE GPIO_Pin_0
|
12 |
|
13 | [...]
|
14 |
|
15 | /* Enable GPIO clock */
|
16 | RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC, ENABLE);
|
17 | RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART2, ENABLE);
|
18 |
|
19 | // Port C -> LEDs
|
20 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
|
21 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
22 | GPIO_InitStructure.GPIO_Pin = LED_GREEN | LED_BLUE;
|
23 | GPIO_Init(LED_PORT, &GPIO_InitStructure);
|
24 |
|
25 | // Port A -> blue button
|
26 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
27 | GPIO_InitStructure.GPIO_Pin = BUTTON_BLUE;
|
28 | GPIO_Init(BUTTON_PORT, &GPIO_InitStructure);
|
29 |
|
30 | /* Configure USART2 Rx (PA3) as input floating */
|
31 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
|
32 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
33 | GPIO_Init(GPIOA, &GPIO_InitStructure);
|
34 |
|
35 | /* Configure USART2 Tx (PA2) as alternate function push-pull */
|
36 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
|
37 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
|
38 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
39 | GPIO_Init(GPIOA, &GPIO_InitStructure);
|
40 |
|
41 | /* USART2 configured as follow:
|
42 | - BaudRate = 115200 baud
|
43 | - Word Length = 8 Bits
|
44 | - One Stop Bit
|
45 | - No parity
|
46 | - Hardware flow control disabled (RTS and CTS signals)
|
47 | - Receive and transmit enabled
|
48 | - USART Clock disabled
|
49 | - USART CPOL: Clock is active low
|
50 | - USART CPHA: Data is captured on the middle
|
51 | - USART LastBit: The clock pulse of the last data bit is not output to
|
52 | the SCLK pin
|
53 | */
|
54 | USART_InitStructure.USART_BaudRate = 115200;
|
55 | USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
56 | USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
57 | USART_InitStructure.USART_Parity = USART_Parity_No ;
|
58 | USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
59 | USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
|
60 | USART_Init(USART2, &USART_InitStructure);
|
61 | USART_Cmd( USART2, ENABLE);
|