Page 1 of 1

error_cb design patterns when using WAIT

Posted: Mon Feb 09, 2026 7:52 am
by law
Hiya,

I'm interested in some advice on intended design patterns for error_cb.
I'm in the process of tracking down an issue with QSPI on STM32F7. I'm using wspiSend and wspiReceive with WSPI_USE_WAIT = TRUE.
I have a thread that makes periodic calls to wspiSend and (very occasionally) that thread just never wakes up when wspiSend is waiting to complete.
I *think* I might be getting something like an QUADSPI_SR_TEF (error flag) interrupt. Out of the box, wspisend look like it gets the interrupt (any QSPI interrupt) and just wakes the wspiSend thread. The thread then thinks that the transmit is complete, then tries to transmit more on the next tick around, gets stuck, then waits forever for an interrupt that never comes.

Since wspiSend etc, don't return any error status, any error handling must be done through error_cb (or end_cb). I imagine I should add any checks for error interrupts in one of those callbacks.
However, this means there is no way to signal back to wspiSend that the transmission failed and it should abort.
How do you folks intend for this to be used? Can you point me to any examples of how others have used it? I've had a dig around in testhal (eg spi examples), but they just halt on error_cb.

Thanks

Re: error_cb design patterns when using WAIT

Posted: Mon Feb 09, 2026 9:29 am
by Giovanni
Hi,

It is done in this way under the assumption (we can debate this) that WSPI cannot returns errors that can be handled at API call level. This TEF is an error generated by accessing an invalid flash address, it is a programming error and should not randomly happen at runtime, this is why it is handled as an halt.

Bit 0 TEF: Transfer error flag
This bit is set in indirect mode when an invalid address is being accessed in indirect
mode. It is cleared by writing 1 to CTEF.


Said that, the new SPI driver model in XHAL introduced errors for transfer functions, WSPI could receive a similar treatment if needed.

Giovanni

Re: error_cb design patterns when using WAIT

Posted: Mon Feb 09, 2026 11:23 pm
by law
Hi Giovanni,

Thanks for your reply. I'm actually not 100% sure my issue is due to TEF - it is just a hypothesis at the moment and I'm still in the process of getting to the bottom of it. It can take hours before the problem pops up.
I suppose I was more interested how you intended error_cb etc to work with wspiSend etc, or if you guys have any common patterns you use with error_cb / spiSend. I'll have a dig around in the xhal stuff.
Thanks again

Re: error_cb design patterns when using WAIT

Posted: Tue Feb 10, 2026 6:09 am
by Giovanni
Hi,

XHAL is experimental it includes only few drivers (not WSPI yet), it is meant to address current HAL limitations.

The kind of errors triggering error_cb are programming errors, there is no need to handle those, just to fix the cause. You need to understand what is the cause triggering it.

Giovanni

Re: error_cb design patterns when using WAIT

Posted: Tue Feb 10, 2026 10:43 pm
by law
Hey Giovanni,

You need to understand what is the cause triggering it.

Yeah, ok I think I have a bit of tunnel-vision on my issue I'm trying to track down. I appreciate the reality check.
Thanks again.

Re: error_cb design patterns when using WAIT

Posted: Fri Feb 13, 2026 2:28 am
by law
Just an update for anyone interested. My issue looks like it is related to the STM32F7 errata 2.4.1:
"A data is read in the instant when the FIFO buffer gets full at the end of a read transfer, an extra data is unduly written in the FIFO buffer"
I initially wrote this off as I'm not hitting all the conditions that the errata sheet says are required.
But I see this person: https://github.com/STMicroelectronics/S ... /issues/82
says they see the errata outcome without hitting all the conditions too.
And sure enough, I abort on reads and the problem goes away:

Code: Select all

  if (wspip->state == WSPI_RECEIVE) {
    wspip->qspi->CR |= QUADSPI_CR_ABORT;
    while (wspip->qspi->CR & QUADSPI_CR_ABORT) {}
  }


Im actually on an older Chibios version. I look in the latest version of wspi_lld_serve_interrupt and see:

Code: Select all

#if defined(STM32L471xx) || defined(STM32L475xx) ||                         \
    defined(STM32L476xx) || defined(STM32L486xx)
  /* Handling of errata: Extra data written in the FIFO at the end of a
     read transfer.*/
  if (wspip->state == WSPI_RECEIVE) {
    while ((wspip->qspi->SR & QUADSPI_SR_BUSY) != 0U) {
      (void) wspip->qspi->DR;
    }
  }
#endif


It looks like the 1st workaround is being applied (read out until busy low), where I'm just doing abort. This is fine, however any ideas why it is only being applied to STM32L devices?

Thanks again

Re: error_cb design patterns when using WAIT

Posted: Fri Feb 13, 2026 6:28 am
by Giovanni
Hi,

It is because loops are not a good idea generally, I prefer implementing such workarounds only where really required.

If it is fixing also the H7 problem then probably should be re-evaluated on all devices.

Giovanni