Forked.
Fork of mbed-dev by
Diff: targets/TARGET_STM/stm_spi_api.c
- Revision:
- 153:fa9ff456f731
- Parent:
- 149:156823d33999
- Child:
- 156:95d6b41a828b
diff -r 9a67f0b066fc -r fa9ff456f731 targets/TARGET_STM/stm_spi_api.c --- a/targets/TARGET_STM/stm_spi_api.c Thu Dec 15 11:48:27 2016 +0000 +++ b/targets/TARGET_STM/stm_spi_api.c Tue Dec 20 17:27:56 2016 +0000 @@ -434,8 +434,8 @@ // enable the interrupt IRQn_Type irq_n = spiobj->spiIRQ; + NVIC_DisableIRQ(irq_n); NVIC_ClearPendingIRQ(irq_n); - NVIC_DisableIRQ(irq_n); NVIC_SetPriority(irq_n, 1); NVIC_EnableIRQ(irq_n); @@ -520,19 +520,16 @@ } } -uint32_t spi_irq_handler_asynch(spi_t *obj) +inline uint32_t spi_irq_handler_asynch(spi_t *obj) { - // use the right instance - struct spi_s *spiobj = SPI_S(obj); - SPI_HandleTypeDef *handle = &spiobj->handle; int event = 0; // call the CubeF4 handler, this will update the handle - HAL_SPI_IRQHandler(handle); + HAL_SPI_IRQHandler(&obj->spi.handle); - if (HAL_SPI_GetState(handle) == HAL_SPI_STATE_READY) { + if (obj->spi.handle.State == HAL_SPI_STATE_READY) { // When HAL SPI is back to READY state, check if there was an error - int error = HAL_SPI_GetError(handle); + int error = obj->spi.handle.ErrorCode; if(error != HAL_SPI_ERROR_NONE) { // something went wrong and the transfer has definitely completed event = SPI_EVENT_ERROR | SPI_EVENT_INTERNAL_TRANSFER_COMPLETE; @@ -545,9 +542,11 @@ // else we're done event = SPI_EVENT_COMPLETE | SPI_EVENT_INTERNAL_TRANSFER_COMPLETE; } + // enable the interrupt + NVIC_DisableIRQ(obj->spi.spiIRQ); + NVIC_ClearPendingIRQ(obj->spi.spiIRQ); } - if (event) DEBUG_PRINTF("SPI: Event: 0x%x\n", event); return (event & (obj->spi.event | SPI_EVENT_INTERNAL_TRANSFER_COMPLETE)); }