1 | INTERRUPTS_OFF();
|
2 |
|
3 | //Define all of the periphals we use.
|
4 | uint32_t apb1Peripherals = ( RCC_APB1Periph_PWR |
|
5 | RCC_APB1Periph_USART3
|
6 | );
|
7 | uint32_t apb2Peripherals = ( 0 );
|
8 | uint32_t ahbPeripherals = ( RCC_AHBPeriph_GPIOA |
|
9 | RCC_AHBPeriph_GPIOB |
|
10 | RCC_AHBPeriph_GPIOC);
|
11 |
|
12 | //Enable clocks to all of our peripherals.
|
13 | RCC_APB1PeriphClockCmd(apb1Peripherals, ENABLE);
|
14 | RCC_APB2PeriphClockCmd(apb2Peripherals, ENABLE);
|
15 | RCC_AHBPeriphClockCmd(ahbPeripherals, ENABLE );
|
16 |
|
17 | //Allow access to BKP Domain
|
18 | PWR_BackupAccessCmd(ENABLE);
|
19 |
|
20 | //De-initialize our peripherals here so each module only has to
|
21 | //worry about initializing them as needed. DeInit works by toggling
|
22 | //PeriphResetCmd enable/disable.
|
23 | EXTI_DeInit();
|
24 |
|
25 | GPIO_DeInit(GPIOA);
|
26 | GPIO_DeInit(GPIOB);
|
27 | GPIO_DeInit(GPIOC);
|
28 | GPIO_DeInit(GPIOD);
|
29 |
|
30 | USART_DeInit(USART3);
|
31 |
|
32 | //Configure USART TX GPIO as alternate function push-pull
|
33 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
34 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
|
35 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
36 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
37 | GPIO_Init(GPIOB, &GPIO_InitStructure);
|
38 | GPIO_PinAFConfig(GPIOB, GPIO_Pin_10, GPIO_AF_7);
|
39 |
|
40 | //Configure USART RX GPIO as input floating
|
41 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
42 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
|
43 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
44 | GPIO_Init(GPIOB, &GPIO_InitStructure);
|
45 | GPIO_PinAFConfig(GPIOB, GPIO_Pin_11, GPIO_AF_7);
|
46 |
|
47 | //Configure USART (but without enabling it)
|
48 | USART_InitStructure.USART_BaudRate = 9600;
|
49 | USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
50 | USART_InitStructure.USART_Parity = USART_Parity_No;
|
51 | USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
52 | USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
53 | USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
|
54 | USART_Init(USART3, &USART_InitStructure);
|
55 |
|
56 | USART_Cmd(USART3, ENABLE);
|
57 |
|
58 | INTERRUPTS_ON(); // Safe to enable interrupts at this point
|
59 |
|
60 | while( true )
|
61 | {
|
62 | while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
|
63 | USART_SendData(USART3, 0xAA);
|
64 | while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
|
65 | USART_SendData(USART3, 0x55);
|
66 | }
|