//define 对应映射后的usart1
#define EVAL_COM2_STR "USART1"
#define EVAL_COM2 USART1
#define EVAL_COM2_CLK RCC_APB2Periph_USART1
#define EVAL_COM2_TX_PIN GPIO_Pin_6
#define EVAL_COM2_TX_GPIO_PORT GPIOB
#define EVAL_COM2_TX_GPIO_CLK RCC_APB2Periph_GPIOA
#define EVAL_COM2_RX_PIN GPIO_Pin_7
#define EVAL_COM2_RX_GPIO_PORT GPIOB
#define EVAL_COM2_RX_GPIO_CLK RCC_APB2Periph_GPIOA
#define EVAL_COM2_IRQn USART1_IRQn
void STM_EVAL_COMInit(COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable GPIO clock */
RCC_APB2PeriphClockCmd(COM_TX_PORT_CLK[COM] | COM_RX_PORT_CLK[COM] | RCC_APB2Periph_AFIO, ENABLE);
if (COM == COM1)
{
/* Enable the USART2 Pins Software Remapping */
GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
RCC_APB1PeriphClockCmd(COM_USART_CLK[COM], ENABLE);
}
else //com == com2
{
/* Enable the USART1 Pins */
GPIO_PinRemapConfig(GPIO_Remap_USART1, ENABLE);//自己增加 重映射usart1
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); //开usart1映射后io口时钟PB( Tx PB6 , Rx PB7)
RCC_APB2PeriphClockCmd(COM_USART_CLK[COM], ENABLE);
}
/* Configure USART Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = COM_TX_PIN[COM];
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(COM_TX_PORT[COM], &GPIO_InitStructure);
/* Configure USART Rx as input floating */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = COM_RX_PIN[COM];
GPIO_Init(COM_RX_PORT[COM], &GPIO_InitStructure);
/* USART configuration */
USART_Init(COM_USART[COM], USART_InitStruct);
/* Enable USART */
USART_Cmd(COM_USART[COM], ENABLE);
}
时钟开了的~
[ 本帖最后由 dong_j_t 于 2011-5-9 13:39 编辑 ]