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

📄 probe_rs232c.c

📁 编译环境是 iar EWARM ,STM32 下的UCOSII
💻 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.00
* Programmer(s) : BAN
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                            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
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                      ProbeRS232_InitTarget()
*
* Description : Initialize the UART for uC/Probe communication.
*
* Argument(s) : baud_rate   Intended baud rate of the RS-232.
*
* Return(s)   : 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;
    USART_ClockInitTypeDef  usart_clk_init;


                                                                /* ----------------- INIT USART STRUCT ---------------- */
    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_clk_init.USART_Clock           = USART_Clock_Disable;
    usart_clk_init.USART_CPOL            = USART_CPOL_Low;
    usart_clk_init.USART_CPHA            = USART_CPHA_2Edge;
    usart_clk_init.USART_LastBit         = USART_LastBit_Disable;


#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
    BSP_PeriphEn(BSP_PERIPH_ID_USART1);

                                                                /* ----------------- SETUP USART1 GPIO ---------------- */
#if (PROBE_RS232_UART_1_REMAP > 0)
    BSP_PeriphEn(BSP_PERIPH_ID_IOPB);
    BSP_PeriphEn(BSP_PERIPH_ID_IOPD);
    BSP_PeriphEn(BSP_PERIPH_ID_AFIO);

    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
    BSP_PeriphEn(BSP_PERIPH_ID_IOPA);

                                                                /* 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(USART1, &usart_init);
    USART_ClockInit(USART1, &usart_clk_init);
    USART_Cmd(USART1, ENABLE);

    BSP_IntVectSet(BSP_INT_ID_USART1, ProbeRS232_RxTxISRHandler);
    BSP_IntEn(BSP_INT_ID_USART1);
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_2)
    BSP_PeriphEn(BSP_PERIPH_ID_USART2);

                                                                /* ----------------- SETUP USART2 GPIO ---------------- */
#if (PROBE_RS232_UART_2_REMAP > 0)
    BSP_PeriphEn(BSP_PERIPH_ID_IOPD);
    BSP_PeriphEn(BSP_PERIPH_ID_AFIO);
    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
    BSP_PeriphEn(BSP_PERIPH_ID_IOPA);

                                                                /* 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(USART2, &usart_init);
    USART_ClockInit(USART2, &usart_clk_init);
    USART_Cmd(USART2, ENABLE);

    BSP_IntVectSet(BSP_INT_ID_USART2, ProbeRS232_RxTxISRHandler);
    BSP_IntEn(BSP_INT_ID_USART2);
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_3)
    BSP_PeriphEn(BSP_PERIPH_ID_USART3);

                                                                /* ----------------- SETUP USART3 GPIO ---------------- */
#if (PROBE_RS232_UART_3_REMAP_PARTIAL > 0)
    BSP_PeriphEn(BSP_PERIPH_ID_IOPC);
    BSP_PeriphEn(BSP_PERIPH_ID_AFIO);
    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);

                                                                /* Configure GPIOC.11 as input floating                 */
    gpio_init.GPIO_Pin   = GPIO_Pin_11;
    gpio_init.GPIO_Mode  = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOC, &gpio_init);

#elif (PROBE_RS232_UART_3_REMAP_FULL > 0)

⌨️ 快捷键说明

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