Serial driver Transmission End Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
Post Reply
alexblack
Posts: 277
Joined: Mon Sep 24, 2012 3:52 pm
Been thanked: 33 times

Serial driver Transmission End

Post by alexblack »

Hi.
I used ChibiOS 17.6.x and after updating to the latest version I was found that changes in SERIAL drivers is affect to my program.
I have function to send 1 (ONE) byte over serial driver is SPI mode.

Code: Select all

/** ------------------------------------------------------------------------ **
 * \brief       Setting the given value to potenciometer
 * \param[in]   value - given value
 * ------------------------------------------------------------------------- */
void PGA_Class::set_value(char value) {

  // Start the driver
  static const SerialConfig pga_serial_cfg = {
  4500000,
  0,
  USART_CR2_MSBFIRST | USART_CR2_CLKEN | USART_CR2_LBCL, // | USART_CR2_CPHA | USART_CR2_CPOL
  0 
  };
  sdStart(&PGA_SERIAL_DRIVER, &pga_serial_cfg);
  // RX not used
  PGA_SERIAL_DRIVER.usart->CR1 &= ~USART_CR1_RE;
 
  // Register event listener to receive USART events
  event_listener_t el_sd;
  chEvtRegisterMask(chnGetEventSource(&PGA_SERIAL_DRIVER), &el_sd, 128);
 
  // Accert the CS line
  palClearPad(cs->port, cs->pin_n);
 
  // write to register 
  sdPut(&PGA_SERIAL_DRIVER, value);
 
  // wait the end of transmission
  for (;;) {
    eventmask_t m = chEvtWaitOneTimeout(128, MS2ST(100));
    if (m == 0) break;
 
    // event of the UART
    eventflags_t flags = chEvtGetAndClearFlags(&el_sd);
    if (flags & CHN_TRANSMISSION_END)
      break;
  }
   
  // Release the CS
  palSetPad(cs->port, cs->pin_n);
 
  // Unregiister
  chEvtUnregister(chnGetEventSource(&PGA_SERIAL_DRIVER), &el_sd);
 
  // Stop the driver
  sdStop(&PGA_SERIAL_DRIVER);
}

When I used before the function was success to wait end of transmission, but now it exit with timeout.
I looking to the change history and found that there was this changes:
Clip2net_180605083906.png

Clip2net_180605084004.png

What was the need to really change this behavior?
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Serial driver Transmission End

Post by Giovanni »

The idea is that the flag should be raised only if the TCIE interrupt is enabled.

TCIE is enabled when a transmission is started and cleared when it is completed and the event has been triggered.

Giovanni
alexblack
Posts: 277
Joined: Mon Sep 24, 2012 3:52 pm
Been thanked: 33 times

Re: Serial driver Transmission End

Post by alexblack »

In my case (one byte transsmission) the TC flag is raised before the TXE flag is served and thus do not generate TC interrupt.
I tried send 2 bytes - new code work well. But what to do with one byte. I need to wait the end of transmission to deactivate the CS line.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Serial driver Transmission End

Post by Giovanni »

You could try, in the LLD, to set USART_CR1_TCIE in those notifyX() functions and remove it from serve_interrupt(), this should fix that specific problem.

Code: Select all

static void notify5(io_queue_t *qp) {

  (void)qp;
  UART5->CR1 |= USART_CR1_TXEIE | USART_CR1_TCIE;
}


Let me know how this goes, I would make the change in repository too.

Giovanni
alexblack
Posts: 277
Joined: Mon Sep 24, 2012 3:52 pm
Been thanked: 33 times

Re: Serial driver Transmission End

Post by alexblack »

I thinking that there will be errornous TC events when there are the gaps between the chars if the baud rate is fast enough or if the system has large load.
alexblack
Posts: 277
Joined: Mon Sep 24, 2012 3:52 pm
Been thanked: 33 times

Re: Serial driver Transmission End

Post by alexblack »

I tried your suggestion to notifyX function and it works.
The DEBUG OUT function is:

Code: Select all

PGA: > set value 127
PGA: > m = 0080
PGA: > flags = 0018
PGA: > end

Was before:

Code: Select all

PGA: > set value 127
PGA: > m = 0080
PGA: > flags = 0008
PGA: > m = 0000
PGA: > timeout
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Serial driver Transmission End

Post by Giovanni »

Moving this in "bug reports", it is definitely a problem in the driver.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Serial driver Transmission End

Post by Giovanni »

Fixed as bug #958.

Giovanni
Post Reply