cancel
Showing results for 
Search instead for 
Did you mean: 

[STM32F4-Discovery] UART4 Problem

regiuliano2009
Associate II
Posted on February 24, 2012 at 12:36

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-wordlengt
40 REPLIES 40
regiuliano2009
Associate II
Posted on March 01, 2012 at 15:44

Ops... sorry for the wrong posting.

Thanks Clive1

niqbal
Associate
Posted on March 15, 2012 at 07:28

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6jn&d=%2Fa%2F0X0000000buK%2FhjLIlh04z8DfZt6UDSV1C0shktAJvzHmus4wWgSbzIE&asPdf=false
Posted on March 15, 2012 at 13:21

GPIO_PinAFConfig(GPIOD,GPIO_Pin_11,GPIO_AF_USART3);               // CTS

 

To reiterate what I've said previously, you MUST use the GPIO_PinSource?? values in GPIO_PinAFConfig().

Don't enable/disable the interrupts in the service routine.

Don't spin use while() spin loops in interrupts.

Use some form of elastic buffering to handle different rates, and the fact different ports may block based on the flow control.

Use transmit and CTS interrupts as required. Disable transmit interrupt if no data pending.

Handle USART error conditions, identify and clear overrun, etc.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
niqbal
Associate
Posted on March 16, 2012 at 08:03

Thanks Clive1 for the response.I have amended the GPIO_PinSource, Still there is no change in the system response, Haven't ST made working example of USARTS? The issue if i implement buffers is that even buffers will stop the overflow to the extent of its size, if i have bulk of data coming at 115200bps and sending port is at 9600bps than it will again choke after buffers size and we will need to hold the PC transmitter using RTS of CortexM4. What I have observed is that RTS of USART2 does not change value to hold the overflow( the case that M4's USART2 is receiving from PC and sending on USART3 to another PC, while :  RTS of USART2 is connected on CTS of PC1 and RTS of PC1 on CTS of USART2).

I am yet pondering on the RM0090, there is HardwareFlow Control mentioned on it that the M4 itself is managing the Hardware Flow Control. Even the TDR and RDR are serving for normal byte overwrite. The documentation is poor and the reference designs are not made available. I wrote to ST few days back, even no response till now.

rcurtiss
Associate II
Posted on March 19, 2012 at 01:09

I am using even parity.  To get it to work for 8 databits it was necessary to specify USART_WordLength_9b.  The symptom appeard for any character that resulted in the parity bit = 1.  Terminal emulators usually treat bits and parity settings independently, whereas the UART/USART_InitStructure has a different idea about that.

russdx
Associate II
Posted on September 08, 2012 at 16:37

I have the same problem.

I have copied an uart example from another stm32 board to the stm32discovery board

im trying to send 

''\n\r  *********************** RTC Hardware Calendar Example ***********************\n\r''

but just receiving

''÷÷÷÷÷÷÷÷÷÷÷[07][00][00][06][01][00][02]íÿÿ÷÷÷÷÷÷÷÷÷÷÷÷÷÷ôü''

the HSE_VALUE is deffo correct

#define HSE_VALUE    ((uint32_t)8000000)

the pc Terminal is setup correct, the code works fine on the other stm32 board (25mhz) 

cant quite see where its going wrong, definitely seams like a clock speed is set wrong some where.

Posted on September 08, 2012 at 17:13

Review also the PLL settings in system_stm32f4xx.c, PLL_M is typically set to the crystal frequency so the comparison in the PLL occurs at 1 MHz.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
russdx
Associate II
Posted on September 08, 2012 at 17:51

yup looks correct, comparing it to other stm32 discovery projects i have downloaded

#define PLL_M      8

#define PLL_N      336

/* SYSCLK = PLL_VCO / PLL_P */

#define PLL_P      2

/* USB OTG FS, SDIO and RNG Clock =  PLL_VCO / PLLQ */

#define PLL_Q      7

i also have being playing with a little micro second delay function which runs about twice as fast as it should, timing some where is set wrong. but where!!!

russdx
Associate II
Posted on September 08, 2012 at 21:11

using all the correct files that came with the discovery example zip projects

the ide is set to 8mhz

just cant see how its going wrong :(
Posted on September 08, 2012 at 23:53

Are you in a position to scope the pins and confirm bit times, or clocks?

HSE_VALUE can often be defined in the IDE's meta-data and passed to the compiler via the command line options. Other places it often appears are stm32f4xx_conf.h and stm32f4xx.h.

Be cognizant of the include path settings and precedents which may cause different files of the same name being pulled in preference to the ones you think are coming in.

You might want to inspect the generated code, or have the tool chain output pre-processor data to confirm expected values, etc.

Parity in USART output of 8-bits assumes the 9-bit mode is selected.

Scaling the baud rate setting might permit you to evaluate if the wrong basis is being applied.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..