2014-05-13 08:03 AM
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
2014-05-13 08:30 AM
Don't park the debugger over the peripheral view of the USART, it is likely to be invasive
Don't use TCwhile(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, (u16) 'T');
See end of [DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32F107%20SEND%20RECEIVE%20USART&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=1344]this thread also
2014-05-15 06:40 AM
Hi clive1,
thank you for your answer. The TC was just in place because TXE was not working aswell and I forgot to change it back. Ofc TXE is the more proper way. As I am using OpenOCD via the olimex-tiny-H jtag adapter also for programming the device out of eclipse, I see no way around OpenOCD without scrapping my current toolchain setup. Do you mean that some code(as this UART2) might be not copatible with OpenOCD in general? This would have to make me rethink my whole project...2014-05-15 10:02 AM
No, what I'm saying is that if you park any debugger over the peripherals, so it dumps the current content of their registers, it will break how the part functions, so don't do that.
Reading USART->DR impacts the content of USART->SR, the debugger doesn't have any special or magical access that works in a non-invasive manner. Send a constant stream of characters, verify the bit timing on a scope, the wrong external crystal or HSE_VALUE will cause the baud rate to be expressed incorrectly. The output from the USART pins is not RS232 compatible, the board will need some level converters on it. I don't have a schematic to hand.