Page 1 of 1

Olimex UEXT RS 232 newbie print to screen

Posted: Thu Jun 27, 2013 1:01 pm
by stinkytiger
Hi,

I am a complete Newbie to ChibiOS and hope this question makes some sense.

I have a Olimex STM32F4-E407 board and I also have a Olimex MOD-RS232. The
Olimex MOD-RS232 is a board that converts 3.3v to 5 volts for RS232 signals.
The MOD-RS232 I have connected to a Flyswatter2 OpenOCD interface and finaly
to a Linux Box. On the Linux Box I see the RS232 port via Minicom a terminal
emulation program. (The FLyswatter 2 has a JTAG and a RS232 port on it).

I have Eclipse, OpenOCD, and Chibios/RT plugin in Eclipse working. I have
a simple blinky light working in Chibios and also in plain C code.
I tried the Chibios demo code and that worked right out of the box for STM32F4-E407
right down to seeing the lwip served web page.

What I am trying to do is to write some utility code to help debug. Right
now what I would like to to is to print to a screen on the linux box.

My approach is to use the UEXT port on the Olimex board which maps to
USARTD6 in Chibios. I have enabled the USART in halconf.h and USART6 mcuconf.h.
The UEXT port connects to MOD-RS232. I have not managed to send anything
to the screen yet.

The next bit is where I think I need some help. I think I need to attach / create
a BaseSequentialStream to the USARTD6 so that I can use chprintf. I am trying
to use the UARTDriver. However I noticed that the UARTDriver is not something
that can be cast to be a BaseSequentialStream, only a Serial Driver works. So
question one is am which Driver should I use? UARTDriver or Serial Driver?

If it is the Serial Driver, then how do I configure that to hook up to the USART6
pins on the STM32F4?

I also noticed that the UART driver has three config registers, these are for
configurating the UART, so things like partity, stop bits etc make sense to me
making me think that the UART driver is the correct one to use.

Sorry for the rambling post.

I idealy an example of how to do this would help be out quite a bit.

Warmest regards, Mike.

Re: Olimex UEXT RS 232 newbie print to screen

Posted: Thu Jun 27, 2013 1:24 pm
by Giovanni
Hi Mike,

The right driver to use is the Serial driver, it implements the BaseSequentialStream interface so you can use chprintf() directly using (BaseSequentialStream )&SD6 as first parameter: chprintf((BaseSequentialStream )&SD6, "Hello World!!"); for example.

GPIOC-6 and GPIOC-7 should be already set up as USART6 alternate function so you don't need to change anything in board.h, connect your levels translator there.

Giovanni

Re: Olimex UEXT RS 232 newbie print to screen

Posted: Fri Jun 28, 2013 12:03 pm
by stinkytiger
Hi,

Thank you for your kind help. I think I am making progress. I went home and gave it a go. I think that the Serial Driver on SD6 definately does something. The reason I know is that on my Linux box I see /dev/ttyUSB0, then when I start the program Minicon complains that this device does not exist. So I know I have the Pin / SD6 bit right, and the code does so something. To reset the /dev/ttyUSB0 I need to halt the STM32F4. Then simply unplug and replug the Flyswatter 2. Then the /dev/USB0 reappears. I.E. the program crashes / causes the /dev/ttyUSB0 to dissappear.

I think what I am doing wrong is in the sdStart call. I have:

sdStart(&SD6, &serialconfig)

I think all I have to do to get the serialconfig is:

SerialConfig serialconfig;
serialconfig.sc_speed = 115800; // The compiler complains about this line, may be I do not have the correct XXXX.h include file here.

I see in the documentation I can have:

sdStart($SD5, NULL) and some sort of default will be used. In the end I am passing probablly an unitialized SerialConfig struct and that is probably what is messing things up.

I think what I need is an example of configuring the Serial Driver. I have the chstream.h and the chprintf.h include files in the main.c and have those.

Am I on the right track here?

Thanks again for your kind help.

Warmest regards, Mike.

Re: Olimex UEXT RS 232 newbie print to screen

Posted: Fri Jun 28, 2013 7:54 pm
by Giovanni
Hi, You definitely have to initialize the whole structure or pass NULL to the function. Start in easy mode and use the NULL then set the interface to 38400-N-8-1.

BTW, the default initialization structure is this one:

Code: Select all

/** @brief Driver default configuration.*/
static const SerialConfig default_config =
{
  SERIAL_DEFAULT_BITRATE,
  0,
  USART_CR2_STOP1_BITS | USART_CR2_LINEN,
  0
};


Giovanni

Re: Olimex UEXT RS 232 newbie print to screen

Posted: Sat Jun 29, 2013 5:33 pm
by Tectu
May I ask at this point why exactly there's a macro for the default baud rate? I think every controller should be able to handle 38400, no?


~ Tectu

Re: Olimex UEXT RS 232 newbie print to screen

Posted: Sat Jun 29, 2013 11:58 pm
by stinkytiger
Hi,

Success!!!!

Thank you for all your kind help. I think the issue was I had my Mincom looking at /dev/ttyUSB0 when I should have had it look at /dev/ttyUSB1.

Warmest regards, Mike.

This is what I get out of my Minicom:

Welcome to minicom 2.3

OPTIONS: I18n
Compiled on Aug 19 2010, 05:50:19.
Port /dev/ttyUSB1

Press CTRL-A Z for help on special keys

Hello World

And this is my small program:


/*
*
*
*/

#include "ch.h"
#include "hal.h"
#include "chprintf.h"
#include <chstreams.h>

static SerialConfig sc;

int main(void)
{

halInit();
chSysInit();

sc.speed = 38400;
sc.cr1 = 0;
sc.cr2 = USART_CR2_STOP1_BITS | USART_CR2_LINEN;
sc.cr3 = 0;

sdStart(&SD6, &sc);
chprintf((BaseSequentialStream*)&SD6, "Hello World");

while(TRUE)
{
int i;
for(i = 100; i < 1000; i += 100)
{
palTogglePad(GPIOC, GPIOC_LED);
chThdSleepMilliseconds(i);
}
}

return 0;
}

Re: Olimex UEXT RS 232 newbie print to screen

Posted: Sun Jun 30, 2013 10:58 am
by Tectu
Good to hear that you got it working!
Could you please use the [ code]your code here[/code] tags in the future in your post? This creates a small code box with a scroll bar so the forum posts keep being the same length.


~ Tectu