2012-06-23 04:55 AM
Hello,
After dealing with my code for two days I have no other option than ask you guys. I have problems with my USART3/6 serial port on my Olimex STM32-P407 board:
http://www.olimex.com/dev/pdf/ARM/ST/STM32-P407 Initial release.pdf
http://www.olimex.com/dev/pdf/ARM/ST/STM32-P407 Initial release.pdf
2012-06-23 05:56 AM
''if I send '*' to the output, I get '}'''
The fact that you get anything indicates that your connections are probably good. The corruption is most likely due to baud rate error - either the wrong baud rate, or too much error from the nominal rate. Or both. (possibly also other mismatched settings like number of bits). Use an oscilloscope to verify that you have the correct baud rate, and that it is stable, and that the character framing is correct. You would need to use an RS232 transceiver to connect to a PC COM: port - the oscilloscope should also show whether that is working and giving good, clean signals...2012-06-23 06:09 AM
You'd need to check the bit times with a scope.
One of the biggest potential problems would be what the HSE crystal is set to in software, vs the placed hardware. The STM32F4-Discovery uses an 8 MHz crystal, the Olimex board uses a 25 MHz crystal. You NEED to ensure that HSE_VALUE is correctly defined in your project, and the PLL settings are correct. See system_stm32f4xx.c Using HSI might be more predictable, it's always 16 MHz2012-06-23 08:21 AM
First of all, thanks a lot for the support guys.
I think you are probably right. I have to check the settings again and see what is wrong with the clocks. The USART settings are correct and match with the hyperterminal. I connect the other board with the same settings and works perfectly. On Monday I will have a look again at the code and use a scope to check the signal. I will get back to you to tell how it went. Thanks for now.2012-06-23 10:34 AM
Hi again,
I could not wait and I managed to get the code. as I said above, I created an empty Keil project and then put the code related to the USART. Now, what happens is that SystemInit() is called automatically from the ''startup_stm32f4xx.s'' file and then the configuration for the USART get started. Checking the HSE_VALUE value in the stm32f4xx.h file I can see that it is set as 25000000 Hz, indeed because Olimex uses a 25MHz external clock, which is used as the external source. The setting for the other buses look fine. At this point I do not know whether there is something in the code. Nevertheless, I will check with the scope. Is it correct what I just wrote?2012-06-24 05:23 AM
// STM32 USART3 (Tx PD.8, Rx PD.9) Olimex STM32-P407 - sourcer32@gmail.com
#include ''stm32f4xx.h''
/**************************************************************************************/
void RCC_Configuration(void)
{
/* --------------------------- System Clocks Configuration -----------------*/
/* USART3 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
/* GPIOD clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
}
/**************************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/*-------------------------- GPIO Configuration ----------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* Connect USART pins to AF */
GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_USART3);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_USART3);
}
/**************************************************************************************/
void USART3_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
/* USARTx configuration ------------------------------------------------------*/
/* USARTx configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
USART_InitStructure.USART_BaudRate = 115200;
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(USART3, &USART_InitStructure);
USART_Cmd(USART3, ENABLE);
}
/**************************************************************************************/
int main(void)
{
RCC_Configuration();
GPIO_Configuration();
USART3_Configuration();
while(1)
{
uint16_t Data;
while(USART_GetITStatus(USART3, USART_IT_RXNE) == RESET); // Wait for Char
Data = USART_ReceiveData(USART3); // Collect Char
while(USART_GetITStatus(USART3, USART_IT_TXE) == RESET); // Wait for Empty
USART_SendData(USART3, Data); // Echo Char
}
while(1); // Don't want to exit
}
2012-06-24 10:08 AM
Give a look at the schematics. This board shares a lot of pins with many peripherals. Usart 3 and 6 signals are shared with the external RAM and the camera respectively.
I have had similar random problems with the external RAM that I solved simply disconnecting the camera connector.good luck2012-06-24 10:22 AM
''Olimex uses a 25MHz external clock''
I think you mean, ''Olimex fits a 25MHz crystal'' - but does your application actually use it...?
2012-06-24 12:38 PM
Yes, the board has a great deal of opportunity to clash with itself, Jason or whomever must had fun with that. Would of thought PG8 might have been a cleaner exit for USART6_TX, but whatever.
// STM32 USART6 (Tx PC.6, Rx PG.9) Olimex STM32-P407 - sourcer32@gmail.com
#include ''stm32f4xx.h''
/**************************************************************************************/
void RCC_Configuration(void)
{
/* --------------------------- System Clocks Configuration -----------------*/
/* USART6 clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE);
/* GPIOC & G clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOG, ENABLE);
}
/**************************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/*-------------------------- GPIO Configuration ----------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_Init(GPIOG, &GPIO_InitStructure);
/* Connect USART pins to AF */
GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_USART6); // TX PC.6
GPIO_PinAFConfig(GPIOG, GPIO_PinSource9, GPIO_AF_USART6); // RX PG.9
}
/**************************************************************************************/
void USART6_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
/* USARTx configuration ------------------------------------------------------*/
/* USARTx configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
USART_InitStructure.USART_BaudRate = 115200;
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(USART6, &USART_InitStructure);
USART_Cmd(USART6, ENABLE);
}
/**************************************************************************************/
int main(void)
{
RCC_Configuration();
GPIO_Configuration();
USART6_Configuration();
while(1)
{
uint16_t Data;
while(USART_GetITStatus(USART6, USART_IT_RXNE) == RESET); // Wait for Char
Data = USART_ReceiveData(USART6); // Collect Char
while(USART_GetITStatus(USART6, USART_IT_TXE) == RESET); // Wait for Empty
USART_SendData(USART6, Data); // Echo Char
}
while(1); // Don't want to exit
}
2012-06-27 01:00 AM
Sorry for the late,
Found the issue. The HSE_VALUE was the problem. Even though the value of 25MHz was set correctly in the stm32fxx.h file, there is a config file included in the middle of it that unset the 25MHz and set it as the Discovery, 8MHz. Which means that the max speed of the processor was wrong, instead of 168MHz it was around 53MHz. It works well now. Again, thanks a lot to all of you guys for the support and hints. Have a nice day,