void SER2_Init (void) {
RCC->APB1ENR |= (1UL << 17); /* Enable USART2 clock */
RCC->AHB1ENR |= (1UL << 3); /* Enable GPIOD clock */
/* Connect PD5 and PD6 to Alternate Function 7 (AF7) */
GPIOD->MODER &= (3 << 2*5) | (3 << 2*6);
GPIOD->MODER |= (2 << 2*5) | (2 << 2*6);
GPIOD->AFR[0] &= ~0x0FF00000;
GPIOD->AFR[0] |= 0x07700000;
/* Configure USART2: 115200 baud @ 42MHz, 8 bits, 1 stop bit, no parity */
USART2->BRR = (22 << 4) | 12;
USART2->CR3 = 0x0000;
USART2->CR2 = 0x0000;
USART2->CR1 = 0x200C;
}
void SER3_Init (void) {
int i;
GPIO_InitTypeDef GPIO_InitStructure;
RCC->APB1ENR |= ( 1 << 18); /* Enable USART3 clock */
RCC->AHB1ENR |= ( 1 << 3); /* Enable GPIOD clock */
/* Connect PD8 and PD9 to Alternate Function 7 (AF7) */
GPIOD->MODER &= (3 << 2*8) | (3 << 2*9);
GPIOD->MODER |= (2 << 2*8) | (2 << 2*9);
GPIOD->AFR[1] &= ~0x000000FF;
GPIOD->AFR[1] |= 0x00000077;
/* Configure USART2: 115200 baud @ 42MHz, 8 bits, 1 stop bit, no parity */
USART3->BRR = (22 << 4) | 12;
USART3->CR3 = 0x0000;
USART3->CR2 = 0x0000;
for (i = 0; i < 0x1000; i++) __NOP(); /* avoid unwanted output */
USART3->CR1 = 0x200C;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_Init(GPIOD, &GPIO_InitStructure);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_Init(GPIOD, &GPIO_InitStructure);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_Init(GPIOD, &GPIO_InitStructure);
} |