The code for the serial config and transmission thread :
Code: Select all
/* Serial configuration. */
static const SerialConfig myserialcfg = {
115200,
0,
USART_CR2_STOP1_BITS,
0
};
static THD_FUNCTION(ThdSerial, arg) {
(void) arg;
chRegSetThreadName("Serial manager");
/* Configuring VCP related GPIO. This configuration is already
performed at board level initialization but is here reported
only as example of how to configure GPIO at application level. */
palSetPadMode(GPIOA, 2U, PAL_MODE_ALTERNATE(7) | PAL_STM32_OSPEED_HIGHEST |
PAL_STM32_OTYPE_PUSHPULL);
palSetPadMode(GPIOA, 3U, PAL_MODE_ALTERNATE(7) | PAL_STM32_OSPEED_HIGHEST |
PAL_STM32_OTYPE_PUSHPULL);
/* Starting Serial Driver 2 with our configuration. */
sdStart(&SD2, &myserialcfg);
while(true) {
chprintf(chp, "12345");
chThdSleepMilliseconds(20);
}
}
Main thread:
Code: Select all
int main(void) {
halInit();
chSysInit();
palSetPadMode(GPIOA, 1, PAL_MODE_INPUT_ANALOG);
palSetPadMode(GPIOA, 8, PAL_MODE_ALTERNATE(1));
// Serial thread
chThdCreateStatic(waThdSerial, sizeof(waThdSerial), NORMALPRIO+1, ThdSerial,NULL)
while (true) {
chThdSleepMilliseconds(2);
}
I've noticed the data is only being read by the C++ program correctly when the thread sleep function in the serial thread is 20ms (from trial and error) ( chThdSleepMilliseconds(20) )
When it is 5ms. The c++ application reads the data multiple times in one instance like so:
Code: Select all
S12345123451234512345E S123451234512345E S12345123451234E S5123451234512345E S123451234512345E S123451234512345E S1234512345123451234512345E S1234512345E S123451234512345E
When it is raised to 35ms some of the incoming data is skipped like so:
Code: Select all
SE S12345E SE S12345E SE S12345E SE S12345E SE S12345E SE S12345E SE S12345E SE SE S12345E SE S12345E SE S12345E SE S12345E SE S12345E S12345E SE
Why is this happening and how can i make it so that whatever the length of the message that needs to be sent isn't related to the delay time so both short and long messages arrive in one complete instance?
(as a note, there is no sleeping on the C++ application side. It is polling 24/7)