firmware/src/peripheral/src/usart.c
/* use usart2 for user communication with microcontroller */
use usart2 for user communication with microcontroller
use usart2 for user communication with microcontroller
void usart2_configuration(void) {
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2);
    GPIO_PinAFConfig(GPIOA, EXTI_PinSource3, GPIO_AF_USART2);
    GPIO_InitTypeDef GPIO_InitStructure;
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_Init(GPIOA,&GPIO_InitStructure);
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
    GPIO_Init(GPIOA,&GPIO_InitStructure);
    USART_InitTypeDef USART_InitStructure;
    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
    USART_InitStructure.USART_BaudRate = 115200;
    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_Init(USART2,&USART_InitStructure);
    USART_Cmd(USART2,ENABLE);
    USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
    NVIC_InitTypeDef NVIC_InitStructure;
    NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
    NVIC_Init(&NVIC_InitStructure);
}
void usart2_configuration ( void ) { RCC_AHB1PeriphClockCmd ( RCC_AHB1Periph_GPIOA , ENABLE ) ; RCC_APB1PeriphClockCmd ( RCC_APB1Periph_USART2 , ENABLE ) ; GPIO_PinAFConfig ( GPIOA , GPIO_PinSource2 , GPIO_AF_USART2 ) ; GPIO_PinAFConfig ( GPIOA , EXTI_PinSource3 , GPIO_AF_USART2 ) ; GPIO_InitTypeDef GPIO_InitStructure ; GPIO_InitStructure . GPIO_Pin = GPIO_Pin_2 ; GPIO_InitStructure . GPIO_Mode = GPIO_Mode_AF ; GPIO_InitStructure . GPIO_Speed = GPIO_Speed_100MHz ; GPIO_InitStructure . GPIO_PuPd = GPIO_PuPd_NOPULL ; GPIO_InitStructure . GPIO_OType = GPIO_OType_PP ; GPIO_Init ( GPIOA , & GPIO_InitStructure ) ; GPIO_InitStructure . GPIO_Pin = GPIO_Pin_3 ; GPIO_Init ( GPIOA , & GPIO_InitStructure ) ; USART_InitTypeDef USART_InitStructure ; USART_InitStructure . USART_Mode = USART_Mode_Rx | USART_Mode_Tx ; USART_InitStructure . USART_BaudRate = 115200 ; 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_Init ( USART2 , & USART_InitStructure ) ; USART_Cmd ( USART2 , ENABLE ) ; USART_ITConfig ( USART2 , USART_IT_RXNE , ENABLE ) ; NVIC_InitTypeDef NVIC_InitStructure ; NVIC_InitStructure . NVIC_IRQChannel = USART2_IRQn ; NVIC_InitStructure . NVIC_IRQChannelCmd = ENABLE ; NVIC_InitStructure . NVIC_IRQChannelPreemptionPriority = 2 ; NVIC_Init ( & NVIC_InitStructure ) ; }
use usart2 for user communication with microcontroller
use usart2 for user communication with microcontroller
/* enable gpio clock */ /* enable usart clock */ /* connect usart pin to AF7 */ /* configure usart tx and usart rx as alternate function */ /* config usart2 peripheral */ /* enable usart2 */ /* enable usart2 receive interrupt */