USART2 Problem on STM32-P103 with ARM-USB-OCD-H

Started by yueda, February 16, 2014, 03:03:21 PM

Previous topic - Next topic

yueda

Dear

I have some troubles of USART2 on STM32-P103 with ARM-USB-OCD-H.
Would you please give me any advice to solve these?
The goal is to communicate with Terminal via serial port. (ex. STM32-P103 get the keycode from PC)

[Trouble]
1. When serial terminal software on windows sends the character(s) to the STM32-P103 via serial connection with ARM-USB-OCD-H, the USART2 Rx(received) data will be always 0xFF.

2. When STM32-P103 tries to send USART2 Tx data on the C program, the Tx data will be always 0xFF.

[Settings]
STM32-P103
ARM-USB-OCD-H
windows7 64bit
Eclipse 64bit
Tera term (serial terminal software)
RS232 straight cable

[Installation]
I'm sure that ARM-USB-OCD-H driver has been correctly installed, because I can find that "Olimex OpenOCD ARM-USB-H" and "USB Serial Port (COM4)" in the device manager.
JTAG debugger works fine.
I set the Tera term to connect to COM4.

[C Program]
Please read following source code.
(Header and definition part is omitted. If needed, I'll add it)

int main(void) {
  uint16_t foo;

  USART2_Configuration();

  while(1){
     if(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) != RESET){
       foo = USART_ReceiveData(USART2); // foo is always 0xFF
       USART_SendData(USART2, 0x49); // send '1', but USART always sends 0xFF (USARTx->DR == 0xFF)
     }
  }
}


void USART2_Configuration(void){

   /* variables */
   GPIO_InitTypeDef GPIO_InitStructure;
   USART_InitTypeDef USART_InitStructure;

   /* GPIOA Periph clock enable for USART2 */
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

   /* USART2 Periph clock enable (need GPIOA clock enable) */
   RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

   /* Configure USART2 TX as alternate function push-pull */
   GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_2;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
   GPIO_Init(GPIOA, &GPIO_InitStructure);

   /* Configure USART2 RX as input floating */
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
   GPIO_InitStructure.GPIO_Mode =  GPIO_Mode_IN_FLOATING;
   GPIO_Init(GPIOA, &GPIO_InitStructure);

   /* USART2 configuration ------------------------------------------------------*/
   /* USART2 configured as follow:
             - BaudRate = 115200 baud
             - Word Length = 8 Bits
             - One Stop Bit
             - No parity
             - Hardware flow control disables
             - Receive and transmit enabled
    */

   USART_InitStructure.USART_BaudRate = 11520;
   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(USART2, &USART_InitStructure);
   USART_Cmd(USART2, ENABLE);

}

If you cannot understand my English, it's my fault.
Please be patient to tell me unclear points.

Thanks,
Yui Ueda