STM32 SPI Configuration Issue on STM32F765ZGT – HAL_BUSY Error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-04-02 5:25 AM - last edited on 2025-04-02 5:34 AM by mƎALLEm
Hello Everyone,
I am currently configuring SPI on the STM32F765ZGT board and using both blocking (polling) and interrupt-based methods for SPI transmission and reception. However, I am encountering an issue where the following condition evaluates to true, resulting in a HAL_BUSY error:
if (hspi->State != HAL_SPI_STATE_READY)
{
errorcode = HAL_BUSY;
goto error;
}
Thank you in advance!
- Labels:
-
SPI
-
STM32F7 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-04-02 1:21 PM
That piece of code is inside the HAL SPI functions. We need to see what YOUR code does - how and when it calls the HAL SPI functions. And which call results in the BUSY return.
Is your program using an RTOS (FreeRTOS, ThreadX, etc.)?
In general, BUSY means the HAL SPI code thinks the interface is already doing something. So (in general) look for an SPI call when the previous IT (interrupt) or DMA based SPI operation is still in progress.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-04-02 10:27 PM - edited 2025-04-02 10:30 PM
Is your program using an RTOS (FreeRTOS, ThreadX, etc.)? : No
I am printing the state before this condition
printf("SPI State: %d\n", hspi->State);
if (hspi->State != HAL_SPI_STATE_READY)
{
errorcode = HAL_BUSY;
goto error;
}
i am getting
SPI State: 1 (1 means already in ready state)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-04-03 12:38 AM
But what did you do before the call to HAL_SPI_Transmit?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-04-03 11:39 AM
> But what did you do before the call to HAL_SPI_Transmit?
Actually show ALL of your calls to ALL of the SPI transmit/receive functions, or at least all the ones up to the call you showed above.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-04-07 7:07 AM
Hello @anuj18ap
The issue arises because the SPI polling process is being called before the SPI interrupt process finishes.
To resolve this, you need to add a flag in the SPI transfer complete callback function. Then, check this flag in the main function before calling the polling process.
Thanks
Omar
