|
在网上搜了一下,有这方面的提问( 1 k" y5 V I: B# `$ M 在2010-7-5 16:11:34 有提到过 一下为原帖 文字 1 q$ a; U/ o6 t0 S USART3映射方式2(映射到PD8,PD9)时,要先开启AFIO功能,再初始化相关外设后,USART才有效。6 N2 x* n+ x1 }2 b# g5 ] 4 h' Z+ d# J( Y% ?3 P9 U9 p 以下代码是正确的:: F: |% Z+ j" o. r1 C( x6 p 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);% i5 H: Y1 J9 L# f1 P 0 Y& O0 {* x2 D1 z) G 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;7 f4 F) n9 E6 y1 M- J3 x GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;: R; d# G, L" i( O. M: k GPIO_Init(GPIOD, &GPIO_InitStructure);+ b7 o$ E0 f: z /* Configure USART3 Rx (PD.9) as input Up */ g# d" b+ s% f+ \ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOD, &GPIO_InitStructure); # E ~( V/ Z- k/ V" B9 i if(!backRcc) { RCC->APB2ENR &= ~backRcc; //restore }7 f& G. U% v8 T 初始化USART等。。。4 O3 _. a; z2 q# I0 ? 9 @( X* y& K! l 若去掉 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO,ENABLE);$ T" D8 z: A. ?) e+ X & L4 B$ V, {3 C. Y& u0 E/ V 不正常! / |/ W$ r. M0 r! K5 f1 V0 d )6 R! n: s6 l- M7 L) E2 H: m8 B ( m+ Q `1 `$ x+ B6 \ 根据上述还是没有解决这个问题 (其他口的重映射验证都是OK的),所以又开了一下此贴,希望得到大家的帮助 ,本人代码如下( O& L$ y; r% V$ n/ ` //重映射成功的 方式1* C: Q0 ]. r3 T8 y+ \ #ifdef DEFINE_UART_MAP_PORT_3 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO , ENABLE);6 z% x& y( `( I RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);7 x! z9 f$ ]4 J6 u2 w& ^9 I6 { . W% p& D( K6 i& `' v- V GPIO_PinRemapConfig(GPIO_PartialRemap_USART3 ,ENABLE); // GPIO_FullRemap_USART35 E% j2 H/ q8 N" {* y4 f [ /* Configure USART3 Tx (PC10) as alternate function push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;" F" M# z$ r4 a4 D, M# G& o GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOC, &GPIO_InitStructure);1 ?' V) R/ u% N J' E: l /* Configure USART3 Rx (PC11) as input floating */% I) j, z7 Y* R7 s" Y" G- D GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;6 Y! H; B3 j* X. R' m2 m2 F/ q" | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOC, &GPIO_InitStructure); #endif $ v5 z- l& E+ V( p4 ?/ T$ c( g //方式2 重映射失败 / R/ \) q7 Y. T! G# O$ G #ifdef DEFINE_UART_MAP_3 6 L. s8 [$ k: D: b 9 q, C1 F" V% K4 S F# T4 o. j4 p; s RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO,ENABLE);; P! t0 S6 J3 `* y: B/ _4 F1 d RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3 , ENABLE); ) @1 @1 G5 F) M+ O4 L. Z RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO , ENABLE); GPIO_PinRemapConfig(GPIO_FullRemap_USART3 ,ENABLE); // GPIO_FullRemap_USART3$ }" C5 } E, t l! c; C2 n# w 1 j5 M* Q( `2 p2 ?. Z /* Configure USART3 Tx (PD9) as alternate function push-pull */ r2 @, j C* ~9 O' K7 Q GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;; \+ m% W8 S! H# P GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;& o2 M4 Q+ R9 q1 u+ |9 w2 q GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;1 O) U2 p) i6 _3 ?6 |, E GPIO_Init(GPIOD, &GPIO_InitStructure); /* Configure USART3 Rx (PD8) as input floating */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;$ d4 i# N. Q) f: x9 l. A( e/ c GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOD, &GPIO_InitStructure);( Q9 z2 Z7 P, G+ Q' r! ^/ J #endif 附图为keil寄存器值 |
微信公众号
手机版
RE:stm32 USART3 映射方式2
RE:stm32 USART3 映射方式2
RE:stm32 USART3 映射方式2