
在网上搜了一下,有这方面的提问(* C: _' s% k3 k- ]' e/ ]% V) b# y; Y ( v8 a& M$ o }% ]1 ~# j 在2010-7-5 16:11:34 有提到过 一下为原帖 文字 USART3映射方式2(映射到PD8,PD9)时,要先开启AFIO功能,再初始化相关外设后,USART才有效。* U) j# d; {: \. O 以下代码是正确的: u32 backRcc = RCC->APB2ENR & (RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO);//read status of rcc_gpiob & rcc_afio+ k# ?3 {+ W# Z+ t# R RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO,ENABLE);& m# a( J: L4 ?1 e GPIO_PinRemapConfig(GPIO_FullRemap_USART3,ENABLE);9 L* u, V. i& g p2 q RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE); /* Configure USART3 Tx (PD.8) as alternate function push-pull */ GPIO_InitStructure.GPIO_Pin =GPIO_Pin_8;5 a2 J. O: ], f/ h- J9 L9 T GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;$ _/ ^( y8 Y: W: k* }& x GPIO_Init(GPIOD, &GPIO_InitStructure);( R! i* C/ v' E* a: h9 z; t! R* s8 n & e2 o2 V. t- [! w /* 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);6 [/ X; j8 F8 j9 ^! m1 \$ W9 e7 ? if(!backRcc) { RCC->APB2ENR &= ~backRcc; //restore # e3 K! ]+ ?6 u M9 d } / t9 P' D& k. Q# V' ^/ j k$ x 初始化USART等。。。# \( P5 E. O+ W% w2 ~# c 若去掉 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO,ENABLE); 不正常! ) L6 J$ b! Y. _$ L9 I : ~6 C, T4 _4 R5 s" T- l. H )9 H$ ?) j" O/ I8 W& A" ` 根据上述还是没有解决这个问题 (其他口的重映射验证都是OK的),所以又开了一下此贴,希望得到大家的帮助 ,本人代码如下 //重映射成功的 方式1' C9 K" G+ g7 i3 f/ @ #ifdef DEFINE_UART_MAP_PORT_3 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO , ENABLE);7 |# w* X" h+ N( b0 p RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); GPIO_PinRemapConfig(GPIO_PartialRemap_USART3 ,ENABLE); // GPIO_FullRemap_USART3 /* Configure USART3 Tx (PC10) as alternate function push-pull */; ~! U& G8 a5 g8 Q- m GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;& o& H5 _) r# B8 A/ r GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;* P( {+ O* ~8 C% e5 X' w GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;% Z2 X, l* Y. R GPIO_Init(GPIOC, &GPIO_InitStructure); {6 @0 |8 h# s2 H! E /* Configure USART3 Rx (PC11) as input floating */# D) P+ ~! ?- b) ^ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;- G0 q2 }: _, K# d, G! X9 V8 } l GPIO_Init(GPIOC, &GPIO_InitStructure);0 `8 W0 C9 V% v- N, Y4 q #endif , o# B( B. x9 X) k# G //方式2 重映射失败, t% c% t! F6 K. }2 F! F #ifdef DEFINE_UART_MAP_3 ; W3 f4 a0 k+ L- K RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO,ENABLE); 1 {1 B, w# {* ?6 B RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3 , ENABLE); * Q2 e& a" F5 W0 P {- m: m- a7 Z' g RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO , ENABLE);* B9 g; a6 T$ ]4 D% L7 O, Z& [ 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;3 V5 a/ a2 U. G" w6 P GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOD, &GPIO_InitStructure);& H, {4 q- Q3 k% }( ` F0 H; s4 Y+ `( q) [ /* Configure USART3 Rx (PD8) as input floating *// @- b$ [; X/ i5 M) W5 M$ V+ K GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOD, &GPIO_InitStructure); #endif 附图为keil寄存器值 |
RE:stm32 USART3 映射方式2
RE:stm32 USART3 映射方式2
RE:stm32 USART3 映射方式2