Question
stm32f107vc (olimex stm32-p107 revB) usart2
Posted on May 13, 2014 at 17:03
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:
void initUSART(void){
USART_InitTypeDef USART_InitStruct;
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable port D clock & Alternate function remapping*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO, ENABLE);
/* Enable USART2 clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
/* Configure USART2 Tx (PD5) as alternate function push-pull */
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* Configure USART2 Rx (PD6) as input floating */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* Remap USART, as USART2 is used as alternate pins on PD5/6 */
GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
//configure the USART
USART_InitStruct.USART_BaudRate = 9600;
USART_InitStruct.USART_WordLength = USART_WordLength_8b;
USART_InitStruct.USART_StopBits = USART_StopBits_1;
USART_InitStruct.USART_Parity = USART_Parity_No;
USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART2,&USART_InitStruct);
USART_Cmd(USART2, ENABLE);
}
int main(void)
{
//''ensure all the priority bits are assigned to be preempt priority bits''
//see http://www.freertos.org/RTOS-Cortex-M3-M4.html
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
//initialize the USART
initUSART();
/* Send some test data */
while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);
USART_SendData(USART2, (u16) 'T');
while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);
USART_SendData(USART2, (u16) 'e');
while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);
USART_SendData(USART2, (u16) 's');
while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);
USART_SendData(USART2, (u16) 't');
for (;;)
{
}
return 0;
}
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