2011-06-15 03:51 AM
hi,
I used STM32F217ZG for my new project, and cofigure USART2 as SmartCard mode, the source code showed as following:&sharpdefine SAM_CLK_FREQ (uint32_t)5000000
&sharpdefine SAMCARD_USART USART2 &sharpdefine SAMCARD_USART_CLK RCC_APB1Periph_USART2&sharpdefine SAMCARD_IO_PIN GPIO_Pin_2
&sharpdefine SAMCARD_IO_GPIO_PORT GPIOA &sharpdefine SAMCARD_IO_GPIO_CLK RCC_AHB1Periph_GPIOA &sharpdefine SAMCARD_IO_SOURCE GPIO_PinSource2 &sharpdefine SAMCARD_IO_AF GPIO_AF_USART2&sharpdefine SAMCARD_CLK_PIN GPIO_Pin_7
&sharpdefine SAMCARD_CLK_GPIO_PORT GPIOD &sharpdefine SAMCARD_CLK_GPIO_CLK RCC_AHB1Periph_GPIOD &sharpdefine SAMCARD_CLK_SOURCE GPIO_PinSource7 &sharpdefine SAMCARD_CLK_AF GPIO_AF_USART2 void samcard_hw_init(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_ClocksTypeDef Sys_RCC_Clocks;RCC_GetClocksFreq(&Sys_RCC_Clocks);
RCC_AHB1PeriphClockCmd( SAMCARD_IO_GPIO_CLK | SAMCARD_CLK_GPIO_CLK,ENABLE); RCC_APB1PeriphClockCmd(SAMCARD_USART_CLK,ENABLE); USART_DeInit(SAMCARD_USART); /* Configure USART CK alternate function push-pull */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Pin = SAMCARD_CLK_PIN; GPIO_Init(SAMCARD_CLK_GPIO_PORT, &GPIO_InitStructure);/* Configure USART Tx pin as alternate function open-drain */
GPIO_InitStructure.GPIO_Pin = SAMCARD_IO_PIN; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_Init(SAMCARD_IO_GPIO_PORT, &GPIO_InitStructure);/* Connect PA2 to USART2_TX */
GPIO_PinAFConfig(SAMCARD_IO_GPIO_PORT, SAMCARD_IO_SOURCE, SAMCARD_IO_AF);/* Connect PD7 to USART2_CK */
GPIO_PinAFConfig(SAMCARD_CLK_GPIO_PORT, SAMCARD_CLK_SOURCE, SAMCARD_CLK_AF);/* SC_USART configuration ----------------------------------------------------*/
/* SC_USART configured as follow: - Word Length = 9 Bits - 1.5 Stop Bit - Even parity - BaudRate = 8064 baud - Hardware flow control disabled (RTS and CTS signals) - Tx and Rx enabled - USART Clock enabled */ /* USART Clock set to 5 MHz (PCLK1 (30 MHz) / 6) */ USART_SetPrescaler(SAMCARD_USART,Sys_RCC_Clocks.PCLK1_Frequency/(2*SAM_CLK_FREQ)); /* USART Guard Time set to 16 Bit */ USART_SetGuardTime(SAMCARD_USART, 16);SAM_USART_ClockInitStructure.USART_Clock = USART_Clock_Enable;
SAM_USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low; SAM_USART_ClockInitStructure.USART_CPHA = USART_CPHA_1Edge; SAM_USART_ClockInitStructure.USART_LastBit = USART_LastBit_Enable; USART_ClockInit(SAMCARD_USART, &SAM_USART_ClockInitStructure);SAM_USART_InitStructure.USART_BaudRate = (SAM_CLK_FREQ+186)/372;
SAM_USART_InitStructure.USART_WordLength = USART_WordLength_9b; SAM_USART_InitStructure.USART_StopBits = USART_StopBits_1_5; SAM_USART_InitStructure.USART_Parity = USART_Parity_Even; SAM_USART_InitStructure.USART_Mode = USART_Mode_Rx|USART_Mode_Tx; SAM_USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_Init(SAMCARD_USART, &SAM_USART_InitStructure); /* Disable the SC_USART Parity Error Interrupt */ USART_ITConfig(SAMCARD_USART, USART_IT_PE, DISABLE); /* Disable the SC_USART Framing Error Interrupt */ USART_ITConfig(SAMCARD_USART, USART_IT_ERR, DISABLE); /* Disable the SC_USART Receive Not Empty Interrupt */ USART_ITConfig(SAMCARD_USART, USART_IT_RXNE, DISABLE); /* Disable the SC_USART Transmitter Buffer Empty Interrupt */ USART_ITConfig(SAMCARD_USART, USART_IT_TXE, DISABLE); /* Disable the SC_USART Transmitter Complete Interrupt */ USART_ITConfig(SAMCARD_USART, USART_IT_TC, DISABLE); /* Disable the SC_USART OverRun Interrupt */ USART_ITConfig(SAMCARD_USART, USART_IT_ORE, DISABLE); /* Enable SC_USART */ USART_Cmd(SAMCARD_USART, ENABLE); USART_SmartCardNACKCmd(SAMCARD_USART,DISABLE); /* Enable the Smartcard Interface */ USART_SmartCardCmd(SAMCARD_USART, ENABLE); } The CPU system clock is 120MHz, and USART2 clock is 30MHz. after samcard_hw_init() be called, the SmartCard clock from PD7(USART2 CK pin) is measured by DPO, the smartcard clock is only 80Hz, not be 5MHz. I do not what happened or any error in my code, anyone can help me? thanks a lot. #stm32f217zg-version-'y'-usart2-smartcard