Page 2 of 3

Re: Serrial communication massive data loss

Posted: Tue Mar 27, 2012 9:00 pm
by Giovanni
You should examine the Serial driver flags, are you getting errors? if so it could be the clock not accurate enough.

Re: Serrial communication massive data loss

Posted: Tue Mar 27, 2012 9:11 pm
by DrunkenDonkey
Ouch. SD_OVERRUN_ERROR all the way from the start of the data, the 2nd byte... does that mean I shall just go and cry in the corner, then put external 4/8mhz crystal?

Re: Serrial communication massive data loss

Posted: Tue Mar 27, 2012 9:22 pm
by Giovanni
You still have the option to use the UART driver, it is possible it can handle it.

About the clock, why not HSI? you can divide it by two or three using the AHB prescaler if you don't want to go up to 16MHz.

Anyway, I can try to rewrite that ISR in a more efficient way using that loop I mentioned.

Giovanni

Re: Serrial communication massive data loss

Posted: Tue Mar 27, 2012 9:41 pm
by DrunkenDonkey
Yeah def will go try to UART, tried the HSI on 8mhz - works, went to 4mhz and got SD_OVERRUN_ERROR and SD_BREAK_DETECTED right away. The serial port just dislikes 4mhz and thats it ;)
And I'm all up for optimizations, serial driver looks way better to a higher level developers like me, there is quite some time before I get to the moment to try to squeeze every uA out of the board, I got the hardware a week ago, and it is still incomplete, so will be happy to test any optimized version along the way :)

Time for me to hit the sack, gn

Re: Serrial communication massive data loss

Posted: Tue Mar 27, 2012 9:48 pm
by Giovanni
I suggest to try 16/3 too and hold on that solution, I want to optimize that handler now and see how much it can improve with that solution.

Currently it goes out of the ISR after one byte received and, while this is the safest way, it is not optimal. Matter for the next weekend :-)

Giovanni

Re: Serrial communication massive data loss

Posted: Wed Mar 28, 2012 8:22 pm
by DrunkenDonkey
Thanks a lot Giovanni, looking forward to it and my first working device somewhere along the way :)

Re: Serrial communication massive data loss

Posted: Wed Mar 28, 2012 8:24 pm
by Giovanni
Do you mind testing this code?

Code: Select all

static void serve_interrupt(SerialDriver *sdp) {
  USART_TypeDef *u = sdp->usart;
  uint16_t cr1 = u->CR1;
  uint16_t sr, dr;

  /* RX-related sources have priority.*/
  while (TRUE) {
    sr = u->SR;  /* SR reset step 1.*/
    dr = u->DR;  /* SR reset step 2.*/

    if ((sr & (USART_SR_RXNE | USART_SR_ORE | USART_SR_NE  |
               USART_SR_FE | USART_SR_PE)) == 0)
      break;

    /* Error condition detection.*/
    if (sr & (USART_SR_ORE | USART_SR_NE | USART_SR_FE  | USART_SR_PE))
      set_error(sdp, sr);

    /* Data available.*/
    if (sr & USART_SR_RXNE) {
      chSysLockFromIsr();
      sdIncomingDataI(sdp, (uint8_t)dr);
      chSysUnlockFromIsr();
    }
  }

  /* Special case, LIN break detection.*/
  if (sr & USART_SR_LBD) {
    chSysLockFromIsr();
    chIOAddFlagsI(sdp, SD_BREAK_DETECTED);
    chSysUnlockFromIsr();
    u->SR = ~USART_SR_LBD;
  }
  /* Transmission buffer empty.*/
  if ((cr1 & USART_CR1_TXEIE) && (sr & USART_SR_TXE)) {
    msg_t b;
    chSysLockFromIsr();
    b = chOQGetI(&sdp->oqueue);
    if (b < Q_OK) {
      chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
      u->CR1 = (cr1 & ~USART_CR1_TXEIE) | USART_CR1_TCIE;
    }
    else
      u->DR = b;
    chSysUnlockFromIsr();
  }
  /* Physical transmission end.*/
  if (sr & USART_SR_TC) {
    chSysLockFromIsr();
    chIOAddFlagsI(sdp, IO_TRANSMISSION_END);
    chSysUnlockFromIsr();
    u->CR1 = cr1 & ~USART_CR1_TCIE;
    u->SR = ~USART_SR_TC;
  }
}


Just replace the current function with this one and see if you notice improvements.

Giovanni

Re: Serrial communication massive data loss

Posted: Wed Mar 28, 2012 8:42 pm
by DrunkenDonkey
No improvement I can see, still goes to overrun when I hit the 4mhz.
I'm afraid you might be chasing an error that might be related to clock instability, already asked my hardware guy to solder me an external crystal to test, just don't know when he will be available to do it.

Re: Serrial communication massive data loss

Posted: Wed Mar 28, 2012 8:51 pm
by Giovanni
I find it unlikely that it is unstable at 4MHz but not at 8MHz, try to obtain 4MHz from HSI instead of MSI, that would not be less stable that the 8MHz that work.

Re: Serrial communication massive data loss

Posted: Wed Mar 28, 2012 9:01 pm
by DrunkenDonkey
Both 4mhz from MSI and 4mhz from HSI result in overrun errors (and sometimes framing too). Going below that barely getting half the data and worse.