AnsweredAssumed Answered

stm32f107vc (olimex stm32-p107 revB) usart2

Question asked by hstum on May 13, 2014
Latest reply on May 15, 2014 by Clive One
Hi all,
As I have basically spent the whole day on this problem, trying to figure it out by myself, I am hoping to get some help from someone more experienced.

My setup is the following:
-(olimex stm32-p107 revB)
-eclipse toolchain
-programming via jtag-uart
-hyperterminal running on my pc
-com/usb adapter for comunication between pc and rs232 on the board

As for my board the rs232 is used by usart2, I tried to set up the usart2 with the following code:

01.void initUSART(void){
02.    USART_InitTypeDef USART_InitStruct;
03.    GPIO_InitTypeDef GPIO_InitStructure;
04. 
05.        /* Enable port D clock & Alternate function remapping*/
06.        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO, ENABLE);
07. 
08.        /* Enable USART2 clock */
09.        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
10. 
11.        /* Configure USART2 Tx (PD5) as alternate function push-pull */
12.        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
13.        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
14.        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
15.        GPIO_Init(GPIOD, &GPIO_InitStructure);
16. 
17.        /* Configure USART2 Rx (PD6) as input floating */
18.        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
19.        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
20.        GPIO_Init(GPIOD, &GPIO_InitStructure);
21. 
22.        /* Remap USART, as USART2 is used as alternate pins on PD5/6 */
23.        GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
24. 
25.        //configure the USART
26.        USART_InitStruct.USART_BaudRate = 9600;
27.        USART_InitStruct.USART_WordLength = USART_WordLength_8b;
28.        USART_InitStruct.USART_StopBits = USART_StopBits_1;
29.        USART_InitStruct.USART_Parity = USART_Parity_No;
30.        USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
31.        USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
32. 
33.        USART_Init(USART2,&USART_InitStruct);
34. 
35.        USART_Cmd(USART2, ENABLE);
36.}
37. 
38.int main(void)
39.{
40.    //"ensure all the priority bits are assigned to be preempt priority bits"
42.    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
43. 
44.    //initialize the USART
45.    initUSART();
46. 
47.    /* Send some test data */
48.            while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);
49.            USART_SendData(USART2, (u16) 'T');
50.            while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);
51.            USART_SendData(USART2, (u16) 'e');
52.            while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);
53.            USART_SendData(USART2, (u16) 's');
54.            while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);
55.            USART_SendData(USART2, (u16) 't');
56. 
57.    for (;;)
58.    {
59.    }
60.    return 0;
61.}


What happens is that the debugger gets stuck after the first char has been sent(but hyperterminal didnt recieve it) because the sc-register gets set to 0 and is somehow not set by the hardware again, resulting in an endless while loop before the second sendData.

All in all its quite a standard code which is mostly equivalent with various web tutorials.

Has anybody an idea where the problem might be located?

If required I can provide you with more detailed information about my project structure etc.

Thx in advance
 

Outcomes