Problem with Serial

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

Moderator: RoccoMarco

User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: Problem with Serial

Post by Tectu »

@skute: I must have misunderstood something then. I thought this one works:

Code: Select all

chprintf(....);
while(1);


while this doesn't:

Code: Select all

while(1)
    chprintf(.....);



Edit: I just read back your first post where you mentioned that the //while(TRUE) causes the problem, skute. I totally meant you mean that the while(TRUE) does cause the problem, but you obviously tell that the problem is that it's commented-out. I'm sorry for the trouble!
I have missed the // part. I completely agree with you at all your points, skute ^^


~ Tectu
M.H.Roohi
Posts: 17
Joined: Wed Mar 20, 2013 1:33 pm

Re: Problem with Serial

Post by M.H.Roohi »

hi ALL
@Giovanni: I don't know witch stack i should check? and where is it?
the problem is not from USART timing.
@Skute: your right that it takes 1ms for data to come out but when i use following format there is no problem:

Code: Select all

while(1)
   print(....);


but following format has problem:

Code: Select all

while(1) {
    print(.....);
    wait();
}
M.H.Roohi
Posts: 17
Joined: Wed Mar 20, 2013 1:33 pm

Re: Problem with Serial

Post by M.H.Roohi »

hi
i have another problem that is more important for me
the following code is OK except in one situation:

Code: Select all

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "ch.h"
#include "hal.h"
#include "chprintf.h"

/* Total number of channels to be sampled by a single ADC operation.*/
#define ADC_GRP1_NUM_CHANNELS   2

/* Depth of the conversion buffer, channels are sampled four times each.*/
#define ADC_GRP1_BUF_DEPTH      1
static WORKING_AREA(Sampler, 128);
static WORKING_AREA(SampleSender, 128);
/*
 * ADC samples buffer.
 */
static adcsample_t samples[ADC_GRP1_NUM_CHANNELS * ADC_GRP1_BUF_DEPTH];

/*
 * ADC conversion group.
 * Mode:        Linear buffer, 4 samples of 2 channels, SW triggered.
 * Channels:    IN11   (480 cycles sample time)
 */
static const ADCConversionGroup adcgrpcfg = {
  FALSE,
  ADC_GRP1_NUM_CHANNELS,
  NULL,
  NULL,
  /* HW dependent part.*/
  0,
  ADC_CR2_SWSTART,
  ADC_SMPR1_SMP_AN11(ADC_SAMPLE_480)|ADC_SMPR1_SMP_AN10(ADC_SAMPLE_480),
  0,
  ADC_SQR1_NUM_CH(ADC_GRP1_NUM_CHANNELS),
  0,
  ADC_SQR3_SQ1_N(ADC_CHANNEL_IN11)|ADC_SQR3_SQ2_N(ADC_CHANNEL_IN10)
};
static msg_t ADCSampler(void *arg){
   systime_t time = chTimeNow();
   while(TRUE){
      time += MS2ST(10);
      chSysLockFromIsr();
    adcStartConversionI(&ADCD1, &adcgrpcfg, samples, ADC_GRP1_BUF_DEPTH);
    chSysUnlockFromIsr();
      chThdSleepUntil(time);
   }
}
static msg_t USARTSampleSender(void *arg){
   systime_t time = chTimeNow();
   while(TRUE){
      time += MS2ST(10);
      chprintf((BaseChannel *)&SD2, "%D\r\n",samples[1]);
      chThdSleepUntil(time);
   }
}
int main(void){
  /*
   * Shell thread
   */
  halInit();
  chSysInit();
    /*
   * Initializes the ADC driver 1 and enable the thermal sensor.
   */
  adcStart(&ADCD1, NULL);
  palSetGroupMode(GPIOC,PAL_PORT_BIT(1) | PAL_PORT_BIT(0),0,PAL_MODE_INPUT_ANALOG);
   
   sdStart(&SD2, NULL);
  palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7));
  palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7));
   (void)chThdCreateStatic(Sampler, sizeof(Sampler), NORMALPRIO, ADCSampler, NULL);
   (void)chThdCreateStatic(SampleSender, sizeof(SampleSender), NORMALPRIO, USARTSampleSender, NULL);
while(1){
  //chprintf((BaseChannel *)&SD2, "%CH2: %D\r\n",(samples[0]));

}
}


in the following part of code if i decrease the delay in (time += US2ST(10);) the program will not work. i red (Reliable timings using Threads) article and i know that for this code to work the program time should be less than the delay but with the rate of 921600 it takes about 0.026 (ms) for USART to send out the data!

Code: Select all

static msg_t USARTSampleSender(void *arg){
   systime_t time = chTimeNow();
   while(TRUE){
      time += MS2ST(10);
      chprintf((BaseChannel *)&SD2, "%D\r\n",samples[1]);
      chThdSleepUntil(time);
   }
}
Last edited by M.H.Roohi on Sun Mar 24, 2013 3:54 pm, edited 2 times in total.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Problem with Serial

Post by Giovanni »

You can't have delays of 10uS that way, the system counter resolution is 1mS. The result of the US2ST() macro is approximated to the next system tick, 1mS in you case.

Giovanni
M.H.Roohi
Posts: 17
Joined: Wed Mar 20, 2013 1:33 pm

Re: Problem with Serial

Post by M.H.Roohi »

Giovanni wrote:You can't have delays of 10uS that way, the system counter resolution is 1mS. The result of the US2ST() macro is approximated to the next system tick, 1mS in you case.

Giovanni


excuse me i change the delay to US just for fun (test!) now i correct the above POST Mr Giovanni
Post Reply