打印

USART3方式2重映射问题

[复制链接]
7542|10
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 pentral0311 于 2013-5-23 11:37 编辑

在论坛里搜了一下,有这方面的提问(2010-7-5 16:11:34 有提到过 一下为原帖  文字
USART3映射方式2(映射到PD8,PD9)时,要先开启AFIO功能,再初始化相关外设后,USART才有效。

     以下代码是正确的:

     u32 backRcc = RCC->APB2ENR & (RCC_APB2Periph_GPIOB  | RCC_APB2Periph_AFIO);//read status of rcc_gpiob & rcc_afio
            RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB  | RCC_APB2Periph_AFIO,ENABLE);
            
            GPIO_PinRemapConfig(GPIO_FullRemap_USART3,ENABLE);
            RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);
            /* Configure USART3 Tx (PD.8) as alternate function push-pull */
            GPIO_InitStructure.GPIO_Pin =GPIO_Pin_8;
            GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
            GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
            GPIO_Init(GPIOD, &GPIO_InitStructure);
            
            /* Configure USART3 Rx (PD.9) as input Up */
            GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
            GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
            GPIO_Init(GPIOD, &GPIO_InitStructure);
            
            if(!backRcc)
            {
                RCC->APB2ENR &= ~backRcc; //restore
            }

   初始化USART等。。。

   若去掉  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB  | RCC_APB2Periph_AFIO,ENABLE);

   不正常!



根据上述还是没有解决这个问题 (其他口的重映射验证都是OK的),所以又开了一下此贴,希望得到大家的帮助 ,本人代码如下
//重映射成功的 方式1
#ifdef        DEFINE_UART_MAP_PORT_3    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO , ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);

        GPIO_PinRemapConfig(GPIO_PartialRemap_USART3 ,ENABLE);        //        GPIO_FullRemap_USART3
          /* Configure USART3 Tx (PC10) as alternate function push-pull */
          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
          GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
          GPIO_Init(GPIOC, &GPIO_InitStructure);

          /* Configure USART3 Rx (PC11) as input floating */
          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
          GPIO_Init(GPIOC, &GPIO_InitStructure);
#endif


//方式2 重映射失败

#ifdef DEFINE_UART_MAP_3


        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB  | RCC_APB2Periph_AFIO,ENABLE);

        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3 , ENABLE);


    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO , ENABLE);
        GPIO_PinRemapConfig(GPIO_FullRemap_USART3 ,ENABLE);        //        GPIO_FullRemap_USART3

          /* Configure USART3 Tx (PD9) as alternate function push-pull */
          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
          GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
          GPIO_Init(GPIOD, &GPIO_InitStructure);

          /* Configure USART3 Rx (PD8) as input floating */
          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
          GPIO_Init(GPIOD, &GPIO_InitStructure);

#endif

附图为keil寄存器值





usart.JPG (86.59 KB )

usart.JPG
沙发
香水城| | 2013-5-23 12:10 | 只看该作者
你的方式二(重映射失败)的代码里,明明要使用PD8/9,却打开的是PortB的时钟?

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB  | RCC_APB2Periph_AFIO,ENABLE);

使用特权

评论回复
评论
pentral0311 2013-5-24 13:05 回复TA
谢谢回复 
评分
参与人数 1威望 +3 收起 理由
pentral0311 + 3
板凳
airwill| | 2013-5-23 12:22 | 只看该作者
要先开启AFIO功能,再初始化相关外设后,USART才有效。

我觉得 AFIO 和 外设分属两块系统. 不应该有这个先后关系.
或者说先后关系不会影响功能性问题.
最多就是起始阶段会收到错误的输入而已

使用特权

评论回复
评论
pentral0311 2013-5-24 13:06 回复TA
谢谢解答,aiwill是是ti的吗? 
评分
参与人数 1威望 +3 收起 理由
pentral0311 + 3 很给力!
地板
pentral0311|  楼主 | 2013-5-23 12:48 | 只看该作者
问题已找到,是与FSCM有关。

使用特权

评论回复
5
pentral0311|  楼主 | 2013-5-23 13:04 | 只看该作者
香水城 发表于 2013-5-23 12:10
你的方式二(重映射失败)的代码里,明明要使用PD8/9,却打开的是PortB的时钟?

RCC_APB2PeriphClockCmd(R ...

这个是硬件组提供的文档有误,我已修改,此问题已解决,在找中文误勘文档,3Q

使用特权

评论回复
6
pentral0311|  楼主 | 2013-5-23 13:05 | 只看该作者
airwill 发表于 2013-5-23 12:22
要先开启AFIO功能,再初始化相关外设后,USART才有效。

我觉得 AFIO 和 外设分属两块系统. 不应该有这个先 ...

谢谢解惑,问题已找到解答了

使用特权

评论回复
7
小班儿| | 2014-11-27 09:58 | 只看该作者
路过,学习下。多谢分享!

使用特权

评论回复
8
springvirus| | 2015-11-18 17:09 | 只看该作者
pentral0311 发表于 2013-5-23 12:48
问题已找到,是与FSCM有关。

能否具体说说啊,谢谢,正在使用USART3的remap

使用特权

评论回复
9
springvirus| | 2015-11-18 18:21 | 只看该作者
已找到原因,因为是从USART1的初始化修改来的
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
而RCC_APB1Periph_USART3要求使用的是RCC_APB1PeriphClockCmd() !!!!!!!!!!!!!!!!!!!
低级错误。。。。

使用特权

评论回复
10
pentral0311|  楼主 | 2015-12-18 15:34 | 只看该作者
springvirus 发表于 2015-11-18 18:21
已找到原因,因为是从USART1的初始化修改来的
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
而 ...

恭喜问题找到了

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

11

主题

175

帖子

1

粉丝