硬汉嵌入式论坛

 找回密码
 立即注册
查看: 2533|回复: 0
收起左侧

[客户分享] STM32F103的USART3重映射的话,注意是部分重映射还是全部重映射

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106660
QQ
发表于 2018-7-10 12:03:22 | 显示全部楼层 |阅读模式
手册说明:
QQ截图20180710120149.png


对应函数:

  *     @arg GPIO_PartialRemap_USART3    : USART3 Partial Alternate Function mapping
  *     @arg GPIO_FullRemap_USART3       : USART3 Full Alternate Function mapping



  1. /**
  2.   * @brief  Changes the mapping of the specified pin.
  3.   * @param  GPIO_Remap: selects the pin to remap.
  4.   *   This parameter can be one of the following values:
  5.   *     @arg GPIO_Remap_SPI1             : SPI1 Alternate Function mapping
  6.   *     @arg GPIO_Remap_I2C1             : I2C1 Alternate Function mapping
  7.   *     @arg GPIO_Remap_USART1           : USART1 Alternate Function mapping
  8.   *     @arg GPIO_Remap_USART2           : USART2 Alternate Function mapping
  9.   *     @arg GPIO_PartialRemap_USART3    : USART3 Partial Alternate Function mapping
  10.   *     @arg GPIO_FullRemap_USART3       : USART3 Full Alternate Function mapping
  11.   *     @arg GPIO_PartialRemap_TIM1      : TIM1 Partial Alternate Function mapping
  12.   *     @arg GPIO_FullRemap_TIM1         : TIM1 Full Alternate Function mapping
  13.   *     @arg GPIO_PartialRemap1_TIM2     : TIM2 Partial1 Alternate Function mapping
  14.   *     @arg GPIO_PartialRemap2_TIM2     : TIM2 Partial2 Alternate Function mapping
  15.   *     @arg GPIO_FullRemap_TIM2         : TIM2 Full Alternate Function mapping
  16.   *     @arg GPIO_PartialRemap_TIM3      : TIM3 Partial Alternate Function mapping
  17.   *     @arg GPIO_FullRemap_TIM3         : TIM3 Full Alternate Function mapping
  18.   *     @arg GPIO_Remap_TIM4             : TIM4 Alternate Function mapping
  19.   *     @arg GPIO_Remap1_CAN1            : CAN1 Alternate Function mapping
  20.   *     @arg GPIO_Remap2_CAN1            : CAN1 Alternate Function mapping
  21.   *     @arg GPIO_Remap_PD01             : PD01 Alternate Function mapping
  22.   *     @arg GPIO_Remap_TIM5CH4_LSI      : LSI connected to TIM5 Channel4 input capture for calibration
  23.   *     @arg GPIO_Remap_ADC1_ETRGINJ     : ADC1 External Trigger Injected Conversion remapping
  24.   *     @arg GPIO_Remap_ADC1_ETRGREG     : ADC1 External Trigger Regular Conversion remapping
  25.   *     @arg GPIO_Remap_ADC2_ETRGINJ     : ADC2 External Trigger Injected Conversion remapping
  26.   *     @arg GPIO_Remap_ADC2_ETRGREG     : ADC2 External Trigger Regular Conversion remapping
  27.   *     @arg GPIO_Remap_ETH              : Ethernet remapping (only for Connectivity line devices)
  28.   *     @arg GPIO_Remap_CAN2             : CAN2 remapping (only for Connectivity line devices)
  29.   *     @arg GPIO_Remap_SWJ_NoJTRST      : Full SWJ Enabled (JTAG-DP + SW-DP) but without JTRST
  30.   *     @arg GPIO_Remap_SWJ_JTAGDisable  : JTAG-DP Disabled and SW-DP Enabled
  31.   *     @arg GPIO_Remap_SWJ_Disable      : Full SWJ Disabled (JTAG-DP + SW-DP)
  32.   *     @arg GPIO_Remap_SPI3             : SPI3/I2S3 Alternate Function mapping (only for Connectivity line devices)
  33.   *                                        When the SPI3/I2S3 is remapped using this function, the SWJ is configured
  34.   *                                        to Full SWJ Enabled (JTAG-DP + SW-DP) but without JTRST.   
  35.   *     @arg GPIO_Remap_TIM2ITR1_PTP_SOF : Ethernet PTP output or USB OTG SOF (Start of Frame) connected
  36.   *                                        to TIM2 Internal Trigger 1 for calibration (only for Connectivity line devices)
  37.   *                                        If the GPIO_Remap_TIM2ITR1_PTP_SOF is enabled the TIM2 ITR1 is connected to
  38.   *                                        Ethernet PTP output. When Reset TIM2 ITR1 is connected to USB OTG SOF output.   
  39.   *     @arg GPIO_Remap_PTP_PPS          : Ethernet MAC PPS_PTS output on PB05 (only for Connectivity line devices)
  40.   *     @arg GPIO_Remap_TIM15            : TIM15 Alternate Function mapping (only for Value line devices)
  41.   *     @arg GPIO_Remap_TIM16            : TIM16 Alternate Function mapping (only for Value line devices)
  42.   *     @arg GPIO_Remap_TIM17            : TIM17 Alternate Function mapping (only for Value line devices)
  43.   *     @arg GPIO_Remap_CEC              : CEC Alternate Function mapping (only for Value line devices)
  44.   *     @arg GPIO_Remap_TIM1_DMA         : TIM1 DMA requests mapping (only for Value line devices)
  45.   *     @arg GPIO_Remap_TIM9             : TIM9 Alternate Function mapping (only for XL-density devices)
  46.   *     @arg GPIO_Remap_TIM10            : TIM10 Alternate Function mapping (only for XL-density devices)
  47.   *     @arg GPIO_Remap_TIM11            : TIM11 Alternate Function mapping (only for XL-density devices)
  48.   *     @arg GPIO_Remap_TIM13            : TIM13 Alternate Function mapping (only for High density Value line and XL-density devices)
  49.   *     @arg GPIO_Remap_TIM14            : TIM14 Alternate Function mapping (only for High density Value line and XL-density devices)
  50.   *     @arg GPIO_Remap_FSMC_NADV        : FSMC_NADV Alternate Function mapping (only for High density Value line and XL-density devices)
  51.   *     @arg GPIO_Remap_TIM67_DAC_DMA    : TIM6/TIM7 and DAC DMA requests remapping (only for High density Value line devices)
  52.   *     @arg GPIO_Remap_TIM12            : TIM12 Alternate Function mapping (only for High density Value line devices)
  53.   *     @arg GPIO_Remap_MISC             : Miscellaneous Remap (DMA2 Channel5 Position and DAC Trigger remapping,
  54.   *                                        only for High density Value line devices)     
  55.   * @param  NewState: new state of the port pin remapping.
  56.   *   This parameter can be: ENABLE or DISABLE.
  57.   * @retval None
  58.   */
  59. void GPIO_PinRemapConfig(uint32_t GPIO_Remap, FunctionalState NewState)
  60. {
  61.   uint32_t tmp = 0x00, tmp1 = 0x00, tmpreg = 0x00, tmpmask = 0x00;

  62.   /* Check the parameters */
  63.   assert_param(IS_GPIO_REMAP(GPIO_Remap));
  64.   assert_param(IS_FUNCTIONAL_STATE(NewState));  
  65.   
  66.   if((GPIO_Remap & 0x80000000) == 0x80000000)
  67.   {
  68.     tmpreg = AFIO->MAPR2;
  69.   }
  70.   else
  71.   {
  72.     tmpreg = AFIO->MAPR;
  73.   }

  74.   tmpmask = (GPIO_Remap & DBGAFR_POSITION_MASK) >> 0x10;
  75.   tmp = GPIO_Remap & LSB_MASK;

  76.   if ((GPIO_Remap & (DBGAFR_LOCATION_MASK | DBGAFR_NUMBITS_MASK)) == (DBGAFR_LOCATION_MASK | DBGAFR_NUMBITS_MASK))
  77.   {
  78.     tmpreg &= DBGAFR_SWJCFG_MASK;
  79.     AFIO->MAPR &= DBGAFR_SWJCFG_MASK;
  80.   }
  81.   else if ((GPIO_Remap & DBGAFR_NUMBITS_MASK) == DBGAFR_NUMBITS_MASK)
  82.   {
  83.     tmp1 = ((uint32_t)0x03) << tmpmask;
  84.     tmpreg &= ~tmp1;
  85.     tmpreg |= ~DBGAFR_SWJCFG_MASK;
  86.   }
  87.   else
  88.   {
  89.     tmpreg &= ~(tmp << ((GPIO_Remap >> 0x15)*0x10));
  90.     tmpreg |= ~DBGAFR_SWJCFG_MASK;
  91.   }

  92.   if (NewState != DISABLE)
  93.   {
  94.     tmpreg |= (tmp << ((GPIO_Remap >> 0x15)*0x10));
  95.   }

  96.   if((GPIO_Remap & 0x80000000) == 0x80000000)
  97.   {
  98.     AFIO->MAPR2 = tmpreg;
  99.   }
  100.   else
  101.   {
  102.     AFIO->MAPR = tmpreg;
  103.   }  
  104. }
复制代码



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-4-28 06:34 , Processed in 0.154689 second(s), 28 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表