2012-02-24 03:36 AM
Hi all,
I'm searching to get work my UART4 port on my Discovery. I used the USART HyperTerminal_Interrupt example on stdPerif_example and I adapted to DISCOVERY. I see by some LedOn on the program that UART is working and sending interrupt. I manage to have a virtual USB-UART port with UM232R Ftdi but on my Putty nothing appeared I post my code /* USARTx configuration ------------------------------------------------------*/ /* USARTx configured as follow: - BaudRate = 9600 baud - Word Length = 8 Bits - Two Stop Bit - Odd parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 9600; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_2; USART_InitStructure.USART_Parity = USART_Parity_Odd; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; STM_EVAL_COMInit(&USART_InitStructure); Function void STM_EVAL_COMInit(USART_InitTypeDef* USART_InitStruct) { GPIO_InitTypeDef GPIO_InitStructure; /* Enable GPIO clock */ //RCC_AHB1PeriphClockCmd(UART4_TX_PIN | UART4_RX_PIN, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); //clock a PORTC RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE); //clock alla UART4! /* Connect PXx to USARTx_Tx*/ GPIO_PinAFConfig(GPIOC, GPIO_Pin_10, GPIO_AF_UART4); /* Connect PXx to USARTx_Rx*/ GPIO_PinAFConfig( GPIOC, GPIO_Pin_11, GPIO_AF_UART4); /* Configure USART Tx as alternate function */ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); /* Configure USART Rx as alternate function */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_Init(GPIOC, &GPIO_InitStructure); /* USART configuration */ USART_Init(UART4, USART_InitStruct); /* Enable USART */ USART_Cmd(UART4, ENABLE); } I also add void UART4_IRQHandler(void); to _it.h to manage interrupt _it.c void UART4_IRQHandler(void) { if(USART_GetITStatus(UART4, USART_IT_RXNE) != RESET) { GPIO_SetBits(GPIOD, GPIO_Pin_14); // accende led /* Read one byte from the receive data register */ RxBuffer[RxCounter++] = (USART_ReceiveData(UART4) & 0x7F); if(RxCounter == NbrOfDataToRead) { /* Disable the UART4 Receive interrupt */ USART_ITConfig(UART4, USART_IT_RXNE, DISABLE); } } if(USART_GetITStatus(UART4, USART_IT_TXE) != RESET) { GPIO_SetBits(GPIOD, GPIO_Pin_13); // accende led /* Write one byte to the transmit data register */ USART_SendData(UART4, TxBuffer[TxCounter++]); if(TxCounter == NbrOfDataToTransfer) { /* Disable the UART4 Transmit interrupt */ USART_ITConfig(UART4, USART_IT_TXE, DISABLE); } } } Where I'm failing? THanks #uart/usart-parity-and-wordlengt2012-09-09 04:54 AM
Hello
I have now added a timer to the code and have it flashing a led every 5seconds exactly. so i assume all mycrystaltimingis correct. yet the uart code still produces jumbledcharacters. are there some othervariablesthat specifically effect the uart timing? (the uart code has been copied from a 25mhz board and this discovery board is 8mhz) the code works great on the 25mhz board but jumbled on the 8mhz board. yet the uart code simply sets up the uart there is nothing to do with clocks in it. so some where else must be some thing that sets up the uart timing? i haveattachedthe uart code, if you could have a quick look over and see what i am missing i would really appreciate it :) my main program is using one of the examples that came in the stm32f4discovery.zip so it is all setup correctly for 8mhz. ________________ Attachments : usart.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I06G&d=%2Fa%2F0X0000000bTO%2F1mZAi5i6Cnv4uNZveJSfYxZjjNZn9pMg_Xthn1BqG2A&asPdf=falseusart.h : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I066&d=%2Fa%2F0X0000000bTP%2FVfWOjbWP6BgYXS85GtKB.zAzyreO9MlelICLZw6bs98&asPdf=false2012-09-09 11:55 AM
Doesn't look unreasonable, I might configure the GPIO thusly
GPIO_InitStructure.GPIO_Pin = Port_USART_TX_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(Port_USART_TX_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = Port_USART_RX_PIN;
GPIO_Init(Port_USART_RX_GPIO_PORT, &GPIO_InitStructure);
The AF fabric handles the direction and other aspects of the pin in many cases.
Perhaps we should examine how things are connected up. The Tx/Rx pins are CMOS 3-3.3V levels, and are not directly compatible with RS232 Serial levels. To connect to a PC you'd need RS232 drivers. An alternate way is to us a USB-to-CMOS Serial converter board, using chips from Silicon Labs, Prolific or FTDI.
2012-09-09 04:08 PM
hey :)
i am using a ftdi232r breakout board set to 3.3v for uart to pc coms.i have tx/rx plugged into pa9/10this setup works great on my other stm32f4 25mhz board.just this stm32f54discovery which seams to be upset :(2012-10-07 11:18 AM
Hi, do you know how I could change the HSE_VALUE globally in IAR. I also see my HSE configured to 25000000 in the stm32f4xx.h and do not know how I can change it.
Thanks2012-10-07 12:18 PM
Hi, do you know how I could change the HSE_VALUE globally in IAR. I also see my HSE configured to 25000000 in the stm32f4xx.h and do not know how I can change it.
The way this normally works is by adjusting the meta-data options of a project. So you need to go into to the options for the compiler and the defines it passes in on the command line.2015-02-27 11:04 AM
Dear clive1,
Can you elaborate the idea behind this statment?Thanks for that post because it worked for me.2015-02-27 11:52 AM
Can you elaborate the idea behind this statement?
USART_InitStructure.USART_BaudRate = 9600 * 25 / 8;
Thanks for that post because it worked for me. I'm creating a ratio between 25 MHz and 8 MHz (3.125) to account for what HSE_VALUE is set to with respect to what the crystal actually is. Fix your project so HSE_VALUE reflects reality, then the math that computes the baud rate settings will work correctly.
2015-02-27 12:04 PM
I'm using a system_stm32f4xx.c file from a template of ''STM32F4xx_DSP_StdPeriph_Lib_V1.4.0''.
I believe this template is for stm32f401xx and thats why HSE is set to 25 Mhz.I tried to use my IDE to create a file for stm32f407, which I'm using. I didn´t succed because I'm using Keil IDE and that file has dependencies of stm32f4xx_HAL.Any ideia where I can get a system_stm32f4xx.c file for my stm32f407 board?Thanks again and sorry for my English2015-02-27 12:11 PM
Nevermind, I was confused.
Problem solved.Thanks a lot ;)2015-02-27 12:28 PM
The files from the STM32F4-DISCO firmware would be a better starting point, if that's what you are using.
The 1.4 DSP is newer, but I suspect most of the newness is attributable to new chips rather than and bug fixes. You could always inspect with your favorite merge/diff tool.