
在网上搜了一下,有这方面的提问( 在2010-7-5 16:11:34 有提到过 一下为原帖 文字 " u, m! u; R" ]/ S2 _) j# } U1 ^ USART3映射方式2(映射到PD8,PD9)时,要先开启AFIO功能,再初始化相关外设后,USART才有效。 以下代码是正确的:& t0 ^6 I F, n$ q% J 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); $ _, x" y" d- {8 [$ L+ s GPIO_PinRemapConfig(GPIO_FullRemap_USART3,ENABLE);7 c' c# H- T2 o5 z* h0 u! S RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE); /* Configure USART3 Tx (PD.8) as alternate function push-pull */+ x- ~- B1 h# D5 z3 G GPIO_InitStructure.GPIO_Pin =GPIO_Pin_8; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;6 x6 Z1 Y" M' g. O GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOD, &GPIO_InitStructure); /* Configure USART3 Rx (PD.9) as input Up */6 e1 w: X/ @+ @, w& c" h GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;! [4 K; U, [ g- g9 ^& A' P GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOD, &GPIO_InitStructure); ) W; L; ~) I) i9 p if(!backRcc) { RCC->APB2ENR &= ~backRcc; //restore * X1 b7 k& t8 v, E0 ?( @ p }) w2 g6 ^8 w9 ~* U' s9 [# z ) E# c& y) C* f% _- w& ~0 e+ b 初始化USART等。。。 若去掉 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO,ENABLE); 9 v, i5 `, A; {$ y( { 不正常! 1 v- E8 k) `1 J ) 根据上述还是没有解决这个问题 (其他口的重映射验证都是OK的),所以又开了一下此贴,希望得到大家的帮助 ,本人代码如下 //重映射成功的 方式1 #ifdef DEFINE_UART_MAP_PORT_3 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO , ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); 2 H( P H4 c" w# S- q+ v GPIO_PinRemapConfig(GPIO_PartialRemap_USART3 ,ENABLE); // GPIO_FullRemap_USART3 ]( L3 A9 |8 v9 }8 X7 e+ l# | /* Configure USART3 Tx (PC10) as alternate function push-pull */" y$ K; O6 u2 k3 W GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;7 w1 r! \1 N# u D2 o5 c GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;2 v8 ?) e2 W3 v5 w8 t9 k GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;( W# g+ W1 v! G$ R5 e2 r# a GPIO_Init(GPIOC, &GPIO_InitStructure); 6 |% e5 p2 L* p6 B7 E3 d. h /* Configure USART3 Rx (PC11) as input floating */( i ^ t( f7 G+ B. f4 i- A4 x/ ~ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;6 ?1 `8 Z4 ?8 I0 G( u" ` GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOC, &GPIO_InitStructure);" V* [. ?2 S, a9 O/ X' k #endif 0 L* N2 Q# Y" t4 z7 V 3 q6 L1 ?) \& v7 U) o5 | //方式2 重映射失败, B: B) `/ y8 p2 K 3 E) d& {: D( j8 y #ifdef DEFINE_UART_MAP_39 F' T' w! O# L5 _( C 8 l! M4 w+ R5 U/ ] RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO,ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3 , ENABLE);) a+ \0 a0 i" J& _/ _ . O/ B2 F! k/ f& W. N. w 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);4 s3 \3 @+ |1 k9 n+ i 5 I$ J3 M5 u4 ]) ? /* Configure USART3 Rx (PD8) as input floating */! J0 p, P6 U) N1 B GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;3 U! {: o$ I3 q( m GPIO_Init(GPIOD, &GPIO_InitStructure); #endif, d3 Y8 e0 ]' q" ` ? 附图为keil寄存器值 |
RE:stm32 USART3 映射方式2
RE:stm32 USART3 映射方式2
RE:stm32 USART3 映射方式2