Page 1 of 3
Problem with Serial
Posted: Wed Mar 20, 2013 2:48 pm
by M.H.Roohi
hi every body.
I'm new to ChibiOS but I found it very useful.
I'm trying to print a string into serial port:
Code: Select all
chprintf((BaseChannel *)&SD2, "test....\r\n");
chThdSleepMilliseconds(1);
but in the terminal i just see "tes" !
but when i increase the delay in "chThdSleepMilliseconds" the whole of the string ("test...") is appear.
please help me, i want to print some strings whit the frequency of for example 1 ms.
Re: Problem with Serial
Posted: Wed Mar 20, 2013 3:10 pm
by Giovanni
Hi,
The behavior is not normal, the whole string should be printed. Without the whole code is hard to guess what the cause could be. I would verify if there is a stack overflow somewhere that is masked by the chThdSleepMilliseconds() call.
If you are doing that into a thread try increasing the stack sizes, also activate all the debug options in chconf.h.
Giovanni
Re: Problem with Serial
Posted: Wed Mar 20, 2013 8:58 pm
by Tectu
First of all, I'm not sure if you reall want to call chprintf() every 1ms.
For another, there have been many issues together around the entire string manipulation and chprintf() stuff which around. Many many have been related to the used toolchain. I cannot tell you why some or most of them don't work as expected, but I can tell you that
this one works for 100% sure.
However, you might want to dump the full code here as Giovanni suggested.
~ Tectu
Re: Problem with Serial
Posted: Thu Mar 21, 2013 5:43 am
by M.H.Roohi
Thanks for reply.
i use MDK-KEIL
Here is my simple code:
Code: Select all
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "ch.h"
#include "hal.h"
#include "chprintf.h"
int main(void) {
/*
* Shell thread
*/
halInit();
chSysInit();
sdStart(&SD2, NULL);
palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7));
palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7));
//while(TRUE)
{
chprintf((BaseChannel *)&SD2, "test....\r\n");
chThdSleepMilliseconds(1);
}
}
and i also tried following code, but with the same result:
Code: Select all
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "ch.h"
#include "hal.h"
#include "chprintf.h"
int main(void) {
/*
* Shell thread
*/
halInit();
chSysInit();
sdStart(&SD2, NULL);
palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7));
palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7));
//while(TRUE)
{
sdPut(&SD2,'t');
sdPut(&SD2,'e');
sdPut(&SD2,'s');
sdPut(&SD2,'t');
sdPut(&SD2,'.');
sdPut(&SD2,'.');
sdPut(&SD2,'.');
chThdSleepMilliseconds(1);
}
}
Regards
Re: Problem with Serial
Posted: Thu Mar 21, 2013 6:27 am
by Tectu
KEIL really shouldn't be a problem.
Please try to cast to (BaseSequentialStream*) instead of (BaseChannel*). Otherwise I've no idea. I can try the same code with my hardware this evening.
~ Tectu
Re: Problem with Serial
Posted: Thu Mar 21, 2013 9:14 am
by steved
I saw something similar with the UART driver at one point, which I think was because each new sendbuffer cancels the remainder of the previous one.
Even if that's not the problem, is your serial port fast enough to output a continuous stream of data when you're adding 10 characters each millisecond? Suggests to me that at 115200 baud you're running pretty much flat out.
Re: Problem with Serial
Posted: Thu Mar 21, 2013 10:08 am
by Giovanni
The serial driver, unlike the UART driver, is buffered so no character should be lost, the write function waits for the string to be completely inserted into the buffer.
It should not lose chars regardless those delays.
Giovanni
Re: Problem with Serial
Posted: Fri Mar 22, 2013 9:07 pm
by M.H.Roohi
i solve the problem....!
just by following stupid code!!
Code: Select all
chprintf((BaseChannel *)&SD2, "test....\r\n");
while(1);
i dont know why, but it works well
can somebody tell me why??? maybe micro doing something else?
Regards
Re: Problem with Serial
Posted: Fri Mar 22, 2013 9:50 pm
by Tectu
Huh? Am I misunderstanding something? I thought you want to call the chprintf() in a regular intervall? What you're doing now is just calling it once and then you don't do anything anymore.
~ Tectu
Re: Problem with Serial
Posted: Sat Mar 23, 2013 7:13 am
by M.H.Roohi
the following code didn't work:
Code: Select all
chprintf((BaseChannel *)&SD2, "test....\r\n");
chThdSleepMilliseconds(1);
but this code is working:
Code: Select all
chprintf((BaseChannel *)&SD2, "test....\r\n");
while(1);
and also this code is working properly:
Code: Select all
while(1)
chprintf((BaseChannel *)&SD2, "test....\r\n");