166 lines
5.3 KiB
C
166 lines
5.3 KiB
C
/* add user code begin Header */
|
|
/**
|
|
**************************************************************************
|
|
* @file wk_usart.c
|
|
* @brief work bench config program
|
|
**************************************************************************
|
|
* Copyright notice & Disclaimer
|
|
*
|
|
* The software Board Support Package (BSP) that is made available to
|
|
* download from Artery official website is the copyrighted work of Artery.
|
|
* Artery authorizes customers to use, copy, and distribute the BSP
|
|
* software and its related documentation for the purpose of design and
|
|
* development in conjunction with Artery microcontrollers. Use of the
|
|
* software is governed by this copyright notice and the following disclaimer.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
|
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
|
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
|
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
|
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
|
*
|
|
**************************************************************************
|
|
*/
|
|
/* add user code end Header */
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include "includes.h"
|
|
|
|
/* add user code begin 0 */
|
|
|
|
/* add user code end 0 */
|
|
|
|
/**
|
|
* @brief init usart2 function
|
|
* @param none
|
|
* @retval none
|
|
*/
|
|
void wk_usart2_init(void)
|
|
{
|
|
/* add user code begin usart2_init 0 */
|
|
|
|
/* add user code end usart2_init 0 */
|
|
|
|
gpio_init_type gpio_init_struct;
|
|
gpio_default_para_init(&gpio_init_struct);
|
|
|
|
/* add user code begin usart2_init 1 */
|
|
|
|
/* add user code end usart2_init 1 */
|
|
|
|
/* configure the TX pin */
|
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
|
gpio_init_struct.gpio_pins = GPIO_PINS_2;
|
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
|
gpio_init(GPIOA, &gpio_init_struct);
|
|
|
|
/* configure the RX pin */
|
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
|
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
|
|
gpio_init_struct.gpio_pins = GPIO_PINS_3;
|
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
|
gpio_init(GPIOA, &gpio_init_struct);
|
|
|
|
/* configure param */
|
|
usart_init(USART2, 31250, USART_DATA_8BITS, USART_STOP_1_BIT);
|
|
usart_transmitter_enable(USART2, TRUE);
|
|
usart_receiver_enable(USART2, TRUE);
|
|
usart_parity_selection_config(USART2, USART_PARITY_NONE);
|
|
|
|
usart_hardware_flow_control_set(USART2, USART_HARDWARE_FLOW_NONE);
|
|
|
|
/* add user code begin usart2_init 2 */
|
|
nvic_irq_enable(USART2_IRQn,1,0);
|
|
|
|
usart_interrupt_enable(USART2,USART_RDBF_INT,TRUE);
|
|
usart_interrupt_enable(USART2,USART_TDBE_INT,FALSE);
|
|
/* add user code end usart2_init 2 */
|
|
|
|
usart_enable(USART2, TRUE);
|
|
|
|
/* add user code begin usart2_init 3 */
|
|
|
|
/* 关联 USART2 环形队列外设 */
|
|
uart_ring_usart2_init();
|
|
|
|
/* 使能中断:清残留标志 → 开 NVIC → 开外设中断源 */
|
|
usart_flag_clear(USART2, USART_RDBF_FLAG);
|
|
usart_flag_clear(USART2, USART_ROERR_FLAG);
|
|
nvic_irq_enable(USART2_IRQn, 5, 0);
|
|
usart_interrupt_enable(USART2, USART_RDBF_INT, TRUE);
|
|
usart_interrupt_enable(USART2, USART_ERR_INT, TRUE);
|
|
|
|
/* add user code end usart2_init 3 */
|
|
}
|
|
|
|
/**
|
|
* @brief init uart4 function
|
|
* @param none
|
|
* @retval none
|
|
*/
|
|
void wk_uart4_init(void)
|
|
{
|
|
/* add user code begin uart4_init 0 */
|
|
|
|
/* add user code end uart4_init 0 */
|
|
|
|
gpio_init_type gpio_init_struct;
|
|
gpio_default_para_init(&gpio_init_struct);
|
|
|
|
/* add user code begin uart4_init 1 */
|
|
|
|
/* add user code end uart4_init 1 */
|
|
|
|
/* configure the TX pin */
|
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
|
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
|
gpio_init_struct.gpio_pins = GPIO_PINS_10;
|
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
|
gpio_init(GPIOC, &gpio_init_struct);
|
|
|
|
/* configure the RX pin */
|
|
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
|
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
|
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
|
|
gpio_init_struct.gpio_pins = GPIO_PINS_11;
|
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
|
gpio_init(GPIOC, &gpio_init_struct);
|
|
|
|
/* configure param */
|
|
usart_init(UART4, 115200, USART_DATA_8BITS, USART_STOP_1_BIT);
|
|
usart_transmitter_enable(UART4, TRUE);
|
|
usart_receiver_enable(UART4, TRUE);
|
|
usart_parity_selection_config(UART4, USART_PARITY_NONE);
|
|
|
|
usart_hardware_flow_control_set(UART4, USART_HARDWARE_FLOW_NONE);
|
|
|
|
/* add user code begin uart4_init 2 */
|
|
|
|
/* add user code end uart4_init 2 */
|
|
|
|
usart_enable(UART4, TRUE);
|
|
|
|
/* add user code begin uart4_init 3 */
|
|
|
|
/* 关联 UART4 环形队列外设 */
|
|
uart_ring_uart4_init();
|
|
|
|
/* 使能中断:清残留标志 → 开 NVIC → 开外设中断源 */
|
|
usart_flag_clear(UART4, USART_RDBF_FLAG);
|
|
usart_flag_clear(UART4, USART_ROERR_FLAG);
|
|
nvic_irq_enable(UART4_IRQn, 5, 0);
|
|
usart_interrupt_enable(UART4, USART_RDBF_INT, TRUE);
|
|
usart_interrupt_enable(UART4, USART_ERR_INT, TRUE);
|
|
|
|
/* add user code end uart4_init 3 */
|
|
}
|
|
|
|
/* add user code begin 1 */
|
|
|
|
/* add user code end 1 */
|