SPI API Bug

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

Moderator: RoccoMarco

Post Reply
gnif
Posts: 8
Joined: Wed Jan 08, 2014 12:23 am

SPI API Bug

Post by gnif »

This is just a bug report with ChibiOS 3.

If spiSend is called with a zero size buffer, the dma transfer is configured, and stared, but will never issue an IRQ due to the zero size, and as such the thread will never unsuspend.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: SPI API Bug

Post by Giovanni »

Hi,

The OS does not check parameters unless checks are enabled in chconf.h. The condition is actually tested:

Code: Select all

void spiSend(SPIDriver *spip, size_t n, const void *txbuf) {

  osalDbgCheck((spip != NULL) && (n > 0U) && (txbuf != NULL));


Enabling debug options would have stopped execution.

Giovanni
gnif
Posts: 8
Joined: Wed Jan 08, 2014 12:23 am

Re: SPI API Bug

Post by gnif »

Hrmm, ok, but personally I would have added a simple check for zero size, and return quietly if it is, just like all other IO type methods in most other APIs and languages, ie

Code: Select all

fwrite(buffer, 0, 0, fp) == 0
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: SPI API Bug

Post by Giovanni »

Hi,

Our design pattern is that error checks are only performed at development time for efficiency/codesize reasons. The application is responsible for passing correct values to the API.

Giovanni
Post Reply