+ int i=0;
+ while(s[i++]);
+ return i-1;
+}
+
+
+//! Initialize the USART
+void usartinit(){
+ USART_InitTypeDef USART_InitStructure;
+ GPIO_InitTypeDef GPIO_InitStructure;
+ USART_ClockInitTypeDef USART_ClockInitStruct;
+
+ /* Enable GPIOA and USART1 clock */
+ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
+
+ //USART1 and USART6, other in APB1
+ RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
+
+ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
+ /* A 9 to USART1_Tx
+ * A10 to USART1_Rx
+ * A11 to USART1_CTS
+ * A12 to USART1_RTS
+ */
+ GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);
+ GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);
+ GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_USART1);
+ GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_USART1);
+
+ /* Configure USART Tx and Rx as alternate function push-pull */
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
+ GPIO_Init(GPIOA, &GPIO_InitStructure);
+
+
+ USART_StructInit(&USART_InitStructure);
+ USART_InitStructure.USART_BaudRate = 9600;
+ USART_InitStructure.USART_WordLength = USART_WordLength_8b;
+ USART_InitStructure.USART_StopBits = USART_StopBits_1;
+ USART_InitStructure.USART_Parity = USART_Parity_No;
+ USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
+ USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
+ USART_Init(USART1, &USART_InitStructure);
+
+
+ USART_ClockStructInit(&USART_ClockInitStruct);
+ USART_ClockInit(USART1,&USART_ClockInitStruct);
+
+ USART_Cmd(USART1, ENABLE);