STM32F4 Discovery UART 2

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
Faisal Mehmood
Posts: 25
Joined: Sat Jan 26, 2013 10:18 pm

STM32F4 Discovery UART 2

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F4 Discovery UART 2

Post 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
Faisal Mehmood
Posts: 25
Joined: Sat Jan 26, 2013 10:18 pm

Re: STM32F4 Discovery UART 2

Post 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
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F4 Discovery UART 2

Post 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
Faisal Mehmood
Posts: 25
Joined: Sat Jan 26, 2013 10:18 pm

Re: STM32F4 Discovery UART 2

Post 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??
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F4 Discovery UART 2

Post by Giovanni »

You don't need to set anything, just read and write from SD2. Low level details are hidden.

Giovanni
Faisal Mehmood
Posts: 25
Joined: Sat Jan 26, 2013 10:18 pm

Re: STM32F4 Discovery UART 2

Post 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
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F4 Discovery UART 2

Post by Giovanni »

The serial driver can generate something called events, see here: viewtopic.php?f=2&t=1348

Giovanni
Faisal Mehmood
Posts: 25
Joined: Sat Jan 26, 2013 10:18 pm

Re: STM32F4 Discovery UART 2

Post 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
Post Reply