⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 probe_rs232c.c

📁 ST32F10xxx+uCOSII2.85的官方源代码,带LCD驱动,支持Keil3和IAR环境.这个可以做为参考,实际使用需要修改,他做的太复杂了,目录也很深
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
*********************************************************************************************************
*                                      uC/Probe Communication
*
*                           (c) Copyright 2007; Micrium, Inc.; Weston, FL
*
*               All rights reserved.  Protected by international copyright laws.
*               Knowledge of the source code may NOT be used to develop a similar product.
*               Please help us continue to provide the Embedded community with the finest
*               software available.  Your honesty is greatly appreciated.
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*
*                                              uC/Probe
*
*                                      Communication: RS-232
*                                      Port for the ST STM32
*
* Filename      : probe_rs232c.c
* Version       : V1.20
* Programmer(s) : Brian Nagel
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                            INCLUDE FILES
*********************************************************************************************************
*/

#include  <probe_rs232.h>
#include  <includes.h>

/*
*********************************************************************************************************
*                                            LOCAL DEFINES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                       LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                      LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                      LOCAL CONFIGURATION ERRORS
*********************************************************************************************************
*/

#ifndef    PROBE_RS232_COMM_SEL

  #error  "PROBE_RS232_COMM_SEL              not #define'd in 'probe_com_cfg.h'     "
  #error  "                                  [MUST be  PROBE_RS232_UART_1   ]       "
  #error  "                                  [     ||  PROBE_RS232_UART_2   ]       "
  #error  "                                  [     ||  PROBE_RS232_UART_3   ]       "

#elif     (PROBE_RS232_COMM_SEL != PROBE_RS232_UART_1) && \
          (PROBE_RS232_COMM_SEL != PROBE_RS232_UART_2) && \
          (PROBE_RS232_COMM_SEL != PROBE_RS232_UART_3)

  #error  "PROBE_RS232_COMM_SEL        illegally #define'd in 'probe_com_cfg.h'     "
  #error  "                                  [MUST be  PROBE_RS232_UART_1   ]       "
  #error  "                                  [     ||  PROBE_RS232_UART_2   ]       "
  #error  "                                  [     ||  PROBE_RS232_UART_3   ]       "
#endif

#ifndef    PROBE_RS232_UART_1_REMAP

  #error  "PROBE_RS232_UART_1_REMAP          not #define'd in 'probe_com_cfg.h'     "
  #error  "                                  [MUST be  DEF_TRUE   ]                 "
  #error  "                                  [     ||  DEF_FALSE  ]                 "
#endif

#ifndef    PROBE_RS232_UART_2_REMAP

  #error  "PROBE_RS232_UART_2_REMAP          not #define'd in 'probe_com_cfg.h'     "
  #error  "                                  [MUST be  DEF_TRUE   ]                 "
  #error  "                                  [     ||  DEF_FALSE  ]                 "
#endif

#ifndef    PROBE_RS232_UART_3_REMAP_PARTIAL

  #error  "PROBE_RS232_UART_3_REMAP_PARTIAL  not #define'd in 'probe_com_cfg.h'     "
  #error  "                                  [MUST be  DEF_TRUE   ]                 "
  #error  "                                  [     ||  DEF_FALSE  ]                 "
#endif

#ifndef    PROBE_RS232_UART_3_REMAP_FULL

  #error  "PROBE_RS232_UART_3_REMAP_FULL     not #define'd in 'probe_com_cfg.h'     "
  #error  "                                  [MUST be  DEF_TRUE   ]                 "
  #error  "                                  [     ||  DEF_FALSE  ]                 "
#endif

/*
*********************************************************************************************************
*********************************************************************************************************
*                                         GLOBAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                       Initialize COM port for uC/Probe RS-232 Communication Module
*
* Description: Initialize the UART for uC/Probe communication.
*
* Argument(s): baud_rate    is intended baud rate of the RS-232.
*
* Returns    : None
*
* Note(s)    : (1) The following constants control the GPIO remap for the USART control lines:
*
*                       PROBE_RS232_UART_1_REMAP
*                       PROBE_RS232_UART_2_REMAP
*                       PROBE_RS232_UART_3_REMAP_PARTIAL
*                       PROBE_RS232_UART_3_REMAP_FULL
*
*                   Though the #error directives in "Local Configuration Errors" will require that
*                   all are defined, the value of those bearing on the USART not used will have no
*                   effect.
*
*               (2) PROBE_RS232_UART_3_REMAP_PARTIAL has precedence over PROBE_RS232_UART_3_REMAP_FULL,
*                   if both are defined to DEF_TRUE.
*********************************************************************************************************
*/

void  ProbeRS232_InitTarget (CPU_INT32U baud_rate)
{
    GPIO_InitTypeDef   gpio_init;
    USART_InitTypeDef  usart_init;
    NVIC_InitTypeDef   nvic_init;


#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

                                                                /* ------------------- SETUP USART1 GPIO ------------------ */
#if (PROBE_RS232_UART_1_REMAP > 0)
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
    GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);

                                                                /* Configure GPIOB.6 as push-pull                           */
    gpio_init.GPIO_Pin   = GPIO_Pin_6;
    gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
    gpio_init.GPIO_Mode  = GPIO_Mode_AF_PP;
    GPIO_Init(GPIOD, &gpio_init);

                                                                /* Configure GPIOB.7 as input floating                      */
    gpio_init.GPIO_Pin   = GPIO_Pin_7;
    gpio_init.GPIO_Mode  = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOB, &gpio_init);
#else
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

                                                                /* Configure GPIOA.9 as push-pull                           */
    gpio_init.GPIO_Pin   = GPIO_Pin_9;
    gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
    gpio_init.GPIO_Mode  = GPIO_Mode_AF_PP;
    GPIO_Init(GPIOA, &gpio_init);

                                                                /* Configure GPIOA.10 as input floating                     */
    gpio_init.GPIO_Pin   = GPIO_Pin_10;
    gpio_init.GPIO_Mode  = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOA, &gpio_init);
#endif

                                                                /* -------------------- SETUP USART1 ---------------------- */
    usart_init.USART_BaudRate            = baud_rate;
    usart_init.USART_WordLength          = USART_WordLength_8b;
    usart_init.USART_StopBits            = USART_StopBits_1;
    usart_init.USART_Parity              = USART_Parity_No ;
    usart_init.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
    usart_init.USART_Mode                = USART_Mode_Rx | USART_Mode_Tx;
    usart_init.USART_Clock               = USART_Clock_Disable;
    usart_init.USART_CPOL                = USART_CPOL_Low;
    usart_init.USART_CPHA                = USART_CPHA_2Edge;
    usart_init.USART_LastBit             = USART_LastBit_Disable;

    USART_Init(USART1, &usart_init);
    USART_Cmd(USART1, ENABLE);

    nvic_init.NVIC_IRQChannel                   = USART1_IRQChannel;
    nvic_init.NVIC_IRQChannelPreemptionPriority = 0;
    nvic_init.NVIC_IRQChannelSubPriority        = 0;
    nvic_init.NVIC_IRQChannelCmd                = ENABLE;
    NVIC_Init(&nvic_init);
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_2)
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

                                                                /* ------------------- SETUP USART2 GPIO ------------------ */
#if (PROBE_RS232_UART_2_REMAP > 0)
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO, ENABLE);
    GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);

                                                                /* Configure GPIOD.4 as push-pull                           */
    gpio_init.GPIO_Pin   = GPIO_Pin_4;
    gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
    gpio_init.GPIO_Mode  = GPIO_Mode_AF_PP;
    GPIO_Init(GPIOD, &gpio_init);

                                                                /* Configure GPIOD.3 as input floating                      */
    gpio_init.GPIO_Pin   = GPIO_Pin_3;
    gpio_init.GPIO_Mode  = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOD, &gpio_init);
#else
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

                                                                /* Configure GPIOA.2 as push-pull                           */
    gpio_init.GPIO_Pin   = GPIO_Pin_2;
    gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
    gpio_init.GPIO_Mode  = GPIO_Mode_AF_PP;
    GPIO_Init(GPIOA, &gpio_init);

                                                                /* Configure GPIOA.3 as input floating                      */
    gpio_init.GPIO_Pin   = GPIO_Pin_3;
    gpio_init.GPIO_Mode  = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOA, &gpio_init);
#endif



                                                                /* -------------------- SETUP USART2 ---------------------- */
    usart_init.USART_BaudRate            = baud_rate;
    usart_init.USART_WordLength          = USART_WordLength_8b;
    usart_init.USART_StopBits            = USART_StopBits_1;
    usart_init.USART_Parity              = USART_Parity_No ;
    usart_init.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
    usart_init.USART_Mode                = USART_Mode_Rx | USART_Mode_Tx;
    usart_init.USART_Clock               = USART_Clock_Disable;
    usart_init.USART_CPOL                = USART_CPOL_Low;
    usart_init.USART_CPHA                = USART_CPHA_2Edge;
    usart_init.USART_LastBit             = USART_LastBit_Disable;

    USART_Init(USART2, &usart_init);
    USART_Cmd(USART2, ENABLE);

    nvic_init.NVIC_IRQChannel                   = USART2_IRQChannel;
    nvic_init.NVIC_IRQChannelPreemptionPriority = 0;
    nvic_init.NVIC_IRQChannelSubPriority        = 0;
    nvic_init.NVIC_IRQChannelCmd                = ENABLE;
    NVIC_Init(&nvic_init);
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_3)
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);

                                                                /* ------------------- SETUP USART3 GPIO ------------------ */
#if (PROBE_RS232_UART_3_REMAP_PARTIAL > 0)
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE);
    GPIO_PinRemapConfig(GPIO_PartialRemap_USART3, ENABLE);

                                                                /* Configure GPIOC.10 as push-pull                          */
    gpio_init.GPIO_Pin   = GPIO_Pin_10;
    gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
    gpio_init.GPIO_Mode  = GPIO_Mode_AF_PP;
    GPIO_Init(GPIOC, &gpio_init);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -