Skip to content

Commit e2613d5

Browse files
committed
stm32 spi : IRQ handler light optimization
This commit contains a few optimizations to get a better performance in SPI Asynch mode
1 parent 79af576 commit e2613d5

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

targets/TARGET_STM/stm_spi_api.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -520,19 +520,16 @@ void spi_master_transfer(spi_t *obj, const void *tx, size_t tx_length, void *rx,
520520
}
521521
}
522522

523-
uint32_t spi_irq_handler_asynch(spi_t *obj)
523+
inline uint32_t spi_irq_handler_asynch(spi_t *obj)
524524
{
525-
// use the right instance
526-
struct spi_s *spiobj = SPI_S(obj);
527-
SPI_HandleTypeDef *handle = &spiobj->handle;
528525
int event = 0;
529526

530527
// call the CubeF4 handler, this will update the handle
531-
HAL_SPI_IRQHandler(handle);
528+
HAL_SPI_IRQHandler(&obj->spi.handle);
532529

533-
if (HAL_SPI_GetState(handle) == HAL_SPI_STATE_READY) {
530+
if (obj->spi.handle.State == HAL_SPI_STATE_READY) {
534531
// When HAL SPI is back to READY state, check if there was an error
535-
int error = HAL_SPI_GetError(handle);
532+
int error = obj->spi.handle.ErrorCode;
536533
if(error != HAL_SPI_ERROR_NONE) {
537534
// something went wrong and the transfer has definitely completed
538535
event = SPI_EVENT_ERROR | SPI_EVENT_INTERNAL_TRANSFER_COMPLETE;
@@ -546,11 +543,10 @@ uint32_t spi_irq_handler_asynch(spi_t *obj)
546543
event = SPI_EVENT_COMPLETE | SPI_EVENT_INTERNAL_TRANSFER_COMPLETE;
547544
}
548545
// enable the interrupt
549-
NVIC_DisableIRQ(spiobj->spiIRQ);
550-
NVIC_ClearPendingIRQ(spiobj->spiIRQ);
546+
NVIC_DisableIRQ(obj->spi.spiIRQ);
547+
NVIC_ClearPendingIRQ(obj->spi.spiIRQ);
551548
}
552549

553-
if (event) DEBUG_PRINTF("SPI: Event: 0x%x\n", event);
554550

555551
return (event & (obj->spi.event | SPI_EVENT_INTERNAL_TRANSFER_COMPLETE));
556552
}

0 commit comments

Comments
 (0)