Page 1 of 1

STM32F4 Discovery UART 2

Posted: Thu Feb 13, 2014 6:15 pm
by Faisal Mehmood
Hi

I need to use UART module of STM32F4 discovery kit. I have been going through the documentations but am unable to get the UART module running.
Here is the configuration instance. For simplicity, i have disabled all the callbacks.

Code: Select all

static UARTConfig uartcfg = {
   NULL,                    /* End of Transmission buffer callback               */
   NULL,                    /* Physical end of transmission callback             */
   NULL,                    /* Receive buffer filled callback                    */
   NULL,                   /* Char received while out of the UART_RECEIVE state */
   NULL,                    /* Receive error callback                            */
   9600,                     /* Baudrate                                          */
   0,                       /* cr1 register values                               */
   0,                       /* cr2 register values                               */
   0                        /* cr3 register values                               */
};


Setting TX and RX pins mode:

Code: Select all

  /* PD5 == USART2 TX PIN ;   PD == USART2 RX PIN */
  palSetPadMode(GPIOD, 5 , PAL_MODE_ALTERNATE(7));
  palSetPadMode(GPIOD, 6 , PAL_MODE_ALTERNATE(7));



Code: Select all

/*   UART 2 Initialization and stuff */
  uartStart(&UARTD2, &uartcfg);


Continuously transmit a string with 500mSec breaks.

Code: Select all

while(1)
{
uartStartSend(&UARTD2,13,"Started\n");
chThdSleepMilliseconds(500);
}


Can someone please point out the mistake(s) I am making.
The device is working. There is an led that keeps blinking, indicating that the program is executing fine.

Re: STM32F4 Discovery UART 2

Posted: Thu Feb 13, 2014 7:39 pm
by Giovanni
Hi,

If you don't have special requirements I suggest to try the Serial driver instead of the UART driver. It is a traditional serial driver with circular queues and is usually easier to use.

If you really need to use the UART driver please give a try to the demo located under ./testhal/STM32F4xx/UART if you haven't seen it yet.

Giovanni

Re: STM32F4 Discovery UART 2

Posted: Sat Feb 15, 2014 11:56 pm
by Faisal Mehmood
Thanks for the suggestion. My requirement is just simple transmission and reception so I guess serial driver would do.

I have been searching the web for an example regarding the serial driver. Actually its my final year project and i am running out of time. Can you please tell me how can I get the serial (or UART) driver running in minimum time?

An example would be very helpful.

cheers

Re: STM32F4 Discovery UART 2

Posted: Sun Feb 16, 2014 9:24 am
by Giovanni
Most demos contain examples of the serial driver...

You start the driver:

Code: Select all

  /*
   * Activates the serial driver 2 using the driver default configuration.
   * PA2(TX) and PA3(RX) are routed to USART2.
   */
  sdStart(&SD2, NULL);
  palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7));
  palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7));


Then you can use the I/O channers API to read and write: http://chibios.sourceforge.net/html/gro ... n_e_l.html

Giovanni

Re: STM32F4 Discovery UART 2

Posted: Sun Feb 16, 2014 3:59 pm
by Faisal Mehmood
sorry if this is a noob-ish question but I can't see how to use Rx buffer full and Tx buffer empty interrupts??
There is a single option (bit rate) in the serial Config structure. How to set interrupts??

Re: STM32F4 Discovery UART 2

Posted: Sun Feb 16, 2014 6:51 pm
by Giovanni
You don't need to set anything, just read and write from SD2. Low level details are hidden.

Giovanni

Re: STM32F4 Discovery UART 2

Posted: Tue Feb 18, 2014 3:56 pm
by Faisal Mehmood
Actually I have to control a motor's speed depending on what I receive on the serial port. So I want to have an interrupt like function that would inform me whenever a byte arrives on the serial port.
One last question. Will the SD2 notify me by itself or I will have to poll??
Cheers

Re: STM32F4 Discovery UART 2

Posted: Tue Feb 18, 2014 4:07 pm
by Giovanni
The serial driver can generate something called events, see here: viewtopic.php?f=2&t=1348

Giovanni

Re: STM32F4 Discovery UART 2

Posted: Wed Feb 19, 2014 9:20 am
by Faisal Mehmood
Thanx a lot Giovanni!
Actually I have very limited knowledge of operating system stuff like thread, working area, events etc that's why I had to ask so many basic questions.
Cheers