Serial driver Transmission End Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
alexblack
Posts: 276
Joined: Mon Sep 24, 2012 3:52 pm
Location: Donetsk
Been thanked: 32 times
Contact:

Serial driver Transmission End  Topic is solved

Postby alexblack » Tue Jun 05, 2018 6:40 am

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: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Serial driver Transmission End

Postby Giovanni » Tue Jun 05, 2018 7:19 am

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: 276
Joined: Mon Sep 24, 2012 3:52 pm
Location: Donetsk
Been thanked: 32 times
Contact:

Re: Serial driver Transmission End

Postby alexblack » Tue Jun 05, 2018 8:29 am

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: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Serial driver Transmission End

Postby Giovanni » Tue Jun 05, 2018 8:44 am

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: 276
Joined: Mon Sep 24, 2012 3:52 pm
Location: Donetsk
Been thanked: 32 times
Contact:

Re: Serial driver Transmission End

Postby alexblack » Tue Jun 05, 2018 9:04 am

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: 276
Joined: Mon Sep 24, 2012 3:52 pm
Location: Donetsk
Been thanked: 32 times
Contact:

Re: Serial driver Transmission End

Postby alexblack » Tue Jun 05, 2018 10:04 am

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: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Serial driver Transmission End

Postby Giovanni » Sat Jul 07, 2018 10:52 am

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

Giovanni

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Serial driver Transmission End

Postby Giovanni » Sat Jul 07, 2018 3:05 pm

Fixed as bug #958.

Giovanni


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 15 guests